Security Engineering
Advanced 18 min read Security Engineering

CI/CD Pipeline Security

The pipeline is the blast radius center: hardened runners, least-privilege credentials, unsigned artifacts, and the supply-chain attacks that target build infrastructure itself.

CI/CDrunner securityGitHub Actionssupply chain defenseartifact signingleast privilege
Introduction

What is this?

Pipeline security protects the machinery that builds and ships: runner isolation, scoped secrets, artifact integrity, and trust controls against attacks aimed straight at the build.

Motivation

Why do you need it?

  • Attackers target the pipeline because one build compromise fan out to every artifact it produces.
  • A leaked CI credential with prod scope is a full privilege to your release path.
  • Supply-chain incidents (e.g. a malicious dependency, a poisoned runner) live and die here.
Think about it

Mental model

Imagine

A bakery delivering everywhere

Think of

Someone poisoning the flour truck

Compromise the truck (the runner) and every delivery that day carries the surprise — even if each bread recipe looked fine.

Mechanics

How it works

  • Runners execute untrusted-ish code in isolated, disposable environments, not the engineer's laptop.
  • Secrets live in scoped vault/stores injected only for the job that needs them, never in logs.
  • Artifacts are signed at the end of a hardened build so later stages can verify provenance.
  • Supply-chain controls (pin hashes, verify trusted actions, deny untrusted forks) bind each step.

Trust boundaries in a pipeline

Trigger
Runner
Secrets
Actions
Artifact
Real world

In production

  • An org pins every third-party action to a commit SHA and denies unknown-forks in PRs — the Log4shell-era lesson.
  • A platform injects short-lived OIDC tokens instead of long-lived keys, so CI can't persist privileges.
  • A release pipeline signs images and then admission verifies in staging before production promotion.
Guidelines

Best practices

  • Least privilege the runner: read-clone, scoped secrets, scope-limited cloud roles.
  • Pin actions/dependencies to digests or SHAs and require approval for new ones.
  • Use OIDC/federated short-lived credentials over long-lived CI keys wherever possible.
  • Clean the runner after every job and never run untrusted PRs on protected runners.
Watch out

Common mistakes

  • A single 'build' secret with full admin on every stage, rotated never.
  • Running checkout of a fork on a self-hosted runner with host access.
  • Signing artifacts with a key stored beside the pipeline the same scripts can read.
  • Ignoring the pipeline's own config in security reviews — the watchers unwatched again.
When things break

Debugging tips

  • When an 'approved' action misbehaves, pin it to a SHA and diff the vendor's release notes.
  • Audit runner logs for secret leakage: any value echoed in output is a leak event to rotate.
  • Test permission boundaries with a can-it pipeline: a job that tries to read a neighbor's secret and must fail.
Security

Security considerations

  • Treat the pipeline as a privileged system: its logs, runners, and artifacts all carry release authority.
  • Secrets found in pipeline output are incidents: rotate and inspect what the job could touch.
Interviews

Interview checkpoint

Practice

Hands-on lab

Harden a Micro-Pipeline: Scope, Scan, Sign
50 min · advanced
In progress
Objectives
  • Write a minimal CI-style pipeline in a local git repo.
  • Inject a secret safely via env only, and prove it's hidden from output.
  • Add a secret-scan + sign step and verify honest logs.

Harden a Micro-Pipeline: Scope, Scan, Sign

50 min · advanced

0/4 steps
0%
sandbox · Linux sandbox
$
Try these commands
Test yourself

Quick quiz

0/2
1

The best credential model for CI is...

2

The strongest third-party action policy is...

Go deeper

Official documentation