Skip to content

Commit 2b7ccba

Browse files
committed
fix(release): ship SBOMs by scoping to binary artifacts + sign them
The `sboms:` block scoped `artifacts: archive`, but our `archives:` block uses `formats: [binary]` — so goreleaser emits binary-type artifacts and zero archive-type ones. The SBOM stage matched nothing and silently shipped no SBOMs (v1.1.0 and every prior release went out with none). Changes: - Scope sboms to `artifacts: binary` so each OS/arch executable gets a CycloneDX SBOM. - Correct the checksum comment: goreleaser 2.x already folds sbom artifacts into sha256sum.txt (verified via snapshot — each appears exactly once), so cosign's signature over that file covers them. We do NOT add a checksum.extra_files glob, which would double-count and produce duplicate lines. - Guard that undocumented auto-inclusion with a release-workflow assertion: fail loudly if any generated .sbom.json is missing from sha256sum.txt, so a future goreleaser change can't silently ship unsigned SBOMs. - Add a container-image SBOM attestation (docker_signs + scripts/attest-image-sbom.sh): syft the pushed image, cosign attest --type cyclonedx into GHCR. The image is the artifact k8s operators actually run, so it carries its own keyless-signed SBOM.
1 parent 1207705 commit 2b7ccba

3 files changed

Lines changed: 121 additions & 4 deletions

File tree

