🟢 What is Azure Key Vault?
- A cloud service for securely storing and accessing secrets, keys, and certificates.
- Removes the need to keep secrets (like connection strings, passwords, API keys) inside code or config files.
- Provides centralized secret management, encryption, and access control.
👉 Think of it like a secure password manager but for your applications.
🟢 Key Features
- Secrets → store text values (e.g., DB connection string, API key).
- Keys → store cryptographic keys (RSA, EC) for encryption, signing.
- Certificates → store/manage SSL/TLS certificates.
- Access Control →
- Access Policies (older model).
- Azure RBAC (modern, preferred).
- Integration → works with App Service, Functions, AKS, VMs, SQL DB, etc.
- Logging → audit who accessed secrets via Azure Monitor / Diagnostic Logs.
🟢 Why Use Key Vault?
- Security → secrets are encrypted with HSM (Hardware Security Modules).
- Compliance → meet industry standards (PCI-DSS, ISO, GDPR).
- Automation → auto-rotate secrets & certificates.
- Centralized Management → single place for secrets across apps.
🟢 Accessing Key Vault
- Azure Portal / CLI → manually store secrets.
- Applications → use Managed Identity for secure access.
- SDKs → Azure SDK for .NET, Python, etc.
👉 Never hardcode secrets. Instead, use DefaultAzureCredential
from SDK.
🟢 Example: Access Key Vault in .NET
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
using System;
using System.Threading.Tasks;
class Program
{
static async Task Main()
{
// Key Vault URL
string kvUrl = "https://<your-keyvault-name>.vault.azure.net/";
// Authenticate using Managed Identity / Azure AD
var client = new SecretClient(new Uri(kvUrl), new DefaultAzureCredential());
// Get a secret
KeyVaultSecret secret = await client.GetSecretAsync("DbConnectionString");
Console.WriteLine($"✅ Secret value: {secret.Value}");
}
}
🟢 Security Best Practices
- Use Managed Identity for apps (don’t use keys/passwords).
- Use RBAC instead of Access Policies for fine-grained access.
- Rotate secrets regularly (Key Vault supports auto-rotation).
- Enable soft delete and purge protection to prevent accidental loss.
🟢 Common Interview Questions
- What is Azure Key Vault and why is it used?
- Difference between Secrets, Keys, and Certificates?
- How does an App Service access Key Vault without storing credentials?
- Access Policies vs. Azure RBAC → which one is recommended?
- How do you secure access to Key Vault?
- Can Key Vault auto-rotate secrets?
- Difference between Key Vault and App Config?
- How do you monitor Key Vault usage?
🟢 Pros & Cons
✅ Pros
- Centralized, secure secret management.
- Easy integration with Azure services.
- RBAC + Managed Identity support.
- HSM-backed key storage.
❌ Cons
- Latency overhead (extra call to Key Vault).
- Costs increase with high-frequency secret access.
- Requires internet access (unless using private endpoints).
✅ Quick Recap
- Azure Key Vault = secure store for secrets, keys, and certificates.
- Access using Managed Identity + Azure SDK.
- Use RBAC (modern) instead of Access Policies.
- Best practices → rotate secrets, enable purge protection, monitor access.
Comments
Post a Comment