Azure KeyVault is convenience safe storage for secrets (passwords, keys, etc.) which can be used in your apps instead of storing them in plain text in app settings. It adds number of advantages like access control, expiration policies, versioning, access history and others. However it has some gotchas which you should be aware. In this post I will describe one such gotcha.
First of all you need to configure access to key vault secret so your App service or Azure function will be able to read values from there. You may check how to do that e.g. here: Provide Key Vault authentication with an access control policy. After that go to App service > Configration and click Edit icon for the app setting which uses reference on KeyVault secret and check that there are no errors. Because even if you did everything correctly you may see Status = AccessToKeyVaultDenied and the following error description:
Key Vault reference was not able to be resolved because site was denied access to Key Vault reference's vault
In order to fix it try the following workaround:
- Delete app setting from UI
- Save changes
- Add the same app setting with KeyVault reference (i.e. with @Microsoft.KeyVault(SecretUri=…))
- Save changes again
After that if permissions are configured properly Status should be changed to Resolved:
and your app should be able to successfully resolve secret from KeyVault reference.