‎.github/workflows/release.yml‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,27 @@ jobs:
215215
args: release --clean --timeout 90m --release-notes .release-notes/body.md
216216
env:
217217
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
218+
219+
# Guard the SBOM integrity chain. GoReleaser 2.x folds sbom artifacts
220+
# into sha256sum.txt automatically, and cosign signs that file — so an
221+
# SBOM's integrity is verifiable through the signed checksum. That
222+
# auto-inclusion is undocumented default behavior, though: a future
223+
# GoReleaser could silently drop it, shipping SBOMs that nothing signs.
224+
# Fail the release loudly if any generated .sbom.json is absent from
225+
# the checksum file. Runs after goreleaser has written dist/.
226+
- name: Assert SBOMs are checksummed
227+
run: |
228+
sum="dist/sha256sum.txt"
229+
[ -f "$sum" ] || { echo "::error::$sum not found — did goreleaser run?"; exit 1; }
230+
missing=0
231+
for sbom in dist/*.sbom.json; do
232+
[ -e "$sbom" ] || { echo "::error::no .sbom.json files in dist/ — SBOM generation broke"; exit 1; }
233+
base=$(basename "$sbom")
234+
if grep -qF " ${base}" "$sum"; then
235+
echo "ok: ${base} is in ${sum}"
236+
else
237+
echo "::error::${base} is NOT listed in ${sum} — SBOM would ship unsigned"
238+
missing=1
239+
fi
240+
done
241+
[ "$missing" -eq 0 ] || { echo "::error::one or more SBOMs are not covered by the signed checksums"; exit 1; }

‎.goreleaser.yaml‎

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,67 @@ dockers_v2:
102102
checksum:
103103
name_template: "sha256sum.txt"
104104
algorithm: sha256
105+
# SBOM integrity depends on the .sbom.json files being listed in this
106+
# checksum file, which cosign then signs (see `signs:` below).
107+
#
108+
# GoReleaser 2.x DOES fold `sbom`-type artifacts into the checksum file
109+
# automatically — verified by snapshot: each <binary>.sbom.json appears
110+
# here exactly once. We deliberately do NOT add a `checksum.extra_files`
111+
# glob for them: that double-counts (the sbom is both a pipeline artifact
112+
# AND matched by the glob), producing duplicate lines in sha256sum.txt.
113+
#
114+
# BUT this auto-inclusion is undocumented default behavior, not a
115+
# contract — a GoReleaser upgrade could silently drop it, shipping
116+
# unsigned SBOMs with no error. The release workflow guards against that
117+
# with a post-build assertion (grep the SBOMs out of sha256sum.txt, fail
118+
# the release if any are missing). See "Assert SBOMs are checksummed" in
119+
# .github/workflows/release.yml.
105120

106-
# CycloneDX SBOMs, one per built archive, generated by syft (installed on
121+
# CycloneDX SBOMs, one per released binary, generated by syft (installed on
107122
# the release runner by anchore/sbom-action/download-syft in
108-
# .github/workflows/release.yml). Each `<archive>.sbom.json` is uploaded
123+
# .github/workflows/release.yml). Each `<binary>.sbom.json` is uploaded
109124
# as a release asset alongside the binary it describes. The SBOM files are
110125
# covered by the same sha256sum.txt that cosign signs below, so an SBOM's
111126
# integrity is verifiable through the existing signed-checksum chain — no
112127
# separate signing step needed. Enterprise procurement / vuln-scanning
113128
# tooling (Grype, Trivy, Dependency-Track) ingests these directly.
129+
#
130+
# artifacts MUST be `binary`, not `archive`: our `archives:` block uses
131+
# `formats: [binary]`, so goreleaser emits `binary`-type artifacts and
132+
# ZERO `archive`-type ones. Scoping the SBOM to `archive` matches nothing
133+
# and silently ships no SBOMs (the v1.1.0 miss). `binary` yields one SBOM
134+
# per OS/arch executable.
114135
sboms:
115-
- id: archive-sboms
116-
artifacts: archive
136+
- id: binary-sboms
137+
artifacts: binary
117138
documents:
118139
- "{{ .ArtifactName }}.sbom.json"
119140
args:
120141
- "$artifact"
121142
- "--output"
122143
- "cyclonedx-json=$document"
123144

145+
# docker_signs attests the pushed multi-arch image with cosign, keyless.
146+
# For a k8s-deployed router the image is the artifact enterprises actually
147+
# run, so it carries its own SBOM attestation rather than relying only on
148+
# the binary release assets. We shell out to `scripts/attest-image-sbom.sh`,
149+
# which runs syft against the pushed image to produce a CycloneDX SBOM and
150+
# then `cosign attest --type cyclonedx` pushes it into GHCR alongside the
151+
# image. Verifiable with:
152+
# cosign verify-attestation --type cyclonedx \
153+
# --certificate-identity-regexp 'https://github.com/magma-Devs/smart-router' \
154+
# --certificate-oidc-issuer https://token.actions.githubusercontent.com \
155+
# ghcr.io/magma-devs/smart-router:<tag>
156+
# Same OIDC/Fulcio keyless flow as the checksum signing below — no key to
157+
# manage. `output: true` streams the transparency-log entry to the build log.
158+
docker_signs:
159+
- id: cosign-image-sbom
160+
cmd: scripts/attest-image-sbom.sh
161+
artifacts: images
162+
output: true
163+
args:
164+
- "${artifact}"
165+
124166
# No `changelog:` block. The release workflow passes
125167
# `--release-notes .release-notes/body.md` to goreleaser, which:
126168
# 1. Uses that file as the entire release body, AND

‎scripts/attest-image-sbom.sh‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
# Attach a CycloneDX SBOM attestation to a pushed container image with cosign.
3+
#
4+
# Called by goreleaser's `docker_signs:` block (see .goreleaser.yaml), once
5+
# per pushed image ref. goreleaser passes the fully-qualified image ref
6+
# (ghcr.io/magma-devs/smart-router:<tag>) as the sole argument.
7+
#
8+
# For a k8s-deployed router the image — not the raw binary — is the artifact
9+
# operators actually run, so it carries its own SBOM attestation in the
10+
# registry. We syft the pushed image to a CycloneDX predicate, then
11+
# `cosign attest --type cyclonedx` uploads it as an in-toto attestation
12+
# alongside the image. Keyless: cosign exchanges the GitHub Actions OIDC
13+
# token with Sigstore Fulcio for a short-lived cert — same flow as the
14+
# checksum signing in `signs:`. No private key to manage.
15+
#
16+
# Verify with:
17+
# cosign verify-attestation --type cyclonedx \
18+
# --certificate-identity-regexp \
19+
# '^https://github.com/Magma-Devs/smart-router/.github/workflows/release.yml@refs/tags/' \
20+
# --certificate-oidc-issuer https://token.actions.githubusercontent.com \
21+
# ghcr.io/magma-devs/smart-router:<tag>
22+
#
23+
# Usage: scripts/attest-image-sbom.sh <image-ref>
24+
# Requires: syft, cosign (both installed by the release workflow).
25+
set -euo pipefail
26+
27+
IMAGE="${1:?usage: attest-image-sbom.sh <image-ref>}"
28+
29+
for bin in syft cosign; do
30+
command -v "$bin" >/dev/null || { echo "missing required tool: $bin" >&2; exit 1; }
31+
done
32+
33+
workdir="$(mktemp -d)"
34+
trap 'rm -rf "$workdir"' EXIT
35+
sbom="${workdir}/image.sbom.json"
36+
37+
echo "==> generating CycloneDX SBOM for image $IMAGE"
38+
# syft resolves the multi-arch manifest and catalogs the image's contents.
39+
syft "$IMAGE" --output "cyclonedx-json=$sbom"
40+
41+
echo "==> attesting SBOM to $IMAGE (cosign keyless)"
42+
# --yes skips the interactive Fulcio consent prompt (non-interactive CI).
43+
# --replace so re-running a release overwrites rather than stacking dupes.
44+
COSIGN_EXPERIMENTAL=1 cosign attest \
45+
--predicate "$sbom" \
46+
--type cyclonedx \
47+
--replace \
48+
--yes \
49+
"$IMAGE"
50+
51+
echo "==> done. CycloneDX SBOM attestation pushed for $IMAGE"

0 commit comments

Comments
 (0)