A CI/CD system is one of the most privileged pieces of software in any organization. It can read every repository, it holds credentials for every environment, and its output runs in production. That makes it an attractive target — compromise the pipeline and you don’t need to compromise anything else.
The good news is that most of the risk comes from a handful of well-understood gaps. The controls below are grouped by area; the last section suggests an order to tackle them. Examples use GitHub Actions and AWS because they are common, but every major CI system and cloud provider has an equivalent.
1. Replace long-lived cloud keys with OIDC federation
Static access keys stored as CI secrets are the most common way pipeline compromises turn into cloud compromises. They don’t expire, they’re often over-privileged, and they’re easy to exfiltrate from a malicious build step.
Instead, let the CI job exchange a short-lived OpenID Connect token for temporary cloud credentials:
permissions:
contents: read
id-token: write # allow this workflow to request an OIDC token
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@<full-commit-sha> # pin, see section 3
- uses: aws-actions/configure-aws-credentials@<full-commit-sha>
with:
role-to-assume: arn:aws:iam::123456789012:role/deploy-production
aws-region: us-west-2
The important part lives on the cloud side: the role’s trust policy should accept tokens only from the specific repository and environment allowed to deploy.
"Condition": {
"StringEquals": {
"token.actions.githubusercontent.com:aud": "sts.amazonaws.com",
"token.actions.githubusercontent.com:sub": "repo:your-org/your-service:environment:production"
}
}
A trust policy that only checks the organization name lets any repository in it assume the role — scope it as tightly as you would a password.
2. Give every job the least privilege it needs
Set the default token permissions for workflows to read-only at the organization level, then grant extra scopes per job. A job that runs unit tests has no reason to push tags, publish packages or comment on pull requests.
The same principle applies to deployment roles: separate roles for each environment, with production permissions that cover deployment and nothing else.
3. Pin third-party dependencies of the pipeline itself
A reference like some-org/some-action@v3 points to a tag that its owner — or anyone who compromises the owner — can move. Pin third-party actions, plugins and build images to an immutable reference instead:
- actions and reusable workflows to a full commit SHA;
- container images to a digest (
image@sha256:…), not a tag; - tool downloads to a checksum you verify before use.
Pinning is only sustainable with automation, so pair it with a dependency-update bot that proposes new SHAs and digests as reviewable pull requests.
4. Protect the pipeline definition
If anyone who can open a pull request can also change what the pipeline does with production credentials, the rest of these controls can be bypassed. At a minimum:
- require reviews on the default branch and block force-pushes;
- add a
CODEOWNERSrule and enable Require review from Code Owners on the branch rule, so changes to workflow files need approval from the platform or security team; - restrict which branches can deploy to protected environments, and require approvals for production.
5. Never run untrusted code with secrets
Pull requests from forks — and from compromised contributor accounts — are untrusted code. Keep the workflows that build and test pull requests separate from the ones that hold secrets or publish artifacts.
Be especially careful with triggers that run in the context of the base repository, such as pull_request_target. Checking out and executing the pull request’s code inside such a workflow hands that code your secrets.
6. Use ephemeral, isolated runners
A runner that persists between jobs can carry a compromise from one build into the next: a poisoned cache, a modified toolchain, a leftover credential. Prefer runners that are created fresh for each job and destroyed afterwards. If you operate self-hosted runners, isolate them per trust level and never attach them to public repositories.
7. Treat secrets as short-lived and scoped
Even with OIDC, some secrets remain — API tokens, signing keys, third-party credentials. Store them in a secrets manager or your CI’s environment-scoped secrets, expose them only to the jobs that need them, and rotate them on a schedule. Run secret scanning both before commit and in CI, so a leaked credential is caught in minutes rather than months.
8. Know what you ship: SBOMs and dependency scanning
Generate a software bill of materials for every build artifact and keep it alongside the artifact. It turns “are we affected by this new vulnerability?” from a week of archaeology into a query.
Scan dependencies and images as part of the pipeline, but be deliberate about policy: blocking every finding trains people to bypass the gate, while blocking nothing makes it decoration. Start by failing builds on known-exploited or critical issues with an available fix, and report the rest.
9. Sign artifacts and verify them before deploying
Signing build outputs — and attaching provenance that records which source, which workflow and which builder produced them — lets you prove that what’s running in production came from your pipeline. Open tooling such as Sigstore makes keyless signing practical, and the SLSA framework is a useful map for how far to take provenance.
Signing only helps if something checks the signature. Verify at deploy time, for example with an admission policy in Kubernetes that rejects unsigned images or images built outside your trusted workflows.
10. Audit everything the pipeline does
Keep a durable record of pipeline changes, deployments, approvals and credential use, and forward it somewhere the pipeline itself can’t modify. Alert on the unusual: a workflow file changed outside a reviewed pull request, a production deployment from an unexpected branch, a role assumed from a repository that has never used it.
A sensible order of operations
You don’t need to do all ten at once. A practical sequence for most teams:
- This week: read-only default token permissions (2), branch protection and
CODEOWNERSfor workflow files (4), and no secrets in workflows that run untrusted pull-request code (5). - This month: OIDC federation for cloud access (1), pinned third-party actions with automated updates (3), secret scanning (7).
- This quarter: ephemeral runners (6), SBOM generation (8), artifact signing and verification at deploy time (9), and audit logs forwarded out of the pipeline’s reach (10).
Each step closes a real class of attack, and none of them requires stopping feature work.
Enforcing controls like these consistently across hundreds of repositories is exactly what pipeline templates are for — it’s a big part of why we’re building Zentral Flow. If you’d like a second pair of eyes on your pipeline’s security, Zentral Minds offers hands-on DevSecOps consulting.