Symptoms
- Every database on a logical server (or one database, with database-level CMK) shows status
Inaccessiblein the portal. - Applications fail at login with "database is not currently available" style errors; exact error numbers vary by driver and service version.
- The Key Vault activity log shows a recent change: key disabled, key expired, key deleted, access policy or RBAC assignment removed, Key Vault firewall tightened, or the server's managed identity deleted.
The clock matters. When the service gets key errors (4xx from Key Vault) for about 30 minutes, it marks the database inaccessible. If you restore key access within the first 30 minutes after that, the database heals on its own, usually within the following hour. After that window you have to revalidate the key manually, and recovery time grows with database size.
Caution
Do not purge the key, delete the vault, or "rotate to a new key" to try to fix this. The database is encrypted with the original key material. Without it, the data and its backups cannot be read.
1. Confirm scope and impact (5 minutes)
RG=rg-data; SRV=sql-prod-weu
# Which databases are down?
az sql db list -g $RG -s $SRV --query "[].{name:name, status:status}" -o table
# What is the server's TDE protector, and which identity reads it?
az sql server tde-key show -g $RG -s $SRV -o table
az sql server show -g $RG -n $SRV \
--query "{identity:identity.type, uami:identity.userAssignedIdentities, primaryUami:primaryUserAssignedIdentityId, kek:keyId}" -o json
Note the key URI (https://<vault>.vault.azure.net/keys/<key>/<version>) and the identity. Everything below checks whether that identity can still use that key.
2. Find what broke key access
Work down this table. Most incidents are one of the first four rows.
| Check | Command | Fix |
|---|---|---|
| Key disabled | az keyvault key show --id <uri> --query attributes.enabled | az keyvault key set-attributes --vault-name <kv> -n <key> --enabled true |
| Key expired | az keyvault key show --id <uri> --query attributes.expires | Clear or extend expiry (below) |
| Key deleted (soft-deleted) | az keyvault key list-deleted --vault-name <kv> -o table | az keyvault key recover --vault-name <kv> -n <key> |
| Vault deleted | az keyvault list-deleted -o table | az keyvault recover -n <kv> |
| Identity lost permission | RBAC or access policy check (below) | Re-grant get, wrapKey, unwrapKey |
| Vault firewall blocks SQL | az keyvault show -n <kv> --query properties.networkAcls | Re-enable "Allow trusted Microsoft services" or the private endpoint path |
| Managed identity deleted or replaced | az identity show --ids <uami-id> | Re-create isn't the same identity; see section 4 |
Fix an expired key by setting a new expiry date on the same key version:
az keyvault key set-attributes --vault-name kv-sql-prod -n sql-tde-key \
--expires "2027-12-31T00:00:00Z"
Check the identity's permissions
For a vault using Azure RBAC, the server identity needs a role that includes get, wrapKey and unwrapKey on the key or vault, typically Key Vault Crypto Service Encryption User:
PRINCIPAL=$(az sql server show -g $RG -n $SRV --query identity.principalId -o tsv) # system-assigned
KV_ID=$(az keyvault show -n kv-sql-prod --query id -o tsv)
az role assignment list --assignee $PRINCIPAL --scope $KV_ID -o table
az role assignment create --assignee-object-id $PRINCIPAL --assignee-principal-type ServicePrincipal \
--role "Key Vault Crypto Service Encryption User" --scope $KV_ID
For a user-assigned identity, use that identity's principalId instead. For a vault using access policies:
az keyvault set-policy -n kv-sql-prod --object-id $PRINCIPAL \
--key-permissions get wrapKey unwrapKey
Tip
RBAC assignments can take a few minutes to take effect. Don't stack more changes on top while you wait; check the database status again after five minutes.
3. Bring the database back
If access was restored within the auto-heal window, watch the status:
watch -n 60 "az sql db list -g $RG -s $SRV --query \"[].{name:name,status:status}\" -o table"
If the database stays Inaccessible, or you are past the window, revalidate the key. For database-level CMK, the CLI has a direct command:
az sql db tde key revalidate -g $RG -s $SRV -n appdb
For server-level keys, use SQL database > Transparent data encryption > Revalidate key in the portal (retry the existing key, or pick a backup key you added earlier). Command names and options vary by CLI version; check az sql db tde key -h on your build.
Warning
After a long outage, a recovered database can lose settings such as failover group membership, point-in-time restore history and tags. Record them now (
az sql db show,az sql failover-group list) so you can put them back.
4. If the key is truly gone
- Identity deleted: a re-created managed identity has a new object ID. Grant the new identity access to the same key, assign it to the server, and revalidate.
- Key purged or vault purged: the key material cannot be recovered. Your options are a geo-replica or failover group secondary that uses a different key, or a backup that was taken under an older protector you still have. Open a Microsoft support case at the highest severity immediately.
5. Verify recovery
- All databases show
Onlineinaz sql db list. - Applications connect and run a write; check the Azure SQL
connection_failedmetric drops to normal. - Failover groups, geo-replicas and long-term retention are re-checked and re-created if they were lost.
Communicate
Tell users that the database was unavailable because its encryption key was not reachable, that no data was changed, and give the time access was restored. If PITR history was lost, tell data owners which restore points are no longer available.
Prevent it next time
- Never set an expiry date on TDE protector keys, or alert on it 60 days ahead with Azure Policy and Event Grid
Microsoft.KeyVault.KeyNearExpiryevents. - Enable purge protection on every vault holding TDE keys. It is required for TDE CMK and stops the worst outcome.
- Put a
CanNotDeletelock on the vault and restrict key operations to a small PIM-controlled group. - Alert on the Key Vault activity log for
Microsoft.KeyVault/vaults/keys/updateand role assignment deletes on the vault scope. - Keep a second key version or a backup key registered on the server so revalidation has a fallback.
- Test key access changes in non-production first: disable the key in a test server and time how long until
Inaccessible.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get