user251395
user251395

Reputation: 73

Azure Key Vault - Storage and Access for Connection Strings

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

Answers (1)

Jason Freeberg
Jason Freeberg

Reputation: 159

Yes, you can use Key Vault references for this. The high level instructions are:

  1. Add your secret to Key Vault.

  2. Create a managed identity for the webapp which has access to the key vault.

  3. Create a key vault reference as the value of an application setting. (App settings are just environment variables.)

  4. 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

Related Questions