What is secrets management, and why shouldn't secrets be in code?
BeginnerConceptSecurity basics for DevOps
Answer
In one line: Secrets management is storing, distributing, rotating and auditing sensitive values — passwords, API keys, certificates, tokens — in a secure system, instead of putting them in code, config files or images.
Why secrets in code are dangerous:
- Git keeps history forever — deleting the line later doesn't remove it from old commits.
- Code spreads — forks, clones, CI logs, laptops, backups and AI tools all get a copy.
- Public leaks — bots scan GitHub for keys within minutes of a push; leaked cloud keys are often abused for crypto mining almost immediately.
- No rotation or audit — you can't easily change the secret or see who used it.
- Same secret everywhere — dev and prod end up sharing credentials.
Proper secrets management:
- Central secret stores: HashiCorp Vault, AWS Secrets Manager / SSM Parameter Store, Azure Key Vault, GCP Secret Manager.
- Inject at runtime — environment variables or mounted files, fetched when the app or pipeline starts.
- Kubernetes: External Secrets Operator or the Secrets Store CSI driver to sync from the vault; Sealed Secrets or SOPS if encrypted secrets must live in Git.
- Least privilege — each app can only read its own secrets.
- Rotation — change secrets regularly and automatically where possible.
- Dynamic secrets — Vault can create short-lived database credentials per app that expire automatically.
- Audit logs — record who accessed which secret and when.
- Workload identity / OIDC — often the best secret is no secret: pods and pipelines get temporary cloud credentials based on their identity.
Prevention:
- Pre-commit hooks and CI scanning with Gitleaks or TruffleHog.
- GitHub secret scanning and push protection.
.gitignorefor.envfiles.
If a secret leaks: rotate/revoke it immediately, check logs for misuse, then clean up history — rotating comes first.
Tip for interviews: mention runtime injection, rotation and scanning — and that rotation is the first step after a leak.
More on Security basics for DevOps
What is the principle of least privilege?BeginnerWhat is SAST, DAST and SCA?BeginnerWhat is a CVE, and how do you handle vulnerabilities found by scanners?BeginnerWhat is container image scanning, and where should it happen?BeginnerWhat is software supply chain security (SBOM, image signing, SLSA)?IntermediateWhat is encryption in transit and encryption at rest?Beginner