Lesson 8 of 9 · 29m
Securing Runners, Secrets, and the Build Supply Chain
Limit runner privilege, isolate untrusted code, scope credentials tightly, and sign artifacts so CI cannot become the easiest lateral movement path.
CI runners are high-value targets because they sit at the intersection of source code, secrets, artifact publishing, cloud credentials, and production deployment. Attackers understand this. Many organizations still treat runners as disposable compute and then reuse the same hosts for untrusted pull requests and signed releases. That is not efficiency; it is lateral movement with a scheduler.
Use least privilege by default
Every job identity should answer: why does this need permission? Prefer OIDC federation over long-lived cloud keys:
permissions:
contents: read
id-token: write
- run: |
aws sts get-caller-identityCloud roles can then trust a specific repository, branch, workflow, or environment. Keep the token lifetime short and role permissions narrow. A deployment role able to administer the whole account because deployment was inconvenient is an incident already in progress.
Understand GitHub permissions
Set the default workflow token to read-only, then grant explicitly:
permissions:
contents: read
jobs:
release:
permissions:
contents: write
packages: writeDo not grant actions: write, security-events: write, or pull-requests: write without a concrete need. Audit third-party actions that unexpectedly request broad token access.
Isolate untrusted execution
Forked pull requests, generated code, dependency install scripts, and test fixtures can execute attacker-controlled content. Use ephemeral runners, no persistent home directories, restricted egress, separate cache scopes, and no deployment secrets. Self-hosted runners need even more care: one poisoned runner image can compromise every subsequent job.
Protect secrets in practice
- name: Deploy
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
run: ./deploy.shScope secrets at the step that uses them. Never echo them, pass them into untrusted child processes unnecessarily, or write them to files that later become artifacts. Secret masking catches exact strings, not derived or re-encoded values.
Sign and verify artifacts
Provenance makes release evidence portable:
cosign sign --key cosign.key "$IMAGE_DIGEST"
cosign verify --key cosign.pub "$IMAGE_DIGEST"For stronger supply-chain metadata, generate SBOMs and attestations:
syft "$IMAGE" -o cyclonedx-json > sbom.jsonSigning does not make software good. It makes substitution detectable. Verification must happen at deployment time or signatures are decorative.
Dependency and action provenance
Review lockfile changes, unexpected postinstall scripts, new native binaries, and dependency confusion exposure. Keep internal package scopes configured correctly and audit public registry lookups. A runner that can fetch arbitrary code from the internet during every build is convenient and unavoidably risky; constrain egress where high-value secrets exist.
Field notes
- Rotate any secret that appeared in a log, artifact, shell history, or untrusted execution environment; masking does not equal non-exposure.
- Separate build credentials from deploy credentials. Compiling untrusted code should not imply production authority.
- Reusable workflows and composite actions are part of your supply chain, not harmless abstractions.
- Treat cache servers, artifact registries, and runner images as production infrastructure with owners and patch policy.
Was this lesson helpful?