![]() |
VOOZH | about |
dotnet add package VaultSharp.Extensions.Configuration --version 1.1.5
NuGet\Install-Package VaultSharp.Extensions.Configuration -Version 1.1.5
<PackageReference Include="VaultSharp.Extensions.Configuration" Version="1.1.5" />
<PackageVersion Include="VaultSharp.Extensions.Configuration" Version="1.1.5" />Directory.Packages.props
<PackageReference Include="VaultSharp.Extensions.Configuration" />Project file
paket add VaultSharp.Extensions.Configuration --version 1.1.5
#r "nuget: VaultSharp.Extensions.Configuration, 1.1.5"
#:package VaultSharp.Extensions.Configuration@1.1.5
#addin nuget:?package=VaultSharp.Extensions.Configuration&version=1.1.5Install as a Cake Addin
#tool nuget:?package=VaultSharp.Extensions.Configuration&version=1.1.5Install as a Cake Tool
👁 GitHub Actions Status
👁 Nuget
👁 badge
VaultSharp.Extensions.Configuration is an extension to VaultSharp that allows reading configuration options from Vault.
VaultSharp.Extensions.Configuration is a .NET Standard 2.0, 2.1, .NET 6.0, .NET 7.0, and .NET 8.0 based cross-platform C# Library.
VaultSharp.Extensions.Configuration can be installed using the Nuget package manager or the dotnet CLI.
dotnet add package VaultSharp.Extensions.Configuration
It can be injected as a IConfigurationProvider to load configuration from HashiCorp Vault:
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext, config) =>
{
config.AddJsonFile("appsettings.json")
.AddVaultConfiguration(() => new VaultOptions("http://localhost:8200", "root"), "sampleapp", "secret");
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
The AddVaultConfiguration method accepts several parameters:
Function to provide VaultOptions with Vault connection configuration (optional).
Application alias in Vault data. It's used a part of the path to read secrets.
Mount point of KV secrets. The default value is secret (optional).
You can enable monitoring of changes in Vault data and automatic reload by setting VaultOptions.ReloadOnChange to true.
The default check interval is 5 minutes, but can be configured.
Data is checked using version information from key metadata.
config.AddVaultConfiguration(
() => new VaultOptions(
"http://localhost:8200",
"root",
reloadOnChange: true,
reloadCheckIntervalSeconds: 60),
"sampleapp",
"secret");
Also you would need to register hosted services VaultChangeWatcher in your Startup.cs that will check Vault data for updates:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddHostedService<VaultChangeWatcher>();
}
Later in your services you can track changes in app configuration using IOptionsSnapshot or IOptionsMonitor.
Keep in mind that your service should be registered as scoped or transient to receive updates.
Also IOptionsSnapshot can return empty value in some cases (it's .net core bug)
This will be helpful when you want to flatten the structure of the secrets.
For example the following two secret objects will evaluate to the same configuration if for the second object the additionalCharactersForConfigurationPath option is used with new []{'.'} value:
{
"secrets":
{
"DB":
{
"ConnectionString": "secret value"
}
}
}
{
"secrets":
{
"DB.ConnectionString": "secret value"
}
}
config.AddVaultConfiguration(
() => new VaultOptions(
"htpp://localhost:8200",
"root",
additionalCharactersForConfigurationPath: new []{'.'}),),
"sampleapp",
"secret");
new VaultOptions("http://localhost:8200", "root", null, null, false, 300, false, new []{'.'}),
Alternatively, you can configure Vault connection using next environment variables:
VAULT_ADDR : Address of the Vault instance. Default value is "http://locahost:8200.VAULT_TOKEN : Vault token. Used for token-based authentication. Default value is root.VAULT_ROLEID : Vault AppRole ID. Used for AppRole-based authentication.VAULT_SECRET : Vault AppRole secret. Used for AppRole-based authentication.VAULT_INSECURE : Allow insecure SSL connections to Vault. Default value is false.You can configure Vault connection using any supported auth method (look at https://github.com/rajanadar/VaultSharp#auth-methods):
config.AddVaultConfiguration(
() => new VaultOptions(
"htpp://localhost:8200",
new KerberosAuthMethodInfo(),
reloadOnChange: true,
reloadCheckIntervalSeconds: 60),
"sampleapp",
"secret");
You can enable insecure TLS connections to Vault:
builder.AddVaultConfiguration(
() => new VaultOptions("https://localhost:8200", "root", insecureConnection: true),
"test",
"secret",
this._logger);
Or manually validate TLS certificate:
builder.AddVaultConfiguration(
() => new VaultOptions("https://localhost:8200", "root", additionalCharactersForConfigurationPath: new[] { '.' }, insecureConnection: false, serverCertificateCustomValidationCallback: (message, cert, chain, errors) =>
{
return true; //add your validation logic here
}),
"test",
"secret",
this._logger);
You need to store your secrets with special naming rules.
First of all, all secrets should use KV2 storage and have prefix {app_alias} or {app_alias}/{env}.
For example, if your app has alias sampleapp and environment producton and you want to have configuration option ConnectionString your secret path would be or sampleapp or sampleapp/producton.
All parameters are grouped and arranged in folders and can be managed within the group. All secret data should use JSON format with secret data inside:
{
"ConnectionString": "secret value",
"Option1": "secret value 2",
}
There are two ways to create nested parameters.
{
"DB":
{
"ConnectionString": "secret value"
}
}
{
"ConnectionString": "secret value"
}
Before starting work on a pull request, I suggest commenting on, or raising, an issue on the issue tracker so that we can help and coordinate efforts.
To run tests locally you need to have Docker running and have Vault's default port 8200 free.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 is compatible. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on VaultSharp.Extensions.Configuration:
| Package | Downloads |
|---|---|
|
Wcz.Layout
Package Description |
|
|
AIC.Core.Configuration.Providers.HashiCorp.Vault
Shared .NET library for Aerospace, Intelligence, and Cyber solutions. |
|
|
AIC.Core.Configuration.Secrets.HashiCorp.Vault
Shared .NET library for Aerospace, Intelligence, and Cyber solutions. |
|
|
MediVoyage.Infrastructure
Package Description |
|
|
CorePackages.Infrastructure
Package Description |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.5 | 24,308 | 3/25/2026 |
| 1.1.4 | 7,900 | 3/2/2026 |
| 1.1.3 | 259,706 | 5/6/2025 |
| 1.1.2 | 2,175 | 4/28/2025 |
| 1.1.1 | 1,444 | 4/23/2025 |
| 1.1.0 | 2,917 | 4/23/2025 |
| 1.0.5 | 174,819 | 7/10/2024 |
| 1.0.4 | 519 | 7/9/2024 |
| 1.0.3 | 52,296 | 4/2/2024 |
| 1.0.2 | 6,750 | 2/17/2024 |
| 1.0.1 | 1,917 | 2/6/2024 |
| 1.0.0 | 2,405 | 1/30/2024 |
| 0.6.4 | 78,057 | 9/5/2023 |
| 0.6.3 | 12,327 | 8/31/2023 |
| 0.6.2 | 158,707 | 5/5/2023 |
| 0.5.3 | 20,996 | 2/23/2023 |
| 0.5.2 | 18,241 | 9/16/2022 |
| 0.5.1 | 4,837 | 7/26/2022 |
| 0.4.3 | 18,737 | 5/25/2022 |
| 0.4.2 | 24,812 | 12/11/2021 |