Azure Key Vault Best Practices: Secure Your Secrets Like a Pro
If you’re running workloads in Azure, Azure Key Vault is one of your most important security building blocks. It’s where your secrets, keys, and certificates live and if that vault is misconfigured, attackers don’t need to hack your app… they just need to walk through an unlocked door.
In this post, we’ll walk through practical best practices to:
- Lock down access
- Integrate securely with your apps
- Protect keys and secrets at scale
- Monitor, audit, and govern usage
1. Design Your Key Vault Strategy Up Front
Before you create your first vault, decide how you’ll organize them.
1.1 Use multiple vaults for isolation
Avoid a single “god” Key Vault for everything. Instead:
- Per-environment: e.g.
myapp-dev-kv,myapp-test-kv,myapp-prod-kv - Per-application or business unit: so teams don’t step on each other
- Per compliance boundary: data residency, regulatory zones, or sensitivity levels
This limits the blast radius: a misconfiguration or compromise in one vault shouldn’t expose everything.
1.2 Naming conventions matter
Use a consistent pattern, for example:
<org>-<app>-<env>-kv contoso-payments-prod-kv contoso-internal-tools-dev-kv
It makes automation easier and helps teams immediately understand what a vault is for.
2. Prefer RBAC Over Vault Access Policies
Azure Key Vault now supports Azure role-based access control (RBAC) at the vault level. For new designs, prefer RBAC over “classic” access policies.
Why RBAC?
- Centralized management through Azure AD roles
- Easier to audit who can do what
- Consistent with the rest of Azure permissions
- Better fit for least privilege and just-in-time access
Typical roles:
Key Vault Reader: read metadata (not secrets)Key Vault Secrets User: get/list secretsKey Vault Crypto User: use keys for cryptographic operationsKey Vault Administrator: manage settings, but don’t usually give this role widely
Tip: Turn off the habit of making everyone an “Owner” or full “Administrator.” Most apps only need read access to secrets.
3. Always Use Managed Identities for App Access
Hard-coding credentials or storing Key Vault access keys in config is the fastest way to defeat the whole purpose of Key Vault.
Instead, use Managed Identities:
- No client secret to manage or rotate
- Automatically trusted by Azure AD
- Fine-grained vault access via RBAC
3.1 How it fits together
- Enable a Managed Identity on your resource (App Service, Function App, VM, AKS, Logic Apps, etc.)
- Assign the managed identity a Key Vault role
(for example,
Key Vault Secrets Useron that vault). - In your app, use the default Azure credentials (e.g.
DefaultAzureCredentialin the Azure SDKs). - Your code requests secrets from Key Vault; Azure handles auth under the hood.
3.2 Avoid client secrets in CI/CD too
For pipelines (GitHub Actions, Azure DevOps, etc.):
- Use Workload identity federation or managed identities instead of long-lived service principal secrets.
- Grant those identities access to Key Vault using RBAC and least privilege.
4. Enable Soft Delete and Purge Protection
Accidental (or malicious) deletion of keys and secrets can be catastrophic.
Modern Key Vaults have Soft Delete enabled by default, but you should still verify:
- Soft Delete: deleted objects go to a recoverable state for a retention period
- Purge Protection: prevents permanent deletion until the retention period elapses
Together, these protect you from:
- “Oops, I deleted a key” scenarios
- Attackers trying to cover their tracks by purging secrets
Action item: Ensure both soft delete and purge protection are enabled on all production Key Vaults. Treat it like a non-negotiable baseline.
5. Lock Down Network Access
Do not leave your Key Vault wide open to the internet unless you have a very good reason.
5.1 Use Private Endpoints
Where possible:
- Enable a Private Endpoint for the Key Vault
- Restrict traffic so that only resources in your virtual networks can reach it
- Use NSGs and routing to further control access paths
This prevents exposure to public IP-based attacks and tightens your network security posture.
5.2 Restrict public access and use firewall rules
If you must allow public access:
-
Configure the Key Vault firewall to allow only:
-
Trusted IP ranges
-
Specific Azure services where needed
-
Avoid “Allow public access from all networks” in production
6. Implement Strong Key Management Practices
For cryptographic keys, Key Vault is only as secure as your lifecycle practices.
6.1 Use Key Vault for key creation and storage
- Generate keys inside Key Vault rather than importing from arbitrary sources.
- Where compliance demands, consider Managed HSM for FIPS-certified hardware-backed keys.
6.2 Enable key rotation
-
Configure automatic rotation for keys where possible.
-
For application secrets that depend on keys (e.g. DB connection strings), tie rotation into:
-
CI/CD pipelines
-
Config or secret-update processes
You want rotating a key to be boring and routine, not a firefight.
6.3 Versioning and rollback
Key Vault keeps versions of secrets and keys:
- Use versions intentionally when rolling out changes
- Keep track of which app version expects which secret format
- Roll back to a previous version if a deployment breaks
7. Secure Secrets and Certificates
Secrets are more than just passwords. They can be tokens, API keys, connection strings, and more.
7.1 Store everything sensitive in Key Vault
Avoid:
- Secrets hard-coded in code repositories
- Secrets stored in plain text in app settings
- Secrets shared via chat, email, or wikis
Instead:
- Store secrets in Key Vault
- Reference them from app config (e.g. Key Vault references in App Service settings)
- Use role-based access for people and identities
7.2 Use built-in certificate management
For TLS/SSL certificates:
- Store certificates in Key Vault
- Use certificate auto-renewal for supported issuers (e.g. some integrated CA providers)
- Automate syncing certificates down to services (App Service, Application Gateway, etc.)
This reduces the chance of certificate expiry outages and manual handling errors.
8. Apply Least Privilege Everywhere
Least privilege isn’t just a buzzword — it’s a hard requirement for Key Vault.
8.1 Separate duties
-
Admins who manage vault configuration don’t necessarily need access to secrets.
-
App identities that read secrets usually don’t need to create or delete them.
-
Transparent separation:
-
Operations: deploy/manage infrastructure and policies
-
Security: monitor and audit usage
-
Developers: read only the secrets they strictly require
8.2 Use scoped access
- Scope RBAC roles to resource group or vault levels as low as possible.
- Avoid subscription-wide assignments unless there’s a clear governance need.
9. Monitor, Log, and Alert
If you’re not monitoring Key Vault activity, you’re flying blind.
9.1 Enable diagnostic logging
Send Key Vault diagnostic logs to:
- Log Analytics workspace
- Event Hub
- Storage account
Key events to pay attention to:
- Access denied / authentication failures
- Secret/key creation, update, and deletion
- Changes to vault configuration, including network settings and access policies
9.2 Build alerts
Set alerts for:
-
Unusual activity, like:
-
High volume of secret reads
-
Repeated access failures
-
Access from unusual IP ranges or regions (if public endpoints)
-
Critical configuration changes:
-
Disabling firewall rules
-
Updating access control
You can route alerts via Azure Monitor to email, Teams, or ticketing systems so incidents are not missed.
10. Govern at Scale: Policies, Blueprints, and Automation
When you have many vaults across many subscriptions, manual management doesn’t scale.
10.1 Use Azure Policy
Examples of helpful policies:
- Require soft delete and purge protection
- Require private endpoints for production vaults
- Audit vaults that allow public access from all networks
- Restrict the creation of vaults to specific regions
Policies help keep your environment compliant by default.
10.2 Templates and automation
Use:
-
Bicep / ARM templates / Terraform to standardize Key Vault creation
-
CI/CD pipelines to deploy and update vaults and access assignments
-
Scripts to audit:
-
Expiring secrets and certificates
-
RBAC assignments and access anomalies
Treat your security configuration as code, so you can review, version, and roll back changes.
11. Developer Experience: Make Secure the Easy Path
If using Key Vault feels painful, people will work around it.
Make secure usage the path of least resistance:
-
Provide simple examples for each language (C#, Python, Node, Java, etc.) using
DefaultAzureCredential -
Document:
-
How to request access
-
How secrets are named
-
How to rotate and test changes safely
-
Build helper libraries or SDK wrappers that hide the complexity and enforce conventions
The smoother the experience, the more consistently Key Vault will be used correctly.
12. Periodic Reviews and Security Testing
Security is not “set it and forget it.”
-
Quarterly access reviews: who has what roles, at what scope?
-
Pen-tests / red team exercises: test whether secrets can be exfiltrated
-
Game days: rehearse:
-
Key rotation
-
Vault restoration
-
Incident response if a secret is compromised
These practices ensure you’re ready before a real incident happens.
Conclusion
Azure Key Vault is a powerful service, but it doesn’t make you secure by itself. You get real protection when you combine it with:
- Solid identity design (managed identities + RBAC)
- Network controls (private endpoints and firewalls)
- Good key and secret lifecycle management
- Strong monitoring, alerting, and governance
- A developer experience that makes “the secure way” the easiest way
Start with a single app or environment, apply these best practices, and then roll the pattern out across your organization. Every vault you lock down properly is one more door that attackers can’t easily walk through.