Reputation: 73
I would like to store my Db password in the Azure KeyVault and be able to use it in the connection string in appsettings.json. Is it possible?
Things done
I can see that my App Service application is configured with the key vault since there is a relevant configuration entry in launchSettings.json
.
This is what I would like to do in appsettings.json
:
"myContext": "Server=myServer;Database=myDb;User Id=myUser; Password={KEYVAULTSECRET}"
Is it possible and if so how?
Upvotes: 1
Views: 2253
Reputation: 159
Yes, you can use Key Vault references for this. The high level instructions are:
Add your secret to Key Vault.
Create a managed identity for the webapp which has access to the key vault.
Create a key vault reference as the value of an application setting. (App settings are just environment variables.)
Finally, in your config file just reference your environment variable ( ... ${MY_DB_PASSWORD} ..
The official docs on this are here: Use Key Vault references for App Service and Azure Functions.
I wrote an example of this for Java apps Key Vault References with Spring.
Upvotes: 1