Azure Key Vault and Encryption: Secrets, Keys, Certificates, Managed HSM, Disk Encryption and Customer-Managed Keys
What Key Vault Stores
| Object | Examples |
|---|---|
| Secrets | Connection strings, passwords, API keys |
| Keys | RSA/EC keys for encrypt, sign and wrap. Software or HSM protected |
| Certificates | TLS certificates with auto renewal and rotation |
| Service | Protection |
|---|---|
| Key Vault Standard | Software-protected keys |
| Key Vault Premium | HSM-protected keys (FIPS 140-2/3 validated hardware, check current level) |
| Managed HSM | Dedicated, single-tenant HSM pool under your control |
Create and Use a Vault
bash
az keyvault create -g rg-sec -n kv-shop-482 -l centralindia --enable-rbac-authorization true --enable-purge-protection true --retention-days 90
az role assignment create --assignee <user-or-group-id> --role "Key Vault Secrets Officer" --scope $(az keyvault show -n kv-shop-482 --query id -o tsv)
az keyvault secret set --vault-name kv-shop-482 -n SqlPassword --value '<StrongPassword>'
az keyvault secret show --vault-name kv-shop-482 -n SqlPassword --query value -o tsv
Authorization Models
- Azure RBAC (recommended): roles like Key Vault Secrets User (read secrets), Secrets Officer, Crypto User, Certificates Officer, Administrator
- Access policies (legacy): per-vault permission lists
- Separate management plane (create the vault) from data plane (read secrets)
Protect Against Deletion
- Soft delete (always on): deleted objects can be recovered for the retention period
- Purge protection: even admins cannot purge before the retention ends. Required for customer-managed keys scenarios
- Add resource locks, diagnostic logs and alerts for access
Apps Read Secrets with Managed Identity
python
from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
client = SecretClient(vault_url="https://kv-shop-482.vault.azure.net", credential=DefaultAzureCredential())
password = client.get_secret("SqlPassword").value
- Turn on a system-assigned identity for the app and give it Key Vault Secrets User. No password is stored in the app
- App Service and Functions can read secrets directly with a Key Vault reference in app settings:
@Microsoft.KeyVault(SecretUri=https://kv-shop-482.vault.azure.net/secrets/SqlPassword/) - AKS can use the Secrets Store CSI driver with workload identity
Network Security for Key Vault
- Use firewall rules or a private endpoint with the
privatelink.vaultcore.azure.netDNS zone, then disable public access - Allow trusted Microsoft services only when needed
Encryption in Azure
| Layer | Option |
|---|---|
| Storage and many services | Always encrypted at rest. Use customer-managed keys with Key Vault for control |
| VM disks | Server-side encryption with platform or customer keys (default). Encryption at host covers temp disks and caches. Azure Disk Encryption uses BitLocker or dm-crypt inside the VM |
| Databases | TDE (customer-managed key optional), Always Encrypted for client-side column encryption |
| Confidential computing | Protect data in use with confidential VMs and containers |
| In transit | TLS 1.2+ everywhere, HTTPS only |
bash
az disk-encryption-set create -g rg-sec -n des-prod -l centralindia --key-url https://kv-shop-482.vault.azure.net/keys/disk-key/<version> --source-vault kv-shop-482 --identity-type SystemAssigned
# Give the set's identity "Key Vault Crypto Service Encryption User", then use --disk-encryption-set when creating disks or VMs
Key Rotation and Certificates
- Set rotation policies on keys and use Event Grid events for near-expiry notices
- Key Vault can issue and renew certificates from integrated CAs and notifies before expiry
- Use versionless key URIs so services pick up rotated keys
Practice
- Create a vault with RBAC and purge protection
- Store a secret and read it from a VM or app using managed identity
- Create a disk encryption set with a customer-managed key
- Add a private endpoint and disable public access
Conclusion
Key Vault centralizes secrets, keys and certificates. Use RBAC, soft delete and purge protection, managed identities for access, private endpoints for network safety and customer-managed keys when policy requires.
Quick Summary: objects; vault creation; authorization; protection; managed identity; encryption; rotation.

