mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 04:06:34 +09:00
feat(build): attach a provenance attestation beside the SBOM
An image built with SBOM=1 says what is in it and nothing about how it was built: BUILDX_ARGS set --provenance=false for every build, from when any attestation broke the single-platform stitch. SBOM=1 now also passes --attest type=provenance,mode=min, which BuildKit writes into the same attestation manifest as the SBOM, so the index shape the stitch and the gate read since #4997 is unchanged and a signature over the index covers it. mode=min records the build times, the platform, the frontend and the BuildKit version and leaves out build arguments and secrets, which is what lets it ride every release image. A build without SBOM=1 keeps --provenance=false: the default docker driver cannot attach it, and a PR image turned into an index would buy nothing. Refs #3278 Assisted-by: LLM Signed-off-by: Marian Koreniuk <moriarti@cp.if.ua>
This commit is contained in:
3 files changed
+24
-11
No files matched your search
+1
-1
@@ -355,7 +355,7 @@ 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 <image>@<digest> --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 <image>@<digest> --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 <image>@<digest> --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.
|
||||
|
||||
## Nightly builds
|
||||
|
||||
|
||||
+16
-8
@@ -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)
|
||||
|
||||
@@ -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,'
|
||||
|
||||
Reference in new issue
Block a user