The .env file committed by accident stays in git history forever, even after the force push that promised to clean it. Secrets management treats credentials as data with a lifecycle: central vault, scheduled rotation, controlled injection into production. The migration fits inside a week of work for most teams.

Why does the .env leak?

The file travels between machines, lands in a careless commit, and stays recorded in history. During a debugging session at 11 PM, someone pastes the DATABASE_URL into Slack. Local convenience becomes organizational exposure. Git filter-repo applied after the fact recovers little: clones and forks already spread the value.

Secret manager options

  • HashiCorp Vault: dynamic secrets with leases and TTLs, broad integrations, heavy operation for small teams
  • AWS Secrets Manager and GCP Secret Manager: cloud-native simplicity at about $0.40 per secret/month
  • SOPS with age: encrypted files versioned in git, reviewable diffs on every pull request
  • 1Password Connect: the pragmatic option for teams of up to ten people

Dynamic credentials

Vault creates a database user per request, with TTLs measured in minutes. A leaked credential expiring in 15 minutes shrinks the blast radius from weeks to minutes. A connection string valid for six months is security debt with a deadline attached.

Rotation without downtime

Automated schedule: 90 days as the default, 30 for high-blast-radius keys. The dual-credential window keeps the old credential active while services migrate. Rehearse rotation before an incident forces the team up at 3 AM.

Production injection

Platform-native injection beats SDK calls inside the codebase. ECS task roles and the External Secrets Operator on Kubernetes sync from the vault straight into environment variables or mounted volumes. The sidecar pattern keeps vault dependencies off application code.

Local development

Issue short-lived personal credentials straight from the vault. Run gitleaks or trufflehog on pre-commit and CI to catch accidents before the push leaves the machine.

When a leak occurs

Documented playbook: revoke first, investigate second. Break-glass access gets logged and fires alerts. Forensics answers one objective question: which systems did that credential touch during the exposure window?