diff --git a/docs/release/signatures-and-sbom.md b/docs/release/signatures-and-sbom.md index 8aa47051e..866416294 100644 --- a/docs/release/signatures-and-sbom.md +++ b/docs/release/signatures-and-sbom.md @@ -26,4 +26,4 @@ The script runs the same `cosign verify-blob` before it returns, so a signature ### SBOM of the container images -The container images a release pins by digest each carry an SPDX SBOM of the packages in them, which BuildKit attaches at build time as an attestation (`SBOM=1` in `tags.yaml`, scanner and flags in [`hack/common-envs.mk`](../../hack/common-envs.mk)). The attestation is an entry of the image's index, so the digest the release pins names both, and promotion copies it with the image. Read it with `docker buildx imagetools inspect @ --format '{{ json .SBOM }}'`, which prints one document per platform. The attestations are not signed. A release cut before `SBOM=1` was set has none, and neither has the Talos installer image, which the imager builds and `skopeo` pushes, nor the third-party images `packages/` vendors by digest. +The container images a release pins by digest each carry an SPDX SBOM of the packages in them, which BuildKit attaches at build time as an attestation (`SBOM=1` in `tags.yaml`, scanner and flags in [`hack/common-envs.mk`](../../hack/common-envs.mk)). The attestation is an entry of the image's index, so the digest the release pins names both, and promotion copies it with the image. Read it with `docker buildx imagetools inspect @ --format '{{ json .SBOM }}'`, which prints one document per platform. The same attestation manifest carries a SLSA provenance statement of the build, in BuildKit's `mode=min` (build times, platform, frontend and BuildKit version, no build arguments and no secrets), which `docker buildx imagetools inspect @ --format '{{ json .Provenance }}'` prints. The attestations are not signed. A release cut before `SBOM=1` was set has none, and neither has the Talos installer image, which the imager builds and `skopeo` pushes, nor the third-party images `packages/` vendors by digest. diff --git a/hack/common-envs.mk b/hack/common-envs.mk index 687de095d..8ede2e7d5 100644 --- a/hack/common-envs.mk +++ b/hack/common-envs.mk @@ -66,21 +66,29 @@ PLATFORM ?= $(if $(filter 1,$(LOAD)),,$(DEFAULT_PLATFORMS)) BUILDX_EXTRA_ARGS ?= COZYSTACK_VERSION = $(patsubst v%,%,$(shell git describe --tags --match 'v*')) -# SBOM=1 attaches an SPDX SBOM to every image as a BuildKit attestation. The -# pushed ref then names an index of the image and its attestation manifest, not -# the image itself, which hack/stitch-multiarch.sh and hack/verify-multiarch.sh -# both handle. Attestations need the docker-container buildx driver. The scanner -# is pinned by digest like every other build input, where --sbom=true would pull +# SBOM=1 attaches an SPDX SBOM and a SLSA provenance statement to every image +# as BuildKit attestations, in one attestation manifest per platform. The +# pushed ref then names an index of the image and that manifest, not the image +# itself, which hack/stitch-multiarch.sh and hack/verify-multiarch.sh both +# handle. Attestations need the docker-container buildx driver. The scanner is +# pinned by digest like every other build input, where --sbom=true would pull # a floating tag. Renovate bumps the version and the digest together, through # the manager in .github/renovate.json that reads the SBOM_SCANNER line below. +# +# The provenance is mode=min: build times, the build platform, the frontend +# and BuildKit version, nothing of the build arguments or secrets, so it can +# ride every release image. Without SBOM=1 provenance stays off: the default +# docker driver cannot attach it, and it would turn every PR image into an +# index for nothing that reads it. SBOM ?= 0 SBOM_SCANNER ?= docker.io/docker/buildkit-syft-scanner:1.12.0@sha256:ae4f3b554449e7e25548e7d8ccc029d17357348e30c6e3df01b92bc93654d6a9 -# A variable, because the commas would split the arguments of $(if) below. +# Variables, because the commas would split the arguments of $(if) below. SBOM_ATTEST := --attest type=sbom,generator=$(SBOM_SCANNER) +PROVENANCE_ATTEST := --attest type=provenance,mode=min -BUILDX_ARGS := --provenance=false --push=$(PUSH) --load=$(LOAD) \ +BUILDX_ARGS := --push=$(PUSH) --load=$(LOAD) \ --label org.opencontainers.image.source=https://github.com/cozystack/cozystack \ - $(if $(filter 1,$(SBOM)),$(SBOM_ATTEST)) \ + $(if $(filter 1,$(SBOM)),$(SBOM_ATTEST) $(PROVENANCE_ATTEST),--provenance=false) \ $(if $(strip $(BUILDER)),--builder=$(BUILDER)) \ $(if $(strip $(PLATFORM)),--platform=$(PLATFORM)) \ $(BUILDX_EXTRA_ARGS) diff --git a/hack/common-envs_test.bats b/hack/common-envs_test.bats index fd88ec6cd..59ad1eae6 100644 --- a/hack/common-envs_test.bats +++ b/hack/common-envs_test.bats @@ -144,15 +144,20 @@ load test_helper echo "$out" | grep -q -- '--push=0 --load=1' } -@test "SBOM=1 attaches an SPDX attestation from a scanner pinned by digest, and the default builds none" { +@test "SBOM=1 attaches an SPDX attestation from a scanner pinned by digest and a mode=min provenance, and the default builds none" { # An image built with an attestation is an index, not a plain manifest, which # the stitch and the gate have to read, so it stays off unless a build asks. - # --sbom=true would pull the scanner by a floating tag. + # --sbom=true would pull the scanner by a floating tag. Provenance rides the + # same attestation manifest; mode=max would write build arguments into it. out=$(make -n -C packages/system/cozystack-controller image IMAGE_TAG=pr-1-abc COZYSTACK_VERSION=0 BUILDER=b) if echo "$out" | grep -q -- '--attest\|--sbom'; then echo "FAIL: an attestation without SBOM=1"; false; fi + echo "$out" | grep -q -- '--provenance=false' || { echo "FAIL: provenance not switched off without SBOM=1"; false; } out=$(make -n -C packages/system/cozystack-controller image IMAGE_TAG=pr-1-abc COZYSTACK_VERSION=0 BUILDER=b SBOM=1) echo "$out" | grep -qE -- '--attest type=sbom,generator=[^ ]+@sha256:[0-9a-f]{64} ' || { echo "FAIL: no digest-pinned scanner"; false; } if echo "$out" | grep -q -- '--sbom'; then echo "FAIL: --sbom=true pulls a floating scanner tag"; false; fi + echo "$out" | grep -q -- '--attest type=provenance,mode=min' || { echo "FAIL: no mode=min provenance beside the SBOM"; false; } + if echo "$out" | grep -q -- '--provenance=false'; then echo "FAIL: --provenance=false cancels the provenance attestation"; false; fi + if echo "$out" | grep -qE -- 'provenance,mode=max|--provenance=true'; then echo "FAIL: full provenance would carry build arguments"; false; fi # The environment reaches buildx as well, which is how the release workflow sets it. out=$(SBOM=1 make -n -C packages/system/cozystack-controller image IMAGE_TAG=pr-1-abc COZYSTACK_VERSION=0 BUILDER=b) echo "$out" | grep -q -- '--attest type=sbom,'