My application is hosted in AKS, the secrets are stored in Azure secrets storage. What my client has is created a volume which stores /mnt/secrets-store
that directory contains all of the secrets for my application.
For example:
- RabbitMq--Password
- DB--ConnectionString
Apparently this is the standard practice with my current client. There solution is then to read the file every time they want to load the settings. This is all set up in the healm charts.
volumeMounts:
- name: secrets-store-inline
mountPath: "/mnt/secrets-store"
readOnly: true
{{- end}}
A number of my services are loaded as singletons at startup which means the settings need to be available at startup.
Note: My service has no direct access to Azure key vault and this is not something that can be changed. All I have access to are these files.
What I did was create a custom IConfigurationBuilder
called UseAzureKeyVaultMountedSecrets
everything is very strait forward with this. It just checks for the folder and then loads the secrets in replacing whatever is in appsettings..json for that key being the name.
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseAzureKeyVaultMountedSecrets()
.UseSerilog((context, config) => config.ReadFrom.Configuration((context.Configuration)))
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
Locally to test I just created the folder with the files in it and it works like a charm. However when hosted on AKS I started having issues. My health checks state that it can detect the mnt dir. But its not reading them.
After quite a bit of debugging, I found that the issue is that the mnt dir is not available when the microservice is starting up in the pod. Its first after the pod is running that it can access the mnt dir.
Is there a solution for this?
- How can I get it to mnt the volume before start up in AKS?
- Is it possible to load the settings again after the service has started? If it is. then I'm wondering if I could then create something like an IHostedService which would just keep trying to access it and then stop once it has grabbed them.
The main part of the problem is that these settings are used to configure all of the singletons running in the system. If I wait until everything has loaded, they have already been configured.