These are the notes for Cybersecurity Fundamentals (defensive), episode 63. In episode 60 we built a pipeline that tests, scans and deploys code automatically; in episode 62 SolarWinds showed attackers going after the build itself. This episode protects the pipeline: the machines it runs on, the keys it carries, who can change it, the third-party code it borrows, and the classic attack where a stranger's code runs with your secrets. Every term is defined the first time it appears; the Glossary collects them.
Scope. Defensive and educational only. Every program is a toy simulation; the "secret" is a made-up string and no real pipeline is touched. Samples were run on 13 Nov 2026 in the SyntaxPilot compiler (Python 3.13).
Step 1: the pipeline is attack surface
Real-life example: a sweet shop's kitchen makes every box of sweets, and the kitchen staff also hold the shop keys and the van keys. Poison one pot and every customer gets it, in an official box.
- CI (continuous integration): automatically building and testing every code change.
- CD (continuous delivery / deployment): automatically releasing changes that pass the pipeline.
- CI/CD pipeline: the automatic sequence of steps (build, test, scan, package, sign, deploy) run on each change. On GitHub, pipelines are workflows, written as YAML files in
.github/workflows/. - Job / step: a pipeline is made of jobs; a job is a list of steps (commands or reusable actions).
- Pipeline secrets: passwords, tokens and keys the pipeline needs: deploy keys, cloud credentials, signing keys, package-publishing tokens.
- Attack surface (episode 1): every place an attacker can try to get in. The pipeline is often the most valuable one: it can change what every user receives.
Build runners
- Build runner: the machine (physical, virtual or container) that executes a pipeline job.
- Persistent / reused runner: one machine that runs job after job, keeping its disk between them.
- Ephemeral runner: a fresh, clean machine for every job, destroyed afterwards.
- Runner isolation: untrusted jobs (e.g. pull requests from outside contributors) never share a runner, a network or secrets with trusted release jobs.
- Pull request (PR): a proposed change, submitted for review before it is merged.
Demo 1: a reused runner vs an ephemeral runner
# A REUSED build runner vs an EPHEMERAL one (toy simulation).
def run_job(disk, job):
if job == "pr-from-stranger": # untrusted code runs
disk["node_modules/build.js"] = "steal(DEPLOY_KEY)"
return "PR build: tests ok"
if job == "release": # trusted job, later
tool = disk.get("node_modules/build.js", "build()")
return f"release used {tool!r}"
print("REUSED runner (one disk kept between jobs)")
shared = {}
for job in ("pr-from-stranger", "release"):
print(" ", run_job(shared, job))
print("EPHEMERAL runner (a fresh machine per job)")
for job in ("pr-from-stranger", "release"):
print(" ", run_job({}, job)) # new empty disk
Real output:
REUSED runner (one disk kept between jobs)
PR build: tests ok
release used 'steal(DEPLOY_KEY)'
EPHEMERAL runner (a fresh machine per job)
PR build: tests ok
release used 'build()'
On the reused runner, the stranger's PR left a poisoned build.js that the later release job used. On an ephemeral runner the release starts from an empty disk and uses the real tool.
Step 2: the keys the pipeline carries
Least-privilege pipeline tokens
- Pipeline token: an automatic credential each job gets to talk to the code host (on GitHub,
GITHUB_TOKEN). - Least privilege (episode 3): each job gets only the permissions it needs.
- In GitHub Actions:
permissions:
contents: read # default for the whole workflow
jobs:
publish:
permissions:
contents: read
packages: write # only this job can publish
A stolen read-only token from a test job cannot push code or publish a release.
OIDC federation from CI to the cloud
Real-life example: copying the hotel's master key for every staff member (one leak opens everything, forever) vs showing ID at the desk and getting a key card for one room, one night.
- Long-lived credential: a key that never (or rarely) expires, e.g. a cloud access key pasted into CI secrets.
- OpenID Connect (OIDC) (episode 33): a standard for proving identity with signed tokens.
- OIDC federation: the cloud is configured in advance to trust identity tokens from the CI system for specific repositories and branches. At run time the job presents its identity token and receives a short-lived cloud token.
- GitHub's docs: OIDC "allows your workflows to exchange short-lived tokens directly from your cloud provider", you "won't need to duplicate your cloud credentials as long-lived GitHub secrets", and the access token "is only valid for a single job".
- Federation: one system trusting identities issued by another.
Secrets in CI and log masking
- Log masking: the CI system replaces the exact text of a known secret with
***in job logs. - Rotation: replacing a secret with a new one (and disabling the old one), routinely or as soon as it might have leaked.
- Base64 (episode 10): an encoding, not encryption; anyone can decode it.
Demo 2: masking hides the exact text, and nothing else
# CI log masking hides the secret's exact text... and nothing else.
import base64
SECRET = "toy-deploy-key-0000-not-real" # a made-up secret
def ci_log(line): # what CI shows
print("log>", line.replace(SECRET, "***"))
ci_log(f"deploying with key {SECRET}") # masked
ci_log("key reversed: " + SECRET[::-1]) # NOT masked
encoded = base64.b64encode(SECRET.encode()).decode()
ci_log("key in base64: " + encoded) # NOT masked
print("anyone reading the log can decode it:")
print(" ", base64.b64decode(encoded).decode())
Real output:
log> deploying with key ***
log> key reversed: laer-ton-0000-yek-yolped-yot
log> key in base64: dG95LWRlcGxveS1rZXktMDAwMC1ub3QtcmVhbA==
anyone reading the log can decode it:
toy-deploy-key-0000-not-real
Masking caught the exact secret, but the reversed copy and the base64 copy went straight through. Treat masking as a seat belt, not a lock: give each secret only to the job that needs it, prefer short-lived OIDC tokens, never print secrets, rotate on any suspicion.
Step 3: who can change the pipeline
The pipeline is defined by files in the repository, so whoever can change those files controls the pipeline.
Real-life example: a bank locker that opens only with two keys, needs the right manager's signature for that section, and records a signature in the register.
- Branch: a separate line of development in Git;
mainis usually the one that gets released. - Branch protection: rules on an important branch: no direct pushes, no force-pushes (rewriting history), changes only through pull requests that pass required checks.
- Required reviews: a pull request needs a set number of approvals before merging.
- CODEOWNERS: a file (in
.github/, the root ordocs/) that maps paths to their owners. GitHub's docs: "Code owners are automatically requested for review when someone opens a pull request that modifies code that they own", and branch protection can "Require review from Code Owners".
# .github/CODEOWNERS
/.github/workflows/ @acme/platform-team
/payments/ @acme/payments-team
- Commit: one saved change in Git, with an author name that anyone can type.
- Signed commit: a commit carrying a digital signature made with the author's key. GitHub supports GPG, SSH or S/MIME signatures and marks verified ones "Verified". It proves the commit came from that key, not just from someone typing your name.
Step 4: pinning actions by commit SHA
- Action: a reusable pipeline step published by someone else (e.g. "check out code", "list changed files"), used with
uses: owner/name@ref. - Tag: a human-friendly label like
v45. It can be moved to point at different code. - Commit SHA: the hash that identifies one exact version of the code (a 40-hex-character string in Git). It cannot be moved.
- Pinning by SHA:
uses: owner/name@<full commit SHA>; update deliberately, with review.
Demo 3: a moved tag vs a SHA pin
# Pinning an action by TAG vs by commit SHA (toy registry).
import hashlib
def sha(code): return hashlib.sha1(code.encode()).hexdigest()[:12]
good = "list changed files"
COMMITS = {sha(good): good} # content -> its hash
TAGS = {"v45": sha(good)} # a tag is a movable label
PIN_TAG, PIN_SHA = "v45", sha(good) # two ways to refer to it
def fetch(ref):
return COMMITS[TAGS.get(ref, ref)]
print("before, by tag:", fetch(PIN_TAG))
print("before, by SHA:", fetch(PIN_SHA))
evil = "list changed files + dump secrets to the log"
COMMITS[sha(evil)] = evil # attacker pushes a commit
TAGS["v45"] = sha(evil) # ...and MOVES the tag
print("after, by tag:", fetch(PIN_TAG))
print("after, by SHA:", fetch(PIN_SHA), " <- still", PIN_SHA)
Real output:
before, by tag: list changed files
before, by SHA: list changed files
after, by tag: list changed files + dump secrets to the log
after, by SHA: list changed files <- still f57f5c33e8a8
Case study: tj-actions/changed-files (March 2025)
- CVE-2025-30066; compromise window 14–15 March 2025.
- The attacker changed the action's existing version tags (v1 through v45.0.7) to point to a malicious commit.
- The code dumped CI runner memory containing workflow secrets into the workflow logs, obfuscated as double-encoded base64; on public repositories those logs were readable.
- Users who had pinned to a commit hash were not affected (unless they updated to a malicious hash during the window).
- It was listed in CISA's KEV catalog (episode 61). Recommended response: pin by SHA, rotate any leaked secrets, audit past runs, allow-list trusted actions.
Step 5: poisoned pipeline execution (PPE)
- Poisoned pipeline execution (PPE): an attacker changes files the pipeline executes (test scripts, a
Makefile, build configuration) so the pipeline runs their code with the pipeline's secrets and permissions, without editing the pipeline definition itself. pull_request_target(GitHub Actions trigger): per GitHub's docs, the job "receives the base repository'sGITHUB_TOKENand access to repository and organization secrets". By default no code from the fork is executed. The vulnerability is completed when the workflow checks out the pull request's code and a later step runs it (e.g.make test).pull_request(the safer trigger): runs the fork's code with a read-only token and no secrets.- Makefile: a file of build commands run by
make. - Safe pattern: untrusted code runs with a read-only token, no secrets, on an isolated (ideally ephemeral) runner. Treat checked-out PR code only as data in privileged workflows.
Demo 4: a toy workflow linter
- Linter: a tool that checks text or code for risky or wrong patterns without running it.
# A toy workflow linter: find risky settings BEFORE the pipeline runs.
WORKFLOW = """on: pull_request_target
permissions: write-all
steps:
- uses: actions/checkout@v4
with: ref: ${{ github.event.pull_request.head.sha }}
- run: npm install && npm test
- uses: some-org/deploy-action@main
- run: deploy --key ${{ secrets.CLOUD_KEY }}
"""
RULES = [
("pull_request_target", "HIGH runs PR code with secrets: PPE risk"),
("pull_request.head", "HIGH checks out the untrusted PR code"),
("write-all", "HIGH token can write everything"),
("@main", "MED action not pinned to a commit SHA"),
("@v4", "LOW tag, not SHA (tags can move)"),
("secrets.CLOUD_KEY", "MED long-lived cloud key: use OIDC"),
]
for n, line in enumerate(WORKFLOW.splitlines(), 1):
for pattern, msg in RULES:
if pattern in line:
print(f"line {n}: {msg}")
Real output:
line 1: HIGH runs PR code with secrets: PPE risk
line 2: HIGH token can write everything
line 4: LOW tag, not SHA (tags can move)
line 5: HIGH checks out the untrusted PR code
line 7: MED action not pinned to a commit SHA
line 8: MED long-lived cloud key: use OIDC
Six findings before anything ran. Run real workflow linters on every change to .github/workflows/ and triage their findings like any other (episode 61).
Step 6: the OWASP Top 10 CI/CD Security Risks
| ID | Risk | Where we met it |
|---|---|---|
| CICD-SEC-1 | Insufficient Flow Control Mechanisms | branch protection, required reviews |
| CICD-SEC-2 | Inadequate Identity and Access Management | who can do what, joiners/leavers (episode 34) |
| CICD-SEC-3 | Dependency Chain Abuse | dependency confusion, typosquatting (episode 62) |
| CICD-SEC-4 | Poisoned Pipeline Execution (PPE) | Step 5 |
| CICD-SEC-5 | Insufficient PBAC (Pipeline-Based Access Controls) | least-privilege tokens, per-job secrets |
| CICD-SEC-6 | Insufficient Credential Hygiene | masking limits, OIDC, rotation |
| CICD-SEC-7 | Insecure System Configuration | reused, shared runners |
| CICD-SEC-8 | Ungoverned Usage of 3rd Party Services | unpinned actions, tj-actions |
| CICD-SEC-9 | Improper Artifact Integrity Validation | signing, provenance, SLSA (episode 62) |
| CICD-SEC-10 | Insufficient Logging and Visibility | audit logs of who changed and ran pipelines |
- Flow control: rules that stop a change reaching production without the required checks and approvals.
- Audit log: a record of who did what and when.
The whole chain
- The pipeline holds the keys → treat it as attack surface.
- A reused runner gets poisoned → ephemeral, isolated runners.
- Tokens can do everything → least-privilege tokens; stored cloud keys → OIDC federation.
- Masking leaks copies → fewer, short-lived, rotated secrets.
- Anyone can change the pipeline → branch protection, required reviews, CODEOWNERS, signed commits.
- Tags move → pin by commit SHA; strangers' code with your secrets → prevent PPE.
Common mistakes (and the fix)
| Mistake | What you see | Why | Fix |
|---|---|---|---|
uses: some-org/action@v1 |
the tag moves; new code runs with your secrets | tags are mutable | pin the full commit SHA; update with review |
permissions: write-all |
any compromised step can push or release | too much privilege | contents: read by default; write per job |
long-lived CLOUD_KEY in CI secrets |
one leak works everywhere, forever | never expires | OIDC federation, short-lived tokens |
pull_request_target + checkout PR head + run it |
a stranger's Makefile runs with your secrets | PPE | untrusted code: no secrets, read-only token, isolated runner |
| self-hosted runner reused for public PRs | poisoned tools persist into release jobs | no isolation | ephemeral runners; separate pools for untrusted jobs |
echo $SECRET \| base64 in a debug step |
log> key in base64: dG95... readable |
masking matches exact text only | never print secrets; rotate if printed |
no CODEOWNERS for .github/workflows/ |
anyone with write access edits the pipeline | no owner review | CODEOWNERS + "Require review from Code Owners" |
Mini project: harden a workflow
Take a workflow you own (or write a small one that runs tests and deploys a static site). (1) Add permissions: contents: read at the top and grant write only to the deploy job. (2) Pin every uses: to a full commit SHA with the version in a comment. (3) Replace any stored cloud key with OIDC (follow your cloud provider's GitHub OIDC guide). (4) Add a CODEOWNERS entry for .github/workflows/ and enable branch protection with required reviews and status checks. (5) Extend the toy linter so it fails (exit code 1) on any HIGH finding, and run it on the workflow.
Practice
1. Which jobs in a "test → build → publish → deploy" workflow need write permissions?
Solution
Only publish (to write packages) and deploy (to one environment, ideally via OIDC). test and build need read-only access to the code.
2. Extend the toy linter to flag secrets. used in a run: line.
Solution
for n, line in enumerate(WORKFLOW.splitlines(), 1):
if "run:" in line and "secrets." in line:
print(f"line {n}: MED secret passed on a command line (may leak to logs)")
On the sample workflow it flags line 8.
3. Why doesn't moving the tag affect a SHA pin in Demo 3?
Solution
fetch(PIN_SHA) looks up COMMITS[sha]: the SHA is derived from the content, and the original content is still stored under it. Only TAGS changed, and the SHA pin never consults it.
4. Make Demo 2's masking also catch the reversed and base64 forms. Is that enough?
Solution
import base64
FORMS = [SECRET, SECRET[::-1], base64.b64encode(SECRET.encode()).decode()]
def ci_log(line):
for f in FORMS: line = line.replace(f, "***")
print("log>", line)
No: there are endless transformations (hex, double base64, splitting into characters). Masking is a last line; the real fixes are not exposing secrets to code that might print them, and short-lived credentials.
5. Write a CODEOWNERS file where the security team must approve workflow changes and the payments team owns /payments/.
Solution
/.github/workflows/ @acme/security-team
/payments/ @acme/payments-team
Then enable branch protection with "Require review from Code Owners".
6. A workflow uses pull_request_target only to add a label to the PR and never checks out the PR's code. Is it vulnerable to PPE?
Solution
Not by itself: no code from the fork is executed. It still has a write token and secrets, so keep its permissions minimal (e.g. pull-requests: write only) and never add a step that runs the PR's code.
Quick quiz
A: uses: tj/changed-files@v45
B: uses: tj/changed-files@main
C: uses: tj/changed-files@<full commit SHA>
D: uses: tj/changed-files@latest
An action's v45 tag was moved to malicious code. Whose pipeline is still safe?
Answer
C. A commit SHA identifies one exact version of the code and cannot be moved. Tags (v45, latest) and branches (main) are labels that can point to different code.
Interview questions
- Why is the CI/CD pipeline a high-value target? It holds secrets and can change what every user receives, often with signed, official output.
- What is an ephemeral runner, and why use it? A fresh machine per job, destroyed after; nothing a previous (possibly untrusted) job left behind can affect the next.
- How do you apply least privilege to pipelines? Read-only default tokens, per-job permissions, per-environment secrets, short-lived credentials.
- How does OIDC federation improve CI-to-cloud access? No long-lived cloud keys stored in CI; the job proves its identity and gets a short-lived, scoped token.
- Why isn't log masking enough? It only matches the exact secret text; encoded or transformed copies leak.
- What do branch protection and CODEOWNERS give you? Changes only via reviewed PRs with passing checks, and the right owners must approve sensitive paths such as the workflows folder.
- What does a signed commit prove? That the commit was signed by a particular key; GitHub shows it as Verified.
- Why pin actions by SHA? Tags and branches can be moved to malicious code (as in tj-actions/changed-files, March 2025); a SHA can't.
- What is poisoned pipeline execution? Getting the pipeline to run attacker-controlled files (scripts, Makefiles, configs) with its secrets, e.g. via
pull_request_targetplus running the PR's code. - Name five of the OWASP Top 10 CI/CD risks. Insufficient flow control; inadequate IAM; dependency chain abuse; PPE; insufficient PBAC; credential hygiene; insecure system configuration; ungoverned third-party services; improper artifact integrity validation; insufficient logging and visibility.
Glossary
| Term | Meaning |
|---|---|
| CI | continuous integration: build and test every change automatically |
| CD | continuous delivery / deployment: release passing changes automatically |
| CI/CD pipeline | the automatic build-test-scan-deploy sequence |
| workflow | GitHub Actions' name for a pipeline, a YAML file in .github/workflows/ |
| job / step | a unit of pipeline work / one command or action inside a job |
| YAML | a plain-text format for configuration files |
| pipeline secrets | keys and tokens the pipeline uses |
| attack surface | every place an attacker can try to get in |
| build runner | the machine that executes a job |
| reused (persistent) runner | a runner that keeps its disk between jobs |
| ephemeral runner | a fresh machine per job, destroyed afterwards |
| runner isolation | untrusted and trusted jobs never share runners, networks or secrets |
| pull request (PR) | a proposed change submitted for review |
| pipeline token / GITHUB_TOKEN | the automatic credential a job gets |
| least privilege | only the permissions needed |
| long-lived credential | a key that rarely or never expires |
| OIDC | OpenID Connect: identity proven with signed tokens |
| federation | one system trusting identities issued by another |
| short-lived token | a credential that expires quickly (here: one job) |
| log masking | replacing a secret's exact text with *** in logs |
| rotation | replacing a secret with a new one |
| base64 | an encoding anyone can decode, not encryption |
| branch | a separate line of development; main is usually released |
| branch protection | rules: no direct or force pushes, reviewed PRs, passing checks |
| force-push | overwriting a branch's history |
| required reviews | approvals needed before merging |
| CODEOWNERS | a file mapping paths to owners who must review changes |
| commit | one saved change in Git |
| signed commit | a commit with a digital signature (GPG, SSH or S/MIME) |
| GPG | GNU Privacy Guard, an OpenPGP signing and encryption tool |
| action | a reusable pipeline step published by someone else |
| tag | a movable label for a commit, like v45 |
| commit SHA | the hash identifying one exact version of the code |
| pinning by SHA | referencing an action by its full commit SHA |
| tj-actions/changed-files | a GitHub Action whose tags were moved to malicious code in March 2025 (CVE-2025-30066) |
| poisoned pipeline execution (PPE) | making the pipeline run attacker-controlled files with its secrets |
| pull_request_target | a GitHub trigger that runs with the base repo's token and secrets |
| Makefile | a file of build commands run by make |
| linter | a tool that checks text or code for risky patterns |
| flow control | rules that stop unreviewed changes reaching production |
| PBAC | pipeline-based access controls |
| credential hygiene | how secrets are stored, shared, scoped and rotated |
| audit log | a record of who did what and when |
| OWASP Top 10 CI/CD Security Risks | OWASP's list CICD-SEC-1 to CICD-SEC-10 |
Summary
- The CI/CD pipeline holds the keys to production, so it is attack surface.
- Run jobs on ephemeral, isolated runners; keep untrusted PRs away from release jobs.
- Default tokens to read-only; grant write per job; use OIDC instead of stored cloud keys.
- Log masking only hides exact text; keep secrets few, short-lived, never printed, and rotate them.
- Protect branches, require reviews, use CODEOWNERS for the workflows folder, and sign commits.
- Pin third-party actions by full commit SHA (tj-actions, March 2025).
- Never run a stranger's code with your secrets: that is poisoned pipeline execution.
- The OWASP Top 10 CI/CD Security Risks is the checklist.
- Next episode: cloud security fundamentals.
Sources (fetched 13 Nov 2026)
- OWASP Top 10 CI/CD Security Risks (project repository): https://github.com/cider-security-research/top-10-cicd-security-risks
- GitHub Docs, OpenID Connect: https://docs.github.com/en/actions/concepts/security/openid-connect
- GitHub Docs, securely using pull_request_target: https://docs.github.com/en/actions/reference/security/securely-using-pull_request_target
- GitHub Docs, about code owners: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners
- GitHub Docs, about commit signature verification: https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification
- Wiz, tj-actions/changed-files supply chain attack: https://wiz.io/blog/github-action-tj-actions-changed-files-supply-chain-attack-cve-2025-30066
- SentinelOne, CVE-2025-30066: https://www.sentinelone.com/vulnerability-database/cve-2025-30066