Prompt
How do I manage database passwords across dev, staging, and prod?
Latest observation
Oct 25, 2026
OpenAI APIWeb search: off
A good rule is: never hardcode database passwords in code, config files committed to git, or shared docs. Instead, use a secret management approach that changes by environment.
Recommended approach
1) Use separate credentials per environment
Have distinct database users/passwords for:
- dev
- staging
- prod
This limits blast radius if one environment is compromised.
2) Store secrets outside the repository
Common options:
- Environment variables for simple setups
- Secret managers for better security:
- AWS Secrets Manager / SSM Parameter Store
- HashiCorp Vault
- GCP Secret Manager
- Azure Key Vault
- Kubernetes Secrets, ideally encrypted with something like Sealed Secrets or external secret operators
3) Inject secrets at deploy/runtime
Your app reads the password from:
- environment variables
- mounted secret files
- a secret manager API at startup
Example pattern:
- Dev: local
.envfile not committed - Staging/Prod: secrets injected by CI/CD or orchestration platform
4) Rotate passwords regularly
Use:
- periodic rotation
- immediate rotation after staff changes or incidents
- automated rotation if supported by your secret manager/database
5) Use least privilege
Don’t use the same DB user everywhere. Create users with only the permissions needed:
- app read/write user
- migration user
- read-only reporting user
6) Make it environment-specific
Typical setup:
dev→ local.envstaging→ secret manager entrymyapp/staging/dbprod→ secret manager entrymyapp/prod/db
Practical examples
Simple local development
.envfile:DB_HOST=localhost DB_USER=myapp_dev DB_PASSWORD=dev-password- Add
.envto.gitignore
Production with a secret manager
- App gets
DB_PASSWORDfrom AWS Secrets Manager or Vault - CI/CD only deploys the app with permission to read that one secret
What to avoid
- Passwords in source code
- Committing
.envfiles with real secrets - Reusing the same password across environments
- Putting prod secrets in developer laptops
- Sharing passwords in Slack/email
Best practice summary
If you want the safest common pattern:
- Separate credentials per environment
- Store them in a secret manager
- Inject them at runtime
- Rotate them regularly
- Give each environment minimal privileges
If you want, I can also show you a concrete setup for Docker, Kubernetes, AWS, or GitHub Actions.