Skip to content
Hands-on IT IT Drills

Day 8: SBOM, Scan, Signature, Provenance

Goal: Scan the image for vulnerabilities after the build, generate a bill of materials (SBOM), attach both together with a proof of origin to the image as attestations, sign it with cosign – and verify all of it on the VM. · Duration: approx. 90 min · Prerequisite: Day 7

Briefing

  • Trivy scans an image for known vulnerabilities (CVEs) in packages and Go modules.
  • An SBOM (software bill of materials) lists every component in the image. Syft generates it, e.g. in SPDX format.
  • An attestation is a signed statement about an artifact: “this image was built by this workflow from this commit” (provenance) or “this is its SBOM”. GitHub signs it via Sigstore, without any keys of your own.
  • cosign also signs images keylessly: the run’s OIDC token proves who signed.
  • Everything refers to the digest (sha256:…), never to a tag – tags can move.
 image ──digest──► absichern: trivy (CVE) ─► syft (SBOM) ─► attest SBOM
                                          ─► attest provenance ─► cosign sign
 VM: gh attestation verify, cosign verify ◄── ghcr.io/<du>/notes-api@sha256:…

Drill 1: Passing on the digest and scanning

image.yml gets a second job. The first one passes on the digest of the built image as an output:

cd ~/gha-lab/notes-actions
cat > .github/workflows/image.yml <<'EOF'
name: image
on:
  push:
    branches: [main]
    tags: ['v*']
    paths-ignore: ['**.md']
  pull_request:
  workflow_dispatch:

permissions:
  contents: read
  packages: write

env:
  IMAGE: ghcr.io/${{ github.repository_owner }}/notes-api

jobs:
  image:
    runs-on: ubuntu-24.04
    outputs:
      digest: ${{ steps.build.outputs.digest }}
    steps:
      - uses: actions/checkout@v7
      - uses: docker/setup-buildx-action@v4
      - if: github.event_name != 'pull_request'
        uses: docker/login-action@v4
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - id: meta
        uses: docker/metadata-action@v6
        with:
          images: ${{ env.IMAGE }}
          tags: |
            type=ref,event=branch
            type=ref,event=pr
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}
            type=sha
      - id: build
        uses: docker/build-push-action@v7
        with:
          context: .
          platforms: linux/amd64,linux/arm64
          push: ${{ github.event_name != 'pull_request' }}
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}
          build-args: |
            VERSION=${{ steps.meta.outputs.version }}
            REVISION=${{ github.sha }}
          cache-from: type=gha
          cache-to: type=gha,mode=max

  absichern:
    needs: image
    if: github.event_name != 'pull_request'
    runs-on: ubuntu-24.04
    permissions:
      contents: read
      packages: write
      id-token: write
      attestations: write
    env:
      DIGEST: ${{ needs.image.outputs.digest }}
    steps:
      - uses: docker/login-action@v4
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Schwachstellen
        uses: aquasecurity/[email protected]
        with:
          image-ref: ${{ env.IMAGE }}@${{ env.DIGEST }}
          severity: HIGH,CRITICAL
          ignore-unfixed: true
          exit-code: "1"
EOF
git commit -qam "image: Digest weiterreichen, Trivy"
git push -q
  • env: at the top level applies to all jobs. ${{ env.IMAGE }} substitutes it in with:.
  • outputs.digest passes the digest from steps.build to the absichern job. There it is available in env.DIGEST; together with env.IMAGE that yields the immutable reference ghcr.io/<du>/notes-api@sha256:….
  • permissions: in the job replaces the permissions from above completely. id-token: write allows the job to request an OIDC token – Sigstore needs that. attestations: write allows storing attestations at GitHub.
  • The job logs in to GHCR itself: every job runs on a fresh runner, the login from image does not exist here. It is needed from Drill 2 on, when attestations go into the registry.
  • exit-code: "1" turns the step red if Trivy finds anything from HIGH up for which a fix already exists (ignore-unfixed).

With the ID from gh run list --workflow image.yml --limit 1, as soon as the run is finished:

gh run view <ID>

Expected (shortened):

X main image · 41620540968
...
JOBS
✓ image in 1m13s (ID 125864812633)
X absichern in 13s (ID 125865407059)
  ✓ Set up job
  X Schwachstellen
...

Red. What did Trivy find?

gh run view <ID> --log | grep -oE '│ golang.org/x/text .*' | cut -c1-80

Expected:

│ golang.org/x/text │ CVE-2026-56851 │ HIGH     │ fixed  │ v0.29.0           │

The table is wider; cut -c1-80 cuts it off. In the full log, the fixed version and a description follow:

gh run view <ID> --log | grep -oE 'CVE-2026-5685[0-9] .*' | cut -c1-90

Expected:

CVE-2026-56851 │ HIGH     │ fixed  │ v0.29.0           │ 0.41.0        │ golang.org/...
CVE-2026-56852 │          │        │                   │ 0.39.0        │ golang.org/...
  • Trivy recognizes the Go binary in the image and reads the embedded module versions – including indirect dependencies such as golang.org/x/text.
  • Two vulnerabilities with severity HIGH, status fixed: there is a version without them. From 0.41.0 on, both are fixed.

