Blog Post

Azure Infrastructure Blog
7 MIN READ

Azure Key Vault and BYOK: Lessons Learned

gurjsing's avatar
gurjsing
Icon for Microsoft rankMicrosoft
Oct 08, 2026

Key rotation, backup, and recovery

Bring Your Own Key (BYOK) lets you import externally generated key material into Azure Key Vault. Importing that material again creates a new version; it does not recreate the original version identifier. If Azure Storage still requires the original customer-managed key (CMK) version to unwrap (decrypt) its account encryption key, re-importing the same material under a new version does not restore that access.

With Azure Storage CMK, the key in Key Vault wraps the account encryption key. A key change requires access to the current CMK version to unwrap the account encryption key before it can be wrapped with the new key. If the required version cannot be recovered at the referenced endpoint, importing the material under a new URI does not complete the transition.

Keep both the key material and the required Key Vault versions recoverable. Re-importing the material alone cannot complete a recovery operation that requires the original version.

The backup and restore procedures below apply to Azure Key Vault, not Azure Key Vault Managed HSM.

BYOK re-import vs. key restore

A versioned key URI includes the vault endpoint, key name and version identifier. Importing a key under an existing name creates a new version. Restoring a Key Vault key backup preserves the name and the version identifiers captured in that backup. These operations are not interchangeable, even when the imported material is identical. 

Restoring to another vault preserves the saved version identifiers but changes the vault endpoint and therefore the full URI. A service that still needs the original URI may be unable to switch to the restored copy. Account for the original endpoint, access permissions and service configuration when planning recovery.

Record each versioned key URI together with its dependent workloads, access identities and owner. This inventory is needed when rotating a shared key, changing vaults or recovering from a deletion. Retain the external key material and any Key Vault object backups required by the recovery policy.

If a dependent service references a key version that is no longer available, work in this order:

  1. Check whether the key or the vault is soft-deleted. If it is, recover it; recovery brings back the original identifiers.
  2. Otherwise, restore the most recent Key Vault backup that contains the referenced version into the original vault.
  3. If neither is possible, open a Microsoft support case before you import replacement material or change the service's key configuration.

Key rotation in Azure Storage

Creating a new version in Key Vault does not immediately change every dependent service. Azure Storage must start using the new key version before the previous version is disabled. Keep the old and new versions enabled and accessible while the change completes. Storage updates the protection of its root encryption key without re-encrypting the stored data.

When automatic version updates are configured, Storage checks for a new version daily. Microsoft recommends waiting 24 hours after rotation before disabling the previous version. If the account is pinned to a specific version, update the configured version explicitly. Confirm the version in use and test data access before disabling the previous version; elapsed time alone is not sufficient.

If new keys must originate in your HSM, generate the material there and import it through the supported BYOK process. Re-importing unchanged material creates a version, but does not constitute cryptographic key rotation. Key Vault auto-rotation generates new material in Azure, not in your HSM, so you cannot use it for these keys.

This sequence assumes that the account is pinned to a key version, so the switch in step 4 happens only after the backup in step 3. With automatic version updates, Storage can adopt the new version at its next daily check, possibly before the backup exists. If your policy requires a backup before use, pin the key version and update it explicitly once the backup has completed.

Soft delete and purge protection

Azure Storage CMK requires soft delete and purge protection. Soft delete provides a configured recovery window of 7 to 90 days, with a default of 90 days. Purge protection prevents permanent deletion before that window expires. It does not prevent the initial deletion or keep a deleted key available to the service. 

Monitor key deletions and failed key access, and investigate before the recovery window closes. If the required object is still soft-deleted, recover it rather than importing a replacement. A recovery procedure must include the permissions, network access and responsible owner needed to perform that operation.

Monitoring and guardrails

Key Vault records key operations in its AuditEvent log category. Send these logs to a Log Analytics workspace with a diagnostic setting, and alert on operations that change which keys and versions exist.

AzureDiagnostics
| where ResourceProvider == "MICROSOFT.KEYVAULT"
| where OperationName in ("KeyDelete", "KeyPurge", "KeyRecover",
                          "KeyImport", "KeyBackup", "KeyRestore")
| project TimeGenerated, Resource, OperationName, requestUri_s,
          CallerIPAddress, ResultSignature
| sort by TimeGenerated desc

If your diagnostic setting writes to resource-specific tables, query AZKVAuditLogs instead; some column names differ.

On the storage side, lost key access surfaces as HTTP 403 errors such as KeyVaultEncryptionKeyNotFound, KeyVaultVaultNotFound or KeyVaultAccessTokenCannotBeAcquired. Treat these errors as incidents, not as transient failures.

