SECURITY ENGINEERING · PART 9 · DEVSECOPS AND SUPPLY CHAIN · PIPELINE · 133 OF 229

CI/CD Security: Runners, Tokens, Poisoned Pipelines

Your pipeline has the keys to production, so attackers target it directly. This episode covers securing the CI/CD system itself: why it is such a high-value target, poisoned pipeline execution and malicious pull requests, protecting runners and secrets, pinning third-party actions, least-privilege tokens and OIDC, protected branches, and treating the pipeline as the production system it really is.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21. 22
  22. 23
  23. 24
  24. 25
  25. 26
  26. 27
  27. 28
  28. 29
  29. 30
  30. 31
  31. 32
  32. 33
  33. 34
  34. 35
  35. 36
  36. 37
  37. 38
  38. 39
  39. 40
  40. 41
  41. 42
  42. 43
  43. 44
  44. 45
  45. 46
  46. 47
  47. 48
  48. 49
  49. 50
  50. 51
  51. 52
  52. 53
  53. 54
  54. 55
  55. 56
  56. 57
  57. 58
  58. 59
  59. 60
  60. 61
  61. 62
  62. 63
  63. 64
  64. 106
  65. 107
  66. 108
  67. 109
  68. 110
  69. 111
  70. 112
  71. 113
  72. 114
  73. 115
  74. 116
  75. 117
  76. 118
  77. 119
  78. 120
  79. 121
  80. 122
  81. 123
  82. 124
  83. 125
  84. 126
  85. 127
  86. 128
  87. 129
  88. 130
  89. 131
  90. 132
  91. 133
  92. 134
  93. 135
  94. 136
  95. 137
  96. 138
  97. 139
  98. 140
  99. 141
  100. 142
  101. 143
  102. 144
1 / 10

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • CI deploys to prod and holds the keys
  • no secrets on untrusted PRs
  • pin actions to SHAs
  • treat it as prod

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.

What CI can do
  • 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.

The classic attacks
  • 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.

Supply chain in CI
  • 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.

Protect the execution
  • 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.

Scope the access
  • 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.

Repo and config controls
  • 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.

Avoid these
  • 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.

In the interview
  • "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."

Interview questions

Q1Why is a CI/CD pipeline a high-value target?

Because it can build and deploy to production and holds the credentials to do so, including cloud, registry and signing keys, while running arbitrary repository code and often being less monitored than production. Compromising it lets an attacker ship signed, seemingly legitimate malware.

Q2What is poisoned pipeline execution?

An attack where a pull request modifies build configuration or scripts that the pipeline then executes, running attacker-controlled code within CI, potentially with access to secrets. It is prevented by not exposing secrets to untrusted pull-request builds and isolating where untrusted code runs.

Q3Why pin third-party CI actions to a commit SHA?

Because referencing an action by a moving tag pulls whatever that tag points to at run time, so a hijacked or maliciously updated action runs in your pipeline automatically. Pinning to an immutable commit hash and reviewing before updates prevents silent compromise.

Q4How should secrets be handled in CI?

Scope each secret to only the jobs that need it, mask them in logs, never expose them to jobs triggered by untrusted pull requests, prefer OIDC federation over stored long-lived cloud keys, and keep everything short-lived.

Q5Why are self-hosted runners a particular risk?

Because they often run inside the organisation's network with broad access and persist between jobs, so untrusted code or a compromised build can reach internal systems and leave persistent footholds. They should be ephemeral and strongly isolated.

Q6What is an ephemeral runner?

A build runner that uses a fresh, disposable environment for each job and is destroyed afterwards, so nothing persists between builds. This limits the blast radius of a compromised build and prevents attacker artefacts from carrying into later jobs.

Q7How do protected branches help pipeline security?

They prevent pushing directly to branches that deploy, requiring reviewed, approved pull requests to merge. Combined with required reviews and approval to run CI on external pull requests, they stop a single actor or outside contributor from injecting code into the build.

Q8Why review changes to pipeline configuration carefully?

Because the pipeline configuration determines what is built and shipped, so a change to it is effectively a change to production. Unreviewed edits to build scripts or workflow files can introduce malicious steps or exfiltrate secrets.