Your list may look different – new CVEs are added every day. The solution is always the same: update the dependency. You don’t have Go on the VM; a container with Go is enough:

docker run --rm -u "$(id -u)" -e HOME=/tmp -v "$PWD":/src -w /src golang:1.27-alpine \
  go get golang.org/x/[email protected]
git diff --stat

Expected (shortened):

go: upgraded golang.org/x/sync v0.17.0 => v0.22.0
go: upgraded golang.org/x/text v0.29.0 => v0.41.0
 go.mod | 4 ++--
 go.sum | 4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)
  • -e HOME=/tmp: As your user, the container has no writable home directory, but Go needs one for its cache.
  • go get has bumped golang.org/x/sync along with it – the new version of x/text requires it.
git commit -qam "deps: golang.org/x/text 0.41.0"
git push -q

With the new ID, as soon as the run is finished:

gh run view <ID> --log | grep -E 'absichern.*│ notes-api'

Expected (timestamp shortened):

absichern   Schwachstellen  ... │ notes-api │ gobinary │        0        │    -    │

Save your progress? Sign up for free

Drill 2: SBOM and SBOM attestation

You append new steps directly – absichern is the last job in the file, and the indentation of six spaces makes them steps:

cat >> .github/workflows/image.yml <<'EOF'
      - name: SBOM
        uses: anchore/[email protected]
        with:
          image: ${{ env.IMAGE }}@${{ env.DIGEST }}
          format: spdx-json
          output-file: sbom.spdx.json
          upload-release-assets: false
      - name: SBOM-Attestation
        uses: actions/attest@v4
        with:
          subject-name: ${{ env.IMAGE }}
          subject-digest: ${{ env.DIGEST }}
          sbom-path: sbom.spdx.json
          push-to-registry: true
EOF
git commit -qam "image: SBOM"
git push -q
  • sbom-action calls Syft and also uploads the SBOM as an artifact.
  • upload-release-assets: false: On a tag push, the action would otherwise also attach the SBOM to the release – the job lacks contents: write for that, and the step fails with Resource not accessible by integration.
  • actions/attest with sbom-path signs the SBOM and, with push-to-registry, puts it next to the image in the registry. Whoever has the image also finds its bill of materials.

As soon as the run is finished:

gh run view <ID>

Expected (shortened):

JOBS
✓ image in 1m2s (ID 125874935333)
✓ absichern in 23s (ID 125875422164)

ARTIFACTS
<du>~notes-actions~Q3IEUP.dockerbuild
<du>-notes-api_sha256_7145981e51f8728e420640328602a355f0859a61f05ffa821e79b...spdx.json
  • The second artifact is the SBOM, named after image and digest.
  • The first one is created by build-push-action on its own: an export of the build that Docker Desktop can open as a build report.
