Azure Key Vault
Vaults and Managed HSM · soft delete and purge protection · Azure RBAC and access policies · firewall and Private Link · keys, secrets, certificates · Defender CSPM secrets scanning · Defender for Key Vault
By the tools4free.dev team · Last reviewed November 13, 2026
Practice questions for this topic →
Deploy a vault and configure its settings
Key Vault has two container types. Vaults store software-protected and HSM-backed keys, secrets and certificates. Managed HSM pools store only HSM-backed keys. Vaults are low-cost, multi-tenant and zone-resilient where available; Managed HSM is single-tenant and suited to high-value keys and the strictest compliance needs.
| Topic | Rule |
|---|---|
| Vault name | 3 to 24 characters: letters, numbers and hyphens. Must be unique. |
| Create (CLI) | az keyvault create --name "<vault-name>" --resource-group "myResourceGroup" --enable-rbac-authorization true --enable-purge-protection true. Microsoft calls purge protection a security best practice. |
| Default access model | Starting with API version 2026-02-01, Azure RBAC is the default access control model for newly created vaults. |
| Key types | Standard and Premium support RSA and EC keys. HSM key types need Premium. Symmetric oct-HSM (AES) keys in Premium vaults are in public preview and not recommended for production. |
| Key protection | Vaults protect keys with FIPS 140 validated HSMs. HSM Platform 2 (FIPS 140-3 Level 3) now protects all new keys and key versions. |
| Vault layout | Use one vault per application, region and environment (dev, preproduction, production) to limit the blast radius. In multitenant SaaS, one vault per tenant. |
| Not for | Configuration data, customer content, or certificates stored as secrets. Use Azure Storage or App Configuration, Cosmos DB or Storage, and Key Vault certificates. |
Soft delete and purge protection
| Soft delete | Purge protection | |
|---|---|---|
| Default | On for new vaults; once enabled it can't be disabled | Not enabled by default; optional |
| Prerequisite | - | Soft delete must be enabled first |
| Retention | 7 to 90 days, default 90. Set only at vault creation; can't be changed later. The same interval applies to purge protection. | Same interval |
| Effect | Deleted vault or object stays recoverable. Permanent deletion takes two steps: delete, then purge. | A vault or object in the deleted state can't be purged until the retention period passes |
- Most Azure services that integrate with Key Vault, such as Storage, require purge protection to prevent data loss when keys are used for encryption.
- A soft-deleted vault's name can't be reused until the retention period expires.
- Purging a vault needs the subscription owner or the Key Vault Purge Operator role.
- Recovering a soft-deleted vault does not restore Azure RBAC role assignments or Event Grid subscriptions; recreate them.
- Logging: enabling it creates a container
insights-logs-auditeventin the storage account you choose. Entries are available at most 10 minutes after the operation. Securing and cleaning the logs is up to you.
Configure access to Key Vault
Access has two independent planes. The control plane manages the vault itself (create, delete, properties, tags) and uses Azure RBAC. The data plane works with keys, secrets and certificates and uses either Azure RBAC or a Key Vault access policy (legacy). Both planes authenticate with Microsoft Entra ID. Granting data access to an app is a data plane grant; a user who only needs to read vault properties and tags needs a control plane role.
| Azure RBAC (recommended) | Access policy (legacy) | |
|---|---|---|
| Scopes | Management group, subscription, resource group, vault, or an individual key, secret or certificate | Vault level only |
| Entries | Role assignments | Up to 1024 access policy entries per vault; prefer groups |
| PIM / JIT | Supported (eligible assignments) | Not supported |
| Privilege escalation | Permission management is limited to Owner and User Access Administrator | Contributor (or any role with Microsoft.KeyVault/vaults/write) can grant themselves data plane access |
Built-in data plane roles
| Role | What it allows |
|---|---|
| Key Vault Administrator | All data plane operations on the vault and its objects. Can't manage vault resources or role assignments. |
| Key Vault Reader | Read metadata of the vault, certificates, keys and secrets. Can't read secret contents or key material. |
| Key Vault Secrets Officer / Secrets User | Officer: any action on secrets except managing permissions. User: read secret contents (including a certificate's secret with private key). |
| Key Vault Crypto Officer / Crypto User | Officer: any action on keys except managing permissions. User: perform cryptographic operations with keys. |
| Key Vault Crypto Service Encryption User | Read key metadata and wrap/unwrap. |
| Key Vault Certificates Officer / Certificate User | Officer: any action on certificates except managing permissions. User: read the entire certificate including secret and key. |
| Key Vault Purge Operator | Permanently delete soft-deleted vaults. |
| Key Vault Data Access Administrator | Add or remove assignments of the Key Vault roles (includes an ABAC condition to constrain them). |
| Key Vault Contributor | Control plane only. Doesn't allow access to keys, secrets or certificates. |
These data plane roles work only on vaults that use the Azure RBAC permission model. ABAC conditions for Key Vault are in preview and apply only to secret data actions.
Switching the permission model
- Changing the model needs unrestricted
Microsoft.Authorization/roleAssignments/write(Owner or User Access Administrator). With User Access Administrator you also needMicrosoft.KeyVault/vaults/write(part of Key Vault Contributor). Classic Service Administrator and Co-Administrator roles, and the restricted Key Vault Data Access Administrator, can't change it. - Setting the Azure RBAC model invalidates all access policy permissions and can cause outages if equivalent Azure roles aren't assigned. Migration order: prepare, inventory, create the Azure roles, enable Azure RBAC, validate, monitor.
- Assigning roles on individual keys, secrets or certificates is not recommended. Exceptions: individual secrets needing individual user access, or secrets shared by several applications. Object-scope assignments only support read operations; administration needs vault-level permissions.
- Legacy access policies have known security vulnerabilities and lack PIM support; don't use them for critical data.
How callers authenticate
- Managed identity is the recommended way (system-assigned for the app). Azure rotates the identity, so the app doesn't manage a first secret.
- Service principal with certificate or secret: not recommended, because the owner must rotate the certificate and the bootstrap secret is hard to rotate automatically.
- Application-plus-user (compound identity) isn't available for data plane Azure RBAC.
- A vault is automatically associated with the Microsoft Entra tenant of its subscription.
Key Vault firewall and network access
By default the Key Vault firewall is disabled: all applications and Azure services can send requests. Authentication and authorization are still required. Options, from most to least restricted, are: disable public access and use private endpoints only; enable the firewall; use a Network Security Perimeter.
| Option | Details |
|---|---|
| Firewall with IPv4 rules | Public static IPs or CIDR ranges only: private ranges (10.x, 172.16-31.x, 192.168.x) are not allowed. IPv4 only. Max 1000 IPv4 rules. |
| Firewall with virtual networks | Enable the Microsoft.KeyVault service endpoint on the subnet, then add the network rule. Up to 15 minutes to take effect. Max 200 virtual network rules. Use this when you can't rely on static IPs (for example VMs). |
| Trusted services bypass | Allow trusted Microsoft services to bypass this firewall. Only services on the trusted list qualify; Azure DevOps is not on it. The trusted list covers services where Microsoft controls all the code. Services not on the list are blocked whether or not the bypass is on. |
| Private endpoint (Private Link) | Private endpoint and virtual network must be in the same region; the vault can be in another region. Needs Owner or Contributor on the vault and the virtual network. |
| Disable public access | Denies all public configurations; only private endpoints work. Trusted services still bypass and need no private endpoint; other services (for example Azure DevOps) need a private endpoint. |
| Network Security Perimeter | With public network access set to Secure by perimeter, the trusted services bypass is overridden: even trusted services are blocked unless a perimeter rule admits them. |
- Once firewall rules apply, data plane operations only work from allowed networks, including from the Azure portal. A user can open the vault in the portal yet fail to list keys, secrets or certificates from a client that isn't allowed.
- Clients should be pinned to TLS 1.2 or 1.3, which Key Vault supports.
Keys, secrets and certificates
Keys and rotation
- Rotation generates a new key version with new key material. It re-wraps data encryption keys with the new version; it does not re-encrypt the underlying data, so keep old and new versions enabled until re-wrapping completes. Target services should use the versionless key URI.
- Rotation policy settings: expiry time (applies to the newly rotated key, not the current one), enabled flag, rotation type (a time after creation, which is the default, or a time before expiry), rotation time (minimum seven days from creation and seven days from expiry) and notification time (Event Grid near-expiry event).
- The Key Vault Crypto Officer role manages the rotation policy and on-demand rotation. With access policies you need the Rotate, Set Rotation Policy and Get Rotation Policy key permissions.
- Rotate encryption keys at least every two years. Each scheduled rotation has an extra cost. Services that use customer-managed keys take from one hour to 24 hours or more to apply a new version.
Secrets
- Secrets are stored encrypted, up to 25 KB each.
contentTypeis a hint of up to 255 characters. Up to 15 tags, each with a 512-character name and value; anyone with list or get can read tags. expandnbfare informational. A get still works for expired and not-yet-valid secrets, for recovery and testing;enabledcontrols retrieval.- Secret access is controlled at the vault level. Secret permissions: get, list, set, delete, recover, backup, restore, and purge as a privileged operation.
- Near-expiry automation: 30 days before a secret expires Key Vault publishes a near-expiry event to Event Grid, which can trigger a function to rotate it.
Certificates
- Creating a certificate also creates an addressable key and secret with the same name. Retrieve it with its private key in PFX or PEM only if the policy marks the key exportable. Exportable keys are allowed only with RSA and EC; HSM keys are non-exportable.
- One policy applies to all versions of a certificate. Lifetime actions trigger on days before expiry or a lifetime percentage and either email contacts or autoRenew.
- Automatic renewal works with partner issuers (DigiCert and GlobalSign). Non-partnered CAs are allowed but don't support automatic renewal.
- Issuer objects are created in a vault and can be used only with certificates in that same vault.
- An expired certificate can still be retrieved but may stop working where expiry is validated, such as TLS.
Defender CSPM secrets scanning and Defender for Key Vault
| Secrets scanning type | What it does | Plan needed |
|---|---|---|
| Machine scanning | Agentless secrets scanning on multicloud VMs | Defender CSPM plan, or Defender for Servers Plan 2 |
| Cloud deployment resource scanning | Agentless scanning of infrastructure-as-code deployment resources across clouds | Defender CSPM plan |
| Code repository scanning | Finds exposed secrets in Azure DevOps | Defender CSPM plan |
- Findings raise a recommendation under the Remediate vulnerabilities security control. Review them in the asset inventory, recommendations, cloud security explorer (query the cloud security graph) and attack paths. Not every secret type supports every method.
- Foundational CSPM is free; Defender CSPM is the paid plan with advanced features such as attack path analysis. Permissions listed for secrets scanning: Security Reader, Security Admin, Reader, Contributor, Owner.
- Discovered types include insecure SSH private keys, plaintext Azure SQL connection strings, storage account connection strings and SAS tokens, Microsoft Entra client secrets, AWS access keys and GitHub personal access tokens.
Microsoft Defender for Key Vault
- General availability (GA). It detects unusual and potentially harmful attempts to access or exploit Key Vault accounts, and it is billed as shown on the pricing page.
- Alerts show in Key Vault's Security page, Workload protections and the Defender for Cloud security alerts page, and can optionally be emailed. Fields include Object ID and User Principal Name or IP address; some may be missing depending on the access type.
- Don't dismiss an alert because you recognize the user or application: it is designed to catch suspicious activity caused by stolen credentials. Contact the owner to verify, and use a suppression rule for noise.
- Response: unrecognized IP address, so enable the Key Vault firewall and add trusted resources and virtual networks; unauthorized app or user, so open the vault's access policy settings and remove or restrict the principal; Microsoft Entra role involved, so contact your administrator.
- Measure impact on the vault's Security page (secrets accessed and timestamps; diagnostic logs if enabled), then rotate every secret, key and certificate that was accessed, and disable or delete affected secrets.
- You can simulate alerts. Azure VMs have Microsoft IPs, so an alert can show a Microsoft IP for activity from outside Microsoft.
The cached Learn pages for Defender for Key Vault describe features, alerts and response, but not the plan enablement steps, so this page doesn't list them.
CLI and PowerShell
| Task | Azure CLI | PowerShell |
|---|---|---|
| Create a vault with Azure RBAC and purge protection | az keyvault create --name "<vault-name>" --resource-group "myResourceGroup" --enable-rbac-authorization true --enable-purge-protection true | - |
| Assign a Key Vault data plane role | az role assignment create --role "Key Vault Secrets Officer" --assignee <user-principal-name> --scope /subscriptions/<subscription-id>/resourcegroups/<resource-group>/providers/Microsoft.KeyVault/vaults/<vault-name> | New-AzRoleAssignment -RoleDefinitionName "Key Vault Secrets Officer" -SignInName <user-principal-name> -Scope "/subscriptions/<subscription-id>/resourcegroups/<resource-group>/providers/Microsoft.KeyVault/vaults/<vault-name>" |
| Let trusted Microsoft services bypass the firewall | az keyvault update --resource-group "myresourcegroup" --name "mykeyvault" --bypass AzureServices | Update-AzKeyVaultNetworkRuleSet -VaultName "mykeyvault" -Bypass AzureServices |
| Add an IP address rule | az keyvault network-rule add --resource-group "myresourcegroup" --name "mykeyvault" --ip-address "191.10.18.0/24" | Add-AzKeyVaultNetworkRule -VaultName "mykeyvault" -IpAddressRange "16.17.18.0/24" |
| Enable the Key Vault service endpoint on a subnet | az network vnet subnet update --resource-group "myresourcegroup" --vnet-name "myvnet" --name "mysubnet" --service-endpoints "Microsoft.KeyVault" | - |
| Set the firewall default action to deny | az keyvault update --resource-group "myresourcegroup" --name "mykeyvault" --default-action Deny | Update-AzKeyVaultNetworkRuleSet -VaultName "mykeyvault" -DefaultAction Deny |
| Disable public network access | az keyvault update --resource-group "myresourcegroup" --name "mykeyvault" --public-network-access Disabled | Update-AzKeyVault -ResourceGroupName "myresourcegroup" -VaultName "mykeyvault" -PublicNetworkAccess "Disabled" |
| Set a key rotation policy | az keyvault key rotation-policy update --vault-name <vault-name> --name <key-name> --value </path/to/policy.json> | Set-AzKeyVaultKeyRotationPolicy -VaultName <vault-name> -KeyName <key-name> -ExpiresIn (New-TimeSpan -Days 720) -KeyRotationLifetimeAction @{Action="Rotate";TimeAfterCreate= (New-TimeSpan -Days 540)} |
| Rotate a key now | az keyvault key rotate --vault-name <vault-name> --name <key-name> | Invoke-AzKeyVaultKeyRotation -VaultName <vault-name> -Name <key-name> |
Exam Tips
Tick each tip once you can answer it without looking.
“New vault must resist accidental or malicious permanent deletion” → Soft delete (on by default) plus purge protection (opt in). Trap: Purge protection needs soft delete first and isn't enabled by default; retention (7 to 90 days) is fixed at creation.
“Storage account encrypted with a customer-managed key in Key Vault” → Purge protection must be on. Trap: Most integrating services, such as Storage, require purge protection to prevent data loss.
“Recreate a vault with the same name right after deleting it” → Not possible until the soft-delete retention period expires (or it is purged). Trap: With purge protection even the owner can't purge early. Recovering the vault doesn't restore RBAC assignments.
“App needs to read secret values only” → Key Vault Secrets User on the vault, for the app's managed identity. Trap: Key Vault Reader reads metadata only; Secrets Officer can also write and delete.
“App needs to sign and encrypt with keys but not manage them” → Key Vault Crypto User. Trap: Crypto Officer manages keys; Crypto Service Encryption User only does wrap/unwrap and reads metadata.
“User has Key Vault Contributor but can't read secrets” → Key Vault Contributor is control plane only; assign a data plane role. Trap: Under the legacy access policy model, a Contributor can add an access policy for themselves.
“After enabling Azure RBAC, apps that worked are now denied” → Switching to Azure RBAC invalidates all access policies; assign equivalent roles. Trap: Only Owner or User Access Administrator (plus vaults/write) can switch the model; Co-Administrator can't.
“Grant one team access to many vaults at once” → Azure RBAC role at management group, subscription or resource group scope (use PIM eligible assignments). Trap: Access policies exist only at the vault level.
“Vault firewall on; a Microsoft service needs access” → Check that the service is on the trusted services list and enable Allow trusted Microsoft services to bypass this firewall. Trap: Azure DevOps isn't trusted; use a firewall rule or private endpoint instead. Secure by perimeter overrides the bypass.
“VMs with changing IPs must reach the vault through the firewall” → Subnet service endpoint Microsoft.KeyVault plus a virtual network rule. Trap: IP rules accept only public IPv4 ranges: 10.x, 172.16-31.x and 192.168.x are rejected.
“No public exposure at all; traffic only from your virtual network” → Private endpoint, then disable public network access. Trap: Trusted services still bypass when public access is disabled; the endpoint must be in the same region as the virtual network.
“Portal shows the vault but not its keys after firewall rules were added” → Your client machine isn't in the allowed networks; data plane calls are blocked. Trap: Listing vaults is control plane; listing keys is data plane.
“Automatically create a new key version every 18 months” → Key rotation policy (rotate after creation), managed by Key Vault Crypto Officer. Trap: Rotation re-wraps DEKs; it doesn't re-encrypt data, so don't disable the old version early.
“Certificate private key must not be retrievable” → Policy with a non-exportable key (HSM keys are non-exportable). Trap: If the policy marks the key exportable, the addressable secret returns the private key in PFX or PEM.
“Auto-renew a certificate” → Lifetime action autoRenew with a partner issuer (DigiCert or GlobalSign). Trap: Non-partnered CAs work but can't auto-renew; an issuer object works only in its own vault.
“Find plaintext connection strings and SSH keys on VMs and IaC deployments” → Defender CSPM secrets scanning (machine scanning also with Defender for Servers Plan 2). Trap: Code repository scanning for Azure DevOps and cloud deployment scanning need the Defender CSPM plan.
“Defender for Key Vault alert from a user you recognize” → Still investigate: verify with the owner, rotate accessed objects. Trap: It targets suspicious activity from stolen credentials; recognition isn't proof of legitimacy.
Sources
- What is Azure Key Vault? (basic concepts)
- Quickstart: create a key vault with the Azure CLI
- Secure your Azure Key Vault
- Azure Key Vault soft-delete
- Azure Key Vault logging
- Azure RBAC for Key Vault
- Migrate to Azure role-based access control
- Assign a Key Vault access policy
- Authenticate to Azure Key Vault
- Configure network security for Azure Key Vault
- Integrate Key Vault with Azure Private Link
- About keys
- Configure key auto-rotation
- About Azure Key Vault secrets
- Secret rotation tutorial
- About Azure Key Vault certificates
- Protecting secrets in Microsoft Defender for Cloud
- Cloud security posture management in Defender for Cloud
- Microsoft Defender for Key Vault
Checked against Microsoft Learn on November 13, 2026.