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
A release has signed its assets since #4861, but not the container images a cluster installed from it pulls, and the SBOM each image carries since #4997 sat in the registry only, readable with buildx and signed by nothing. A user could verify the ISO they booted and not the platform it installed. hack/sign-release-images.sh signs every first-party digest the repinned tree holds with cosign, keylessly, in prepare-release after the stitch, one cosign call per digest so that cosign's per-call timeout does not grow with the number of images. It skips a digest that already verifies, so a re-run stacks no second signature, and verifies each one against the identity docs/release/signatures-and-sbom.md names before hack/upload-assets.sh runs, so nothing is uploaded over an unsigned image. The draft release is created only after that step, so a failed signing run leaves no draft for a re-run to take for a finished release. The signature over an index covers the attestation manifest the index lists, so the SBOM needs none of its own, and cosign stores it as a referrer of the digest in the repository hack/promote-retag.sh copies the digest within, so promote-rc.yaml only verifies, with the rc tree's script, before it stages the stable release, and prints cosign's reason for every digest that fails. hack/collect-image-sboms.sh reads the SBOM attestation of every such image back into cozystack-images-sbom.tar.gz, one SPDX document per platform, and fails on an image that lacks one for any platform its index serves. With cozystack-images.txt, the digests the signatures are bound to, both join the asset list hack/upload-assets.sh hands to hack/sign-release-assets.sh, so the existing checksums signature covers them. docs/release/signatures-and-sbom.md gains the verification recipe for a whole release, which requires a signed checksum entry for each of the two image assets; cozystack-scheduler, whose image a separate repository builds, is not in the list. The bats files pin the scripts, the recipe, the upload list and the two workflow steps. Refs #2937, #3278 Assisted-by: LLM Signed-off-by: Marian Koreniuk <moriarti@cp.if.ua>
This commit is contained in:
12 files changed
+847
-35
No files matched your search
@@ -616,6 +616,25 @@ jobs:
|
||||
with:
|
||||
cosign-release: v3.1.3
|
||||
|
||||
# The stable release ships the rc's image digests, so their signatures
|
||||
# are the rc's too: tags.yaml signed each index in the repository that
|
||||
# finalize's retag copies the digest within, where cosign keeps the
|
||||
# signature. Checked here, before any stable asset is uploaded, with the
|
||||
# rc tree's script, so an rc cut from a tree without it is promoted as it
|
||||
# always was, and one whose signatures are missing never reaches the
|
||||
# promote PR.
|
||||
- name: Verify the rc image signatures
|
||||
env:
|
||||
DOCKER_CONFIG: ${{ runner.temp }}/.docker
|
||||
REGISTRY: ghcr.io/cozystack/cozystack
|
||||
RC_TAG: ${{ needs.parse.outputs.rc_tag }}
|
||||
run: |
|
||||
if [ -f hack/sign-release-images.sh ]; then
|
||||
hack/sign-release-images.sh --verify-only packages "$REGISTRY"
|
||||
else
|
||||
echo "::notice::${RC_TAG} was cut from a tree without hack/sign-release-images.sh, so its images carry no signature to check"
|
||||
fi
|
||||
|
||||
- name: Create draft stable release and upload assets
|
||||
env:
|
||||
GH_TOKEN: ${{ steps.app-token.outputs.token }}
|
||||
|
||||
+49
-28
@@ -502,7 +502,56 @@ jobs:
|
||||
# tag is cut by pull-requests-release.yaml finalize, at the stable tag's
|
||||
# merge commit (#2677 goal 3).
|
||||
|
||||
# hack/upload-assets.sh writes the release SBOM with syft and signs the
|
||||
# checksums of every asset with cosign, keylessly, as this job. syft is
|
||||
# the release tarball checked against a committed SHA-256, for the reason
|
||||
# given at the same step in promote-rc.yaml: this job holds the app token,
|
||||
# the GHCR login and an OIDC token for the signing identity, so it runs no
|
||||
# install script fetched at run time. Bump with promote-rc.yaml.
|
||||
- name: Set up syft
|
||||
if: needs.build-amd64.outputs.release_exists == 'false'
|
||||
env:
|
||||
SYFT_VERSION: "1.54.1"
|
||||
SYFT_SHA256: "c069905b391cc4c20a5ba65ad5c10be2a7ba074f8ea6ad203e24d14e303dad47"
|
||||
run: |
|
||||
syft_dir="${RUNNER_TEMP}/syft"
|
||||
mkdir -p "$syft_dir"
|
||||
curl -fsSL -o "$syft_dir/syft.tar.gz" \
|
||||
"https://github.com/anchore/syft/releases/download/v${SYFT_VERSION}/syft_${SYFT_VERSION}_linux_amd64.tar.gz"
|
||||
printf '%s %s\n' "$SYFT_SHA256" "$syft_dir/syft.tar.gz" | sha256sum -c -
|
||||
tar -xzf "$syft_dir/syft.tar.gz" -C "$syft_dir" syft
|
||||
rm -f "$syft_dir/syft.tar.gz"
|
||||
echo "$syft_dir" >> "$GITHUB_PATH"
|
||||
# cosign is the version docs/release/signatures-and-sbom.md asks users
|
||||
# for, as in promote-rc.yaml. Bump with it.
|
||||
- name: Set up cosign
|
||||
if: needs.build-amd64.outputs.release_exists == 'false'
|
||||
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
|
||||
with:
|
||||
cosign-release: v3.1.3
|
||||
|
||||
# Every index the stitch repinned the tree on is signed by digest with
|
||||
# this job's OIDC identity, and the SBOM attestation each carries is read
|
||||
# back into one archive, before anything is uploaded: a signature that
|
||||
# does not verify, or an image that lost its SBOM, fails the job with no
|
||||
# asset uploaded. The checksums hack/upload-assets.sh signs next cover
|
||||
# the archive and the image list. The signature over an index covers its
|
||||
# attestation manifest, and promotion copies the digest within the same
|
||||
# repository, so the stable release needs no signing step of its own.
|
||||
- name: Sign the release images and collect their SBOMs
|
||||
if: needs.build-amd64.outputs.release_exists == 'false'
|
||||
run: |
|
||||
set -eu
|
||||
hack/sign-release-images.sh --list _out/assets/cozystack-images.txt packages "$REGISTRY"
|
||||
hack/collect-image-sboms.sh packages "$REGISTRY" _out/assets/cozystack-images-sbom.tar.gz
|
||||
env:
|
||||
DOCKER_CONFIG: ${{ runner.temp }}/.docker
|
||||
REGISTRY: ghcr.io/cozystack/cozystack
|
||||
|
||||
# Create or reuse draft release
|
||||
# Created only after the images are signed and their SBOMs collected: a
|
||||
# draft left by a run that failed before that makes the re-run see an
|
||||
# existing release and skip the whole preparation, leaving the rc unpublished.
|
||||
- name: Create / reuse draft release
|
||||
if: needs.build-amd64.outputs.release_exists == 'false'
|
||||
id: release
|
||||
@@ -536,34 +585,6 @@ jobs:
|
||||
|
||||
core.setOutput('upload_url', rel.upload_url);
|
||||
|
||||
# hack/upload-assets.sh writes the release SBOM with syft and signs the
|
||||
# checksums of every asset with cosign, keylessly, as this job. syft is
|
||||
# the release tarball checked against a committed SHA-256, for the reason
|
||||
# given at the same step in promote-rc.yaml: this job holds the app token,
|
||||
# the GHCR login and an OIDC token for the signing identity, so it runs no
|
||||
# install script fetched at run time. Bump with promote-rc.yaml.
|
||||
- name: Set up syft
|
||||
if: needs.build-amd64.outputs.release_exists == 'false'
|
||||
env:
|
||||
SYFT_VERSION: "1.54.1"
|
||||
SYFT_SHA256: "c069905b391cc4c20a5ba65ad5c10be2a7ba074f8ea6ad203e24d14e303dad47"
|
||||
run: |
|
||||
syft_dir="${RUNNER_TEMP}/syft"
|
||||
mkdir -p "$syft_dir"
|
||||
curl -fsSL -o "$syft_dir/syft.tar.gz" \
|
||||
"https://github.com/anchore/syft/releases/download/v${SYFT_VERSION}/syft_${SYFT_VERSION}_linux_amd64.tar.gz"
|
||||
printf '%s %s\n' "$SYFT_SHA256" "$syft_dir/syft.tar.gz" | sha256sum -c -
|
||||
tar -xzf "$syft_dir/syft.tar.gz" -C "$syft_dir" syft
|
||||
rm -f "$syft_dir/syft.tar.gz"
|
||||
echo "$syft_dir" >> "$GITHUB_PATH"
|
||||
# cosign is the version docs/release/signatures-and-sbom.md asks users
|
||||
# for, as in promote-rc.yaml. Bump with it.
|
||||
- name: Set up cosign
|
||||
if: needs.build-amd64.outputs.release_exists == 'false'
|
||||
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
|
||||
with:
|
||||
cosign-release: v3.1.3
|
||||
|
||||
# The assets were built by build-amd64; the operator manifests are
|
||||
# rendered here, from the tree pinned on the index digests.
|
||||
- name: Upload assets
|
||||
|
||||
@@ -63,6 +63,8 @@ If a package stamps a reference somewhere the two globs do not cover, add that f
|
||||
| `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 |
|
||||
| `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` |
|
||||
| PR build job, image smoke step | all three shapes | list the references a package build stamped, by diffing the tree before and after it, for `hack/image-smoke.bats` to run |
|
||||
| `hack/sign-release-images.sh` | all three shapes, first-party | sign every pinned digest keylessly after the stitch, skipping one that already verifies, or with `--verify-only` fail a promotion whose rc images are unsigned; `--list` writes the `cozystack-images.txt` release asset |
|
||||
| `hack/collect-image-sboms.sh` | all three shapes, first-party | read the SBOM attestation of every pinned index into the `cozystack-images-sbom.tar.gz` release asset, one document per platform; an image missing one for any platform its index serves fails the release |
|
||||
|
||||
`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.
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
| Changelog Copilot job returns 402 | Token quota — `COPILOT_GITHUB_TOKEN` premium-request quota empty | Both changelog entry points hit it: the optional rc-time `changelog-rc` dispatch and the promote-time `changelog` job (both call the reusable `changelog-generate.yaml`), plus the `tags.yaml` backstop | No — `continue-on-error: true` on the AI step, generate changelog by hand following [`agents/changelog.md`](../agents/changelog.md) |
|
||||
| `Prepare Release` skipped and the run red, `Build arm64 images` failed | The rc's arm64 build failed | Read the `build-arm64` log; `build-arm64-nightly.yaml` usually failed the same way first. Fix on the line, cut the next rc | Yes — an rc is not published amd64 only |
|
||||
| `Stitch multi-arch indexes and republish` fails listing refs | `verify-multiarch.sh` found refs that are not amd64+arm64 indexes, or that it could not check | Each listed ref names its reason. Single-platform manifest or index without one architecture: make the image multi-arch, or allowlist its repository with a reason if it cannot be. Manifest unreadable: correct the ref or digest; the allowlist does not excuse it. Rate-limited or unavailable after 3 tries: re-run once the throttle clears | Yes |
|
||||
| `Sign the release images and collect their SBOMs` fails | `hack/sign-release-images.sh` could not sign a pinned digest or its signature does not verify against the release identity, or `hack/collect-image-sboms.sh` found a pinned image with no SBOM attestation | A signing failure names the ref: Fulcio or Rekor unreachable, or the OIDC token missing, re-run once they answer; a signature already there is kept, so a re-run signs only what is missing. An image without an SBOM was built without `SBOM=1` on the docker-container builder, or its index lost the attestation: fix the build, re-cut the rc | Yes |
|
||||
| `Verify the rc image signatures` fails in `promote-rc.yaml` | `hack/sign-release-images.sh --verify-only` could not verify a digest the rc pins against the release identity | Each failing ref is printed as `::error::` after cosign's own error. A registry 429, a TUF or Rekor fetch error: re-run the promote once it clears. `no matching signatures`: the rc was not signed by its `tags.yaml` run; re-run that run's `prepare-release` or cut the next rc. Nothing is staged until it passes | Yes |
|
||||
| E2E `kubernetes-test` fails with `CSINode does not contain driver csi.kubevirt.io` | Test ordering bug | Tenant's `kubernetes-${test_name}-csi` HelmRelease still installing when NFS PVC is created. Fix: wait for `csinode/<node>` to advertise the driver before creating the PVC | Yes — flaky and masks real CSI bugs |
|
||||
| `tenant-root` HR in perpetual upgrade-rollback loop after OIDC patch | Real bug at the intersection of #2602's readiness change and the cozystack reconcile cadence | Look for `rate: Wait(n=1) would exceed context deadline` in operator logs; multiple tenant child HRs stuck `InProgress` | Yes |
|
||||
| `cozy-dashboard` ImagePullBackOff from `cozystack-ui:latest` | Registry flake | Known noisy on some OCI mirrors; not currently in the prepull set | No — retry |
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
## Release signatures and SBOM
|
||||
|
||||
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).
|
||||
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, and one cut from a tree that also has [`hack/sign-release-images.sh`](../../hack/sign-release-images.sh) and [`hack/collect-image-sboms.sh`](../../hack/collect-image-sboms.sh) carries two more, which `tags.yaml::prepare-release` writes before the upload. Releases cut before them have none of these files, and neither does a maintenance line until the scripts are backported to it (see below).
|
||||
|
||||
- `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.
|
||||
- `cozystack-checksums.txt` holds the SHA-256 of every other asset and of the SBOM.
|
||||
- `cozystack-images.txt` lists every first-party container image the release pins, one `<repository>@<digest>` per line: the multi-arch indexes [`hack/stitch-multiarch.sh`](../../hack/stitch-multiarch.sh) repinned the tree on, which is what a cluster installed from this release pulls. The packages artifact and the installer chart are not in it, and neither is `cozystack-scheduler`: its image is built by the [cozystack-scheduler](https://github.com/cozystack/cozystack-scheduler) repository, pinned by a vendored chart under `charts/`, which the shared enumeration leaves out, so this release neither builds nor signs it.
|
||||
- `cozystack-images-sbom.tar.gz` holds the SPDX SBOM of each image in that list, as `<image>.<os>-<arch>.spdx.json`, one document per platform, read from the attestation BuildKit attached to the image at build time (`SBOM=1` in `tags.yaml`, the scanner pinned in [`hack/common-envs.mk`](../../hack/common-envs.mk)). These documents come from the syft inside that scanner, the source SBOM from the syft the workflow installs, so the two need not agree on a version. An image without a document for every platform its index serves fails the release instead of being left out.
|
||||
- `cozystack-checksums.txt` holds the SHA-256 of every other asset, the SBOMs and the image list among them.
|
||||
- `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.
|
||||
|
||||
One signature covers every asset through the checksums. To check a download, verify the checksums, then the file against them, with cosign v3.1.3 or later (v2.6.5 or later on the v2 line):
|
||||
@@ -26,4 +28,36 @@ 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 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.
|
||||
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. They carry no signature of their own: the signature over the index covers them, the SBOM and the provenance statement alike, see [Image signatures](#image-signatures). 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.
|
||||
|
||||
### Image signatures
|
||||
|
||||
The images in `cozystack-images.txt` are signed too. After the stitch, `hack/sign-release-images.sh` signs each digest with cosign, keylessly, as the `tags.yaml` run that prepared the pre-release, and verifies every signature against the same identity as above before `hack/upload-assets.sh` runs, so a release is never published with unsigned images. A signature over an index covers every manifest the index lists by digest, the attestation manifest that holds the SBOM included, which is why the SBOM carries no signature of its own. cosign stores each signature as a Sigstore bundle, an OCI referrer of the digest it signs, in the same repository. GHCR serves no referrers API, so cosign lists the referrer under the fallback tag `sha256-<hex>` of that digest, where `cosign verify` finds it with no extra flags; the tag `sha256-<hex>.sig` is the legacy format, written only with `--new-bundle-format=false`, and a release has none. Every digest gets its own short-lived key, Fulcio certificate and Rekor entry. Promotion copies each digest to its stable tag inside that repository, so a stable release's images carry the signatures made for its rc, and their certificates name `tags.yaml` at the rc tag. `promote-rc.yaml::promote` checks every signature with the rc tree's `hack/sign-release-images.sh --verify-only` before it stages the stable release, and skips the check with a notice for an rc cut from a tree that has no such script. A re-run of `prepare-release` signs only the digests that do not verify yet, so it never stacks a second signature on an image. The packages artifact and the installer chart are not signed: promotion republishes both under a new digest.
|
||||
|
||||
### How to verify a release
|
||||
|
||||
With cosign v3.1.3 or later and the assets of the release in the current directory, this checks the signature over the checksums, every downloaded asset against them, the signature of every image in `cozystack-images.txt`, and unpacks the image SBOMs:
|
||||
|
||||
```sh
|
||||
cosign verify-blob cozystack-checksums.txt \
|
||||
--bundle cozystack-checksums.txt.sigstore.json \
|
||||
--certificate-identity-regexp '^https://github\.com/cozystack/cozystack/\.github/workflows/(tags\.yaml@refs/tags/v|promote-rc\.yaml@refs/heads/main$)' \
|
||||
--certificate-oidc-issuer https://token.actions.githubusercontent.com &&
|
||||
sha256sum --check --ignore-missing cozystack-checksums.txt &&
|
||||
grep -qE '^[0-9a-f]{64} [ *]cozystack-images\.txt$' cozystack-checksums.txt &&
|
||||
grep -qE '^[0-9a-f]{64} [ *]cozystack-images-sbom\.tar\.gz$' cozystack-checksums.txt &&
|
||||
[ -s cozystack-images.txt ] && [ -s cozystack-images-sbom.tar.gz ] &&
|
||||
(
|
||||
while read -r image <&3; do
|
||||
cosign verify "$image" \
|
||||
--certificate-identity-regexp '^https://github\.com/cozystack/cozystack/\.github/workflows/(tags\.yaml@refs/tags/v|promote-rc\.yaml@refs/heads/main$)' \
|
||||
--certificate-oidc-issuer https://token.actions.githubusercontent.com >/dev/null ||
|
||||
{ echo "not verified: $image" >&2; exit 1; }
|
||||
done 3<cozystack-images.txt
|
||||
) &&
|
||||
mkdir -p image-sboms && tar -xzf cozystack-images-sbom.tar.gz -C image-sboms
|
||||
```
|
||||
|
||||
The two `cozystack-images*` entries are required in the signed checksums, and both files non-empty, because `--ignore-missing` alone accepts a signed checksums file from another release that lists neither, with an image list and an archive that nothing signed vouches for. The loop stops at the first image that fails, names it and fails the chain, so the SBOMs are unpacked only after every image verified; the list is read from fd 3 so that cosign cannot read it from stdin. `cosign verify` prints the certificate of each signature; its `Subject` names the workflow and the tag, and the image is pulled only as far as its manifests. The same SBOM can be read from the registry without the archive, with `docker buildx imagetools inspect <image> --format '{{ json .SBOM }}'`, which prints the documents keyed by platform. Checking an image by the tag a release page shows rather than by the digest in `cozystack-images.txt` proves less: a tag can be moved, a digest cannot, and the signature is bound to the digest.
|
||||
|
||||
What fails, and what it means: `cosign verify-blob` rejecting the bundle, or `cosign verify` finding no matching signature, means the file or the image is not what the release workflow published, or cosign is older than the version above; `sha256sum` reporting a mismatch means the download is corrupt or replaced; an image in `cozystack-images.txt` that `cosign verify` cannot find at all means the registry no longer serves that digest. An image missing from the archive cannot happen for a release that has one, since `hack/collect-image-sboms.sh` fails the release instead.
|
||||
@@ -10,7 +10,7 @@ This document is a security self-assessment for [Cozystack](https://github.com/c
|
||||
| Software | <https://github.com/cozystack/cozystack> |
|
||||
| Security Provider | No. Cozystack is a cloud platform, not a security product; security is a supporting property, not its primary function. |
|
||||
| Languages | Go, Helm, shell |
|
||||
| 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. |
|
||||
| SBOM | Published with each release as signed assets, for releases cut from a tree that has the scripts: `cozystack-source-sbom.spdx.json` (SPDX, made with syft from the committed source tree and the cozypkg binaries) and `cozystack-images-sbom.tar.gz` (SPDX, one document per platform of every first-party container image the release pins, read from the attestation BuildKit attaches at build time with `SBOM=1` in `hack/common-envs.mk`, which is off for other builds). Both are listed in `cozystack-checksums.txt`, whose keyless cosign signature a release carries; see [docs/release/signatures-and-sbom.md](../release/signatures-and-sbom.md). |
|
||||
|
||||
### Security links
|
||||
|
||||
@@ -147,7 +147,7 @@ Cozystack does not currently claim compliance with, or certification against, an
|
||||
- **Dependency and image CVE scanning (SCA).** An organization-wide pipeline built on Trivy scans every non-fork, non-archived repository in the `cozystack` organization — Go modules, Dockerfile base images, and container images referenced by the packaged charts — against NVD, vendor advisories and the GitHub Advisory Database. CRITICAL findings are scanned every 6 hours, the remaining severities weekly; findings are noise-filtered and tracked as issues under a triage matrix with per-severity targets (CRITICAL 1 business day to triage, 7-day fix target). Two limitations are worth stating: image references assembled at render time by the `cozy-lib.image` helper are invisible to values-file discovery, and per-CVE findings and triage state are currently held in a private repository, so the control is not yet externally verifiable. Aggregate reporting is now published at [`docs/security/reports/`](reports/): monthly reports reduced to counts by severity, plus a backlog reconciliation auditing every tracked finding against what shipped. Publishing the pipeline policy, the triage matrix, the finding status model and the scanning scripts, while keeping per-finding detail embargoed until fixed, is outstanding. The documented triage target is not being met and the role that owns it is unassigned; remediation is happening but the pipeline cannot record it, and the reconciliation sets out both.
|
||||
- **Dependency updates.** Renovate manages Go modules, Dockerfiles, and GitHub Actions, plus a small set of regex-pinned references, with OpenSSF OSV vulnerability alerts enabled and automerge disabled. The `helm-values` manager is disabled repo-wide, so the curated component images that make up the shipped platform are bumped by maintainers when preparing a release rather than automatically. There is no Dependabot configuration; Renovate is the dependency-update tool.
|
||||
- **Supply-chain posture.** OpenSSF Scorecard runs weekly with published results. Most GitHub Actions are pinned by commit SHA; a small number of recently added workflows still use floating tags and are being brought into line. Renovate is configured to pin digests; applying digest pins across container base images is in progress.
|
||||
- **Signed / reproducible builds.** Honestly noted as gaps: release images are **not** signed (no cosign/sigstore), build provenance is currently disabled (`--provenance=false`), SBOM generation is plumbed but off by default, and reproducible builds are not yet established. These are recognized improvement areas for the incubation timeframe.
|
||||
- **Signed / reproducible builds.** A release cut from a tree that has the scripts signs its assets with one keyless cosign signature over `cozystack-checksums.txt`, and every first-party container image it pins with a keyless cosign signature of its own, made by the workflow that prepared the release; the third-party images `packages/` vendors by digest, the packages artifact and the installer chart are not signed. Release images are built with an SPDX SBOM attestation and a `mode=min` SLSA provenance statement (`SBOM=1` in `tags.yaml`), both covered by the image signature; the SBOM also ships as a release asset. Honestly noted as a gap: reproducible builds are not yet established. This is a recognized improvement area for the incubation timeframe.
|
||||
|
||||
### Communication Channels
|
||||
|
||||
|
||||
@@ -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