Resource locks do not protect keys. A CanNotDelete lock prevents deletion of the vault resource, but locks apply only to control plane operations, and deleting a key is a data plane operation. Limit who can delete, purge, back up and restore keys, and review those assignments regularly.

Retention of previous key versions

Active workloads, migrations and retained data backups can require old key versions after a rotation. Determine those dependencies before setting a retirement date. Data backups may still depend on retained encryption keys. Verify which versions the service requires to restore each retained recovery point; these dependencies vary by service. 

Test the recovery points you must retain before retiring a key. Keep disabling and deleting as separate decisions, with an owner for each. Key Vault does not support deleting individual historical versions, so deletion is not a version-cleanup strategy. 

Backup scope and restore constraints

A Key Vault key backup is an encrypted object snapshot, not a plaintext key export or a whole-vault backup. It can be restored only to a vault in the same Azure subscription and geography as the source vault, though not necessarily the same region. Restore brings back all captured versions, not one selected version. The original key name must be available in the destination. 

A snapshot does not include versions created after the backup, and restoring the key does not rebuild identities, permissions or networking. Backing up a key with more than 500 versions is not supported. Check version counts and backup completion as part of the rotation process.

Where key backups are required, back up the key again after each import or rotation. If policy requires a backup before use, configure the service to use the new version only after its backup has completed. Automatic adoption can otherwise occur before the backup completes. Keep the backup accessible even when the source CMK is unavailable. Restrict backup and restore permissions and monitor their use. Disabling the original key does not disable a copy restored elsewhere. 

Checking the active key version

The following Azure CLI commands use PowerShell line continuation. Replace the placeholders, sign in to the intended tenant and run each command separately, stopping on errors. The storage account and the key vault can be in different subscriptions. You need read, list, backup, and restore permissions, plus network access to the vault. The storage account's managed identity separately needs the get, wrapKey, and unwrapKey permissions. With Azure RBAC, the Key Vault Crypto Service Encryption User role covers these permissions.

Read the account's key properties and list the available versions:

az storage account show `
  --subscription "<storage-subscription>" `
  --resource-group "<resource-group>" `
  --name "<storage-account>" `
  --query "encryption.keyVaultProperties" `
  --output json

az keyvault key list-versions `
  --subscription "<key-subscription>" `
  --vault-name "<source-vault>" `
  --name "<key-name>" `
  --query "[].kid" `
  --output tsv

The currentVersionedKeyIdentifier property reports the version in use. An empty keyVersion means that automatic version updates are enabled; a value means that the account is pinned to that version. Do not rely only on the configured keyVersion or the newest version in Key Vault. Record the identifier before and after the change, and test application reads and writes separately. Azure Storage does not currently log key rotation in its Azure Monitor logs, so this record may be your only evidence of which version was in use.

Backup and restore with Azure CLI

Create a key backup with a unique file name for each snapshot:

$backupFile = ".\cmk-backup-$(Get-Date -Format yyyyMMdd-HHmmss).blob"

az keyvault key backup `
  --subscription "<key-subscription>" `
  --vault-name "<source-vault>" `
  --name "<key-name>" `
  --file $backupFile

To test the restore, use an approved, isolated test vault in the same subscription and geography. The key name must not already be active or reserved by a soft-deleted object. HSM-protected keys require a compatible Premium vault. Do not delete or purge production keys to make room for a restore test.

az keyvault key restore `
  --subscription "<key-subscription>" `
  --vault-name "<isolated-test-vault>" `
  --file $backupFile

az keyvault key list-versions `
  --subscription "<key-subscription>" `
  --vault-name "<isolated-test-vault>" `
  --name "<key-name>" `
  --query "[].kid" `
  --output tsv

Compare the final version segment of each returned URI with the source inventory; the vault hostname will differ. These commands do not change Storage encryption. A successful test restore validates the backup, not the service recovery procedure. Test that procedure separately with a non-production workload before relying on it for production recovery.

Key retirement checklist

  • Identify all services that use the key. Avoid unnecessary key sharing across production and non-production.
  • Verify that the backup includes the required versions and can be restored to the intended destination.
  • Confirm the version in use, test data access, and validate the required backup restores.
  • Disable the old version only after confirming that no active workload or required backup restore still needs it.

Reliable recovery requires the key material, the referenced versions and a tested service recovery procedure. When a recovery operation depends on the original CMK version, re-importing the material under a new version cannot replace it. Disable old versions only after you verify that no remaining workload or backup depends on them.

Updated Oct 08, 2026
Version 1.0
No CommentsBe the first to comment