From de00e55a88c10725ddad2b690c53dc47ed0cef73 Mon Sep 17 00:00:00 2001 From: Ondrej Skutka Date: Mon, 23 Nov 2026 11:44:33 +0100 Subject: [PATCH 1/4] 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" From 3420a99a386a8737cf25021d9efeadd3d76acc27 Mon Sep 17 00:00:00 2001 From: Ondrej Skutka Date: Fri, 27 Nov 2026 15:09:54 +0100 Subject: [PATCH 2/4] build: enforce the pinned image name limit The CEL rule on spec.pinnedImages[*].name caps the reference at 447 characters; the inline check enforced only the shape. Add the limit before the regex check, using the API's wording. Record that the reference rules are duplicated from IMAGE_RE in che-operator's checkPinnedImages.sh, where the downstream and Jenkins checks live. This release must not fetch that script, so the two must be kept in sync by hand. Assisted-by: Claude Code Co-Authored-By: Claude Code Signed-off-by: Ondrej Skutka --- build/scripts/build_digests_bundle.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/build/scripts/build_digests_bundle.sh b/build/scripts/build_digests_bundle.sh index 9969aeb36..30259c253 100755 --- a/build/scripts/build_digests_bundle.sh +++ b/build/scripts/build_digests_bundle.sh @@ -60,9 +60,19 @@ strip_tag() { # 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. +# +# The NAME_RE and the length limit mirror the CEL rules on spec.pinnedImages[*].name. They are +# deliberately duplicated from IMAGE_RE in +# che-operator/build/scripts/release/checkPinnedImages.sh: this release must not fetch the +# checker, so keep the two in sync by hand. 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}$' + local max_reference_length=447 + + if (( ${#ref} > max_reference_length )); then + error "$ref is longer than the ${max_reference_length} characters the PinnedImageSet API accepts" + fi if [[ ! "$ref" =~ $name_re ]]; then error "$ref is not a digest reference accepted by the PinnedImageSet API" From ad4dfc888cea4bffb796a0be6477da7c3ce5b4c8 Mon Sep 17 00:00:00 2001 From: Ondrej Skutka Date: Fri, 27 Nov 2026 15:36:48 +0100 Subject: [PATCH 3/4] build: keep the inspection cause in the pinned image check A dead digest, missing credentials, a TLS or network problem and a single OCI manifest all fail the same podman inspection, but they call for different actions. Capture the output on failure and include a bounded excerpt, keeping the head and the tail because the single-manifest error embeds the whole manifest JSON with the cause at the end. Successful inspections remain silent. Reported by CodeRabbit on #1749. Assisted-by: Claude Code Co-Authored-By: Claude Code Signed-off-by: Ondrej Skutka --- build/scripts/build_digests_bundle.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/build/scripts/build_digests_bundle.sh b/build/scripts/build_digests_bundle.sh index 30259c253..329fa4dd9 100755 --- a/build/scripts/build_digests_bundle.sh +++ b/build/scripts/build_digests_bundle.sh @@ -67,6 +67,7 @@ strip_tag() { # checker, so keep the two in sync by hand. check_pinnable() { local ref="$1" + local output 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}$' local max_reference_length=447 @@ -79,9 +80,14 @@ check_pinnable() { 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" + if ! output=$(podman --log-level error --root "$PINNED_IMAGE_STORE/root" --runroot "$PINNED_IMAGE_STORE/run" \ + manifest inspect "$ref" 2>&1); then + # Keep the cause: a dead digest, missing credentials, a TLS problem and a single OCI + # manifest all fail here, and they call for different actions. The single-manifest error + # embeds the whole manifest JSON with the cause at the end, so keep head and tail. + output="${output//$'\n'/ }" + (( ${#output} > 300 )) && output="${output:0:90} ... ${output: -180}" + error "$ref cannot be pre-pulled: podman manifest inspect failed: ${output}" fi } From 3ac99c4450887ae1cb896881ab1d73e8713e59e8 Mon Sep 17 00:00:00 2001 From: Ondrej Skutka Date: Tue, 1 Dec 2026 09:00:23 +0100 Subject: [PATCH 4/4] build: harden the pinned image check Fail the release when an image it ships cannot be pinned with an OpenShift PinnedImageSet, and make that check robust: - Keep the RELATED_IMAGE_* selector in one variable and reuse it for both queries, so they cannot drift apart. - Check for podman in the preflight rather than failing on an opaque command-not-found during the first inspection. - Fail with the image name when skopeo inspect fails instead of piping an empty result into jq, which aborted before the digest check and lost the cause. - Retry every inspection - skopeo and podman manifest inspect - up to three times, five seconds apart, through a shared retry_inspect helper, and keep a bounded excerpt of the last stderr. These run right after the release pushes the images, so a registry blip would otherwise abort a release whose version tag already exists. - Guard the final NEW_BUNDLE_SHA resolution the same way, instead of rendering an empty or null reference into the catalog. Reported in review on #1749. Assisted-by: Claude Code Co-Authored-By: Claude Code Signed-off-by: Ondrej Skutka --- build/scripts/build_digests_bundle.sh | 66 +++++++++++++++++++-------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/build/scripts/build_digests_bundle.sh b/build/scripts/build_digests_bundle.sh index 329fa4dd9..fddc096db 100755 --- a/build/scripts/build_digests_bundle.sh +++ b/build/scripts/build_digests_bundle.sh @@ -57,6 +57,30 @@ strip_tag() { fi } +# retry_inspect CMD... runs CMD, retrying a transient registry failure up to three times, five +# seconds apart. On success INSPECT_OUT holds stdout. On failure INSPECT_ERR_MSG holds a bounded +# excerpt of the last stderr, and the function returns 1. +retry_inspect() { + local attempt err + local errfile="${TMPDIR}/inspect.err" + + for attempt in 1 2 3; do + if INSPECT_OUT=$("$@" 2>"${errfile}"); then + return 0 + fi + if (( attempt < 3 )); then + sleep 5 + fi + done + + err=$(cat "${errfile}") + err="${err//$'\n'/ }" + (( ${#err} > 300 )) && err="${err:0:90} ... ${err: -180}" + INSPECT_ERR_MSG="${err:-no output}" + INSPECT_ATTEMPTS="${attempt}" + return 1 +} + # 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. @@ -67,7 +91,6 @@ strip_tag() { # checker, so keep the two in sync by hand. check_pinnable() { local ref="$1" - local output 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}$' local max_reference_length=447 @@ -79,16 +102,12 @@ check_pinnable() { 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 ! output=$(podman --log-level error --root "$PINNED_IMAGE_STORE/root" --runroot "$PINNED_IMAGE_STORE/run" \ - manifest inspect "$ref" 2>&1); then - # Keep the cause: a dead digest, missing credentials, a TLS problem and a single OCI - # manifest all fail here, and they call for different actions. The single-manifest error - # embeds the whole manifest JSON with the cause at the end, so keep head and tail. - output="${output//$'\n'/ }" - (( ${#output} > 300 )) && output="${output:0:90} ... ${output: -180}" - error "$ref cannot be pre-pulled: podman manifest inspect failed: ${output}" - fi + # An empty store, because an image already present locally would be inspected offline. Errors + # go to stderr, which retry_inspect keeps: a dead digest, missing credentials, a TLS problem + # and a single OCI manifest all fail here, and they call for different actions. + retry_inspect podman --log-level error --root "$PINNED_IMAGE_STORE/root" --runroot "$PINNED_IMAGE_STORE/run" \ + manifest inspect "$ref" || + error "$ref cannot be pre-pulled: podman manifest inspect failed after ${INSPECT_ATTEMPTS} attempts: ${INSPECT_ERR_MSG}" } parse_args() { @@ -128,6 +147,8 @@ preflight() { if [ ! -f "${SCRIPT_DIR}/../bundle.Dockerfile" ]; then error "Could not find bundle.Dockerfile from repository" fi + command -v podman >/dev/null 2>&1 || + error "podman is required for the pinned image check" } parse_args "$@" @@ -172,11 +193,18 @@ tar -xf "$TMPDIR/bundle.tar" --directory "$BUNDLE_DIR" # Make a copy of the input bundle for modifying, so that we can show a diff later cp -r "$BUNDLE_DIR"/* "$PROCESSED_DIR" +RELATED_IMAGE_ENVS='.spec.install.spec.deployments[]?.spec.template.spec + | (.containers[]?, .initContainers[]?) + | .env[]? + | select(.name | test("^RELATED_IMAGE_"))' + for FILE in "$PROCESSED_DIR"/manifests/*.clusterserviceversion.yaml; do info "Processing file $FILE" 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') + retry_inspect skopeo inspect --tls-verify=false "docker://${IMAGE}" || + error "Failed to inspect $IMAGE: ${INSPECT_ERR_MSG}" + DIGEST=$(jq -r '.Digest // empty' <<< "${INSPECT_OUT}") if [[ -z "$DIGEST" || "$DIGEST" == "null" ]]; then error "Failed to get the digest of $IMAGE" fi @@ -187,15 +215,12 @@ for FILE in "$PROCESSED_DIR"/manifests/*.clusterserviceversion.yaml; do # 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") || + INVALID=$(yq -r "[${RELATED_IMAGE_ENVS} | 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") || + REFS=$(yq -r "${RELATED_IMAGE_ENVS} | .value" "$FILE") || error "Failed to read the RELATED_IMAGE_* values of $FILE" if [[ -z "$REFS" ]]; then error "No RELATED_IMAGE_* values found in $FILE" @@ -233,7 +258,12 @@ else $PODMAN push "$PUSH_IMAGE" 2>&1 | sed 's|^| |g' fi -NEW_BUNDLE_SHA=$(skopeo inspect "docker://${PUSH_IMAGE}" | jq -r '.Digest') +retry_inspect skopeo inspect "docker://${PUSH_IMAGE}" || + error "Failed to inspect $PUSH_IMAGE: ${INSPECT_ERR_MSG}" +NEW_BUNDLE_SHA=$(jq -r '.Digest // empty' <<< "${INSPECT_OUT}") +if [[ -z "$NEW_BUNDLE_SHA" ]]; then + error "Failed to get the digest of $PUSH_IMAGE" +fi NEW_BUNDLE_DIGEST="$(strip_tag "$PUSH_IMAGE")@${NEW_BUNDLE_SHA}" info "Resolved image $NEW_BUNDLE_DIGEST from $PUSH_IMAGE"