Modern Secrets Management: Beyond Environment Variables
Secrets (API keys, database passwords, certificates) are the keys to your kingdom. Yet, they are often the weakest link in application security. Storing them in code repositories or unencrypted environment variables is no longer acceptable.
The Evolution of Secrets Management
- The Dark Ages: Hardcoded secrets in source code.
- The Middle Ages: Secrets stored in
.envfiles or CI/CD variables (unencrypted at rest). - The Renaissance: Centralized secrets managers (HashiCorp Vault, AWS Secrets Manager, Azure Key Vault).
- The Modern Era: Identity-based access and Dynamic Secrets.
The Power of Dynamic Secrets
The best secret is the one that doesn't exist yet. Modern vaults can generate database credentials on-the-fly when an application starts, and revoke them automatically when it stops. If a credential is leaked, it's only valid for a short time and has limited scope.
Best Practices
- Centralize: Use a single source of truth for all secrets.
- Inject, Don't Store: Inject secrets at runtime into the application memory or via ephemeral files (Kubernetes Secrets).
- Rotate Frequently: Automate the rotation of long-lived secrets to reduce the window of exposure.
- Audit Everything: Know exactly who accessed which secret and when.
How to implement it in practice
If you want a secure-by-default setup, focus on two things: identity and delivery.
- Use workload identity: authenticate workloads via Kubernetes ServiceAccounts / cloud IAM roles, not shared static tokens.
- Fetch at runtime: pull secrets during startup (or on demand) and keep them in memory when possible.
- Prefer short-lived credentials: dynamic DB users, signed tokens, short-lived certificates.
If you still need Kubernetes Secrets, treat them as a distribution mechanism (and encrypt etcd).
Common pitfalls
- Copying secrets into config files: you just moved the problem.
- Over-permissioned vault access: least privilege per app and per environment.
- No rotation plan: automate rotation for anything long-lived (API keys, certs).
- Ignoring developer experience: provide templates and docs so teams don’t invent ad-hoc patterns.
A simple starting point
Start with one critical service and implement:
- vault integration + audit logging
- one dynamic secret (database credentials)
- an automated rotation job for remaining static secrets
Conclusion
Modern secrets management is about moving away from static, long-lived credentials toward identity-based, dynamic access. It reduces the impact of leaks and significantly hardens your application's security posture.
Want to go deeper on this topic?
Contact Demkada