Prompt
How do I manage secrets across local dev, CI, and Kubernetes?
Latest observation
A good pattern is: don’t “manage secrets” in three different ways—manage them once as a source of truth, then sync/deliver them differently to local dev, CI, and Kubernetes.
Recommended approach
1) Use a central secret manager as the source of truth
Pick one:
- HashiCorp Vault
- AWS Secrets Manager / Parameter Store
- GCP Secret Manager
- Azure Key Vault
- Or a dedicated secrets platform like Doppler, 1Password Secrets Automation, Infisical
Store all sensitive values there:
- API keys
- DB passwords
- TLS certs
- signing keys
- OAuth client secrets
Keep these out of git entirely.
2) Local development: .env + secrets tool
For dev, the simplest workflow is usually:
- A checked-in
.env.examplewith placeholder names only - A personal untracked
.envfile - Optional sync from your secret manager via CLI
Example:
# .env.example
DATABASE_URL=
STRIPE_SECRET_KEY=
JWT_SECRET=
Then devs use:
cp .env.example .env
Better: use a secret manager CLI to load env vars:
doppler run -- npm startvault kv get ... | export ...aws-vault exec ...gcloud secrets ...
This avoids manually copying secrets around.
3) CI: short-lived credentials + secret injection at runtime
In CI:
- Avoid static long-lived cloud keys if possible
- Use OIDC / workload identity to authenticate the CI runner to your cloud or secret manager
- Pull secrets only for the job that needs them
- Inject them as environment variables or files during the job
Examples:
- GitHub Actions + OIDC to AWS/GCP/Azure
- GitLab CI JWT auth to Vault/cloud
- Jenkins with Vault plugin or cloud identity integration
Best practices:
- Mask secrets in logs
- Don’t echo env vars
- Rotate anything that must exist as a stored secret
- Prefer build-time secrets only when necessary
4) Kubernetes: external secrets, not committed Secret manifests
For Kubernetes, the best practice is usually:
Option A: External Secrets Operator
Use External Secrets Operator (ESO) to sync from your secret manager into Kubernetes Secret objects.
Flow:
- Secret lives in external secret store
- ESO reads it
- Kubernetes
Secretis created/updated automatically
Good when:
- You want native
Secretusage in pods - You already use cloud secret managers
Option B: Secrets Store CSI Driver
Mount secrets directly into pods as files from the external secret manager.
Good when:
- You prefer not to persist secrets in Kubernetes Secrets
- You want file-mounted certs/keys
Option C: Sealed Secrets / SOPS
If you need GitOps and want encrypted secrets in git:
- Bitnami Sealed Secrets
- Mozilla SOPS with age/GPG/KMS
Good when:
- You must store secret manifests in git, but encrypted
- You have a GitOps workflow
5) Use different delivery methods, same source
A clean model looks like this:
- Source of truth: Vault / cloud secret manager
- Local dev: CLI loads secrets into env vars
- CI: OIDC auth + fetch secrets at job runtime
- Kubernetes: ESO or CSI driver fetches from same source
That gives you:
- fewer copies of secrets
- easier rotation
- consistent permissions
- better auditability
6) Security principles to follow
- Least privilege: app/service only gets the secrets it needs
- Separate environments: dev/staging/prod have different secrets
- Rotate regularly
- Never commit secrets to git
- Avoid baking secrets into container images
- Prefer short-lived credentials
- Audit access
- Use secret scanning in git and CI
7) Practical example setup
If you want a straightforward modern setup:
- Source of truth: AWS Secrets Manager / Vault / Doppler
- Local dev:
.envgenerated or loaded from CLI - CI: GitHub Actions OIDC → cloud/secret manager
- Kubernetes: External Secrets Operator
This is a common, maintainable pattern.
8) What not to do
Avoid:
- hardcoding secrets in code
- storing secrets in Helm values files committed to git
- using the same prod secret in dev
- static cloud keys in CI if OIDC is available
- creating manual ad-hoc copies of secrets per environment
If you want, I can give you:
- a reference architecture,
- a GitHub Actions + Kubernetes example, or
- a tool-by-tool recommendation based on your cloud provider.