From de00e55a88c10725ddad2b690c53dc47ed0cef73 Mon Sep 17 00:00:00 2001 From: Ondrej Skutka Date: Mon, 23 Nov 2026 11:44:33 +0100 Subject: [PATCH] build: check that digest bundle images can be pinned The digest bundle is what ships in the release-digest catalog, and its RELATED_IMAGE_* values reach administrators' PinnedImageSets, but nothing verified they could be pre-pulled. A single OCI image manifest is well formed and pullable yet `podman manifest inspect` rejects it, and the prefetch is all-or-nothing per node. After rewriting tags to digests, fail the release when a RELATED_IMAGE_* value is not a digest reference accepted by the API or fails `podman manifest inspect` in an empty store. Also fail when a digest cannot be resolved instead of writing an empty reference, and strip tags with the last-colon rule so a registry port or an existing digest is not mangled. Assisted-by: Claude Code Co-Authored-By: Claude Code Signed-off-by: Ondrej Skutka --- build/scripts/build_digests_bundle.sh | 64 ++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/build/scripts/build_digests_bundle.sh b/build/scripts/build_digests_bundle.sh index e99d02892..9969aeb36 100755 --- a/build/scripts/build_digests_bundle.sh +++ b/build/scripts/build_digests_bundle.sh @@ -46,6 +46,35 @@ debug() { fi } +# strip_tag REF prints REF without its tag, leaving the registry port and any digest alone. +strip_tag() { + local ref="${1%@*}" + local last="${ref##*/}" + if [[ "$last" == *:* ]]; then + echo "${ref%:*}" + else + echo "$ref" + fi +} + +# check_pinnable REF fails when REF cannot be pinned with an OpenShift PinnedImageSet: the +# reference must be a digest accepted by the API, and the machine config daemon runs +# `podman manifest inspect` on it, which rejects a single OCI image manifest with rc=125. +check_pinnable() { + local ref="$1" + local name_re='^([a-zA-Z0-9-]+\.)+[a-zA-Z0-9-]+(:[0-9]{2,5})?/([a-zA-Z0-9_-]{0,61}/)?[a-zA-Z0-9_.-]*@sha256:[a-f0-9]{64}$' + + if [[ ! "$ref" =~ $name_re ]]; then + error "$ref is not a digest reference accepted by the PinnedImageSet API" + fi + + # An empty store, because an image already present locally would be inspected offline. + if ! podman --log-level error --root "$PINNED_IMAGE_STORE/root" --runroot "$PINNED_IMAGE_STORE/run" \ + manifest inspect "$ref" >/dev/null 2>&1; then + error "$ref cannot be pre-pulled: podman manifest inspect failed" + fi +} + parse_args() { if [ "$#" -eq 0 ]; then usage @@ -103,7 +132,13 @@ fi # Work in a temporary directory TMPDIR="$(mktemp -d)" +trap 'rm -rf "$TMPDIR"' EXIT info "Working in $TMPDIR" + +# An empty container store for the pinnability check, because an image already present locally +# would be inspected offline and hide a bad reference. +PINNED_IMAGE_STORE="$TMPDIR/pinned-image-store" +mkdir -p "$PINNED_IMAGE_STORE/root" "$PINNED_IMAGE_STORE/run" BUNDLE_DIR="${TMPDIR}/bundle" mkdir -p "$BUNDLE_DIR" PROCESSED_DIR="${TMPDIR}/bundle-processed" @@ -126,10 +161,35 @@ for FILE in "$PROCESSED_DIR"/manifests/*.clusterserviceversion.yaml; do IMAGES=$(yq -r '.spec.relatedImages[].image' "$FILE") for IMAGE in $IMAGES; do DIGEST=$(skopeo inspect --tls-verify=false "docker://${IMAGE}" 2>/dev/null | jq -r '.Digest') - IMAGE_WITH_DIGEST="${IMAGE%%:*}@${DIGEST}" + if [[ -z "$DIGEST" || "$DIGEST" == "null" ]]; then + error "Failed to get the digest of $IMAGE" + fi + IMAGE_WITH_DIGEST="$(strip_tag "$IMAGE")@${DIGEST}" info "Replacing $IMAGE with $IMAGE_WITH_DIGEST" sed -i "s|$IMAGE|$IMAGE_WITH_DIGEST|g" "$FILE" done + + # The operator passes these to the workspace, so they reach administrators' PinnedImageSets. + info "Checking that every RELATED_IMAGE_* value of $FILE can be pinned" + INVALID=$(yq -r '[.spec.install.spec.deployments[]?.spec.template.spec | (.containers[]?, .initContainers[]?) | .env[]? + | select(.name | test("^RELATED_IMAGE_")) + | select((.value // "") == "" or (.value | test("\n")))] | length' "$FILE") || + error "Failed to read the RELATED_IMAGE_* values of $FILE" + if [[ "$INVALID" != "0" ]]; then + error "Empty or multi-line RELATED_IMAGE_* value in $FILE" + fi + REFS=$(yq -r '.spec.install.spec.deployments[]?.spec.template.spec | (.containers[]?, .initContainers[]?) | .env[]? + | select(.name | test("^RELATED_IMAGE_")) | .value' "$FILE") || + error "Failed to read the RELATED_IMAGE_* values of $FILE" + if [[ -z "$REFS" ]]; then + error "No RELATED_IMAGE_* values found in $FILE" + fi + while IFS= read -r REF; do + if [[ -z "$REF" ]]; then + error "Empty RELATED_IMAGE_* value in $FILE" + fi + check_pinnable "$REF" + done <<< "$REFS" done if [ "$DEBUG" == true ]; then @@ -158,7 +218,7 @@ else fi NEW_BUNDLE_SHA=$(skopeo inspect "docker://${PUSH_IMAGE}" | jq -r '.Digest') -NEW_BUNDLE_DIGEST="${PUSH_IMAGE%%:*}@${NEW_BUNDLE_SHA}" +NEW_BUNDLE_DIGEST="$(strip_tag "$PUSH_IMAGE")@${NEW_BUNDLE_SHA}" info "Resolved image $NEW_BUNDLE_DIGEST from $PUSH_IMAGE" info "Rendering $NEW_BUNDLE_DIGEST to $RENDER"