Skip to content

Commit d32092a

Browse files
authored
feat(release): attach an SBOM to every release image (#4997)
## What this PR does This PR attaches an SPDX SBOM to every first-party image of a release. BuildKit adds it at build time as an attestation, so it sits in the image's index and moves with the digest the release pins, through promotion. `docker buildx imagetools inspect <image>@<digest> --format '{{ json .SBOM }}'` prints it, one document per platform. Releases cut from this change on have it. The Talos installer image (built by the imager, pushed by skopeo) and the third-party images don't. It is more than `SBOM: '1'` in `tags.yaml`, because three things broke on the way: - An image built with an attestation is an index of the image and an attestation manifest. `image_arch` in `hack/stitch-multiarch.sh` read that as not one amd64 and one arm64 image, so the stitch skipped every such image and still exited 0, and `hack/verify-multiarch.sh` then failed the release with "index without linux/arm64". `image_arch` and the rerun check look through the index now, and the stitched index keeps both attestations. - The release `make build` ran on the default docker driver, which cannot attach attestations. It runs on the docker-container builder with the docker.io mirror now, like the arm64 leg. `use: false` stays, so a plain `docker build` keeps the default driver. - `--sbom=true` pulls `docker/buildkit-syft-scanner:stable-1`, a floating tag. `SBOM=1` passes `--attest type=sbom,generator=` with the scanner pinned by digest (1.12.0). The comment in `hack/common-envs.mk` called the output CycloneDX, BuildKit writes SPDX, and the same word in `docs/security/self-assessment.md` is fixed too. Only the release lane changes. PR, main and nightly builds push to OCIR and are not what users install, so the OCIR attestation probe the tracker (A2 in #3278) listed is not on this path, release images go to GHCR. ### How it was checked - Bats 1.14.0: four new tests in `hack/stitch-multiarch_test.bats` (the arm64 leg's workflow shape, a stitch of SBOM images, a rerun after one, an index of two linux images that is skipped), two in `hack/common-envs_test.bats` (the flags, and the Renovate manager held to the `SBOM_SCANNER` line), and the matchbox workflow test rewritten for the new builder. The stitch tests fail on `main`'s `stitch-multiarch.sh`, and each of these mutations fails one: dropping the `length == 1` check, counting the attestation as a platform, looking for the amd64 index itself in the rerun, taking `SBOM`, `BUILDER` or the mirror config out of `tags.yaml`, going back to `--sbom=true`, dropping the scanner digest, turning `SBOM` on by default, reformatting the `SBOM_SCANNER` line out of the Renovate manager's regexp. - A rehearsal on a localhost registry (docker 29.8, buildx 0.37.1) with the real scripts. Images built through the `BUILDX_ARGS` of `common-envs.mk` for amd64 and arm64, one without SBOM beside them, then `stitch-multiarch.sh` (2 stitched, 0 skipped), `verify-multiarch.sh` (0 failed), `imagetools inspect` reading SPDX 2.3 with 15 packages per platform from the stitched index, and `skopeo copy --multi-arch all` keeping the index digest. `containerimage.digest` in `--metadata-file` equals the pushed index digest, so the digest the package Makefiles stamp is the index. The same run with `main`'s stitch skips the SBOM image, exits 0 and fails the gate. - `make bats-unit-tests`: 2444 of 2445. The one failure, "all-topics backup skips double-underscore internals and keeps single-underscore user topics" in `hack/kafka-topic-backup-strategy.bats`, also fails on unmodified `main` on the same machine. `make bats-posix-compat-tests` passes, and the stitch test file passes under dash through `cozytest.sh`. `hack/check-commit-trailers.sh` passes. zizmor and actionlint aren't installed here, so the workflow change (two env keys and one renamed builder step) is covered only by the tests above. - Not checked: that GHCR takes the attestations, what retention does to the child manifests, the fork lane's OCI export (it doesn't set `SBOM`), and a real release build. The first alpha cut after the merge tests the first and the last. Renovate itself did not run on the new manager: the config passes the Renovate JSON schema, and the regexp takes the tag and the digest off the live line, which a test holds. ### Decisions for the release owners - Scope is `tags.yaml` only. SBOMs on main and nightly images would need OCIR to take attestations (not probed) and would change what the nightly mirror copies. - The scanner is 1.12.0 with syft 1.51.0 inside, which is in the range of GHSA-mw2c-m758-9v5q (memory exhaustion parsing binary inputs, fixed in syft 1.52.0). It reads images our own builds produce, so I didn't hold the change for it. A Renovate manager on the `SBOM_SCANNER` line moves the version and the digest together when the scanner ships a newer syft. - The scanner adds a step per image and I didn't time it on the release runners. - A stitch rerun reads the amd64 index the tree pins, which stays in the registry untagged after a stitch. If the registry drops untagged manifests before the rerun, it fails at that read rather than repinning. - After the first alpha with attestations I'll move A2b in #3278 and the SBOM item in #2937 to done. The SBOM row in `docs/security/self-assessment.md` still says SBOMs aren't published, and stays until that alpha shows they are. ### 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. It touches `tags.yaml`, `hack/common-envs.mk`, the stitch and verify scripts and three docs. No release asset is renamed, `hack/package.mk` and the commit convention are untouched, and the flow a maintainer follows to cut and promote a release is the same. ### Release note ```release-note feat(release): every first-party container image of a release carries an SPDX SBOM as a BuildKit attestation in its index, readable with `docker buildx imagetools inspect <image>@<digest> --format '{{ json .SBOM }}'`. Releases cut from this change on have it, the Talos installer image and third-party images don't. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit - **New Features** - Supported release image builds now include SPDX-format software bills of materials (SBOMs) as attestations. - Multi-architecture image stitching, retagging, and mirroring preserve SBOM attestations. - **Documentation** - Updated image-reference guidance to explain how to handle attestation entries in multi-architecture indexes. - Clarified which images include SBOMs, how to inspect them, and that SBOM generation remains disabled by default outside configured release builds. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 94ada11 + 7fceb92 commit d32092a

10 files changed

Lines changed: 219 additions & 34 deletions

File tree

‎.github/renovate.json‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232
"matchStrings": ["clastix/kubectl:(?<currentValue>v[0-9]+\\.[0-9]+(?:\\.[0-9]+)?)@(?<currentDigest>sha256:[a-f0-9]+)"],
3333
"datasourceTemplate": "docker",
3434
"depNameTemplate": "docker.io/clastix/kubectl"
35+
},
36+
{
37+
"customType": "regex",
38+
"description": "Track the BuildKit SBOM scanner pinned by tag and digest in hack/common-envs.mk. The dockerfile manager does not read Makefiles and the helm-values manager is disabled repo-wide (see enabledManagers above), so without this manager the pin would stay on the syft it was cut with: the floating stable-1 tag it replaced moved to a fixed syft on its own, a digest pin does not. Tag and digest move together here, as the comment above the pin asks.",
39+
"managerFilePatterns": ["/^hack/common-envs\\.mk$/"],
40+
"matchStrings": ["SBOM_SCANNER \\?= (?<depName>docker\\.io/docker/buildkit-syft-scanner):(?<currentValue>[0-9]+\\.[0-9]+\\.[0-9]+)@(?<currentDigest>sha256:[a-f0-9]+)"],
41+
"datasourceTemplate": "docker"
3542
}
3643
],
3744
"packageRules": [

‎.github/workflows/tags.yaml‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ jobs:
120120
env:
121121
DOCKER_CONFIG: ${{ runner.temp }}/.docker
122122
BUILDER: ${{ steps.buildx.outputs.name }}
123+
SBOM: '1'
123124
PLATFORM: linux/arm64
124125
CACHE_REGISTRY: iad.ocir.io/idyksih5sir9/cozystack
125126
# Read the arm64 cache build-arm64-nightly.yaml keeps warm; a release
@@ -290,11 +291,14 @@ jobs:
290291
env:
291292
DOCKER_CONFIG: ${{ runner.temp }}/.docker
292293

293-
# Only for the matchbox rebuild below: the default docker driver cannot
294-
# build an index, and `use: false` keeps make build on that driver.
295-
- name: Set up Buildx for matchbox (docker-container driver)
294+
# Every image carries an SBOM attestation, which the default docker driver
295+
# cannot attach, and the matchbox index below needs this driver too.
296+
# docker.io pulls go through the mirror in hack/buildkitd.toml, as the
297+
# arm64 leg's do. `use: false` keeps plain `docker build` on the default
298+
# driver; the builds name this one with BUILDER.
299+
- name: Set up Buildx (docker-container driver, docker.io mirror)
296300
if: steps.check_release.outputs.release_exists == 'false'
297-
id: matchbox_buildx
301+
id: buildx
298302
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
299303
with:
300304
driver: docker-container
@@ -315,17 +319,16 @@ jobs:
315319
# The arm64 leg skips the talos package, so matchbox gets no arm64
316320
# half to stitch. Its Dockerfile only copies files, so both arches
317321
# build here without QEMU and the stamped ref pins the index.
318-
make -C packages/core/talos image-matchbox PLATFORM=linux/amd64,linux/arm64 BUILDER="$MATCHBOX_BUILDER"
322+
make -C packages/core/talos image-matchbox PLATFORM=linux/amd64,linux/arm64
319323
env:
320-
MATCHBOX_BUILDER: ${{ steps.matchbox_buildx.outputs.name }}
321324
DOCKER_CONFIG: ${{ runner.temp }}/.docker
325+
BUILDER: ${{ steps.buildx.outputs.name }}
326+
SBOM: '1'
322327
# Cache manifests are registry-portable (oci-mediatypes=true) — read
323328
# them from OCIR while pushing images to GHCR. A missing :buildcache
324329
# ref 404s harmlessly into a cold build.
325330
CACHE_REGISTRY: iad.ocir.io/idyksih5sir9/cozystack
326-
# amd64 here; build-arm64 builds arm64 natively. This job also
327-
# builds on the default docker driver, which handles a
328-
# multi-platform image only on the containerd image store.
331+
# amd64 here; build-arm64 builds arm64 natively.
329332
PLATFORM: linux/amd64
330333
# Push the release tag as :IMAGE_TAG (vX.Y.Z-rc.N) and the component
331334
# versions as :<component-ver>. Deliberately NO PUBLISH_FLOATING: this

‎docs/agents/image-refs.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ If a package stamps a reference somewhere the two globs do not cover, add that f
4747
- **A package that stamps a reference is in the root `Makefile` `build:` list.** `build-matrix.sh`, the main build and release preparation all iterate that one list, so a package outside it is never rebuilt by any path and its pin freezes permanently. `hack/build-matrix_test.bats` computes the set of packages whose Makefile runs `docker buildx build` and fails on any the list misses.
4848
- **Every consumer of references reads all three storage shapes**, via `hack/lib/image-refs.sh`.
4949
- **Scan wider than you rewrite.** A rewrite is deliberately narrow to avoid corrupting vendored defaults, so the check that follows it must not share that blind spot. `hack/promote-rewrite-tags.sh` rewrites the enumerated files, then greps the whole tree and fails if any reference to the release candidate survives.
50+
- **A pin can name an index that carries attestation manifests.** An image built with `SBOM=1` is pushed as an index of the image and its attestation manifest, and the ref pins that index, not a single-platform manifest. A consumer that reads a pin's manifest takes the entries with `platform.os == "linux"` as its platforms: an entry whose platform is `unknown/unknown` is an attestation, not a platform. `hack/stitch-multiarch.sh` and `hack/verify-multiarch.sh` read pins this way, and `skopeo copy --multi-arch all`, which the retag and the mirror run, copies the attestation with the image.
5051

5152
## What each consumer does
5253

@@ -58,9 +59,9 @@ If a package stamps a reference somewhere the two globs do not cover, add that f
5859
| `hack/promote-retag.sh` | all three shapes | copy each digest to its stable tag in the registry |
5960
| `hack/nightly-mirror.sh` | all three shapes | copy each digest to the public registry, then rewrite hosts in the same file set |
6061
| `hack/overlay-main-images.sh` | `values.yaml` + `*.tag` | overlay current-main references onto packages a PR did not rebuild |
61-
| `hack/stitch-multiarch.sh` | all three shapes | join each amd64 image and its `-arm64` twin into one index, repin the tree on it, then fail if any old digest survives |
62+
| `hack/stitch-multiarch.sh` | all three shapes | join each amd64 image and its `-arm64` twin into one index, each side an image or, built with `SBOM=1`, an index of the image and its attestation that the result keeps, repin the tree on it, then fail if any old digest survives |
6263
| `hack/retention-packages.sh` | all three shapes, in the published nightly tree | name the GHCR packages the retention workflow prunes (those linked to another repository are then skipped); a ref it cannot see is a package whose nightlies are never pruned |
63-
| `hack/verify-multiarch.sh` | all three shapes, first- and third-party | fail a release unless every pinned image is an index with `linux/amd64` and `linux/arm64`, bar the repositories in `hack/multiarch-allowlist` |
64+
| `hack/verify-multiarch.sh` | all three shapes, first- and third-party | fail a release unless every pinned image is an index with `linux/amd64` and `linux/arm64`, attestation entries not counted, bar the repositories in `hack/multiarch-allowlist` |
6465

6566
`hack/multiarch-allowlist` is the only bypass for that gate, and it is for images that cannot exist for arm64, not for images nobody has rebuilt yet. An entry is a repository with no tag or digest, so bumping an allowed image needs no edit, and it must carry a reason after `#` on the same line: the script refuses an entry without one. Allowed refs are still printed, under their own "allowed single-arch" heading, and in tree mode an entry that matches no ref that failed the check is reported as stale without changing the exit status, so it gets removed once the image is multi-arch or gone. `--refs-file` reports no stale entries, since a list of pulled images omits everything the run did not pull.
6667

‎docs/release.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ So a commit on a supported `release-X.Y` line ships when a maintainer promotes t
331331

332332
A release cut from a tree that has [`hack/sign-release-assets.sh`](../hack/sign-release-assets.sh) carries three files beside its other assets, which [`hack/upload-assets.sh`](../hack/upload-assets.sh) has that script write before it uploads anything. Releases cut before it have none of them, and neither does a maintenance line until the script is backported to it (see below).
333333

334-
- `cozystack-source-sbom.spdx.json` is an SPDX SBOM, made with syft, of the committed source tree (the Go modules, npm lockfiles, GitHub Actions references and other manifests syft reads in it) and of the `cozypkg` binaries in the `cozypkg-*.tar.gz` assets. It does not describe what runs in the cluster: neither the container images that `packages/` pins by digest, whose SBOMs are [#2937](https://github.com/cozystack/cozystack/issues/2937) (item A2 in [#3278](https://github.com/cozystack/cozystack/issues/3278)), nor the Talos ISO, disk, kernel and initramfs images. Its name says what it covers, so that `cozystack-sbom` stays free for an SBOM of the release as a whole.
334+
- `cozystack-source-sbom.spdx.json` is an SPDX SBOM, made with syft, of the committed source tree (the Go modules, npm lockfiles, GitHub Actions references and other manifests syft reads in it) and of the `cozypkg` binaries in the `cozypkg-*.tar.gz` assets. It does not describe what runs in the cluster: the container images carry their own SBOMs, see [SBOM of the container images](#sbom-of-the-container-images), and the Talos installer image, ISO, disk, kernel and initramfs images have none. Its name says what it covers, so that `cozystack-sbom` stays free for an SBOM of the release as a whole.
335335
- `cozystack-checksums.txt` holds the SHA-256 of every other asset and of the SBOM.
336336
- `cozystack-checksums.txt.sigstore.json` is a Sigstore bundle with a keyless cosign signature over the checksums. Its certificate names the workflow that published the release: `tags.yaml` for a pre-release, `promote-rc.yaml` for a stable one.
337337

@@ -353,6 +353,10 @@ The script runs the same `cosign verify-blob` before it returns, so a signature
353353

354354
`promote-rc.yaml` runs the `hack/upload-assets.sh` of the rc tree, not the dispatch ref's. A stable release is therefore signed only when its rc was tagged from a tree that has `hack/sign-release-assets.sh`, and a maintenance line starts carrying signatures once that script is backported to its `release-X.Y` branch.
355355

356+
### SBOM of the container images
357+
358+
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.
359+
356360
## Nightly builds
357361

358362
A nightly is an **installable copy of `main` on GHCR — not a rebuild and not a release**. [`build-main.yaml`](../.github/workflows/build-main.yaml) already builds every push to `main` into the CI registry (OCIR); the nightly promotes that build to the public release registry (GHCR) and proves it installs.

‎docs/security/self-assessment.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This document is a security self-assessment for [Cozystack](https://github.com/c
1010
| Software | <https://github.com/cozystack/cozystack> |
1111
| Security Provider | No. Cozystack is a cloud platform, not a security product; security is a supporting property, not its primary function. |
1212
| Languages | Go, Helm, shell |
13-
| SBOM | Not published at this time. Image builds can emit a CycloneDX SBOM attestation (`SBOM=1` in `hack/common-envs.mk`), but this is disabled by default; SBOM generation on release is a planned improvement. |
13+
| SBOM | Not published at this time. Image builds can emit an SPDX SBOM attestation (`SBOM=1` in `hack/common-envs.mk`), but this is disabled by default; SBOM generation on release is a planned improvement. |
1414

1515
### Security links
1616

‎hack/common-envs.mk‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,21 @@ PLATFORM ?= $(if $(filter 1,$(LOAD)),,$(DEFAULT_PLATFORMS))
6666
BUILDX_EXTRA_ARGS ?=
6767
COZYSTACK_VERSION = $(patsubst v%,%,$(shell git describe --tags --match 'v*'))
6868

69-
# SBOM=1 attaches a CycloneDX SBOM as a buildx build attestation (--sbom=true).
70-
# Requires the docker-container buildx driver and registry referrers/attestation
71-
# support. Kept OFF by default until an OCIR referrers/attestation probe confirms
72-
# support — otherwise the attestation push fails the build. See #2937.
69+
# SBOM=1 attaches an SPDX SBOM to every image as a BuildKit attestation. The
70+
# pushed ref then names an index of the image and its attestation manifest, not
71+
# the image itself, which hack/stitch-multiarch.sh and hack/verify-multiarch.sh
72+
# both handle. Attestations need the docker-container buildx driver. The scanner
73+
# is pinned by digest like every other build input, where --sbom=true would pull
74+
# a floating tag. Renovate bumps the version and the digest together, through
75+
# the manager in .github/renovate.json that reads the SBOM_SCANNER line below.
7376
SBOM ?= 0
77+
SBOM_SCANNER ?= docker.io/docker/buildkit-syft-scanner:1.12.0@sha256:ae4f3b554449e7e25548e7d8ccc029d17357348e30c6e3df01b92bc93654d6a9
78+
# A variable, because the commas would split the arguments of $(if) below.
79+
SBOM_ATTEST := --attest type=sbom,generator=$(SBOM_SCANNER)
7480

7581
BUILDX_ARGS := --provenance=false --push=$(PUSH) --load=$(LOAD) \
7682
--label org.opencontainers.image.source=https://github.com/cozystack/cozystack \
77-
$(if $(filter 1,$(SBOM)),--sbom=true) \
83+
$(if $(filter 1,$(SBOM)),$(SBOM_ATTEST)) \
7884
$(if $(strip $(BUILDER)),--builder=$(BUILDER)) \
7985
$(if $(strip $(PLATFORM)),--platform=$(PLATFORM)) \
8086
$(BUILDX_EXTRA_ARGS)

‎hack/common-envs_test.bats‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,34 @@ load test_helper
144144
echo "$out" | grep -q -- '--push=0 --load=1'
145145
}
146146

147+
@test "SBOM=1 attaches an SPDX attestation from a scanner pinned by digest, and the default builds none" {
148+
# An image built with an attestation is an index, not a plain manifest, which
149+
# the stitch and the gate have to read, so it stays off unless a build asks.
150+
# --sbom=true would pull the scanner by a floating tag.
151+
out=$(make -n -C packages/system/cozystack-controller image IMAGE_TAG=pr-1-abc COZYSTACK_VERSION=0 BUILDER=b)
152+
if echo "$out" | grep -q -- '--attest\|--sbom'; then echo "FAIL: an attestation without SBOM=1"; false; fi
153+
out=$(make -n -C packages/system/cozystack-controller image IMAGE_TAG=pr-1-abc COZYSTACK_VERSION=0 BUILDER=b SBOM=1)
154+
echo "$out" | grep -qE -- '--attest type=sbom,generator=[^ ]+@sha256:[0-9a-f]{64} ' || { echo "FAIL: no digest-pinned scanner"; false; }
155+
if echo "$out" | grep -q -- '--sbom'; then echo "FAIL: --sbom=true pulls a floating scanner tag"; false; fi
156+
# The environment reaches buildx as well, which is how the release workflow sets it.
157+
out=$(SBOM=1 make -n -C packages/system/cozystack-controller image IMAGE_TAG=pr-1-abc COZYSTACK_VERSION=0 BUILDER=b)
158+
echo "$out" | grep -q -- '--attest type=sbom,'
159+
}
160+
161+
@test "Renovate moves the SBOM scanner pin, tag and digest together" {
162+
# Renovate reaches hack/common-envs.mk only through a custom manager, and a
163+
# reformatted SBOM_SCANNER line drops out of its regexp without a word, so the
164+
# pin would stay on its syft. The named groups are Renovate's: depName,
165+
# currentValue and currentDigest, in that order.
166+
re=$(jq -r '.customManagers[] | select(any(.managerFilePatterns[]; test("common-envs"))) | .matchStrings[0]' .github/renovate.json)
167+
[ -n "$re" ] || { echo "FAIL: no Renovate custom manager covers hack/common-envs.mk"; false; }
168+
ere=$(printf '%s' "$re" | sed -E 's/\(\?<[A-Za-z]+>/(/g')
169+
pin=$(sed -nE "s#^.*${ere}.*\$#\\1:\\2@\\3#p" hack/common-envs.mk)
170+
[ -n "$pin" ] || { echo "FAIL: the manager matches no SBOM_SCANNER line in hack/common-envs.mk"; false; }
171+
out=$(make -n -C packages/system/cozystack-controller image IMAGE_TAG=pr-1-abc COZYSTACK_VERSION=0 BUILDER=b SBOM=1)
172+
echo "$out" | grep -qF -- "generator=${pin} " || { echo "FAIL: the manager reads ${pin}, not the scanner the build passes"; false; }
173+
}
174+
147175
@test "talos publishes nothing to the registry with PUSH=0" {
148176
out=$(make -n -B -C packages/core/talos image-talos PUSH=0 PUBLISH_VERSIONED=1 PUBLISH_FLOATING=1 IMAGE_TAG=pr-1-abc COZYSTACK_VERSION=0)
149177
echo "$out" | grep -q 'docker://'

‎hack/stitch-multiarch.sh‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
# image as <image-tag>-arm64
1111
#
1212
# The amd64 build and the arm64 leg run on separate native runners, so each
13-
# pushes a single-platform image. For every ref <registry>/<repo>[:<t>]@A in
13+
# pushes a single-platform image. Built with SBOM=1 that image is an index of
14+
# itself and its attestation manifest, and the index made below carries both
15+
# attestations. For every ref <registry>/<repo>[:<t>]@A in
1416
# the tree, whatever tag <t> it carries, with <tag> the <image-tag>:
1517
#
1618
# 1. B is the digest of <repo>:<tag>-arm64. No such image is not an error:
@@ -109,10 +111,18 @@ manifest_digest() {
109111
}
110112

111113
# image_arch <repo@digest> prints the architecture of a single-platform image,
112-
# or nothing for an index or a non-image artifact. A registry error returns
113-
# non-zero, like manifest_digest.
114+
# or nothing for an index of several platforms or a non-image artifact. An
115+
# image built with SBOM=1 is an index of one linux image and its attestation
116+
# manifest, and counts as that image. A registry error returns non-zero, like
117+
# manifest_digest.
114118
image_arch() {
115119
_ia_raw="$(sk inspect --raw "docker://$1")" || return 1
120+
_ia_plat="$(printf '%s' "$_ia_raw" | jq -r '
121+
if .manifests then
122+
[.manifests[] | select(.platform.os == "linux") | .platform.architecture]
123+
| if length == 1 then .[0] else empty end
124+
else empty end')"
125+
if [ -n "$_ia_plat" ]; then printf '%s\n' "$_ia_plat"; return 0; fi
116126
printf '%s' "$_ia_raw" | jq -r '.config.mediaType // empty' \
117127
| grep -qE 'image\.config|container\.image' || return 0
118128
_ia_cfg="$(sk inspect --config "docker://$1")" || return 1
@@ -232,10 +242,15 @@ while read -r repo a reftags <&3; do
232242
else
233243
[ -n "$cur" ] || { echo "::error::${repo}:${tag} does not exist, though the tree pins it" >&2; exit 1; }
234244
raw="$(sk inspect --raw "docker://${repo}@${cur}")"
245+
# An A built with SBOM=1 is itself an index, and the stitched one lists its
246+
# linux image rather than A.
247+
a_raw="$(sk inspect --raw "docker://${repo}@${a}")"
248+
a_members="$(printf '%s' "$a_raw" | jq -c --arg a "$a" \
249+
'if .manifests then [.manifests[] | select(.platform.os == "linux") | .digest] else [$a] end')"
235250
# Its arm64 half need not be this run's B: a rerun rebuilds the arm64
236251
# image, which need not reproduce it byte for byte.
237-
if ! printf '%s' "$raw" | jq -e --arg a "$a" \
238-
'(.manifests // []) as $m | any($m[]; .digest == $a) and any($m[]; .platform.architecture == "arm64")' >/dev/null; then
252+
if ! printf '%s' "$raw" | jq -e --argjson ms "$a_members" \
253+
'(.manifests // []) as $m | ($ms | length) > 0 and all($ms[]; . as $d | any($m[]; .digest == $d)) and any($m[]; .platform.architecture == "arm64")' >/dev/null; then
239254
echo "::error::${repo}:${tag} points at ${cur}, which is neither the digest the tree pins (${a}) nor an index of it and an arm64 image" >&2
240255
exit 1
241256
fi

0 commit comments

Comments
 (0)