Last updated: April 29, 2026
Every application has secrets — database passwords, API keys, TLS certs, encryption keys, third-party tokens. Where you store them determines whether a compromise is contained or catastrophic. This module covers secrets-management patterns for modern cloud applications.
The problem
Secrets historically lived in: environment variables, config files, source code, shared spreadsheets, Slack messages, CI/CD logs. Each is a leak vector. Secrets exposed in any of these = full compromise of whatever they protect.
Where secrets leak
- Git commits — AWS keys in .env files; ~1 in 500 commits to public GitHub leaks a secret
- Docker image layers — secrets via COPY / ENV persist in history even if later removed
- CI/CD logs — echo statements with credentials
- Error messages + stack traces — credentials in connection strings
- Server logs — requests with API keys in query strings
- Lost/stolen laptops — ~/.aws/credentials, config files
- Insider threats — departing employees with credentials in password managers
Managed secret stores — the solution
| Service | Strengths |
|---|---|
| AWS Secrets Manager | Auto-rotation (RDS, Redshift, etc.), versioning, KMS-encrypted, IAM-controlled |
| AWS SSM Parameter Store | Simpler, cheaper; no auto-rotation; good for config + secrets |
| Azure Key Vault | Secrets + keys + certificates; HSM-backed option |
| GCP Secret Manager | Secrets versioning + IAM |
| HashiCorp Vault | Cross-cloud, dynamic secrets (issue DB creds on-demand), multi-engine, self-hosted |
| Doppler / Infisical | Dev-friendly SaaS alternatives |
Core patterns
1. Runtime fetch
Application starts → authenticates to secret store via workload identity (IAM role / Managed Identity / Service Account) → fetches current secret → uses it. Never a secret on disk or in env.
# Python — fetch at startup
import boto3, json
client = boto3.client('secretsmanager')
secret = json.loads(client.get_secret_value(SecretId='prod/db')['SecretString'])
db_password = secret['password']
2. Mount as file / env
Kubernetes: Secrets Store CSI Driver mounts secrets as files in pod’s filesystem. External Secrets Operator syncs external secret stores to K8s Secrets.
3. Dynamic secrets (Vault)
Vault’s killer feature: generate database credentials on-demand with short TTL. App gets fresh creds each session; creds auto-expire. No static password to rotate.
Rotation
- AWS Secrets Manager — built-in rotation for RDS, Redshift, DocumentDB; custom Lambda for others
- Vault — dynamic secrets auto-rotate by design
- Custom — scheduled jobs that generate new secret, update app config, verify, delete old
Rotation cadence: regular (90 days for application secrets), event-driven (after known exposure), auto (dynamic secrets).
Secret scanning
- Git pre-commit hooks — detect-secrets, gitleaks, git-secrets — block commits with pattern matches (AWS key format, private key headers, etc.)
- GitHub secret scanning — built-in, free for public repos
- GitGuardian / Doppler / similar — scan + alert on repos continuously
- CI/CD scanning — TruffleHog, semgrep for code repos
Common mistakes
- Secrets in environment variables visible via
docker inspector container runtime APIs - Writing secrets to log files during startup (“Loaded config: DB_PASSWORD=…”)
- Hardcoded fallback secrets (“if env var missing, use ‘changeme'”)
- Using the same secret across dev/staging/prod
- Not revoking credentials when employees leave
- Committing .env.example with actual values accidentally
When a secret leaks
- Revoke immediately — rotate the secret
- Audit usage — CloudTrail / equivalent for the credential; was it used maliciously?
- Investigate the leak path — git history, logs, Slack; understand how it happened
- Add controls to prevent recurrence — pre-commit hooks, secret scanning, review process
- Document incident + retrospective
Quick reference summary
- Secrets in code, config files, env vars, logs = constant leak risk
- Managed stores: AWS Secrets Manager / SSM Parameter Store, Azure KV, GCP SM, Vault
- Workload identities (IAM role, Managed Identity, SA) fetch secrets at runtime — no long-lived creds
- Dynamic secrets (Vault) = short-TTL on-demand, auto-rotating by design
- Rotation: 90-day baseline, event-driven for incidents, automatic for RDS-type
- Pre-commit hooks + secret scanning prevent accidental commits
- Incident response: rotate → audit → investigate → harden
Module Quiz · 20 questions
Pass with 80%+ to mark this module complete. Unlimited retries. Each question shows an explanation.
Custom team training + practitioner advisory
Beyond the free academy — we run private workshops, vCISO advisory, and red-team exercises tailored to your stack. For Indian SMBs scaling past their first hire.