feat(build): attach a provenance attestation beside the SBOM (#5043)

## What this PR does

Follow-up to #4997 (merged as d32092ac9), rebased onto `main` at that
merge: one commit `57db352ed`. The second half of what was agreed there:
beside the SBOM, each release image gets a SLSA provenance statement
from BuildKit, in the same attestation manifest.

Refs #4759, #3278

`SBOM=1` in `hack/common-envs.mk` now passes `--attest
type=provenance,mode=min` with the SBOM attest, in place of
`--provenance=false`; a build without `SBOM=1` keeps
`--provenance=false` as before. BuildKit writes both predicates into the
one attestation manifest per platform, so the index shape
`hack/stitch-multiarch.sh` and `hack/verify-multiarch.sh` read after
#4997 is unchanged, and a signature over the index covers the provenance
as it covers the SBOM. `mode=min` records the build times, the build
platform, the frontend and the BuildKit version and leaves out the build
arguments and the secrets, which `mode=max` would write in, so it can
ride every release image. `docker buildx imagetools inspect
<image>@<digest> --format '{{ json .Provenance }}'` prints it;
`docs/release.md` says so.

### How it was checked

- `hack/common-envs_test.bats`: the `SBOM=1` test now also holds that
`--attest type=provenance,mode=min` is passed, that `--provenance=false`
is not, that neither `mode=max` nor `--provenance=true` appears, and
that the default build still passes `--provenance=false` and no
`--attest`. `make -n` of `packages/system/cozystack-controller` shows
exactly that in both modes. `hack/stitch-multiarch_test.bats` is green:
the attestation manifest count per platform does not change.
- A real build, by @myasnikovdaniil on a local registry: amd64 and arm64
built with the flags from `common-envs.mk`, stitched,
`verify-multiarch.sh` passes, the index has four manifests (two images,
two attestation manifests with SBOM and provenance each), `.Provenance`
reads for both platforms, and a `--build-arg` value is in `mode=max` and
not in `mode=min`.
- Rebased on `main` at d32092ac9: `hack/common-envs_test.bats` and
`hack/stitch-multiarch_test.bats` 34/34.
- Not checked: the provenance predicate on a release runner. The first
alpha after the merge shows it.

### Decisions for the release owners

- `mode=min` rather than `mode=max`: the Dockerfiles take `--build-arg`
values a reader of a public attestation should not see by default. If a
package's arguments are all public, `max` is one word away.
- `docs/security/self-assessment.md` still says build provenance is
disabled (`--provenance=false`). It stays until the first alpha shows
provenance on a release image, as #4997 holds its SBOM row.
- PR, main and nightly builds stay without provenance, as they stay
without an SBOM: nothing reads it there, and the default docker driver
cannot attach it.

### Screenshots

<!-- REQUIRED for UI changes: attach screenshots or screen recordings
demonstrating
the visual impact of your changes. PRs with UI changes without
screenshots will not be merged. -->

### Downstream repositories

- [x] No downstream repository is affected by this change
- [ ] [cozystack/website](https://github.com/cozystack/website) -
follow-up:
- [ ]
[cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack)
- follow-up:
- [ ]
[cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack)
- follow-up:
- [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up:
- [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up:
- [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) -
follow-up:
- [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) -
follow-up:
- [ ]
[cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server)
- follow-up:
- [ ]
[cozystack/external-apps-example](https://github.com/cozystack/external-apps-example)
- follow-up:
- [ ] [cozystack/examples](https://github.com/cozystack/examples) -
follow-up:
- [ ] [cozystack/community](https://github.com/cozystack/community) -
follow-up:

I walked the trigger map against the diff. `hack/common-envs.mk` changes
the flags one variable expands to and no target, variable name or file
that ccp's skills anchor on; nothing else is touched.

### Release note

```release-note
feat(build): every release image built with `SBOM=1` also carries a SLSA provenance statement (BuildKit `mode=min`: build times, platform, frontend and BuildKit version, no build arguments or secrets) in the same attestation manifest as its SBOM, readable with `docker buildx imagetools inspect <image>@<digest> --format '{{ json .Provenance }}'`.
```



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **New Features**
* Container builds with SBOM generation enabled now include both an SPDX
software bill of materials and a minimal SLSA provenance attestation.
  * Provenance attestations remain disabled when SBOM generation is off.

* **Documentation**
* Updated the container image security guide with details on provenance
contents and how to inspect the attestation.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Marian Koreniuk authored and GitHub committed 2026-11-20 10:32:33 +01:00
commit cfb5119c0b
3 files changed
+24 -11

No files matched your search

+1 -1
View File
@@ -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 <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.
+16 -8
View File
@@ -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)
+7 -2
View File
@@ -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,'