I have build a custom configuration provider that loads the configuration from Hashicorp vault kv2 secrets engine.
Here is the method in my configuration provider
private async Task LoadKv2SecretsAsync()
{
foreach (Kv2EngineOption kv2EngineOption in _kv2EngineOptions)
{
try
{
Secret<SecretData> kv2Secret = await _vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync(path: kv2EngineOption.Path, mountPoint: kv2EngineOption.MountPoint);
if (kv2Secret is null || kv2Secret.Data is null)
{
return;
}
foreach (KeyValuePair<string, object> entry in kv2Secret.Data.Data)
{
Data[entry.Key] = entry.Value.ToString();
}
}
catch (Exception ex)
{
throw new InvalidOperationException($"Unable to load Key-Value version 2 (Kv2) configuration from Vault: {ex.Message}", ex);
}
}
OnReload();
}
I am using a timer to call every hour.
_ = new Timer(state => LoadDatabaseCredentialsAsync().Wait(), null, TimeSpan.Zero, TimeSpan.FromHours(1));
Here is the configuratio i am using in my Worker’s program.cs file:
builder.Configuration
.AddVaultConfiguration(
new VaultClientSettings(
"vault.example.com",
new JWTAuthMethodInfo(
roleName: "developer",
jwt: "",
mountPoint: "jwt"
)),
kv2EngineOptions:
[
new(path: "app/some", mountPoint: "default"),
]
);
After the initial configuration when i change a certain configuration suppose AmazonS3:BucketName
from FirstBucket
to SecondBucket
.
This doesn’t reflect in the current running state of my application. I have to rerun the application.
I am calling OnReload()
method after fetching which should update the configurations. This is working with WebApi app.
What can be done?