Quick answer: Go to your Key Vault in Azure Portal, click Access policies, add your user or app with the right permissions (Get, List, Set for secrets), and save. Most times that's it.
Why This Happens
Azure Key Vault uses access policies to control who can read or write secrets, keys, and certificates. The KeyVaultAccessDenied error shows up when you try to access a secret but your user, service principal, or managed identity doesn't have the right policy. Common triggers: you're using a new account, you changed roles, or someone removed your access. It can also happen if you're using Azure RBAC instead of access policies and your role assignment is wrong.
Fix Steps
- Open your Key Vault in the Azure Portal. Go to https://portal.azure.com, find your key vault by searching the name in the top bar. Click it.
- Click Access policies in the left menu, under Settings. You'll see a list of current policies.
- Click + Add Access Policy. A new panel opens.
- Select permissions. For most cases, choose Secret, then check Get and List. If you need to create or update secrets, also check Set. If you're working with keys, select Key and check Get, List, Decrypt, Encrypt. For certificates, select Certificate and check Get and List.
- Select principal. Click Select principal, search for your user name, group, or app name. Select it, then click Select.
- Click Add. That closes the panel and adds the policy to the list.
- Click Save at the top of the Access policies page. Wait a few seconds for the save to complete. You'll see a green notification: "Access policies updated."
- Test again. Go back to Secrets, click on your secret, then click the current version. You should now see the secret value. If not, refresh the browser and try again.
Alternative Fixes When the Main Fix Fails
If the steps above don't work, try these:
- Check Azure RBAC role assignments. If your key vault uses Azure RBAC instead of access policies, you need a role like
Key Vault Secrets UserorKey Vault Reader. Go to your key vault, click Access control (IAM), then Role assignments. Look for your user or app. If it's missing, click Add, then Add role assignment. SelectKey Vault Secrets User, then select your principal, and save. - Use Azure CLI to add yourself. Open Cloud Shell or your local CLI. Run this command, replacing the placeholders:
If you're a service principal, useaz keyvault set-policy --name YourKeyVaultName --upn user@domain.com --secret-permissions get list--spninstead of--upn. - Check for network restrictions. If your key vault has a firewall enabled, you won't get access even with the right policy. Go to Networking in the key vault menu. Under Firewalls and virtual networks, make sure "Allow trusted Microsoft services" is checked, or add your IP address. If you're using a VM, allow the VM's subnet.
- Wait for replication. After changing policies, Azure can take up to 5 minutes to replicate across regions. Wait a bit and retry. This happens especially with geo-replicated key vaults.
Prevention Tip
To avoid this error in the future, use Azure RBAC instead of access policies. It's simpler and you can manage permissions at scale. Go to your key vault, click Access configuration, and switch the permission model to Azure role-based access control. Then assign roles like Key Vault Secrets User to users or groups. This way, when someone leaves your team, you just remove their role assignment. No need to touch each key vault.
Another tip: if you're automating with scripts, always set the access policy in your deployment script. For example, in an ARM template, use the Microsoft.KeyVault/vaults/accessPolicies resource. That way, new deployments always include the right permissions from the start.
If you're still stuck, check the Azure Activity Log (under Monitoring) for your key vault. Look for failed operations. That log tells you exactly which user or app tried to access what, and why it failed. I've used that to catch cases where someone was trying to access the wrong key vault entirely.