Interview Prep/DevOps Fundamentals/Security basics for DevOps

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:

  1. Git keeps history forever — deleting the line later doesn't remove it from old commits.
  2. Code spreads — forks, clones, CI logs, laptops, backups and AI tools all get a copy.
  3. Public leaks — bots scan GitHub for keys within minutes of a push; leaked cloud keys are often abused for crypto mining almost immediately.
  4. No rotation or audit — you can't easily change the secret or see who used it.
  5. 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.
  • .gitignore for .env files.

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.

All DevOps Fundamentals questions

More on Security basics for DevOps