Secrets Management Fundamentals

What counts as a secret, why it must never live in Git or images, and the patterns for storing, delivering and rotating credentials.

Intermediate · about 3 hours · difficulty 2/5

Learn first: Configuration, Secrets, Storage and RBAC

A secret is anything that grants access: passwords, API keys, tokens, private keys, database URLs with credentials, signing keys. Leaked secrets are one of the most common causes of breaches, and they usually leak through Git history, container images, CI logs or chat.

Rules to live by

  • Never commit secrets, even to private repos. If one is committed, rotate it; deleting the commit is not enough.
  • Never bake secrets into images or pass them as build arguments.
  • Mask secrets in CI logs and avoid set -x around them.
  • Give each workload its own credentials with the least privilege it needs.
  • Prefer short-lived, dynamic credentials over long-lived static ones.

Where secrets live

  • Cloud secret managers: AWS Secrets Manager and Parameter Store, Azure Key Vault, Google Secret Manager.
  • Dedicated vaults such as HashiCorp Vault or OpenBao.
  • Encrypted files in Git with SOPS or Sealed Secrets, decrypted only at deploy time.
  • Kubernetes Secrets are only base64 encoded; enable encryption at rest and restrict RBAC.

Getting secrets to apps

Environment variables are simple but leak into crash dumps and child processes; mounted files are slightly safer and can be refreshed. Identity-based access (cloud IAM roles, workload identity) lets apps fetch secrets without a bootstrap secret at all.

Detection

Run scanners such as gitleaks or trufflehog in pre-commit hooks and CI, and enable push protection on your Git host.

Good enough to move on: you can explain why rotating beats deleting, list three storage options with trade-offs, and add secret scanning to a repository.

Key concepts

  • What counts as a secret
  • Leak paths: Git, images, logs
  • Cloud secret managers
  • Env vars vs mounted files
  • Rotation and short-lived credentials
  • Kubernetes Secret encryption at rest
  • Secret scanning with gitleaks

Mini project

Add gitleaks to a pre-commit hook and CI for one of your repositories, move an app's database password into a cloud secret manager, and have the app read it through its IAM role.

Check yourself

A developer pushed an API key and force-pushed to remove the commit a minute later. Is the key safe? What do you do?

Free resources