Prompt
What is the best approach for secret management in CI/CD?
Latest observation
Oct 25, 2026
OpenAI APIWeb search: off
The best approach is usually a centralized secrets manager plus short-lived access in the pipeline, rather than storing secrets directly in CI/CD variables or source control.
Recommended pattern
-
Store secrets in a dedicated secrets manager
- Examples: HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, GCP Secret Manager, Doppler, 1Password SCIM/CLI, etc.
- Keep secrets out of Git, build configs, and plain CI variables where possible.
-
Use workload identity / OIDC instead of long-lived credentials
- Your CI system authenticates to the secrets manager using OIDC or federated identity.
- This avoids static cloud keys in CI.
- The pipeline gets temporary, scoped credentials only when needed.
-
Inject secrets at runtime
- Fetch secrets only in the job that needs them.
- Don’t write them to disk unless necessary.
- Mask them in logs and avoid echoing environment variables.
-
Use least privilege and separation
- Give each pipeline/job/service only the secrets it needs.
- Separate dev/staging/prod secrets.
- Use per-environment and per-service namespaces or paths.
-
Rotate and expire secrets
- Prefer dynamic secrets when possible, especially for databases and cloud access.
- Set expiry, automatic rotation, and revocation workflows.
-
Audit and monitor access
- Track who/what accessed which secret and when.
- Alert on unusual access patterns.
What to avoid
- Committing secrets to Git, even in private repos.
- Storing long-lived cloud access keys directly in CI/CD settings if OIDC/federation is available.
- Sharing one “master” secret across all pipelines.
- Printing secrets in logs or passing them through artifacts.
Practical baseline
If you want a strong default architecture:
- GitHub Actions / GitLab CI / Jenkins authenticate via OIDC
- CI gets a short-lived token from your cloud provider or Vault
- Pipeline fetches secrets from Secrets Manager/Vault
- Secrets are scoped per environment and rotated regularly
If you tell me which CI/CD platform and cloud you use, I can suggest a concrete setup.