DotNetCore.Azure.Configuration.KvSecrets
3.1.0
See the version list below for details.
dotnet add package DotNetCore.Azure.Configuration.KvSecrets --version 3.1.0
NuGet\Install-Package DotNetCore.Azure.Configuration.KvSecrets -Version 3.1.0
<PackageReference Include="DotNetCore.Azure.Configuration.KvSecrets" Version="3.1.0" />
paket add DotNetCore.Azure.Configuration.KvSecrets --version 3.1.0
#r "nuget: DotNetCore.Azure.Configuration.KvSecrets, 3.1.0"
// Install DotNetCore.Azure.Configuration.KvSecrets as a Cake Addin #addin nuget:?package=DotNetCore.Azure.Configuration.KvSecrets&version=3.1.0 // Install DotNetCore.Azure.Configuration.KvSecrets as a Cake Tool #tool nuget:?package=DotNetCore.Azure.Configuration.KvSecrets&version=3.1.0
Azure Key Vault Secrets configuration provider for Microsoft.Extensions.Configuration
The AspNetCore.Azure.Configuration.KvSecrets based on [Azure.Extensions.AspNetCore.Configuration.Secrets][source] which package allows storing configuration values using Azure Key Vault Secrets.
Improvements
- Allows to load secrets by list and map them into new names.
- Allows to load secrets into the configuration section.
Getting started
Install the package
Install the package with DotNetCore.Azure.Configuration.KvSecrets:
dotnet add package DotNetCore.Azure.Configuration.KvSecrets
Prerequisites
You need an [Azure subscription][azure_sub] and [Azure Key Vault][keyvault_doc] to use this package.
To create a new Key Vault, you can use the [Azure Portal][keyvault_create_portal], [Azure PowerShell][keyvault_create_ps], or the [Azure CLI][keyvault_create_cli]. Here's an example using the Azure CLI:
az keyvault create --name MyVault --resource-group MyResourceGroup --location westus
az keyvault secret set --vault-name MyVault --name MySecret --value "hVFkk965BuUv"
Examples
To load initialize configuration from Azure Key Vault secrets call the AddAzureKeyVault
on ConfigurationBuilder
:
Program.cs
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureAppConfiguration(Startup.AddKvConfigurations);
webBuilder.UseStartup<Startup>();
});
Startup.cs
public static void AddKvConfigurations(WebHostBuilderContext hostingContext, IConfigurationBuilder configurationBuilder)
{
var configBuilder = new ConfigurationBuilder().AddInMemoryCollection();
IHostEnvironment env = hostingContext.HostingEnvironment;
configBuilder.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: false);
configBuilder.AddEnvironmentVariables();
var config = configBuilder.Build();
string KeyVaultUrl = config[nameof(KeyVaultUrl)];
List<string> VaultSecrets = config.GetSection(nameof(UploadKeyList)).Get<List<string>>();
string ConfigurationSectionPrefix = config[nameof(ConfigurationSectionPrefix)];
var credential = new AzureCliCredential();
//var credential = new DefaultAzureCredential();
var client = new SecretClient(vaultUri: new Uri(KeyVaultUrl), credential);
var options = new AzureKvConfigurationOptions()
{
ConfigurationSectionPrefix = ConfigurationSectionPrefix,
UploadKeyList = UploadKeyList
};
configurationBuilder.AddAzureKeyVault(client, options);
}
appsettings.json
"ConfigurationSectionPrefix": "secret",
"KeyVaultUrl": "https://secrets128654s235.vault.azure.net/",
"VaultSecrets": [ "FuseEval--Demo8", "LoadInMess", "RealSecretForVault" ]
The [Azure Identity library][identity] provides easy Azure Active Directory support for authentication.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp3.1 is compatible. |
-
.NETCoreApp 3.1
- Azure.Identity (>= 1.3.0)
- Azure.Security.KeyVault.Secrets (>= 4.1.0)
- System.Linq.Async (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Only supports the .net 5.0.