Azure Key Vault
Store and manage secrets, encryption keys, and certificates in Key Vault, and integrate it with other Azure services to avoid hardcoded credentials.
Azure Key Vault is a free Cloud & IT Cert Prep lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cloud & IT Cert Prep learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
What Is Azure Key Vault?
Azure Key Vault is a cloud service for securely storing and managing secrets (API keys, passwords, connection strings), encryption keys (used to encrypt data), and certificates (TLS/SSL certificates for applications). Instead of embedding sensitive values in application code, configuration files, or environment variables, applications retrieve them from Key Vault at runtime, keeping credentials out of source code and deployment artifacts.
Key Vault Tiers: Standard vs. Premium
Key Vault comes in two tiers. Standard protects secrets and certificates using software-based encryption. Premium adds support for Hardware Security Module (HSM)-protected keys — cryptographic operations are performed inside tamper-resistant hardware, providing FIPS 140-2 Level 2 (Standard) or Level 3 (HSM) certification. A separate offering, Managed HSM, provides a single-tenant, fully managed HSM for the highest-assurance requirements.
Creating a Key Vault
Each Key Vault is created in a specific Azure resource group and region. The vault name must be globally unique within the vault.azure.net namespace. You configure the access model during creation: either the older vault access policies model or the recommended Azure RBAC model where Entra ID roles control read and write access to secrets, keys, and certificates independently.
# Create a Key Vault with RBAC access model
az keyvault create \
--name myUniqueVault123 \
--resource-group myRG \
--location eastus \
--enable-rbac-authorization true
# Grant yourself the Key Vault Secrets Officer role
az role assignment create \
--role 'Key Vault Secrets Officer' \
--assignee your-user@company.com \
--scope /subscriptions/<sub-id>/resourceGroups/myRG/providers/Microsoft.KeyVault/vaults/myUniqueVault123Storing and Retrieving Secrets
A secret in Key Vault is any sensitive string value: database passwords, API keys, OAuth client secrets, storage account connection strings. Each secret has a name, a value, and optional attributes like an expiry date and enabled flag. Applications authenticate to Key Vault (typically via managed identity) and call the Key Vault REST API to retrieve the current secret value at runtime — no hardcoded values anywhere.
# Store a database password as a secret
az keyvault secret set \
--vault-name myUniqueVault123 \
--name db-password \
--value 'SuperSecret!42'
# Retrieve the secret value
az keyvault secret show \
--vault-name myUniqueVault123 \
--name db-password \
--query value \
--output tsvManaging Encryption Keys
Key Vault stores cryptographic keys used to encrypt and decrypt data. Services like Azure Storage, Azure SQL Database, and Azure Disk Encryption integrate with Key Vault to use customer-managed keys (CMK) for Bring Your Own Key (BYOK) scenarios. With CMK, you retain control of the encryption key — revoking the key in Key Vault instantly prevents any service from decrypting the data, giving you a cryptographic kill switch.
# Create an RSA key in Key Vault
az keyvault key create \
--vault-name myUniqueVault123 \
--name myEncryptionKey \
--kty RSA \
--size 2048
# Enable CMK on a Storage Account
az storage account update \
--resource-group myRG \
--name mystorageaccount \
--encryption-key-vault myUniqueVault123 \
--encryption-key-name myEncryptionKey \
--encryption-key-source Microsoft.KeyvaultCertificate Management
Key Vault can act as a certificate authority interface for TLS certificates. You can generate self-signed certificates, import existing PFX/PEM files, or configure Key Vault to automatically request and renew certificates from trusted CAs like DigiCert or GlobalSign. When a certificate is about to expire, Key Vault can auto-renew it and notify administrators via Event Grid events, eliminating manual renewal workflows.
# Import an existing certificate
az keyvault certificate import \
--vault-name myUniqueVault123 \
--name myCert \
--file certificate.pfx \
--password 'CertPassword'Access Control: RBAC vs. Access Policies
Key Vault supports two access models. Vault access policies are the legacy model where you grant a principal permissions to all secrets, keys, or certificates in the vault — you cannot restrict access to individual secret names. The newer and recommended Azure RBAC model uses standard RBAC roles (Key Vault Secrets User, Key Vault Secrets Officer, etc.) and supports deny assignments and Privileged Identity Management, giving much finer-grained control.
Integrating Key Vault with App Service
A common pattern is referencing Key Vault secrets as App Service application settings. Instead of storing the secret value in the app setting, you store a Key Vault reference: @Microsoft.KeyVault(SecretUri=https://myvault.vault.azure.net/secrets/db-password/). App Service automatically retrieves the current secret value at runtime using the app's managed identity. If the secret rotates in Key Vault, the app picks up the new value on the next restart.
# Set an App Service app setting as a Key Vault reference
az webapp config appsettings set \
--resource-group myRG \
--name myWebApp \
--settings 'DB_PASSWORD=@Microsoft.KeyVault(SecretUri=https://myUniqueVault123.vault.azure.net/secrets/db-password/)'Soft Delete and Purge Protection
Soft delete (enabled by default) retains deleted Key Vault items for 7-90 days, allowing recovery if deletion was accidental. Purge protection, when enabled, prevents anyone — including subscription owners — from permanently purging a soft-deleted vault or its objects until the retention period expires. For regulatory and ransomware resilience purposes, enabling both is a security best practice enforced by Azure Policy.
# Recover a soft-deleted secret
az keyvault secret recover \
--vault-name myUniqueVault123 \
--name db-passwordMonitoring and Auditing Key Vault Access
Every operation against Key Vault — reads, writes, certificate renewals, key usage — is recorded in the Key Vault audit log. You enable diagnostic settings to route these logs to a Log Analytics workspace or a storage account for long-term retention. This provides a complete audit trail of who accessed which secret, when, and from which IP address — essential for security investigations and compliance evidence.
# Enable diagnostic logging for Key Vault
az monitor diagnostic-settings create \
--resource /subscriptions/<sub-id>/resourceGroups/myRG/providers/Microsoft.KeyVault/vaults/myUniqueVault123 \
--workspace /subscriptions/<sub-id>/resourceGroups/myRG/providers/Microsoft.OperationalInsights/workspaces/myWorkspace \
--name kv-audit-logs \
--logs '[{"category":"AuditEvent","enabled":true}]'Private Endpoints for Key Vault
By default, Key Vault has a public HTTPS endpoint on the internet. For high-security environments, you can deploy a private endpoint that places Key Vault inside your VNet with a private IP address, and disable the public endpoint entirely. Applications accessing Key Vault through the private endpoint never traverse the public internet, satisfying data exfiltration prevention requirements and making Key Vault invisible from outside your VNet.
Quick Check
Test your understanding of Microsoft Azure Fundamentals (AZ-900) concepts from this lesson.
Lesson Recap
In this lesson you learned: Key Vault stores secrets, encryption keys, and TLS certificates in a managed, audited service, managed identity integration removes the need for any hardcoded credentials in application code, and soft delete and purge protection guard against accidental or malicious deletion of cryptographic material. Next up we explore Microsoft Sentinel, Azure's cloud-native SIEM.
Frequently asked questions
Is the “Azure Key Vault” lesson free?
Yes — the full text of “Azure Key Vault” is free to read here on the web, and the Cloud & IT Cert Prep course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cloud & IT Cert Prep course, upgrade to CoddyKit PRO.
What will I learn in “Azure Key Vault”?
Store and manage secrets, encryption keys, and certificates in Key Vault, and integrate it with other Azure services to avoid hardcoded credentials. You practise Cloud & IT Cert Prep with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Cloud & IT Cert Prep?
No prior experience is required. Cloud & IT Cert Prep on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Azure Key Vault” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Cloud & IT Cert Prep lesson?
Yes. Every Cloud & IT Cert Prep lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.