Prompt
How do I inject secrets into apps without hardcoding them in config files?
Latest observation
Oct 25, 2026
OpenAI APIWeb search: off
Use external secret injection instead of putting secrets directly in config files. Common patterns:
1) Environment variables
Set secrets at runtime, not in code or checked-in configs.
- App reads
DB_PASSWORD,API_KEY, etc. - Keep
.envout of git - Good for: simple apps, containers, CI/CD
Example:
export DB_PASSWORD='supersecret'
In app config:
import os
db_password = os.getenv("DB_PASSWORD")
2) Secret managers
Store secrets in dedicated systems and fetch them when the app starts.
Examples:
- AWS Secrets Manager
- HashiCorp Vault
- Azure Key Vault
- Google Secret Manager
- Kubernetes Secrets
Benefits:
- Rotation support
- Access control
- Audit logs
- Avoids storing secrets in plain config
3) Inject at deploy/runtime
Have your platform populate secrets automatically:
- Kubernetes: mount as env vars or files from Secrets
- Docker Compose: use env files or secrets
- CI/CD: set secret variables in pipelines
- Cloud platforms: Heroku, ECS, Cloud Run, etc. often support secret injection
4) Mount secrets as files
Instead of env vars, mount secrets into the filesystem and read them at runtime.
This is common for:
- TLS certs
- private keys
- service account tokens
Example path:
/run/secrets/db_password
5) Use configuration templating
Keep a non-secret template and render it during deployment:
config.template.yaml- Fill placeholders from env vars or secret store
- Output to runtime-only config file
Best practices
- Never commit secrets to git
- Use least privilege
- Rotate secrets regularly
- Prefer short-lived credentials when possible
- Separate secret storage from application config
- Restrict secret access to only the workloads that need them
Rule of thumb
- Simple app → environment variables
- Production / cloud → secret manager + runtime injection
- Kubernetes → Secrets or external secrets operator
- High security → secret manager + file mount + short-lived credentials
If you tell me your stack (Docker, Kubernetes, AWS, etc.), I can show the exact setup.