Secrets Management
Storing API keys, database passwords, and credentials securely.
1The Safety Deposit Box Analogy
Secrets are sensitive credentials: API keys, database passwords, private keys, tokens. Secrets management is storing, accessing, and rotating them securely.
2Where NOT to Store Secrets
In Source Code
git push → secret in GitHub → scraped by bots → compromised in minutes
In .env Files Committed to Git
.env in repo = .env in everyone's clone. Add to .gitignore!
In Docker Images
docker history exposes build args. Images on public registries = leaked secrets.
In Logs
Accidentally logging config or request bodies with secrets.
In Environment Variables (Unencrypted)
Better than code, but still visible with env command or process inspection.
3Secrets Management Solutions
AWS Secrets Manager
AWS native. Auto-rotation for RDS. $0.40/secret/month.
HashiCorp Vault
Industry standard. Self-hosted or HCP. Dynamic secrets.
Azure Key Vault
Azure native. HSM-backed. Integrates with Azure services.
Google Secret Manager
GCP native. Simple API. Automatic replication.
4Best Practices
Never Commit Secrets
Use .gitignore, pre-commit hooks (like git-secrets), and CI checks.
Rotate Regularly
Automate rotation. If a secret is compromised, rotation limits damage window.
Least Privilege
Each service gets only the secrets it needs. Separate DB passwords per service.
Audit Access
Log who accessed which secrets. Alert on unusual access patterns.
Use Short-Lived Credentials
Dynamic secrets that expire. Better than static keys.
5Environment Variables Done Right
Hierarchy (from least to most secure)
6What to Do When Secrets Leak
7Key Takeaways
?Quiz
1. You pushed an API key to GitHub. First step?
2. Best place for production database password?