TExcelTAD
Home › Software Supply Chain Security: SBOM, SLSA & Sigstore › GitHub Attestations & slsa-github-generator

GitHub Attestations & slsa-github-generator

On GitHub you rarely write provenance yourself. Two mechanisms generate it, signed keylessly with the workflow's identity:

GitHub artifact attestations slsa-github-generator
Maintained by GitHub (actions/attest-build-provenance, actions/attest-sbom, actions/attest) the SLSA project (OpenSSF)
Provenance format in-toto statement, SLSA provenance v1, Sigstore bundle in-toto statement, SLSA provenance, .intoto.jsonl files or registry attestations
Stored GitHub's attestations API (and optionally the registry) release assets or the registry
Verified with gh attestation verify slsa-verifier
SLSA Build level L2; L3 when the attestation is made in a reusable workflow that isolates signing L3 by design (the provenance is generated in a separate, reusable workflow job)

Note: Both require GitHub's OIDC tokens and Sigstore's (or GitHub's) signing services, so this lesson is non-run. Public repositories sign with the public Sigstore instance (entries appear in Rekor); private repositories use GitHub's own Sigstore instance. Check GitHub's plan requirements for private repositories.

Artifact attestations

yaml
name: release
on:
  push:
    tags: ["v*"]

permissions: {}                       # nothing by default; grant per job

jobs:
  build:
    runs-on: ubuntu-24.04
    permissions:
      contents: read
      id-token: write                 # mint an OIDC token for Sigstore
      attestations: write             # store the attestation in GitHub
      packages: write                 # push the image (and its attestation) to GHCR
    steps:
      - uses: actions/checkout@<commit-sha>                    # v5
      - name: Build and push
        id: push
        run: |
          docker buildx build --push -t ghcr.io/acme/shop:${GITHUB_REF_NAME} \
            --metadata-file meta.json .
          echo "digest=$(jq -r '."containerimage.digest"' meta.json)" >> "$GITHUB_OUTPUT"
      - uses: actions/attest-build-provenance@<commit-sha>     # v3
        with:
          subject-name: ghcr.io/acme/shop
          subject-digest: ${{ steps.push.outputs.digest }}
          push-to-registry: true
      - name: SBOM
        run: syft scan ghcr.io/acme/shop@${{ steps.push.outputs.digest }} -o spdx-json=sbom.spdx.json
      - uses: actions/attest-sbom@<commit-sha>                 # v2
        with:
          subject-name: ghcr.io/acme/shop
          subject-digest: ${{ steps.push.outputs.digest }}
          sbom-path: sbom.spdx.json
          push-to-registry: true

For release files, subject-path: dist/*.tar.gz replaces name and digest. Consumers verify with the GitHub CLI:

bash
gh attestation verify oci://ghcr.io/acme/shop@sha256:4c6f… \
  --repo acme/shop \
  --signer-workflow acme/shop/.github/workflows/release.yml \
  --source-ref refs/tags/v1.4.2

gh attestation verify dist/shop-1.4.2.tar.gz --owner acme

--repo/--owner pin where the artifact was built; --signer-workflow pins which workflow signed (important when many workflows in a repository can run); --source-ref pins the ref. Without these, any workflow in any repository of the owner passes.

slsa-github-generator

The generic generator takes the SHA-256 hashes of your build outputs from a normal job and produces provenance in a separate reusable workflow, where your build steps can't touch the signing:

yaml
jobs:
  build:
    runs-on: ubuntu-24.04
    outputs:
      hashes: ${{ steps.hash.outputs.hashes }}
    steps:
      - uses: actions/checkout@<commit-sha>
      - run: make dist
      - id: hash
        run: echo "hashes=$(cd dist && sha256sum * | base64 -w0)" >> "$GITHUB_OUTPUT"

  provenance:
    needs: [build]
    permissions:
      actions: read
      id-token: write
      contents: write                 # upload the provenance to the release
    uses: slsa-framework/slsa-github-generator/.github/workflows/generator_generic_slsa3.yml@v2.1.0
    with:
      base64-subjects: ${{ needs.build.outputs.hashes }}
      upload-assets: true

Note the @v2.1.0 tag: this is the one place where pinning by SHA is wrong. The generator's identity (and what slsa-verifier checks) is the workflow at a release tag, and the project documents that it must be referenced that way. A container variant (generator_container_slsa3.yml, inputs image and digest) attaches the provenance to an image in the registry.

bash
slsa-verifier verify-artifact dist/shop-1.4.2.tar.gz \
  --provenance-path shop.intoto.jsonl \
  --source-uri github.com/acme/shop \
  --source-tag v1.4.2

slsa-verifier verify-image ghcr.io/acme/shop@sha256:4c6f… \
  --source-uri github.com/acme/shop --source-tag v1.4.2

Package registries

The same machinery reaches package ecosystems:

  • npm: npm publish --provenance from GitHub Actions or GitLab CI (with id-token: write) attaches a Sigstore-signed provenance statement; npmjs.com shows where the package was built, and npm audit signatures verifies registry signatures and provenance of installed packages. npm's trusted publishing (OIDC instead of long-lived tokens) generates provenance automatically.
  • PyPI: Trusted Publishing with pypa/gh-action-pypi-publish uploads PEP 740 attestations by default (Trusted Publishing).
  • Container registries: GHCR, Docker Hub and others store attestations as referrers next to images.

A model: matching a workflow identity

A keyless certificate from GitHub Actions names the workflow in its SAN as a URI: https://github.com/<owner>/<repo>/<workflow path>@<ref>. Verifiers match it exactly or with an anchored regular expression. Unanchored patterns are a classic mistake:

python · try it yourself
import re

identities = [
    "https://github.com/acme/shop/.github/workflows/release.yml@refs/tags/v1.4.2",
    "https://github.com/acme/shop/.github/workflows/release.yml@refs/heads/main",
    "https://github.com/acme/shop/.github/workflows/test.yml@refs/tags/v1.4.2",
    "https://github.com/mallory/acme-shop-mirror/.github/workflows/release.yml@refs/tags/v1.4.2",
    "https://github.com/evil/x/.github/workflows/a.yml@refs/heads/github.com/acme/shop/.github/workflows/release.yml@refs/tags/v9",
]

patterns = {
    "unanchored": r"github\.com/acme/shop/\.github/workflows/release\.yml@refs/tags/v",
    "anchored":   r"^https://github\.com/acme/shop/\.github/workflows/release\.yml@refs/tags/v[0-9]+\.[0-9]+\.[0-9]+
quot;, } for name, pattern in patterns.items(): print(f"--- {name}") for ident in identities: ok = re.search(pattern, ident) is not None print(f" {'ACCEPT' if ok else 'reject'} {ident.replace('https://github.com/', '')[:72]}")
--- unanchored
  ACCEPT  acme/shop/.github/workflows/release.yml@refs/tags/v1.4.2
  reject  acme/shop/.github/workflows/release.yml@refs/heads/main
  reject  acme/shop/.github/workflows/test.yml@refs/tags/v1.4.2
  reject  mallory/acme-shop-mirror/.github/workflows/release.yml@refs/tags/v1.4.2
  ACCEPT  evil/x/.github/workflows/a.yml@refs/heads/github.com/acme/shop/.github/w
--- anchored
  ACCEPT  acme/shop/.github/workflows/release.yml@refs/tags/v1.4.2
  reject  acme/shop/.github/workflows/release.yml@refs/heads/main
  reject  acme/shop/.github/workflows/test.yml@refs/tags/v1.4.2
  reject  mallory/acme-shop-mirror/.github/workflows/release.yml@refs/tags/v1.4.2
  reject  evil/x/.github/workflows/a.yml@refs/heads/github.com/acme/shop/.github/w

The unanchored pattern accepts a workflow in a completely different repository, because the attacker chose a branch name that contains the trusted identity. Always anchor with ^…$, or use exact --certificate-identity values and tools' structured flags (--repo, --signer-workflow, --source-uri).

Test yourself

Which permission must a GitHub Actions job have to sign keylessly?

  1. contents: write
  2. id-token: write
  3. packages: read
  4. actions: write

Why is slsa-github-generator referenced by a tag like @v2.1.0 instead of a commit SHA?

  1. Tags are more secure than SHAs in general
  2. The generator's builder identity, which slsa-verifier checks, is the reusable workflow at a release tag, and the project requires it
  3. GitHub doesn't allow SHAs for reusable workflows
  4. SHAs are deprecated

What does --signer-workflow add to gh attestation verify --repo acme/shop?

  1. Nothing
  2. It requires that a specific workflow file signed the attestation, not just any workflow in the repository
  3. It downloads the workflow
  4. It skips Rekor