Monday, June 8, 2020

Fix AccessToKeyVaultDenied error in Azure App service app settings which use KeyVault reference

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:

  1. Delete app setting from UI
  2. Save changes
  3. Add the same app setting with KeyVault reference (i.e. with @Microsoft.KeyVault(SecretUri=…))
  4. 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.

9 comments:

  1. Nice, thanks for the post, it is useful.

    ReplyDelete
  2. Thanks, that works! But why is it needed?

    ReplyDelete
  3. Great tip as I was frustrated by @AccessToKeyVaultDenied

    ReplyDelete
  4. Thanks buddy, that worked

    ReplyDelete
  5. That 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.

    ReplyDelete
  6. I 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

    ReplyDelete
  7. Thank you. Saved my day!

    ReplyDelete
  8. thanks - helped me just now. cheers

    ReplyDelete