mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-01 20:56:02 +09:00
feat(release): sign the release images and attach their SBOMs (#5042)
## What this PR does
Follow-up to #4997 (merged as d32092ac9), which puts the SBOM into each
release image's index. Rebased onto `main` at that merge, one commit
`57346c16d`; bats on the touched files 36/36, shellcheck clean. This is
the follow-up agreed there, and the image half of #4759: the release
images get signed, and their SBOMs become a release asset, along the
lines of #4861.
Refs #4759, #2937, #3278
`hack/sign-release-images.sh` runs in `tags.yaml::prepare-release` after
the stitch, before `make upload_assets`. It enumerates every first-party
`<repo>@<digest>` the repinned tree holds the way
`hack/stitch-multiarch.sh` does (the shared enumeration, refs under the
registry, `cozystack-packages` left out), skips each one that already
verifies, signs the rest with the job's OIDC identity, one `cosign sign
--yes` call per ref so that cosign's per-call `--timeout` (3 minutes by
default) does not have to cover every ref's key, Fulcio certificate,
Rekor entry and registry round trips, and verifies every one against the
identity regexp of `hack/sign-release-assets.sh` before returning; the
two scripts' regexps are held equal by bats. A signature that does not
verify fails the job with nothing uploaded. A signature over an index
covers every manifest the index lists by digest, the attestation
manifest with the SBOM included, so the SBOM has no signature of its
own. cosign v3.1.3 writes the signature as a Sigstore bundle, an OCI
referrer of the digest in the same repository (`--new-bundle-format`
defaults to true). GHCR answers `/v2/<name>/referrers/<digest>` with
404, so go-containerregistry lists the referrer under the fallback tag
`sha256-<hex>`, without `.sig`, which `cosign verify` reads the same
way; the `.sig` tag exists only with `--new-bundle-format=false`.
`hack/promote-retag.sh` copies a digest to its stable tag inside that
repository, so the stable release's images carry the rc's signatures.
`promote-rc.yaml::promote` runs the rc tree's script with
`--verify-only` before it stages the stable release, and prints a notice
instead for an rc cut from a tree without the script. Under
`--verify-only` cosign's stderr is kept, so a registry 429 or a Rekor
fetch error is not reported as a missing signature;
`docs/release/ci-failures.md` has a row for that step.
`hack/collect-image-sboms.sh` reads `docker buildx imagetools inspect
<ref> --format '{{ json .SBOM }}'` for the same refs, takes the
platforms the index serves from `--raw` (entries that are not
attestation manifests, keyed as buildx keys them), and writes
`<image>.<os>-<arch>.spdx.json` per platform (or `<image>.spdx.json` for
an image with one platform, whose SBOM buildx prints unkeyed) into
`cozystack-images-sbom.tar.gz`, with fixed order, times and owners so a
re-run gives the same bytes. An image without a non-null SBOM for every
platform its index serves fails the run, naming it and the platforms:
after #4997 every pinned first-party image is built with `SBOM=1`, so a
missing one is a lost attestation, and I preferred no allowlist over one
with no entry (the Talos installer image, which has no SBOM, is not
pinned in the tree).
`hack/upload-assets.sh` adds `cozystack-images.txt` (the refs, one per
line, from `--list`) and the archive to the list it hands to
`hack/sign-release-assets.sh`, so the existing checksums signature
covers both and nothing new signs anything. `promote-rc.yaml` downloads
every rc asset, so both travel to the stable release as the other assets
do. `docs/release/signatures-and-sbom.md` describes the two files and
the image signatures, drops #4997's "The attestations are not signed",
and gains a "How to verify a release" block that checks the checksums,
every asset, every image signature and unpacks the SBOMs in one go, the
image loop in a subshell that exits on the first image that fails;
`docs/agents/image-refs.md` lists the two new consumers of the
enumeration; the SBOM row and the "Signed / reproducible builds" gap of
`docs/security/self-assessment.md` now say what a release publishes and
signs.
### How it was checked
- Bats 1.14.0: `hack/sign-release-images.bats` (13 tests: the refs it
signs and skips, one `cosign sign` call per ref, the identity and issuer
it verifies, equality with the assets regexp and with
`docs/release/signatures-and-sbom.md`, the fenced verify block of
`docs/release/signatures-and-sbom.md` run with cosign stubbed, which
fails on a rejected first image, on a list read from stdin, on a
checksums file that lacks either image asset and on one that lists one
asset twice in place of the other, a failed verify, `--verify-only`,
`--list`, an empty tree, and the shape of both workflow steps by `yq`)
and `hack/collect-image-sboms.bats` (5: file names and content per
platform, member order, owners and times read from the archive headers,
the same bytes twice, an image without an SBOM, an index with an SBOM on
one platform only, a platform with `"SPDX": null`, an empty tree;
dropping `--sort=name`, the owner flags or `--mtime` fails it on XFS and
ZFS), both with cosign and docker stubbed; `hack/upload-assets.bats`
updated for the two assets; `hack/sign-release-assets.bats` and
`hack/ci-tool-installs-contract.bats` unchanged and green. The
repository's bats contract suites (strict setup, no negated asserts, no
exit traps, runner coverage) pass with the two new files. `make
bats-unit-tests`: see the last comment of this PR for the count.
- `shellcheck -x` on both scripts; `zizmor` on `tags.yaml` and
`promote-rc.yaml` reports nothing.
- Checked against the registry, not the code: GHCR has no referrers API
for a cozystack image (404), so the referrer lands in the `sha256-<hex>`
fallback tag; `hack/promote-retag.sh` copies within the repository; `gh
release download` in promote takes every rc asset.
- Not checked: a real keyless run (the first alpha after the merge, like
#4861 and #4997), a stitched index against a live registry (the `.SBOM`
shape follows buildx v0.31.0 `util/imagetools/printers.go`: keyed by
platform for more than one platform, bare otherwise; @lexfrei's ttl.sh
run on #4997 saw the map), and the time the signing adds to
`prepare-release`.
### Decisions for the release owners
- The packages artifact (`cozystack-packages`) and the installer chart
are not signed: promotion republishes both under a new digest, so
signing them means a signing step in `promote` too. Follow-up if wanted.
- Every pre-release signs about forty indexes, each with its own Fulcio
certificate and Rekor entry. #4861 already writes one per release, so
the policy question is settled; the volume is new.
- An image without an SBOM fails the release rather than being listed as
missing. If an exception appears, an allowlist with a reason, as
`hack/multiarch-allowlist`, is the shape to add.
- The identity regexp accepts `promote-rc.yaml` on `main` as well as
`tags.yaml` on a `v*` tag, though only `tags.yaml` signs images today,
so that `docs/release/signatures-and-sbom.md` has one expression for
every release signature. A reader who wants the tighter check drops the
alternative.
### 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/upload-assets.sh` adds
two assets and renames none, so the install pages that hardcode asset
filenames on the website are untouched. `tags.yaml` gains a step between
the stitch and the upload and `promote-rc.yaml` a check before the
upload; who cuts and who promotes a release, which the ccp guidance
rests on, is the same. `hack/package.mk` and `hack/common-envs.mk` are
not touched.
### Release note
```release-note
feat(release): every first-party container image of a release is signed with cosign, keylessly, by the `tags.yaml` run that prepared it, and a release carries `cozystack-images.txt` (the pinned images by digest) and `cozystack-images-sbom.tar.gz` (the SPDX SBOM of each image, per platform) as assets covered by the signed checksums. `docs/release/signatures-and-sbom.md` shows how to verify a release end to end. Releases cut from this change on have them.
```
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->
## Summary by CodeRabbit
* **New Features**
* Releases now include a list of pinned first-party image digests and an
archive of image software bills of materials (SBOMs), with coverage for
each image platform.
* Release image digests are signed, and release checksums cover the
image list and SBOM archive.
* RC promotion checks image signatures before creating a stable release;
unsigned images can block promotion.
* **Documentation**
* Added guidance on release image signatures, SBOM assets, verification,
and related release failures.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
12 files changed
+847
-35
No files matched your search
@@ -0,0 +1,166 @@
|
||||
#!/usr/bin/env bats
|
||||
# -----------------------------------------------------------------------------
|
||||
# Unit tests for hack/collect-image-sboms.sh.
|
||||
#
|
||||
# docker is a stub on PATH that answers `buildx imagetools inspect --raw` and
|
||||
# `--format '{{ json .SBOM }}'` from a file per digest, the way the real tool
|
||||
# answers from the registry, so the tests hold what the script owns: which
|
||||
# images it reads, one file per platform under a fixed name, an archive whose
|
||||
# order, times and owners do not depend on the machine, and a failure naming
|
||||
# any image that lacks an SBOM for a platform its index serves.
|
||||
#
|
||||
# Expected failures are written as `if CMD; then ... exit 1; fi`, never as a
|
||||
# negated command: see hack/bats-no-negated-assert.bats.
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
load test_helper
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
|
||||
SCRIPT="$REPO_ROOT/hack/collect-image-sboms.sh"
|
||||
REG=registry.example/cozy
|
||||
|
||||
D_API=sha256:1111111111111111111111111111111111111111111111111111111111111111
|
||||
D_FOO=sha256:2222222222222222222222222222222222222222222222222222222222222222
|
||||
D_OTHER=sha256:3333333333333333333333333333333333333333333333333333333333333333
|
||||
D_PKGS=sha256:4444444444444444444444444444444444444444444444444444444444444444
|
||||
|
||||
# A tree pinning a stitched two-platform image, a single-platform image, a
|
||||
# third-party image and the packages artifact, and the docker stub. api is an
|
||||
# index of two platforms and their attestations, and its SBOM is keyed by
|
||||
# platform, as `imagetools inspect` prints it for such an index; foo is an index
|
||||
# of one platform and its attestation, and answers with the document itself.
|
||||
# Anything else is a plain manifest whose SBOM is null.
|
||||
make_fixture() {
|
||||
work="$(mktemp -d)"
|
||||
mkdir -p "$work/tree/system/api" "$work/tree/apps/kube/images" "$work/tree/core/installer" "$work/stub" "$work/sbom" "$work/raw"
|
||||
cat >"$work/tree/system/api/values.yaml" <<EOF
|
||||
image: $REG/api:v1.2.3-rc.1@$D_API
|
||||
sidecar:
|
||||
registry: docker.io
|
||||
repository: other/thing
|
||||
tag: 1.0@$D_OTHER
|
||||
EOF
|
||||
printf '%s/foo:v1.2.3-rc.1@%s\n' "$REG" "$D_FOO" >"$work/tree/apps/kube/images/foo.tag"
|
||||
cat >"$work/tree/core/installer/values.yaml" <<EOF
|
||||
cozystack:
|
||||
platformSourceUrl: 'oci://$REG/cozystack-packages'
|
||||
platformSourceRef: 'digest=$D_PKGS'
|
||||
EOF
|
||||
echo '{"linux/amd64":{"SPDX":{"spdxVersion":"SPDX-2.3","name":"api-amd64"}},"linux/arm64":{"SPDX":{"spdxVersion":"SPDX-2.3","name":"api-arm64"}}}' >"$work/sbom/${D_API#sha256:}"
|
||||
echo '{"SPDX":{"spdxVersion":"SPDX-2.3","name":"foo"}}' >"$work/sbom/${D_FOO#sha256:}"
|
||||
att='"annotations":{"vnd.docker.reference.type":"attestation-manifest"},"platform":{"os":"unknown","architecture":"unknown"}'
|
||||
# arm64 first, so the documents are written out of name order and only
|
||||
# --sort=name puts them back in it, whatever order the filesystem lists.
|
||||
echo "{\"manifests\":[{\"platform\":{\"os\":\"linux\",\"architecture\":\"arm64\"}},{\"platform\":{\"os\":\"linux\",\"architecture\":\"amd64\"}},{$att},{$att}]}" >"$work/raw/${D_API#sha256:}"
|
||||
echo "{\"manifests\":[{\"platform\":{\"os\":\"linux\",\"architecture\":\"amd64\"}},{$att}]}" >"$work/raw/${D_FOO#sha256:}"
|
||||
|
||||
cat >"$work/stub/docker" <<'STUB'
|
||||
#!/bin/sh
|
||||
[ "$1 $2 $3" = "buildx imagetools inspect" ] || exit 2
|
||||
if [ "$5" = --raw ]; then
|
||||
f="$STUB_LOG/raw/${4##*@sha256:}"
|
||||
if [ -f "$f" ]; then cat "$f"; else echo '{"mediaType":"application/vnd.oci.image.manifest.v1+json"}'; fi
|
||||
exit 0
|
||||
fi
|
||||
[ "$5" = --format ] && [ "$6" = '{{ json .SBOM }}' ] || exit 2
|
||||
echo "$4" >> "$STUB_LOG/inspected"
|
||||
f="$STUB_LOG/sbom/${4##*@sha256:}"
|
||||
if [ -f "$f" ]; then cat "$f"; else echo null; fi
|
||||
STUB
|
||||
chmod +x "$work/stub/docker"
|
||||
export PATH="$work/stub:$PATH" STUB_LOG="$work"
|
||||
}
|
||||
|
||||
# The status is returned explicitly: cozytest.sh appends `return 0` before a
|
||||
# closing brace at column zero, which would turn a failed run into a success.
|
||||
collect() {
|
||||
"$SCRIPT" "$work/tree" "$REG" "$work/images-sbom.tar.gz" >"$work/out" 2>"$work/err"
|
||||
return $?
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
cd /
|
||||
rm -rf "$work"
|
||||
}
|
||||
|
||||
@test "writes one SPDX document per platform of every first-party image, and the same bytes on a re-run" {
|
||||
make_fixture
|
||||
collect
|
||||
|
||||
[ "$(sort "$work/inspected")" = "$(printf '%s/api@%s\n%s/foo@%s' "$REG" "$D_API" "$REG" "$D_FOO")" ]
|
||||
# Unsorted here, so the archive has to hold its members in name order.
|
||||
members="$(tar -tzf "$work/images-sbom.tar.gz" | grep -v '/$' | sed 's|^\./||')"
|
||||
[ "$members" = "$(printf 'api.linux-amd64.spdx.json\napi.linux-arm64.spdx.json\nfoo.spdx.json')" ]
|
||||
# Owner and time come from the flags, not from the user and clock of the
|
||||
# run, which a re-run on the same machine cannot tell apart.
|
||||
headers="$(TZ=UTC tar --numeric-owner -tvzf "$work/images-sbom.tar.gz")"
|
||||
[ -n "$headers" ]
|
||||
if echo "$headers" | grep -v ' 0/0 .* 1970-01-01 00:00 '; then
|
||||
echo "FAIL: a member is not owned by 0/0 at the epoch" >&2
|
||||
exit 1
|
||||
fi
|
||||
mkdir "$work/x"
|
||||
tar -xzf "$work/images-sbom.tar.gz" -C "$work/x"
|
||||
[ "$(jq -r .name "$work/x/api.linux-arm64.spdx.json")" = api-arm64 ]
|
||||
[ "$(jq -r .name "$work/x/foo.spdx.json")" = foo ]
|
||||
grep -qx "image-sboms: 3 documents from 2 images in $work/images-sbom.tar.gz" "$work/out"
|
||||
|
||||
first="$(sha256sum <"$work/images-sbom.tar.gz")"
|
||||
sleep 1
|
||||
collect
|
||||
[ "$(sha256sum <"$work/images-sbom.tar.gz")" = "$first" ]
|
||||
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "fails naming every image that carries no SBOM attestation, and writes no archive" {
|
||||
make_fixture
|
||||
rm "$work/sbom/${D_FOO#sha256:}"
|
||||
if collect; then
|
||||
echo "expected an image without an SBOM to fail the run" >&2
|
||||
exit 1
|
||||
fi
|
||||
grep -q "::error::$REG/foo@$D_FOO" "$work/err"
|
||||
if grep -q "::error::$REG/api@" "$work/err"; then echo "FAIL: an image with an SBOM was reported" >&2; exit 1; fi
|
||||
if [ -e "$work/images-sbom.tar.gz" ]; then
|
||||
echo "expected no archive to be written" >&2
|
||||
exit 1
|
||||
fi
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "refuses a tree that pins no first-party image" {
|
||||
make_fixture
|
||||
rm -r "$work/tree/system" "$work/tree/apps"
|
||||
if collect; then
|
||||
echo "expected an empty tree to be refused" >&2
|
||||
exit 1
|
||||
fi
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "fails on an index whose SBOM covers only some of its platforms" {
|
||||
make_fixture
|
||||
echo '{"linux/amd64":{"SPDX":{"spdxVersion":"SPDX-2.3","name":"api-amd64"}}}' >"$work/sbom/${D_API#sha256:}"
|
||||
if collect; then
|
||||
echo "expected an index without an arm64 SBOM to fail the run" >&2
|
||||
exit 1
|
||||
fi
|
||||
grep -q "::error::$REG/api@$D_API carries no SBOM attestation for linux/arm64;" "$work/err"
|
||||
if [ -e "$work/images-sbom.tar.gz" ]; then
|
||||
echo "expected no archive to be written" >&2
|
||||
exit 1
|
||||
fi
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "fails on a platform whose SBOM is null" {
|
||||
make_fixture
|
||||
echo '{"linux/amd64":{"SPDX":{"spdxVersion":"SPDX-2.3","name":"api-amd64"}},"linux/arm64":{"SPDX":null}}' >"$work/sbom/${D_API#sha256:}"
|
||||
if collect; then
|
||||
echo "expected a null SBOM to fail the run" >&2
|
||||
exit 1
|
||||
fi
|
||||
grep -q "::error::$REG/api@$D_API carries no SBOM attestation for linux/arm64;" "$work/err"
|
||||
cleanup
|
||||
}
|
||||
Executable
+117
@@ -0,0 +1,117 @@
|
||||
#!/bin/bash
|
||||
# Gather the SBOM of every first-party image a release pins into one archive.
|
||||
#
|
||||
# Usage: hack/collect-image-sboms.sh <packages-root> <registry> <archive.tar.gz>
|
||||
# <packages-root> a tree hack/stitch-multiarch.sh has repinned (packages/, or
|
||||
# an extracted artifact with the same <group>/<pkg> layout)
|
||||
# <registry> the registry the release pushed to; a ref under it is
|
||||
# first-party, any other is vendored and left alone
|
||||
# <archive.tar.gz> the cozystack-images-sbom.tar.gz release asset to write
|
||||
#
|
||||
# BuildKit attaches an SPDX SBOM to each image as an attestation manifest of
|
||||
# its index (SBOM=1 in hack/common-envs.mk), one document per platform, and
|
||||
# `docker buildx imagetools inspect` reads it back from the registry, and with
|
||||
# --raw the platforms the index serves. The archive holds
|
||||
# <image>.<os>-<arch>.spdx.json per platform of each image, or <image>.spdx.json
|
||||
# for an image with one platform, whose SBOM carries no platform key, so a user
|
||||
# gets every document from one signed download rather than one registry read
|
||||
# per image. The packages artifact is not an image and is left out.
|
||||
#
|
||||
# An image without an SBOM for every platform its index serves fails the run,
|
||||
# naming it and the platforms: every first-party image of a release is built
|
||||
# with SBOM=1, so a missing one is a build that lost its attestation, not an
|
||||
# image that cannot carry one.
|
||||
#
|
||||
# The archive is written with a fixed member order, time and owner and without
|
||||
# a gzip timestamp, so a re-run on the same tree writes the same bytes.
|
||||
#
|
||||
# Requires docker with buildx, jq, yq (mikefarah), GNU tar and gzip, and a
|
||||
# registry login docker reads (DOCKER_CONFIG).
|
||||
set -euo pipefail
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 <packages-root> <registry> <archive.tar.gz>" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
[ "$#" -eq 3 ] || usage
|
||||
ROOT="${1%/}"
|
||||
REGISTRY="${2%/}"
|
||||
ARCHIVE="$3"
|
||||
[ -d "$ROOT" ] || { echo "packages-root '$ROOT' is not a directory" >&2; exit 2; }
|
||||
for tool in docker jq yq tar gzip; do
|
||||
command -v "$tool" >/dev/null || { echo "$tool is required" >&2; exit 2; }
|
||||
done
|
||||
|
||||
# shellcheck source=hack/lib/image-refs.sh
|
||||
. "$(dirname "$0")/lib/image-refs.sh"
|
||||
|
||||
# One "<repo>@<digest>" per first-party image, as in hack/sign-release-images.sh.
|
||||
reg_re="$(printf '%s' "$REGISTRY" | sed -e 's/[].[^$*/\\]/\\&/g')"
|
||||
refs="$(collect_image_refs "$ROOT" \
|
||||
| grep -oE "${reg_re}/[^@[:space:]\"']+@sha256:[0-9a-f]{64}" \
|
||||
| sed -E 's/:[^/@]+@/@/' \
|
||||
| grep -v "^${reg_re}/cozystack-packages@" \
|
||||
| sort -u)" || true
|
||||
[ -n "$refs" ] || { echo "no ${REGISTRY}/ refs found under ${ROOT}; is this a tree the build stamped?" >&2; exit 1; }
|
||||
|
||||
stage=$(mktemp -d)
|
||||
trap 'rm -rf "$stage"' EXIT
|
||||
|
||||
missing=""
|
||||
images=0
|
||||
documents=0
|
||||
# fd 3, so a registry client that reads stdin cannot swallow the list.
|
||||
while IFS= read -r ref <&3; do
|
||||
name="${ref%@*}"
|
||||
name="${name##*/}"
|
||||
raw="$(docker buildx imagetools inspect "$ref" --raw)"
|
||||
sbom="$(docker buildx imagetools inspect "$ref" --format '{{ json .SBOM }}')"
|
||||
# The platforms the image serves are its index entries bar the attestation
|
||||
# manifests, keyed the way buildx keys them (arm64/v8 is plain arm64). buildx
|
||||
# prints the SBOM of an image with one platform as the document itself and
|
||||
# keys it by platform otherwise, so every platform of the index needs a
|
||||
# non-null document: "<file> <key>" per document, "- <platform>" per gap.
|
||||
# No output at all counts as no SBOM, not as an image with nothing to check.
|
||||
plan="$(printf '%s' "$sbom" | jq -rn --arg name "$name" --argjson raw "$raw" '
|
||||
[inputs][0] as $sbom
|
||||
| [ $raw.manifests[]?
|
||||
| select(.annotations["vnd.docker.reference.type"] != "attestation-manifest")
|
||||
| .platform
|
||||
| "\(.os)/\(.architecture)" + (if (.variant // "") == "" or (.architecture == "arm64" and .variant == "v8") then "" else "/" + .variant end)
|
||||
] as $platforms
|
||||
| if ($platforms | length) <= 1 then
|
||||
if ($sbom | type) == "object" and ($sbom.SPDX | type) == "object" then "\($name).spdx.json ."
|
||||
else "- \($platforms[0] // "its platform")" end
|
||||
else
|
||||
$platforms[] as $p
|
||||
| if ($sbom | type) == "object" and ($sbom[$p].SPDX | type) == "object" then "\($name).\($p | gsub("/"; "-")).spdx.json \($p)"
|
||||
else "- \($p)" end
|
||||
end')"
|
||||
gaps="$(printf '%s\n' "$plan" | sed -n 's/^- //p' | paste -sd, -)"
|
||||
if [ -n "$gaps" ]; then
|
||||
missing="${missing}${ref} ${gaps}"$'\n'
|
||||
continue
|
||||
fi
|
||||
images=$((images + 1))
|
||||
while read -r file key; do
|
||||
if [ "$key" = . ]; then
|
||||
printf '%s' "$sbom" | jq '.SPDX' >"$stage/$file"
|
||||
else
|
||||
printf '%s' "$sbom" | jq --arg p "$key" '.[$p].SPDX' >"$stage/$file"
|
||||
fi
|
||||
documents=$((documents + 1))
|
||||
done <<<"$plan"
|
||||
done 3<<<"$refs"
|
||||
|
||||
if [ -n "$missing" ]; then
|
||||
while read -r ref gaps; do
|
||||
[ -n "$ref" ] || continue
|
||||
echo "::error::${ref} carries no SBOM attestation for ${gaps}; was it built with SBOM=1?" >&2
|
||||
done <<<"$missing"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
tar --sort=name --mtime=@0 --owner=0 --group=0 --numeric-owner \
|
||||
-C "$stage" -cf - . | gzip -n >"$ARCHIVE"
|
||||
echo "image-sboms: ${documents} documents from ${images} images in ${ARCHIVE}"
|
||||
@@ -0,0 +1,315 @@
|
||||
#!/usr/bin/env bats
|
||||
# -----------------------------------------------------------------------------
|
||||
# Unit tests for hack/sign-release-images.sh, and for the two workflow steps
|
||||
# that run it.
|
||||
#
|
||||
# cosign is a stub on PATH: a keyless signature needs a GitHub OIDC token,
|
||||
# which no unit runner has. The stub records what it is asked to sign and
|
||||
# answers `verify` from that record, so the tests hold what the script owns:
|
||||
# which refs it signs, that it signs each one once, which identity it verifies
|
||||
# against, what --verify-only and --list do, and that a signature which does
|
||||
# not verify fails the run.
|
||||
#
|
||||
# Expected failures are written as `if CMD; then ... exit 1; fi`, never as a
|
||||
# negated command: see hack/bats-no-negated-assert.bats.
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
load test_helper
|
||||
|
||||
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
|
||||
SCRIPT="$REPO_ROOT/hack/sign-release-images.sh"
|
||||
REG=registry.example/cozy
|
||||
|
||||
D_API=sha256:1111111111111111111111111111111111111111111111111111111111111111
|
||||
D_FOO=sha256:2222222222222222222222222222222222222222222222222222222222222222
|
||||
D_OTHER=sha256:3333333333333333333333333333333333333333333333333333333333333333
|
||||
D_PKGS=sha256:4444444444444444444444444444444444444444444444444444444444444444
|
||||
|
||||
# A tree pinning two first-party images, one of them in two storage shapes, a
|
||||
# third-party image and the packages artifact, and the cosign stub. `verify`
|
||||
# succeeds for a ref the stub has signed or that PRESIGNED names;
|
||||
# COSIGN_VERIFY_EXIT overrides every verify.
|
||||
make_fixture() {
|
||||
work="$(mktemp -d)"
|
||||
mkdir -p "$work/tree/system/api" "$work/tree/apps/kube/images" "$work/tree/core/installer" "$work/stub"
|
||||
cat >"$work/tree/system/api/values.yaml" <<EOF
|
||||
image: $REG/api:v1.2.3-rc.1@$D_API
|
||||
sidecar:
|
||||
registry: docker.io
|
||||
repository: other/thing
|
||||
tag: 1.0@$D_OTHER
|
||||
EOF
|
||||
printf '%s/foo:v1.2.3-rc.1@%s\n' "$REG" "$D_FOO" >"$work/tree/apps/kube/images/foo.tag"
|
||||
printf 'args:\n - --migrate-image=%s/api:v1.2.3-rc.1@%s\n' "$REG" "$D_API" >"$work/tree/apps/kube/values.yaml"
|
||||
cat >"$work/tree/core/installer/values.yaml" <<EOF
|
||||
cozystack:
|
||||
platformSourceUrl: 'oci://$REG/cozystack-packages'
|
||||
platformSourceRef: 'digest=$D_PKGS'
|
||||
EOF
|
||||
|
||||
cat >"$work/stub/cosign" <<'STUB'
|
||||
#!/bin/sh
|
||||
cmd=$1
|
||||
shift
|
||||
case $cmd in
|
||||
sign)
|
||||
echo "$*" >> "$STUB_LOG/cosign-sign"
|
||||
for arg in "$@"; do
|
||||
case $arg in *@sha256:*) echo "$arg" >> "$STUB_LOG/signed" ;; esac
|
||||
done
|
||||
;;
|
||||
verify)
|
||||
printf '%s\n' "$@" > "$STUB_LOG/cosign-verify-last"
|
||||
[ -z "${COSIGN_VERIFY_EXIT:-}" ] || exit "$COSIGN_VERIFY_EXIT"
|
||||
ref=
|
||||
for arg in "$@"; do
|
||||
case $arg in *@sha256:*) ref=$arg ;; esac
|
||||
done
|
||||
if [ -f "$STUB_LOG/signed" ] && grep -qxF "$ref" "$STUB_LOG/signed"; then exit 0; fi
|
||||
case " ${PRESIGNED:-} " in *" $ref "*) exit 0 ;; esac
|
||||
echo "Error: no matching signatures" >&2
|
||||
exit 1
|
||||
;;
|
||||
*) exit 2 ;;
|
||||
esac
|
||||
STUB
|
||||
chmod +x "$work/stub/cosign"
|
||||
export PATH="$work/stub:$PATH" STUB_LOG="$work"
|
||||
}
|
||||
|
||||
# The status is returned explicitly: cozytest.sh appends `return 0` before a
|
||||
# closing brace at column zero, which would turn a failed run into a success.
|
||||
sign() {
|
||||
"$SCRIPT" "$@" "$work/tree" "$REG" >"$work/out" 2>"$work/err"
|
||||
return $?
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
cd /
|
||||
rm -rf "$work"
|
||||
}
|
||||
|
||||
@test "signs every unsigned first-party ref by digest, one cosign call per ref, skipping third-party refs and the packages artifact" {
|
||||
make_fixture
|
||||
sign
|
||||
|
||||
[ "$(grep -c . "$work/cosign-sign")" -eq 2 ]
|
||||
[ "$(sort "$work/signed")" = "$(printf '%s/api@%s\n%s/foo@%s\n' "$REG" "$D_API" "$REG" "$D_FOO")" ]
|
||||
if grep -q 'other/thing' "$work/cosign-sign"; then echo "FAIL: a third-party ref was signed" >&2; exit 1; fi
|
||||
if grep -q 'cozystack-packages' "$work/cosign-sign"; then echo "FAIL: the packages artifact was signed" >&2; exit 1; fi
|
||||
if grep -q ':v1.2.3-rc.1@' "$work/cosign-sign"; then echo "FAIL: a ref was signed with its tag" >&2; exit 1; fi
|
||||
grep -qx 'sign-images: 2 signed, 0 already signed' "$work/out"
|
||||
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "does not sign a ref that already verifies" {
|
||||
make_fixture
|
||||
export PRESIGNED="$REG/api@$D_API"
|
||||
sign
|
||||
|
||||
[ "$(cat "$work/signed")" = "$REG/foo@$D_FOO" ]
|
||||
grep -qx 'sign-images: 1 signed, 1 already signed' "$work/out"
|
||||
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "verifies each signature against the release workflows, with the identity hack/sign-release-assets.sh verifies" {
|
||||
make_fixture
|
||||
sign
|
||||
|
||||
grep -qxF https://token.actions.githubusercontent.com "$work/cosign-verify-last"
|
||||
regexp="$(grep -A1 -xF -- --certificate-identity-regexp "$work/cosign-verify-last" | tail -n1)"
|
||||
printf '%s\n' https://github.com/cozystack/cozystack/.github/workflows/tags.yaml@refs/tags/v1.2.3-rc.1 | grep -qE "$regexp"
|
||||
for identity in \
|
||||
https://github.com/fork/cozystack/.github/workflows/tags.yaml@refs/tags/v1.2.3 \
|
||||
https://github.com/cozystack/cozystack/.github/workflows/tags.yaml@refs/heads/main \
|
||||
https://github.com/cozystack/cozystack/.github/workflows/nightly.yaml@refs/heads/main; do
|
||||
if printf '%s\n' "$identity" | grep -qE "$regexp"; then
|
||||
echo "expected $regexp to reject $identity" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
assets_regexp="$(sed -n "s/^IDENTITY_REGEXP='\(.*\)'\$/\1/p" "$REPO_ROOT/hack/sign-release-assets.sh")"
|
||||
[ -n "$assets_regexp" ]
|
||||
[ "$regexp" = "$assets_regexp" ]
|
||||
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "docs/release/signatures-and-sbom.md tells users to verify the identity the script verifies" {
|
||||
regexp="$(sed -n "s/^IDENTITY_REGEXP='\(.*\)'\$/\1/p" "$SCRIPT")"
|
||||
[ -n "$regexp" ]
|
||||
grep -qF -- "--certificate-identity-regexp '$regexp'" "$REPO_ROOT/docs/release/signatures-and-sbom.md"
|
||||
}
|
||||
|
||||
# Runs the fenced block of "How to verify a release" in docs/release/signatures-and-sbom.md against
|
||||
# a release of two images, with a cosign stub that reads stdin, as a client
|
||||
# may, and rejects the image REJECT names.
|
||||
verify_recipe() {
|
||||
rwork="$(mktemp -d)"
|
||||
mkdir -p "$rwork/stub" "$rwork/rel" "$rwork/sbom"
|
||||
awk '/^### How to verify a release/ { s = 1 } s && /^```sh$/ { b = 1; next } b && /^```$/ { exit } b' \
|
||||
"$REPO_ROOT/docs/release/signatures-and-sbom.md" >"$rwork/recipe.sh"
|
||||
grep -q 'cosign verify "$image"' "$rwork/recipe.sh"
|
||||
cat >"$rwork/stub/cosign" <<'STUB'
|
||||
#!/bin/sh
|
||||
cmd=$1
|
||||
shift
|
||||
case $cmd in
|
||||
verify-blob) exit 0 ;;
|
||||
verify)
|
||||
cat >/dev/null
|
||||
echo "$1" >> "$RWORK/verified"
|
||||
[ "$1" != "${REJECT:-}" ] || exit 1
|
||||
;;
|
||||
*) exit 2 ;;
|
||||
esac
|
||||
STUB
|
||||
chmod +x "$rwork/stub/cosign"
|
||||
cd "$rwork/rel"
|
||||
printf '%s/api@%s\n%s/foo@%s\n' "$REG" "$D_API" "$REG" "$D_FOO" >cozystack-images.txt
|
||||
echo '{}' >"$rwork/sbom/api.linux-amd64.spdx.json"
|
||||
tar -C "$rwork/sbom" -czf cozystack-images-sbom.tar.gz .
|
||||
echo bundle >cozystack-checksums.txt.sigstore.json
|
||||
sha256sum cozystack-images.txt cozystack-images-sbom.tar.gz >cozystack-checksums.txt
|
||||
[ -z "${DUP_CHECKSUM:-}" ] || sed -i "/$DUP_CHECKSUM/p" cozystack-checksums.txt
|
||||
[ -z "${DROP_CHECKSUM:-}" ] || sed -i "/$DROP_CHECKSUM/d" cozystack-checksums.txt
|
||||
PATH="$rwork/stub:$PATH" RWORK="$rwork" bash "$rwork/recipe.sh" </dev/null >"$rwork/out" 2>"$rwork/err"
|
||||
return $?
|
||||
}
|
||||
|
||||
@test "the verify recipe in docs/release/signatures-and-sbom.md checks every image and fails on any one that does not verify" {
|
||||
verify_recipe
|
||||
[ "$(cat "$rwork/verified")" = "$(cat "$rwork/rel/cozystack-images.txt")" ]
|
||||
[ -f "$rwork/rel/image-sboms/api.linux-amd64.spdx.json" ]
|
||||
rm -rf "$rwork"
|
||||
|
||||
export REJECT="$REG/api@$D_API"
|
||||
if verify_recipe; then
|
||||
echo "expected the recipe to fail on an image that does not verify" >&2
|
||||
exit 1
|
||||
fi
|
||||
grep -qx "not verified: $REJECT" "$rwork/err"
|
||||
if [ -e "$rwork/rel/image-sboms" ]; then
|
||||
echo "FAIL: the SBOMs were unpacked after an image failed" >&2
|
||||
exit 1
|
||||
fi
|
||||
cd /
|
||||
rm -rf "$rwork"
|
||||
}
|
||||
|
||||
@test "the verify recipe fails when the signed checksums omit an image asset" {
|
||||
for drop in 'images\.txt' 'images-sbom'; do
|
||||
DROP_CHECKSUM="$drop"
|
||||
export DROP_CHECKSUM
|
||||
if verify_recipe; then
|
||||
echo "expected the recipe to fail without the $drop checksum" >&2
|
||||
exit 1
|
||||
fi
|
||||
[ ! -e "$rwork/rel/image-sboms" ]
|
||||
cd /
|
||||
rm -rf "$rwork"
|
||||
done
|
||||
}
|
||||
|
||||
@test "the verify recipe fails when one image asset is listed twice in place of the other" {
|
||||
export DUP_CHECKSUM='images-sbom' DROP_CHECKSUM='images\.txt'
|
||||
if verify_recipe; then
|
||||
echo "expected the recipe to fail with two sbom entries and no images.txt entry" >&2
|
||||
exit 1
|
||||
fi
|
||||
[ ! -e "$rwork/rel/image-sboms" ]
|
||||
cd /
|
||||
rm -rf "$rwork"
|
||||
}
|
||||
|
||||
@test "fails when a signature does not verify after signing" {
|
||||
make_fixture
|
||||
export COSIGN_VERIFY_EXIT=1
|
||||
if sign; then
|
||||
echo "expected a failed verification to fail the script" >&2
|
||||
exit 1
|
||||
fi
|
||||
grep -q 'does not verify' "$work/err"
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "--verify-only signs nothing and fails on an unsigned ref" {
|
||||
make_fixture
|
||||
export PRESIGNED="$REG/api@$D_API"
|
||||
if sign --verify-only; then
|
||||
echo "expected an unsigned ref to fail --verify-only" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ -e "$work/cosign-sign" ]; then
|
||||
echo "expected no signature to be made" >&2
|
||||
exit 1
|
||||
fi
|
||||
grep -q "::error::$REG/foo@$D_FOO" "$work/err"
|
||||
if grep -q "::error::$REG/api@" "$work/err"; then echo "FAIL: a verified ref was reported" >&2; exit 1; fi
|
||||
|
||||
export PRESIGNED="$REG/api@$D_API $REG/foo@$D_FOO"
|
||||
sign --verify-only
|
||||
grep -qx 'sign-images: 0 signed, 2 already signed' "$work/out"
|
||||
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "--list writes every first-party ref once, by digest, sorted" {
|
||||
make_fixture
|
||||
sign --list "$work/images.txt"
|
||||
|
||||
[ "$(cat "$work/images.txt")" = "$(printf '%s/api@%s\n%s/foo@%s' "$REG" "$D_API" "$REG" "$D_FOO")" ]
|
||||
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "refuses a tree that pins no first-party image" {
|
||||
make_fixture
|
||||
rm -r "$work/tree/system" "$work/tree/apps"
|
||||
if sign; then
|
||||
echo "expected an empty tree to be refused" >&2
|
||||
exit 1
|
||||
fi
|
||||
cleanup
|
||||
}
|
||||
|
||||
@test "prepare-release signs the images and collects their SBOMs after cosign is set up and before the assets are uploaded" {
|
||||
wf="$REPO_ROOT/.github/workflows/tags.yaml"
|
||||
steps=$(yq -r '.jobs.prepare-release.steps[].name' "$wf")
|
||||
pos() { echo "$steps" | grep -nxF "$1" | cut -d: -f1; }
|
||||
cosign=$(pos 'Set up cosign')
|
||||
sign=$(pos 'Sign the release images and collect their SBOMs')
|
||||
upload=$(pos 'Upload assets')
|
||||
[ -n "$cosign" ]
|
||||
[ -n "$sign" ]
|
||||
[ -n "$upload" ]
|
||||
[ "$cosign" -lt "$sign" ]
|
||||
[ "$sign" -lt "$upload" ]
|
||||
sel='.jobs.prepare-release.steps[] | select(.name == "Sign the release images and collect their SBOMs")'
|
||||
run_=$(yq -r "$sel | .run" "$wf")
|
||||
echo "$run_" | grep -qxE '[[:space:]]*hack/sign-release-images.sh --list _out/assets/cozystack-images.txt packages "\$REGISTRY"'
|
||||
echo "$run_" | grep -qxE '[[:space:]]*hack/collect-image-sboms.sh packages "\$REGISTRY" _out/assets/cozystack-images-sbom.tar.gz'
|
||||
[ "$(yq -r "$sel | .env.REGISTRY" "$wf")" = ghcr.io/cozystack/cozystack ]
|
||||
[ "$(yq -r '.jobs.prepare-release.permissions."id-token"' "$wf")" = write ]
|
||||
}
|
||||
|
||||
@test "promote verifies the rc image signatures before it stages the stable release" {
|
||||
wf="$REPO_ROOT/.github/workflows/promote-rc.yaml"
|
||||
steps=$(yq -r '.jobs.promote.steps[].name' "$wf")
|
||||
pos() { echo "$steps" | grep -nxF "$1" | cut -d: -f1; }
|
||||
cosign=$(pos 'Set up cosign')
|
||||
verify=$(pos 'Verify the rc image signatures')
|
||||
upload=$(pos 'Create draft stable release and upload assets')
|
||||
[ -n "$cosign" ]
|
||||
[ -n "$verify" ]
|
||||
[ -n "$upload" ]
|
||||
[ "$cosign" -lt "$verify" ]
|
||||
[ "$verify" -lt "$upload" ]
|
||||
run_=$(yq -r '.jobs.promote.steps[] | select(.name == "Verify the rc image signatures") | .run' "$wf")
|
||||
echo "$run_" | grep -qxE '[[:space:]]*hack/sign-release-images.sh --verify-only packages "\$REGISTRY"'
|
||||
# An rc cut before the script existed has no signatures to check and is
|
||||
# promoted as it always was.
|
||||
echo "$run_" | grep -q 'if \[ -f hack/sign-release-images.sh \]'
|
||||
}
|
||||
Executable
+128
@@ -0,0 +1,128 @@
|
||||
#!/bin/bash
|
||||
# Sign every first-party image a release pins, keylessly, and verify the result.
|
||||
#
|
||||
# Usage: hack/sign-release-images.sh [--verify-only] [--list <file>] <packages-root> <registry>
|
||||
# <packages-root> a tree hack/stitch-multiarch.sh has repinned (packages/, or
|
||||
# an extracted artifact with the same <group>/<pkg> layout)
|
||||
# <registry> the registry the release pushed to; a ref under it is
|
||||
# first-party, any other is vendored and left alone
|
||||
# --verify-only sign nothing: fail unless every ref already verifies,
|
||||
# which is how promote-rc.yaml checks an rc before staging
|
||||
# the stable release on its digests
|
||||
# --list <file> write the refs, one <repo>@<digest> per line, sorted: the
|
||||
# cozystack-images.txt release asset
|
||||
#
|
||||
# Every <registry>/<repo>[:<tag>]@<digest> that hack/lib/image-refs.sh finds in
|
||||
# the tree is signed by its digest with cosign and the job's GitHub OIDC
|
||||
# identity, bar the packages artifact, which promotion republishes under a new
|
||||
# digest. After the stitch a digest names a multi-arch index, and a signature
|
||||
# over an index covers every manifest it lists by digest, the attestation
|
||||
# manifest an image built with SBOM=1 carries included, so the SBOM needs no
|
||||
# signature of its own. cosign v3 stores the signature as a Sigstore bundle,
|
||||
# an OCI referrer of the digest in the same repository; GHCR has no referrers
|
||||
# API, so it lands in the fallback tag sha256-<hex> that cosign verify reads
|
||||
# back. hack/promote-retag.sh copies a digest to its stable tag inside that
|
||||
# repository, so the stable release carries the signatures made for its rc.
|
||||
#
|
||||
# A ref that already verifies is not signed again: a re-run of prepare-release
|
||||
# repins the same digests, and a second signature would say nothing the first
|
||||
# does not. The rest are signed one cosign call per ref: cosign bounds a whole
|
||||
# call by one --timeout (3 minutes by default), and every ref costs its own
|
||||
# key, Fulcio certificate, Rekor entry and registry round trips. Each
|
||||
# ref is then verified against the identity docs/release/signatures-and-sbom.md tells users to
|
||||
# check, so a signature that check would reject fails the job before
|
||||
# hack/upload-assets.sh runs and nothing is uploaded.
|
||||
#
|
||||
# Needs cosign on PATH, yq (mikefarah) to read the tree, a registry login
|
||||
# cosign reads (DOCKER_CONFIG) and, unless --verify-only, `id-token: write` in
|
||||
# the job.
|
||||
set -euo pipefail
|
||||
|
||||
# The workflows that publish releases, at the refs they run from. Images are
|
||||
# signed by tags.yaml only, on a v* tag push, so a verified image certificate
|
||||
# names that run; the promote-rc.yaml alternative is kept so that the one
|
||||
# expression in docs/release/signatures-and-sbom.md checks every release signature.
|
||||
# hack/sign-release-images.bats holds it equal to the one in
|
||||
# hack/sign-release-assets.sh.
|
||||
IDENTITY_REGEXP='^https://github\.com/cozystack/cozystack/\.github/workflows/(tags\.yaml@refs/tags/v|promote-rc\.yaml@refs/heads/main$)'
|
||||
OIDC_ISSUER=https://token.actions.githubusercontent.com
|
||||
|
||||
usage() {
|
||||
echo "usage: $0 [--verify-only] [--list <file>] <packages-root> <registry>" >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
verify_only=0
|
||||
list=""
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--verify-only) verify_only=1; shift ;;
|
||||
--list) [ "$#" -ge 2 ] || usage; list="$2"; shift 2 ;;
|
||||
-*) usage ;;
|
||||
*) break ;;
|
||||
esac
|
||||
done
|
||||
[ "$#" -eq 2 ] || usage
|
||||
ROOT="${1%/}"
|
||||
REGISTRY="${2%/}"
|
||||
[ -d "$ROOT" ] || { echo "packages-root '$ROOT' is not a directory" >&2; exit 2; }
|
||||
for tool in cosign yq; do
|
||||
command -v "$tool" >/dev/null || { echo "$tool is required" >&2; exit 2; }
|
||||
done
|
||||
|
||||
# shellcheck source=hack/lib/image-refs.sh
|
||||
. "$(dirname "$0")/lib/image-refs.sh"
|
||||
|
||||
# One "<repo>@<digest>" per first-party image. grep -o drops anything around a
|
||||
# ref, such as kamaji's --migrate-image= prefix, and the sed drops the tag: a
|
||||
# registry client rejects a ref carrying both, and the digest is what is signed.
|
||||
# The packages artifact is an OCI artifact promotion republishes, not an image.
|
||||
reg_re="$(printf '%s' "$REGISTRY" | sed -e 's/[].[^$*/\\]/\\&/g')"
|
||||
refs="$(collect_image_refs "$ROOT" \
|
||||
| grep -oE "${reg_re}/[^@[:space:]\"']+@sha256:[0-9a-f]{64}" \
|
||||
| sed -E 's/:[^/@]+@/@/' \
|
||||
| grep -v "^${reg_re}/cozystack-packages@" \
|
||||
| sort -u)" || true
|
||||
[ -n "$refs" ] || { echo "no ${REGISTRY}/ refs found under ${ROOT}; is this a tree the build stamped?" >&2; exit 1; }
|
||||
|
||||
verified() {
|
||||
cosign verify \
|
||||
--certificate-identity-regexp "$IDENTITY_REGEXP" \
|
||||
--certificate-oidc-issuer "$OIDC_ISSUER" \
|
||||
"$1" >/dev/null
|
||||
}
|
||||
|
||||
# A ref that does not verify yet is expected when signing; under --verify-only
|
||||
# cosign's reason (a registry 429, a Rekor fetch error) is what the operator needs.
|
||||
quiet=/dev/null
|
||||
[ "$verify_only" -eq 0 ] || quiet=/dev/stderr
|
||||
unsigned=()
|
||||
already=0
|
||||
# fd 3, so a registry client that reads stdin cannot swallow the list.
|
||||
while IFS= read -r ref <&3; do
|
||||
if verified "$ref" 2>"$quiet"; then
|
||||
echo " = ${ref} already signed"
|
||||
already=$((already + 1))
|
||||
else
|
||||
unsigned+=("$ref")
|
||||
fi
|
||||
done 3<<<"$refs"
|
||||
|
||||
if [ "$verify_only" -eq 1 ]; then
|
||||
for ref in ${unsigned[@]+"${unsigned[@]}"}; do
|
||||
echo "::error::${ref} does not verify against this release's identity; cosign's reason is above" >&2
|
||||
done
|
||||
[ "${#unsigned[@]}" -eq 0 ] || exit 1
|
||||
else
|
||||
for ref in ${unsigned[@]+"${unsigned[@]}"}; do
|
||||
cosign sign --yes "$ref"
|
||||
done
|
||||
for ref in ${unsigned[@]+"${unsigned[@]}"}; do
|
||||
verified "$ref" || { echo "::error::${ref}: the signature just made does not verify against ${IDENTITY_REGEXP}" >&2; exit 1; }
|
||||
done
|
||||
fi
|
||||
|
||||
echo "sign-images: ${#unsigned[@]} signed, ${already} already signed"
|
||||
if [ -n "$list" ]; then
|
||||
printf '%s\n' "$refs" >"$list"
|
||||
fi
|
||||
@@ -21,7 +21,8 @@ load test_helper
|
||||
REPO_ROOT="$(cd "$(dirname "${BATS_TEST_FILENAME:-$0}")/.." && pwd)"
|
||||
|
||||
# The fixture's release assets in upload order, with two cozypkg tarballs where
|
||||
# a release has one per platform.
|
||||
# a release has one per platform, and the image list and image SBOM archive
|
||||
# prepare-release writes before the upload.
|
||||
assets() {
|
||||
printf '%s\n' \
|
||||
cozystack-crds.yaml \
|
||||
@@ -40,7 +41,9 @@ assets() {
|
||||
cozypkg-darwin-arm64.tar.gz \
|
||||
cozypkg-linux-amd64.tar.gz \
|
||||
cozypkg-checksums.txt \
|
||||
openapi.json
|
||||
openapi.json \
|
||||
cozystack-images.txt \
|
||||
cozystack-images-sbom.tar.gz
|
||||
}
|
||||
|
||||
# What hack/upload-assets.sh uploads: the assets, then the three files
|
||||
|
||||
@@ -22,6 +22,11 @@ assets+=(
|
||||
_out/assets/cozypkg-*.tar.gz
|
||||
_out/assets/cozypkg-checksums.txt
|
||||
_out/assets/openapi.json
|
||||
# Written by hack/sign-release-images.sh and hack/collect-image-sboms.sh in
|
||||
# prepare-release, before this runs: the images the release pins and their
|
||||
# SBOMs, which the checksums below then cover.
|
||||
_out/assets/cozystack-images.txt
|
||||
_out/assets/cozystack-images-sbom.tar.gz
|
||||
)
|
||||
|
||||
# Before the first upload, so that a release never carries assets without the
|
||||
|
||||
Reference in new issue
Block a user