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.
Nice, thanks for the post, it is useful.
ReplyDeleteThanks, that works! But why is it needed?
ReplyDeleteprobably bug on Azure side
DeleteGreat tip as I was frustrated by @AccessToKeyVaultDenied
ReplyDeleteThanks buddy, that worked
ReplyDeleteThat was useful, I don't know why but I think sometimes if you generate a new version of the kv value, this error occurs. Not for all, in my case it was just one from a long list.
ReplyDeleteI am trying to follow the same process for deployment slot but it throws the above error, is there is different process for keyvault configuration for azure windows web app service
ReplyDeleteThank you. Saved my day!
ReplyDeletethanks - helped me just now. cheers
ReplyDelete