Deep Dive into Azure Key Vault
Azure Key Vault is more than just a secret store; it's a fully managed service that centralizes secret management, key protection, and certificate lifecycle management. It’s designed for high-security workloads, enabling you to enforce zero-trust principles.
Components of Azure Key Vault
Component |
Description |
Secrets |
Key-value pairs like connection strings, API keys, credentials |
Keys |
Cryptographic keys for encryption/decryption and digital signing |
Certificates |
Manage SSL/TLS certificates, integrate with CA |
Managed HSM |
Dedicated hardware security module with full control |
Secrets Management: Practical Use
{
"Name": "DbConnectionString",
"Value": "Server=tcp:sqlserver.database.windows.net;Initial Catalog=MyDB;User Id=admin;Password=xyz;"
}
Access with .NET
var client = new SecretClient(
new Uri("https://yourvault.vault.azure.net/"),
new DefaultAzureCredential()
);
KeyVaultSecret secret = await client.GetSecretAsync("DbConnectionString");
Key Management: Encryption and Signing
Azure Key Vault can store.
- RSA / EC keys.
- Symmetric keys (HSM-backed).
- Use for: Encrypt/Decrypt, Sign/Verify, Wrap/Unwrap.
Encrypt using CryptographyClient.
var keyClient = new KeyClient(new Uri(vaultUri), new DefaultAzureCredential());
var cryptoClient = new CryptographyClient(
keyClient.GetKey("my-key").Value.Id,
new DefaultAzureCredential()
);
EncryptResult encrypted = await cryptoClient.EncryptAsync(
EncryptionAlgorithm.RsaOaep,
Encoding.UTF8.GetBytes("myData")
);
Certificate Management
- Supports import or generation of certificates.
- Auto-renew public certificates via CAs (like DigiCert).
- Direct integration with Azure App Service.
Authentication: Secure & Credential-Free
Identity Type |
Use Case |
Managed Identity |
For Azure-hosted apps (App Service, Functions, etc.) |
Service Principal |
For non-Azure apps or CI/CD pipelines |
User Identity |
For local development/debugging |
Use DefaultAzureCredential to simplify credential management.
RBAC vs Access Policies
Feature |
Access Policies |
RBAC |
Granular Control |
❌ |
✅ |
Scoped Access |
❌ Entire vault |
✅ Per-secret/key/cert |
Modern Standard |
Deprecated |
✅ Recommended |
Common roles: Key Vault Reader, Key Vault Secrets User, Key Vault Administrator.
Secret Versioning and Expiry
- Versioned Access: Retrieve previous versions.
- Expiry: Set TTL for secrets.
- Soft Delete & Purge Protection: Prevent data loss.
Monitoring and Compliance
- Enable diagnostic logs.
- Integrate with Azure Monitor / Log Analytics.
- Use Defender for Cloud for threat detection.
Use Cases
Scenario |
Vault Usage |
Store SQL credentials |
Secrets |
Encrypt sensitive data at rest |
Keys |
Secure JWT signing |
Keys (Sign) |
Manage SSL for web apps |
Certificates |
Best Practices
- Use Managed Identity (never store secrets in code).
- Enable RBAC over Access Policies.
- Turn on Soft Delete & Purge Protection.
- Enforce audit logging and monitoring.
- Rotate secrets/keys regularly.
Summary
Azure Key Vault helps you.
- Securely manage secrets, keys, and certificates.
- Eliminate hardcoded credentials.
- Enforce role-based access and auditing.
- Integrate security deeply into your .NET apps.