gh run download <ID> -p '*.spdx.json' -D /tmp/sbom
jq -r '.packages[].name' /tmp/sbom/*/*.json | sort | head

Expected (shortened):

example.com/notes-api
ghcr.io/<du>/notes-api
github.com/google/uuid
github.com/jackc/pgpassfile
github.com/jackc/pgservicefile
github.com/jackc/pgx/v5
github.com/jackc/puddle/v2
golang.org/x/sync
golang.org/x/text
stdlib

The image itself, notes-api as a Go module, the modules from go.mod and stdlib – the Go standard library in the version it was built with.

Save your progress? Sign up for free

Drill 3: Provenance

cat >> .github/workflows/image.yml <<'EOF'
      - name: Provenance
        uses: actions/attest@v4
        with:
          subject-name: ${{ env.IMAGE }}
          subject-digest: ${{ env.DIGEST }}
          push-to-registry: true
EOF
git commit -qam "image: Provenance"
git push -q

The same action, this time without sbom-path: then actions/attest generates an SLSA provenance. It records: which repository, which workflow, which commit, which runner. Verify it on the VM as soon as the run is finished:

gh attestation verify oci://ghcr.io/<du>/notes-api:main -R <du>/notes-actions

Expected (shortened):

Loaded digest sha256:34516f7eafc7179c857bbf4c81c6a7eeb60475626d4af93101...... for ...
Loaded 1 attestation from GitHub API

The following policy criteria will be enforced:
- Predicate type must match:................ https://slsa.dev/provenance/v1
- Source Repository Owner URI must match:... https://github.com/<du>
- Source Repository URI must match:......... https://github.com/<du>/notes-actions
- Subject Alternative Name must match regex: (?i)^https://github\.com/<du>/notes-act...
- OIDC Issuer must match:................... https://token.actions.githubusercontent.com

✓ Verification succeeded!

The following 1 attestation matched the policy criteria

- Attestation #1
  - Build repo:..... <du>/notes-actions
  - Build workflow:. .github/workflows/image.yml@refs/heads/main
  - Signer repo:.... <du>/notes-actions
  - Signer workflow: .github/workflows/image.yml@refs/heads/main
  • gh fetches the attestations for the digest behind :main and checks them against a policy. -R specifies: it must come from this repository. An image that someone else built and uploaded under your name fails.
  • Without further options, gh checks the provenance (slsa.dev/provenance/v1). The SBOM attestation is attached to the same digest; the checkpoint checks it specifically.

Save your progress? Sign up for free

Drill 4: Signing with cosign

cat >> .github/workflows/image.yml <<'EOF'
      - uses: sigstore/[email protected]
      - name: Signieren
        run: cosign sign --yes "$IMAGE@$DIGEST"
EOF
git commit -qam "image: cosign"
git push -q
  • cosign sign without a key fetches an OIDC token of the run, has Sigstore issue a short-lived certificate for it and signs with that.
  • --yes confirms that the signature is entered into the public transparency log Rekor.
  • "$IMAGE@$DIGEST" instead of ${{ … }}: in run:, the shell reads the variables – safer, as Day 9 shows.

cosign on the VM:

mkdir -p ~/.local/bin
gh release download v3.1.4 -R sigstore/cosign -p cosign-linux-amd64 \
  -O ~/.local/bin/cosign
chmod +x ~/.local/bin/cosign
cosign version | grep GitVersion

Expected:

GitVersion:    v3.1.4

On Ubuntu, ~/.local/bin is in the PATH as soon as it exists – after creating it for the first time, log out and back in once.

As soon as the run is finished:

cosign verify ghcr.io/<du>/notes-api:main \
  --certificate-identity-regexp '^https://github.com/<du>/notes-actions/' \
  --certificate-oidc-issuer https://token.actions.githubusercontent.com >/dev/null

Expected:

Verification for ghcr.io/<du>/notes-api:main --
The following checks were performed on each of these signatures:
  - The cosign claims were validated
  - Existence of the claims in the transparency log was verified offline
  - The code-signing certificate was verified using trusted certificate authority ...

cosign writes the result of the verification to stderr and the signatures as JSON to stdout; >/dev/null hides the JSON. If the verification fails, cosign ends with Error: no matching signatures.

  • --certificate-identity-regexp: Who must have signed? A workflow from your repository.
  • --certificate-oidc-issuer: Who confirmed this identity? The OIDC service of GitHub Actions.
  • Both together are the policy. A signature without this check proves nothing.

Save your progress? Sign up for free

Checkpoint

gh run view <ID> --json jobs --jq '.jobs[] | .name + " " + .conclusion'

Expected:

image success
absichern success
gh attestation verify oci://ghcr.io/<du>/notes-api:main -R <du>/notes-actions \
  --predicate-type https://spdx.dev/Document/v2.3 >/dev/null; echo "Exit: $?"

Expected:

Exit: 0

--predicate-type specifically checks the SBOM attestation.

gh attestation verify oci://ghcr.io/<du>/notes-api:main -R octocat/hello-world \
  >/dev/null 2>&1; echo "Exit: $?"

Expected:

Exit: 1

There is no attestation for this image from a foreign repository.

Challenge

Trivy should additionally store its findings in GitHub’s code scanning so that they appear under Security – without turning the run red.

Hint: A second Trivy step with format: sarif, output: trivy.sarif and exit-code: "0", followed by github/codeql-action/upload-sarif@v4. The job needs security-events: write.

Solution

permissions: sits in the middle of the job. Use the editor (nano or vim) to insert a line below attestations: write:

    permissions:
      contents: read
      packages: write
      id-token: write
      attestations: write
      security-events: write

Then append the steps:

cat >> .github/workflows/image.yml <<'EOF'
      - name: Schwachstellen als SARIF
        uses: aquasecurity/[email protected]
        with:
          image-ref: ${{ env.IMAGE }}@${{ env.DIGEST }}
          format: sarif
          output: trivy.sarif
          exit-code: "0"
      - uses: github/codeql-action/upload-sarif@v4
        with:
          sarif_file: trivy.sarif
EOF
git commit -qam "image: Trivy-Funde nach Code scanning"
git push -q

As soon as the run is finished:

gh api repos/{owner}/{repo}/code-scanning/analyses \
  --jq '.[0] | .tool.name, .results_count'

Expected (the number may differ):

Trivy
0

Zero findings in the image. With format: sarif, Trivy reports all severities, not just HIGH. Findings appear under Security → Code scanning.

Save your progress? Sign up for free

Enterprise Note

  • Verify at deployment: A signature is only useful if someone verifies it. In Kubernetes, admission controllers such as Kyverno or the Sigstore Policy Controller take care of that: images without a matching signature or provenance are rejected.
  • SLSA: GitHub’s provenance meets SLSA Build Level 2, with reusable workflows (Day 12) Level 3 – the build then runs in a workflow that the calling repository cannot change.
  • Private repositories: Attestations there require GitHub Enterprise Cloud. They do not end up in the public Rekor log.
  • Noise: Trivy with exit-code: 1 without ignore-unfixed blocks builds because of vulnerabilities for which no fix exists. A .trivyignore with a justification and an expiry date is better than a disabled scan.