Sub topic 9
From Build Level 2 to Level 3 with reusable workflows
This chapter explains why a plain GitHub Actions workflow reaches SLSA Build Level 2, and how moving the build into a reusable workflow gets you to Level 3. It also covers how a consumer checks which level an artifact actually reached.
What this chapter assumes
You should already know:
- how to write a workflow with jobs, steps and
permissions - how
actions/attest-build-provenanceproduces a signed attestation - how
gh attestation verifychecks one - that the signing certificate carries the workflow's OIDC identity
Earlier chapters covered these. Here we look at what that identity says and who controls it.
What changes between Level 2 and Level 3
The SLSA Build track describes how much you can trust the build platform's claims. The two levels differ in what the platform protects.
| Property | Build Level 2 | Build Level 3 |
|---|---|---|
| Provenance exists | Yes | Yes |
| Provenance is signed by the build platform | Yes | Yes |
| Build runs on a hosted platform, not a developer laptop | Yes | Yes |
| Provenance is hard to forge from inside the build | Not required | Required |
| Builds are isolated from each other | Not required | Required |
| Build definition is controlled apart from the project's own steps | Not required | Effectively required |
At Level 2, a consumer knows a hosted platform signed the provenance. At Level 3, the platform also prevents the build's own code, and the user who triggered it, from falsifying that provenance or reading the signing material.
Why a plain workflow stops at Level 2
Take the workflow from the earlier chapter. The build and the attestation step sit in the same file, in the same repository. Anyone who can change that workflow file can change what it claims. The signed provenance faithfully records the workflow that ran. But a consumer who checks only --repo OWNER/REPO learns that some workflow in that repository produced the file. They don't learn that the workflow was a reviewed, trusted build definition.
Several things remain open in that setup:
- A contributor with write access can add a step that swaps the binary after the build and before the attestation.
- A pull request workflow can attest an artifact built from unreviewed code.
- A repository owner can edit the build steps, and the consumer has no way to tell.
GitHub's documentation describes this setup as Build Level 2. The signature is real, but the signer's identity names a repository, and the repository's contents are not locked down.
The reusable workflow pattern
A reusable workflow is a workflow file with an on: workflow_call trigger. Other workflows invoke it with uses: at a job level. Two properties make it useful for Level 3.
- The caller can't edit the steps. It can only pass the inputs the reusable workflow declares.
- The OIDC token for the job carries a
job_workflow_refclaim that names the reusable workflow, not the caller. Fulcio copies this into the signing certificate.
So the attestation is signed under the identity of the reusable workflow. The consumer can then require that identity, and any build that didn't go through that workflow fails verification.
The reusable workflow
Put this in a repository that a platform or security team controls. This example uses OWNER/build-workflows and protects its default branch and tags with review requirements.
# OWNER/build-workflows/.github/workflows/build-release.yml
name: Build and attest
on:
workflow_call:
inputs:
artifact-name:
description: Name for the uploaded artifact
required: true
type: string
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
attestations: write
steps:
- uses: actions/checkout@v4
- name: Build
run: make build # assumed to write dist/app
- name: Attest build provenance
uses: actions/attest-build-provenance@v2
with:
subject-path: dist/app
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.artifact-name }}
path: dist/appInside a reusable workflow, the github context still describes the caller. actions/checkout therefore checks out the caller's repository at the caller's ref, and the build runs on the caller's source. The workflow's own steps come from the shared repository.
The input is used only in a with: field, never interpolated into a run: script. That choice matters, and the gotchas section explains why.
The caller
# OWNER/app/.github/workflows/release.yml
name: release
on:
push:
tags: ['v*']
jobs:
build:
permissions:
contents: read
id-token: write
attestations: write
uses: OWNER/build-workflows/.github/workflows/build-release.yml@v1
with:
artifact-name: appThe caller must grant the permissions the reusable job needs. A reusable workflow can't raise its own permissions above what the caller gives it, and the job fails if the caller grants less than the called job requests.
Pin the @v1 reference to something stable. A tag is convenient. A full commit SHA is stronger, because tags can be moved by anyone who can push to the shared repository.
What the certificate records
The Fulcio certificate for this build carries several fields taken from the OIDC token:
- The signer workflow: the reusable workflow's path and ref, such as
OWNER/build-workflows/.github/workflows/build-release.yml@refs/tags/v1. - The source repository:
OWNER/app, taken from the caller. - The source ref and digest: the tag and commit that triggered the build.
- The runner environment: GitHub-hosted or self-hosted.
- The trigger event:
push,pull_requestand so on.
These fields let a consumer ask two separate questions. One is "which code was built?" and the other is "which build definition built it?". At Level 2 the two answers collapse into one repository. At Level 3 they come apart.
Verifying for Level 3
Verification is what makes the level real. If the consumer runs only --repo, the artifact is accepted even when it was built by a modified in-repo workflow. To claim and check Level 3, require the reusable workflow.
# Require the shared reusable workflow as the signer
gh attestation verify dist/app \
--repo OWNER/app \
--signer-workflow OWNER/build-workflows/.github/workflows/build-release.yml
# Also require the signer repo, and reject self-hosted runners
gh attestation verify dist/app \
--repo OWNER/app \
--signer-repo OWNER/build-workflows \
--deny-self-hosted-runners
# Inspect the verified fields
gh attestation verify dist/app \
--repo OWNER/app \
--signer-workflow OWNER/build-workflows/.github/workflows/build-release.yml \
--format jsonIf an attacker builds the same file with a workflow in OWNER/app itself, the first command fails. The attestation is valid, but the signer identity doesn't match the required workflow. Newer versions of the CLI also accept flags such as --signer-digest and --source-digest to pin an exact commit. Run gh attestation verify --help to see what your installed version supports.
Gotchas and failure modes
- Input injection. If the reusable workflow interpolates a caller-supplied input into a
run:script, the caller can run arbitrary commands inside the trusted build. That undoes the separation. Pass inputs throughwith:or environment variables, validate them, and keep the input list short. - The source is still trusted.
make buildruns code from the caller's repository. A malicious Makefile can produce a bad binary, and the provenance will correctly say it was built from that Makefile. Level 3 protects the build platform and the record. It does not review the source. - Tag mutability. A signer identity ending in
@refs/tags/v1is only as stable as that tag. Protect tags in the shared repository, or pin by SHA and verify the signer digest. - Self-hosted runners. Isolation depends on the runner. A long-lived self-hosted runner can carry state between builds, so use ephemeral runners or deny them at verification time.
- Caches. A build that restores a shared cache can pick up content from another run. Treat cache restore as an input you must trust, or skip caches in release builds.
- Permissions drift. Giving the caller job
write-all, or giving the reusable job more permissions than it needs, widens the damage if the build is compromised.
Choosing between Level 2 and Level 3
Level 2 is a sensible default for a single project with a small team. It costs nothing beyond the attestation step, and it already ties the artifact to a repository and a commit.
Move to Level 3 when:
- many repositories share one build process and you want one reviewed definition
- consumers are outside your organization and need a stronger statement than "some workflow in that repo"
- compliance asks for isolation between the build definition and project contributors
The cost is operational. You maintain a shared repository, version its releases, and keep every consumer's verification policy in step with it.
Exercises
Exercise
A repository has a workflow that builds and attests dist/app with actions/attest-build-provenance, and consumers verify with gh attestation verify dist/app --repo OWNER/app. A contributor with write access edits the workflow to swap in a different binary before attesting. Does verification fail, and what change would make it fail?
Show answer
Verification still passes. The attestation is validly signed by a workflow in OWNER/app, which is all --repo checks. To catch it, build in a protected reusable workflow in a separate repository and verify with --signer-workflow OWNER/build-workflows/.github/workflows/build-release.yml. A modified in-repo workflow would then carry a different signer identity and be rejected.
Exercise
A reusable workflow takes an input build-args and runs make build ${{ inputs.build-args }} in a run: step. Why does this weaken Level 3, and how would you fix it?
Show answer
The caller controls the input, so it can inject shell commands into the trusted build job. The signed identity would still name the reusable workflow while the build did something the shared repository's owners never intended. Fix it by not interpolating inputs into scripts. Pass the value through an environment variable and quote it, validate it against an allowed list, or drop the input.