How do you secure a CI/CD pipeline itself?
In one line: Treat the pipeline as a production system: protect its configuration, give it least-privilege short-lived credentials, isolate runners, verify everything it uses and produces, and audit what it does — because a compromised pipeline can push malicious code straight to production.
Why pipelines are a big target: they have access to source code, secrets, registries and production environments. Attacks like the Codecov breach and malicious GitHub Actions show how attackers use CI/CD.
Key controls:
Protect pipeline definitions
- Pipeline files are in Git, changed only through reviewed PRs.
CODEOWNERSfor.github/workflows/,Jenkinsfileand shared libraries.- Branch protection: no direct pushes to main or release branches.
Least-privilege, short-lived credentials
- OIDC federation to clouds instead of static access keys.
- Separate roles for dev and prod; production deploy permissions only on protected branches/environments.
- GitHub Actions: set
permissions:to the minimum (for examplecontents: read).
Protect secrets
- Store them in the CI secret store or a vault; scope them to environments.
- Never expose secrets to PRs from forks; be careful with
pull_request_target. - Mask secrets in logs.
Secure runners
- Prefer ephemeral runners (fresh for each job).
- Don't use self-hosted runners for public repositories.
- Isolate runners per sensitivity (separate production deploy runners).
Trust what you use
- Pin third-party actions/plugins to a commit SHA, not a moving tag.
- Review and limit plugins (especially Jenkins); keep CI tools patched.
- Use dependency lock files and a private proxy registry.
Verify what you produce
- Scan code, dependencies, images and IaC.
- Sign artifacts (Cosign), generate SBOMs and provenance (SLSA).
- Enforce signed images at deploy time (admission policies).
Approvals and audit
- Required approvals for production environments.
- Audit logs of pipeline runs, approvals and secret access.
Tip for interviews: mention OIDC, pinned actions by SHA, fork PR secret exposure and artifact signing — these are the modern essentials.