anyone else encountered this - you read your secrets from an azure key vault (typically in Program.cs right? Like this:
.ConfigureAppConfiguration(builder =>
{
var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
var keyVaultEndpoint = configuration.GetSection("KeyVault").GetSection("KeyVaultEndpoint").Value);
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var keyVaultClient = new KeyVaultClient(
new KeyVaultClient.AuthenticationCallback(
azureServiceTokenProvider.KeyVaultTokenCallback));
builder.AddAzureKeyVault(keyVaultUrl, keyVaultClient, new DefaultKeyVaultSecretManager());
var secretValue = Task.Run(async () => await keyVaultClient.GetSecretAsync(keyVaultEndpoint, "SomeDatabasePassword")).Result.Value;
How do you use this secretValue somewhere else, for example in a controller? Considering my appsettings looks like this:
{
"KeyVault": {
"SomeDatabasePassword": ""
}
}
typically empty because we don't want to be explicitly set here in appsettings. But in Program.cs I can read that element from secrets and (while still in Program.cs)
I can overwrite the appsettings key right? Like this:
configuration.GetSection("KeyVault").GetSection("SomeDatabasePassword").Value = secretValue;
However if I then try to read this value configuration.GetSection("KeyVault").GetSection("SomeDatabasePassword").Value
from a controller, I still get an empty string.
Any ideas?