Search code examples
azureazure-keyvaultazure-webapps

Azure key vault. How to set which web app uses what key vault?


I have several versions of the same web app running on the same subscription service.

I have 2 logical environments. Dev and UAT. I have WebAppDev and WebAppUAT.

I have two key vaults KVDev and KVUAT. How can I configure the correct web app to use the correct key vault?

What process assigns the web apps to key vaults?

Edit: I had assumed that the key vault would act like the secrets do when developing.

This Tutorial

seems to suggest that the key vault can be used as a configuration provider. However, the web app is not accessing the key vault values.


Solution

    1. Get the Object ID from the identity blade of the web app.

    2. Find your azure key vault and create a new access policy using the Object Id of web app.

      Alternatively use the following in the powershell cli.

    Set-AzKeyVaultAccessPolicy –VaultName -ObjectId "" -PermissionsToKeys backup,create,delete,get,import,list,restore -PermissionsToSecrets get,list,backup,restore,recover

    1. Follow this tutorial and copy the context from the Program.cs in the sample code.

    Tutorial