Prompt
How do I inject secrets into CI/CD without hardcoding them?
Latest observation
Oct 25, 2026
OpenAI APIWeb search: off
The usual pattern is: store secrets in a secret manager or CI/CD secret store, then inject them at runtime as environment variables or mounted files. Never commit them to source control.
Common options
1) Use your CI/CD platform’s built-in secrets
Most systems support encrypted secrets:
- GitHub Actions:
secrets.* - GitLab CI: masked/protected variables
- Jenkins: Credentials plugin
- CircleCI / Azure DevOps / Bitbucket Pipelines: secret variables
Example in GitHub Actions:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Run with secret
run: echo "Using secret safely"
env:
API_KEY: ${{ secrets.API_KEY }}
2) Use an external secret manager
Best for larger setups or production:
- HashiCorp Vault
- AWS Secrets Manager
- AWS SSM Parameter Store
- Azure Key Vault
- Google Secret Manager
- Kubernetes Secrets (often paired with encryption and external secret operators)
Your pipeline authenticates to the secret manager using a short-lived identity, fetches the secret at runtime, and passes it to the app.
Example flow:
- CI job starts
- It authenticates via OIDC/IAM/service account
- It reads the secret from the manager
- It exports it as an env var or writes it to a temp file
- The app uses it and the job ends
3) Prefer short-lived credentials over static secrets
If possible, avoid long-lived API keys entirely:
- Use OIDC federation from CI to cloud providers
- Use temporary IAM roles
- Use workload identity
- Use ephemeral tokens
This reduces risk if a pipeline is compromised.
Good practices
- Mask secrets in logs
- Restrict access to protected branches/environments
- Rotate secrets regularly
- Use least privilege
- Do not print env vars
- Avoid storing secrets in artifacts
- Separate dev/staging/prod secrets
- Use file mounts for large secrets like certs/keys
Example patterns
Environment variable injection
export DB_PASSWORD="$(fetch-secret db/password)"
File-based injection
fetch-secret tls/private_key > /tmp/private.key
chmod 600 /tmp/private.key
Kubernetes with secret mount
volumeMounts:
- name: app-secret
mountPath: /etc/secrets
readOnly: true
volumes:
- name: app-secret
secret:
secretName: app-secret
Rule of thumb
- Small/simple CI: use built-in CI secrets
- Production/enterprise: use a secret manager + OIDC/short-lived auth
- Never hardcode secrets in code, images, or pipeline files
If you want, I can show a concrete example for GitHub Actions, GitLab CI, Jenkins, or Kubernetes.