CI/CD security
The CI/CD pipeline has access to the code, the deployment secrets, and production: compromising it is compromising everything it builds and deploys. SolarWinds showed that attacking the build is more profitable than attacking an endpoint. This card covers how to secure the software supply chain from commit to deployed artifact.
Threat model
Section titled “Threat model”The pipeline is a prime target because it concentrates trust: everyone trusts whatever comes out of it. The attack classes (aligned with the OWASP Top 10 CI/CD):
- Insufficient flow control (CICD-SEC-1): a PR that modifies the workflow itself and self-approves, or a direct push to
mainwith no review. - Poisoned pipeline execution — PPE (CICD-SEC-4): the attacker injects commands into the pipeline through a config file the pipeline executes (a
Makefile, a test script, a misusedpull_request_target). - Pipeline dependencies (CICD-SEC-3): a third-party action or plugin left unpinned (
@master) is updated with malicious code. - Credential hygiene (CICD-SEC-6): long-lived secrets in CI variables, tokens with excessive permissions.
- Artifact integrity (CICD-SEC-9): nobody verifies that the deployed binary is the one that came out of the build.
flowchart LR
DEV["Commit / PR"] --> REV{"Review + checks"}
REV -->|approved| BUILD["Build in isolated runner"]
BUILD --> SCAN["SAST · SCA · secrets"]
SCAN --> SIGN["Sign (cosign) + SBOM"]
SIGN --> REG["Artifact registry"]
REG --> VERIFY{"Signature/provenance verification"}
VERIFY -->|OK| DEPLOY["Deploy"]
VERIFY -->|fail| STOP["Reject"]
ATK["Attacker"] -. PPE / malicious action .-> BUILD
ATK -. stolen secret .-> REG
Real cases
Section titled “Real cases”Two incidents that defined the discipline:
- SolarWinds (2020): attackers compromised the Orion build process and injected the SUNBURST backdoor into the signed artifact. Customers received a legitimately signed update with malware inside. Lesson: signing isn’t enough if the build is compromised; you must protect provenance.
- Codecov (2021): the
bash uploaderscript that thousands of pipelines ran viacurl | bashwas modified, exfiltrating environment variables (secrets) from victims’ CIs. Lesson: everything the pipeline downloads and runs is part of your attack surface.
Hardening the pipeline
Section titled “Hardening the pipeline”Concrete controls, highest to lowest impact:
Isolate and minimize the runner: each job in an ephemeral environment, no persistent state, minimal network and permissions. Short-lived tokens, not static secrets.
Pin pipeline dependencies by hash, not a moving tag:
# BAD: moving tag, can change under your feet- uses: some/action@v3# GOOD: pinned to the exact commit- uses: some/action@a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0Minimal token permissions and OIDC to the cloud instead of keys:
permissions: contents: read id-token: write # OIDC to authenticate to the cloud without static secretsBranch protection: mandatory review, protected main, the workflow can’t be modified without a code owner approval.
Signing and provenance (SLSA + Sigstore)
Section titled “Signing and provenance (SLSA + Sigstore)”To close the SolarWinds lesson, signing the artifact isn’t enough: you must be able to prove where it came from and how it was built.
- SLSA (Supply-chain Levels for Software Artifacts): a levels framework (L1-L3+) defining provenance integrity guarantees. The higher level requires building in an isolated service and automatic generation of a non-forgeable provenance attestation.
- Sigstore / cosign: artifact signing without managing long-lived keys, using OIDC identity and a transparency log (Rekor).
# Sign an image with OIDC identity (keyless), recorded in Rekorcosign sign --yes registry.example/myapp@sha256:<digest>
# Verify signature and the identity that issued it, before deployingcosign verify \ --certificate-identity-regexp "https://github.com/acme/.+" \ --certificate-oidc-issuer "https://token.actions.githubusercontent.com" \ registry.example/myapp@sha256:<digest>The deployment gate must verify the signature and provenance; an artifact without a valid attestation isn’t deployed.
Red Team
Section titled “Red Team”- PPE: look for inputs the pipeline executes. A repo running
make testruns whatever is in a PR’sMakefile; a workflow withpull_request_targetthat checks out the PR code grants execution with the base repo’s secrets. - Unpinned actions: enumerate workflow dependencies (
@master,@v3) an attacker could compromise upstream. - CI secrets: from execution on the runner, dump environment variables and tokens (the Codecov lesson). Reuse them against the registry and production.
- Self-approval and missing branch protection: PRs that merge themselves, bots with write permissions, workflows modifiable without review.
Blue Team
Section titled “Blue Team”- Ephemeral, isolated runners, short-lived tokens, OIDC to the cloud.
- Pin by hash all actions and plugins; review before updating.
- Minimal permissions per job; never
write-all. - Branch protection with mandatory review and code owners over workflows.
- Signing + SBOM in the build; mandatory verification at deploy.
- No
curl | bashof unpinned external resources without hash verification. - Audit the pipeline itself with the OWASP Top 10 CI/CD as a checklist.
Checklist
Section titled “Checklist”- Ephemeral, stateless runners with minimal network and permissions.
- Actions/plugins pinned by hash, not tag.
- Minimal token permissions per job (no
write-all). - OIDC to the cloud instead of static keys.
- Branch protection + mandatory review + code owners on workflows.
- Artifact signing (cosign) and SBOM generation.
- Signature/provenance verification as a deploy gate.
- A defined and measured SLSA target.
- No external
curl | bashwithout hash verification. - Periodic audit against the OWASP Top 10 CI/CD.