Notes
Why CI is a target
Why is CI such a target? Look at what it can do. It deploys to production. It holds cloud credentials, registry logins and signing keys. By its nature it runs arbitrary code from the repository, because building and testing is running code. And it is often trusted implicitly and monitored far less than production. So an attacker who compromises the pipeline can sign and ship malware that looks legitimate to every downstream check. It is a high-privilege system teams routinely under-protect.
- deploy to production
- hold cloud, registry and signing credentials
- run arbitrary code from the repo (that is its job)
- often trusted implicitly and under-monitored
- compromise it = sign and ship malware as "legitimate"
Poisoned pipeline
The classic attack is poisoned pipeline execution. A pull request modifies the build config or a script the pipeline then runs, and if that pipeline has secrets, the attacker's code runs with them. A malicious pull request from an outside fork tries to read your secrets during CI. The root problem is untrusted code, anyone's pull request, running on a runner with production access. The defence: never expose secrets to untrusted pull requests, and isolate where untrusted code runs from where secrets live.
- PPE: a PR changes the build config or a script, which then runs in CI with secrets
- malicious PR from a fork tries to read secrets or tokens
- untrusted code runs on a runner that has prod access
- fix: do not expose secrets to untrusted PRs; isolate
Third-party actions
The supply-chain attacks from earlier apply to CI too. Every third-party action or plugin you use runs with your pipeline's access. When a popular CI action is hijacked, it suddenly runs in thousands of pipelines, which has happened, harvesting secrets. And referencing an action by a moving tag like at-v-three means you get whatever that tag points to today, including a malicious update. The fix is to pin third-party actions to a specific commit hash, not a tag, and review before bumping them.
- CI actions/plugins run with your pipeline's access
- a popular action gets hijacked -> it runs in thousands of pipelines (this has happened)
- referencing by a moving tag (@v3) pulls whatever that tag points to now
- pin to a commit SHA, review before updating
Runners and secrets
Protect where builds run. Use ephemeral runners, a fresh environment per job, so nothing an attacker leaves persists into the next build. Isolate runners from production networks so a compromised build cannot reach everything. Scope each secret to only the jobs that need it, and mask secrets in logs. Never give secrets to jobs triggered by untrusted pull requests. And be especially careful with self-hosted runners, which are a common target because they often sit inside your network with broad access.
- ephemeral runners: fresh environment per job, nothing persists between builds
- isolate runners from prod networks
- scope secrets to the jobs that need them; mask in logs
- no secrets on untrusted-PR jobs
- self-hosted runners: isolate hard, they are a big target
Least-privilege tokens
Scope what the pipeline can do. Default CI tokens are often far more powerful than a job needs, so restrict them, read-only by default, write only where required. Use OIDC federation so there is no stored long-lived cloud key, as episode nine covered. Use separate credentials per environment, keeping production access distinct and gated behind extra approval. Make everything short-lived. And audit what the pipeline can actually reach, because teams are often surprised a build job holds production credentials.
- default CI tokens are often over-permissioned; restrict them (read-only by default)
- OIDC federation: no stored long-lived cloud key (ep 9)
- separate credentials per environment; prod is separate and gated
- short-lived everything
- audit what the pipeline can actually reach
Protect the source
Finally, the pipeline is only as trustworthy as the repository driving it. Use protected branches and require reviews before merge, so no one can push straight to what deploys. Require manual approval before CI runs on outside pull requests, blocking the fork attack. Sign commits and protect release branches. Treat pipeline config changes as production changes needing review, because changing the build changes what ships. And secure the git platform with branch protection and strong authentication.
- protected branches; required reviews before merge
- require approval to run CI on outside PRs
- sign commits; protect release branches
- review changes to pipeline config like production code
- branch protection and 2FA on the git platform itself
Common mistakes
Mistakes. Exposing secrets to builds from untrusted pull requests, the poisoned-pipeline hole. Pinning third-party actions to moving tags instead of commit hashes, so a hijack reaches you automatically. Over-permissioned CI tokens and long-lived cloud keys in the pipeline. Self-hosted runners on the production network with broad access. Treating pipeline config changes as ordinary, unreviewed edits, when they change what ships. And monitoring CI far less than production, despite it being just as powerful.
- secrets exposed to untrusted PR builds
- third-party actions pinned to moving tags, not SHAs
- over-permissioned CI tokens and long-lived cloud keys
- self-hosted runners with prod network access
- no review on pipeline config changes
- CI monitored less than prod
Say it like this
In the interview: I treat the CI/CD system as production, because it can deploy there and holds the keys. I never expose secrets to untrusted pull-request builds, use ephemeral runners isolated from production, and pin third-party actions to commit hashes, not moving tags. I give pipeline tokens least privilege and short lifetimes, using OIDC instead of stored cloud keys. I protect branches with required reviews, require approval to run CI on outside pull requests, and review pipeline config like production code.
- "Treat CI as production. No secrets on untrusted PR
- builds, ephemeral isolated
- runners, third-party actions
- pinned to SHAs, least- privilege short-lived tokens
- with OIDC not stored keys, protected branches and required reviews, and pipeline
- config reviewed like prod code."