CI/CD security: your pipeline holds the keys
Pipelines run code from pull requests, pull third-party actions and hold credentials for production. That makes them one of the most valuable targets you own. The settings that keep a stranger's PR from becoming a deploy.
In one sentence
Treat PRs from forks as untrusted code, pin actions to a commit SHA, use OIDC instead of stored cloud keys, and gate deploys behind protected branches and reviewers.
What can a pull request reach?
A stranger's PR can steal secrets and ship code to production.
Pipeline hardening checklist
- Fork PRs get no secrets. Be careful with
pull_request_targetand similar triggers that run with secrets on untrusted code. - Pin third-party actions to a full commit SHA, not a tag that can be moved.
- OIDC federation to your cloud: the job gets a short-lived role scoped to that repo and branch; nothing to leak.
- Least-privilege tokens: the default
GITHUB_TOKENread-only, write permissions only where a job needs them. - Separate build and deploy; deploy only from protected branches with required reviews and environment approvals.
- Signed artifacts / provenance (e.g. SLSA, Sigstore) so production only runs what your pipeline built.
permissions:
contents: read
id-token: write # OIDC, no stored AWS keys
steps:
- uses: actions/checkout@<full-commit-sha>
- uses: aws-actions/configure-aws-credentials@<full-commit-sha>
with:
role-to-assume: arn:aws:iam::123456789012:role/deploy-web-mainKey takeaways
- 01CI/CD is production infrastructure with access to everything.
- 02Never expose secrets to workflows running untrusted PR code.
- 03Pin actions to SHAs and prefer OIDC over stored keys.
- 04Deploy only from protected branches with approvals.
Check your understanding
1 of 3
How should pull requests from forks be treated?
Related concepts
Supply chain
Pin versions with a lockfile and npm ci, restrict install scripts, review new dependencies and updates, keep an SBOM, and give your build as few secrets as possible.
7 min read →Secrets management
A secret in a repo is leaked, even after you delete it. Keep secrets in a vault or the platform's secret store, scan before push, scope every key, and revoke first, investigate second.
6 min read →Least privilege
Assume something will get hacked. Least privilege makes sure that when it does, the attacker gets the keys to one room, not the whole building.
6 min read →