0Pricing
Cyber Security Academy · Lesson

Securing CI/CD Pipelines

Hardening the build and release path.

Securing CI/CD Pipelines is a free Cyber Security Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cyber Security Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Pipeline as a Target

A CI/CD pipeline has privileged access to source code, secrets, and production. Compromising it lets an attacker inject backdoors into every future build while bypassing code review. It is one of the highest-value targets in modern engineering.

Treat the pipeline as production infrastructure: it deserves the same hardening, monitoring, and least-privilege discipline as your live systems.

Untrusted Input in Builds

Pipelines run automatically on events you do not fully control: pull requests, tags, external contributions. A malicious PR can try to alter the build itself.

  • A poisoned pipeline definition in a fork can attempt to exfiltrate secrets
  • Untrusted code may run with the same permissions as trusted builds

Separate trusted and untrusted workflows: do not expose secrets to jobs triggered by external pull requests.

Pin Your Actions and Images

Pipeline steps often pull third-party actions or container images by mutable tag. If that tag is re-pointed to malicious content, your build is compromised. Pin to immutable digests.

# BAD: mutable tag can be moved under you
uses: some/action@v3

# GOOD: pinned to an immutable commit SHA
uses: some/action@a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0

# pin container steps by digest too
image: build-tools@sha256:9f86d081884c7d659a2feaa0c55ad015...

Least Privilege for Tokens

Default pipeline tokens are often over-permissioned, granting write access to the whole repository or registry. Scope them down to exactly what each job needs.

# scope the default token to read-only, grant more only where needed
permissions:
  contents: read

jobs:
  publish:
    permissions:
      contents: read
      packages: write   # only this job can publish

Secrets Hygiene

Hardcoded or broadly shared secrets are a primary leak path. Apply strict handling:

  • Store secrets in a secrets manager or the CI secret store, never in code
  • Prefer short-lived OIDC federation over static cloud keys
  • Mask secrets in logs and block their echo
  • Scope each secret to the minimum jobs and environments

OIDC federation lets the pipeline exchange a build-time identity for short-lived cloud credentials, removing long-lived keys entirely.

Ephemeral, Isolated Runners

A reused build runner can carry malware or leaked secrets from one job to the next. Ephemeral runners are created fresh per job and destroyed afterward, so nothing persists.

  • One clean environment per build, then discarded
  • No shared state between trusted and untrusted jobs
  • Network egress restricted to required endpoints

This directly supports SLSA L3 isolation goals.

Protect the Source Branch

The pipeline's trust starts at source control. If anyone can push to the release branch, signing and scanning downstream are moot.

  • Require pull request review before merge
  • Enforce signed commits on protected branches
  • Require status checks (tests, scans) to pass
  • Disallow force-push and direct push to main
# require signed commits on a branch
git config commit.gpgsign true

# verify a commit signature locally
git verify-commit HEAD

Scan Inside the Pipeline

Bake security gates directly into CI so issues fail the build rather than reaching production.

# secret leak detection
gitleaks detect --source . --redact

# dependency vulnerabilities
osv-scanner --lockfile=package-lock.json

# IaC and config misconfig
trivy config .

# fail the job on critical findings (non-zero exit stops CI)

Two-Person Control for Releases

High-impact actions deserve a human gate. Production deploys and credential changes should require approval from someone other than the author.

  • Environment protection rules require a reviewer before deploy
  • Separate the build identity from the deploy identity
  • No single actor can both author code and push it to production unreviewed

This limits both insider risk and the blast radius of one compromised account.

Audit and Tamper-Evidence

You must be able to reconstruct what the pipeline did. Centralize and protect its logs.

  • Ship CI logs to an append-only, access-controlled store
  • Record who changed pipeline definitions and when
  • Emit signed provenance so artifacts trace back to a specific build
  • Alert on anomalies: new self-hosted runner, unexpected secret access, config change outside review

Pipeline Hardening Checklist

A defensible pipeline combines source, build, and release controls:

  • Branch protection, reviewed and signed commits
  • Pinned actions and images by digest
  • Least-privilege, short-lived OIDC tokens
  • Ephemeral isolated runners
  • In-pipeline secret, dependency, and config scanning
  • Two-person release approval
  • Signed artifacts, SBOM, and provenance with audit logging

Quick Check: Token Permissions

Decide the right control for a privileged build token.

Recap: Securing CI/CD Pipelines

You learned to harden the entire build and release path.

  • Treat the pipeline as production; it can backdoor every future build
  • Isolate untrusted PR builds from secrets
  • Pin actions and images by digest; use least-privilege, short-lived OIDC tokens
  • Use ephemeral isolated runners and protect the source branch
  • Scan in-pipeline, require two-person release approval, and keep tamper-evident audit logs

Course complete: you can now secure the software supply chain end to end.

Frequently asked questions

Is the “Securing CI/CD Pipelines” lesson free?

Yes — the full text of “Securing CI/CD Pipelines” is free to read here on the web, and the Cyber Security Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cyber Security Academy course, upgrade to CoddyKit PRO.

What will I learn in “Securing CI/CD Pipelines”?

Hardening the build and release path. You practise Cyber Security Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cyber Security Academy?

No prior experience is required. Cyber Security Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Securing CI/CD Pipelines” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cyber Security Academy lesson?

Yes. Every Cyber Security Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Supply Chain Threats
  2. Software Bill of Materials (SBOM)
  3. Dependency and Artifact Signing
  4. Securing CI/CD Pipelines
← Back to Cyber Security Academy