SecurityPart 3: Cloud and infrastructure security
Chapter 12Software supply chain security
In March 2024 a Microsoft engineer noticed SSH logins taking about half a second too long, and traced it to a backdoor that a trusted maintainer had spent two years planting in the xz compression library. You will learn how attackers get into the code you did not write, and how signing, SBOMs and provenance let you prove what you ship.
After this chapter you can
- Break down real supply chain attacks into the stage they compromised and the control that would have caught them
- Replace stored secrets with vaults and short-lived credentials
- Harden a CI/CD pipeline with pinned actions, least-privilege tokens and isolated runners
- Sign and verify artifacts with Sigstore cosign, and generate and scan SBOMs with Syft and Grype
- Explain SLSA build levels, provenance and reproducible builds, and the new risk of AI-hallucinated packages
Your code is mostly other people's code
A typical application is a thin layer of your code on top of hundreds or thousands of open-source packages, a base image, a build system and a CI platform with its own plugins. The software supply chain is every person, system and artifact between a developer's keyboard and production. An attacker who compromises one link reaches everyone downstream, which is why these attacks scale so well.
Each dotted arrow is a real attack class. The controls in this chapter map onto those links: secrets and CI hardening protect the build, signing protects the artifact, SBOMs tell you what is inside it, and provenance proves how it was made.
Anatomy of real attacks
| Attack | Stage compromised | What happened | Control that helps |
|---|---|---|---|
| SolarWinds (2020) | Build | Malware on the build server injected the SUNBURST backdoor into Orion updates while the source stayed clean. Roughly 18,000 customers installed them. | Hardened, isolated builders; provenance; reproducible builds |
| xz utils, CVE-2024-3094 | Maintainer and release | A contributor known as "Jia Tan" gained maintainer trust over about two years, then shipped versions 5.6.0 and 5.6.1 with a backdoor hidden in test files and a build script present only in the release tarballs. | Build from source, compare tarball to repo, reproducible builds |
| Dependency confusion (2021) | Dependency resolution | Researcher Alex Birsan published public packages with the names of companies' internal packages and higher versions. Build tools at more than 35 companies, including Apple and Microsoft, fetched them. | Scoped or namespaced packages, a single private registry, pinned versions |
| Typosquatting | Dependency choice | Packages named like popular ones (crossenv for cross-env) steal environment variables at install time. | Lockfiles, review of new dependencies, install-script restrictions |
| tj-actions/changed-files, CVE-2025-30066 | CI | Attackers moved the action's version tags to a malicious commit that dumped CI secrets into build logs. | Pin actions to full commit SHAs |
| Trivy (March 2026) | CI and release | Stolen credentials were used to publish a malicious Trivy release and force-push almost every version tag of its GitHub Actions to credential-stealing code. | SHA pinning, immutable releases, short-lived tokens |
Secrets: vaults and short-lived credentials
Supply chain attackers mostly want one thing from your pipeline: credentials. Tokens for package registries, cloud accounts and Git hosting let them publish malicious versions or move into production. The goal is fewer secrets, shorter lives and no secrets at rest in code or images.
| Practice | Weak version | Strong version |
|---|---|---|
| Where secrets live | .env files, CI variables, baked into images | A vault (HashiCorp Vault, OpenBao, AWS Secrets Manager) with audit logs |
| How long they live | Years, until someone remembers to rotate | Minutes to hours: dynamic database credentials, OIDC-issued cloud sessions |
| How CI authenticates | Long-lived cloud access keys in repo secrets | OIDC federation, covered in Cloud identity and access |
| How publishing works | A maintainer's personal npm or PyPI token | Trusted publishing from CI via OIDC, with provenance attached |
| Detecting leaks | Hoping | Secret scanning with push protection, plus gitleaks or TruffleHog in CI |
A dynamic secret is created on request and revoked automatically. With Vault's database engine, each CI job gets its own Postgres user that expires when the job ends, so a leaked credential is worthless an hour later.
Hardening CI/CD
A CI runner executes code from your repository, from every action or plugin it pulls in, and sometimes from strangers' pull requests, while holding your deploy credentials. Treat it as a production system. The most important controls for GitHub Actions apply to other platforms too:
name: release
on:
push:
branches: [main]
permissions:
contents: read # default every job to read-only
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # push to GHCR
id-token: write # OIDC token for keyless signing
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: sigstore/cosign-installer@881c63bd87e38389154debd8331404ce7ca8a3ab # v4.1.4
- name: Build and push
id: push
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u "${{ github.actor }}" --password-stdin
docker build -t ghcr.io/${{ github.repository }}:${{ github.sha }} .
docker push ghcr.io/${{ github.repository }}:${{ github.sha }}
echo "digest=$(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/${{ github.repository }}:${{ github.sha }} | cut -d@ -f2)" >> "$GITHUB_OUTPUT"
- name: Sign by digest, keyless
run: cosign sign --yes ghcr.io/${{ github.repository }}@${{ steps.push.outputs.digest }}- Pin third-party actions to a full commit SHA. A tag like
@v4is a movable pointer, which is exactly what the tj-actions and Trivy attackers moved. Keep the version in a comment and let Dependabot or Renovate propose updates. - Least-privilege tokens. Set
permissionsat the top of every workflow and widen per job. Without this, older repositories give the defaultGITHUB_TOKENwrite access to the repo. - Do not run untrusted code with secrets. The
pull_request_targettrigger runs in the base repository's context with secrets available; checking out and building the PR's code there hands those secrets to any fork. - Never splice untrusted input into shell.
${{ github.event.issue.title }}insiderun:is a script injection. Pass such values through environment variables instead. - Isolate runners. Use ephemeral runners that are destroyed after each job. Never attach self-hosted runners to public repositories, where anyone can open a PR that runs on your hardware.
Signing artifacts with Sigstore
A signature lets a consumer check that an artifact came from who it claims and has not changed since. Classic signing fails in practice because teams must guard a long-lived private key for years. Sigstore removes the long-lived key with three pieces: cosign signs and verifies, Fulcio is a certificate authority that issues a short-lived certificate tied to an OIDC identity, and Rekor is a public, append-only transparency log of signatures.
Verification then checks the signature, that the certificate chains to Fulcio, that Rekor recorded it while the certificate was valid, and, most importantly, which identity signed it:
cosign verify ghcr.io/acme/shop-api@sha256:4f2c... \
--certificate-identity "https://github.com/acme/shop-api/.github/workflows/release.yml@refs/heads/main" \
--certificate-oidc-issuer https://token.actions.githubusercontent.comSBOMs, SLSA and reproducible builds
A software bill of materials (SBOM) is a machine-readable list of every component in an artifact, with versions and identifiers. When the next Log4Shell lands, an SBOM turns "are we affected?" from a week of grepping into a query. The two standard formats are SPDX (a Linux Foundation project, also ISO/IEC 5962) and CycloneDX (an OWASP project). Tools such as Syft generate either, and scanners such as Grype or Trivy match them against vulnerability databases.
SLSA (Supply-chain Levels for Software Artifacts, said "salsa") defines how trustworthy a build is. Its Build track has these levels in the current v1.x specification:
| Level | Requirement | Stops |
|---|---|---|
| Build L0 | Nothing | Nothing |
| Build L1 | Provenance exists describing how the artifact was built | Mistakes, unknown build steps |
| Build L2 | Signed provenance generated by a hosted build platform | Tampering after the build |
| Build L3 | Hardened platform: builds isolated from each other, signing keys unreachable from build steps | Tampering during the build, including by a malicious step |
Provenance is a signed statement (usually in the in-toto attestation format) saying which builder produced which artifact digest, from which source commit, with which parameters. Consumers verify it like a signature, then check its contents against policy: "built by our release workflow, from main, in our repository".
A reproducible build produces bit-for-bit identical output from the same source, so anyone can rebuild and compare. It is the strongest answer to SolarWinds-style build tampering, because a poisoned builder produces a different hash. Debian and NixOS have pushed this furthest; it requires removing timestamps, file ordering and other nondeterminism from the build.
AI-generated dependencies and slopsquatting
AI coding assistants suggest imports and install commands, and sometimes the package they name does not exist. A study presented at USENIX Security 2025 generated 576,000 code samples from 16 models and found that 19.7% of recommended packages were hallucinations, with 205,474 unique invented names. Many repeated reliably: 43% of hallucinated names reappeared in all ten reruns of the same prompt.
That repeatability creates slopsquatting: an attacker registers the names models tend to invent and waits for developers, or autonomous coding agents, to install them. It is typosquatting without the typo.
Key terms
- Software supply chain
- Every person, system and artifact involved in getting code from source to production, including dependencies and build tools.
- Dependency confusion
- Tricking a build into fetching a malicious public package that shares a name with an internal one.
- Typosquatting
- Publishing a malicious package with a name close to a popular one so people install it by mistake.
- Slopsquatting
- Registering package names that AI models hallucinate so that generated code installs the attacker's package.
- Dynamic secret
- A credential generated on demand for one consumer and revoked automatically after a short time.
- Sigstore
- An open-source signing ecosystem of cosign, the Fulcio certificate authority and the Rekor transparency log.
- SBOM
- A software bill of materials: a machine-readable inventory of components in an artifact, in SPDX or CycloneDX format.
- Provenance
- A signed attestation describing how, where and from what source an artifact was built.
- SLSA
- A framework of levels that describe how resistant a build process is to tampering.
- Reproducible build
- A build that produces bit-for-bit identical output from the same source, so anyone can verify it independently.
Sign, inventory and gate a container image
Goal: build an image, publish it to a local registry, sign it with cosign, generate an SBOM with Syft, scan it with Grype, and write a pipeline gate that refuses unsigned or vulnerable images.
You need: Docker, cosign, Syft, Grype and jq. On macOS: brew install cosign syft grype jq. On Linux, download the binaries from each project's GitHub releases page or use Homebrew on Linux. All signing here uses a local key pair and stays on your machine; nothing is uploaded to the public transparency log.
- Start a local registry (port 5001 avoids the macOS AirPlay receiver on 5000) and a helper that asks it for a tag's digest.
docker run -d -p 5001:5000 --name registry registry:2
mkdir chain-lab && cd chain-lab
digest() {
curl -sI -H "Accept: application/vnd.oci.image.index.v1+json, application/vnd.oci.image.manifest.v1+json, application/vnd.docker.distribution.manifest.v2+json, application/vnd.docker.distribution.manifest.list.v2+json" \
"http://localhost:5001/v2/shop-api/manifests/$1" | awk -F': ' 'tolower($1)=="docker-content-digest" {print $2}' | tr -d '\r'
}- Build and push a small app with a deliberately old dependency.
import requests
print("shop-api running, requests", requests.__version__)FROM python:3.12-slim
RUN pip install --no-cache-dir requests==2.19.1
COPY app.py /app.py
USER 65534
CMD ["python", "/app.py"]docker build -t localhost:5001/shop-api:1.0 .
docker push localhost:5001/shop-api:1.0
export IMAGE="localhost:5001/shop-api@$(digest 1.0)"
echo "$IMAGE" # localhost:5001/shop-api@sha256:...- Generate SBOMs in both standard formats and look inside.
syft localhost:5001/shop-api:1.0 -o spdx-json=sbom.spdx.json -o cyclonedx-json=sbom.cdx.json
jq '.packages | length' sbom.spdx.json # a few hundred packages
jq -r '.components[] | select(.name=="requests") | .version' sbom.cdx.json # 2.19.1- Scan the SBOM. Expect high or critical findings for
requestsand its oldurllib3, and a non-zero exit code.
grype sbom:./sbom.cdx.json --only-fixed --fail-on high; echo "exit=$?"- Create a key pair and sign the image by digest.
export COSIGN_PASSWORD='lab-only-password'
cosign generate-key-pair # writes cosign.key and cosign.pub
cosign sign --key cosign.key --tlog-upload=false --allow-http-registry --yes "$IMAGE"
cosign verify --key cosign.pub --insecure-ignore-tlog=true --allow-http-registry "$IMAGE" | jq '.[0].critical.image'The verify output prints the checks performed and the signed digest. Newer cosign releases are replacing --tlog-upload=false with --no-signing-config; if your version rejects the first flag, use the second.
- Write the pipeline gate. It accepts only digest references, requires a valid signature, and fails on fixable high-severity vulnerabilities.
#!/usr/bin/env bash
set -euo pipefail
IMAGE="$1"
[[ "$IMAGE" == *@sha256:* ]] || { echo "BLOCK: deploy by digest, not tag"; exit 1; }
cosign verify --key cosign.pub --insecure-ignore-tlog=true --allow-http-registry "$IMAGE" >/dev/null 2>&1 \
|| { echo "BLOCK: no valid signature for $IMAGE"; exit 1; }
SYFT_REGISTRY_INSECURE_USE_HTTP=true syft -q "registry:$IMAGE" -o cyclonedx-json=gate-sbom.json
grype -q sbom:./gate-sbom.json --only-fixed --fail-on high \
|| { echo "BLOCK: fixable high or critical vulnerabilities"; exit 1; }
echo "PASS: deploying $IMAGE"
docker run --rm "$IMAGE"chmod +x gate.sh
./gate.sh localhost:5001/shop-api:1.0 # BLOCK: deploy by digest, not tag
./gate.sh "$IMAGE" # BLOCK: fixable high or critical vulnerabilities- Fix the dependency, rebuild, sign and pass the gate.
sed -i.bak 's/requests==2.19.1/requests==2.32.3/' Dockerfile
docker build -t localhost:5001/shop-api:1.1 . && docker push localhost:5001/shop-api:1.1
export IMAGE="localhost:5001/shop-api@$(digest 1.1)"
cosign sign --key cosign.key --tlog-upload=false --allow-http-registry --yes "$IMAGE"
./gate.sh "$IMAGE" # PASS: deploying ... then the app's outputIf Grype still blocks on base-image packages, pull a fresh python:3.12-slim and rebuild; scan results depend on the day you run them.
- Simulate an attacker who pushes an unsigned image to the same tag.
docker pull busybox:1.36 && docker tag busybox:1.36 localhost:5001/shop-api:1.1
docker push localhost:5001/shop-api:1.1
./gate.sh "localhost:5001/shop-api@$(digest 1.1)" # BLOCK: no valid signatureCheck your work: the gate blocks the tag reference, the vulnerable 1.0 image and the swapped unsigned image, and passes only the signed, patched 1.1 digest. You also have sbom.spdx.json and sbom.cdx.json you can open and read. Commit everything except cosign.key to a public repo.
Stretch: move this into GitHub Actions using the release workflow from this chapter with keyless signing, attach the SBOM as an attestation with cosign attest --type spdxjson --predicate sbom.spdx.json, and verify both with --certificate-identity and --certificate-oidc-issuer in a separate deploy job.
Check yourself
In the SolarWinds attack the Orion source code in the repository was clean. Which control would most directly have detected the tampering?
A workflow uses a third-party action referenced as some-org/deploy-action@v3. What is the main supply chain risk?
Your gate verifies a cosign signature on the image tag prod, then deploys the tag prod. What can still go wrong?
An AI coding assistant suggests installing a package you have never heard of, and pip installs it successfully. Why is that not reassuring?
Recap
- Supply chain attacks target maintainers, dependencies, build systems and registries, and one compromise reaches every downstream user.
- Short-lived credentials and OIDC publishing remove the long-lived tokens attackers hunt for in pipelines.
- Pin actions to commit SHAs, default tokens to read-only and keep untrusted code away from secrets and self-hosted runners.
- Sign digests with cosign, verify the signer's identity and deploy exactly the digest you verified.
- SBOMs say what is inside an artifact, and SLSA provenance and reproducible builds say how it was made.
- Treat AI-suggested dependencies as untrusted until verified, because slopsquatting turns hallucinations into installs.
Go deeper
- SLSA specification: build levels, provenance and verification requirements.
- Sigstore documentation: cosign usage, keyless signing and verification policies.
- Syft and Grype: Anchore's open-source SBOM generator and vulnerability scanner used in the lab.
- GitHub Actions secure use reference: GitHub's own hardening guidance for workflows and runners.
- We Have a Package for You!: the USENIX Security 2025 paper measuring package hallucinations across 16 models.
- Reproducible Builds: the project's explanation of why and how to make builds verifiable.