Skip to content

Commit a93dcb0

Browse files
oskutkaclaude
andauthored
feat: check that released images can be pinned with a PinnedImageSet (#2280)
* feat: check that released images can be pinned with a PinnedImageSet A PinnedImageSet pre-pulls images to OpenShift nodes, but the machine config daemon rejects some well-formed images silently: a single OCI image manifest is pullable and accepted by the API, yet `podman manifest inspect` fails on it with rc=125, and the prefetch is all-or-nothing per node. A release that ships such an image breaks administrators with no error on the Dev Spaces side. Add checkPinnedImages.sh and run it from addDigests(), after the CSV is digest-pinned and before the commit and every later release step. It rejects any RELATED_IMAGE_* value that is not a digest reference the API accepts, is empty or uses valueFrom, or fails `podman manifest inspect` in an empty store. A release also must not ship an image that was pinned from a moving `:next` tag: addDigests.sh records the source tag as a commented `# tag:` line, and the release passes --forbid-next-tags to reject those. When the flag is set but the file has no such lines, the check fails instead of passing every image. The next catalog keeps `:next` tags by design and does not pass the flag, but it is still checked for pinnability. Dev Spaces builds its bundle from bundle/next rather than a stable release, so also check the next-digest CSV before that bundle and catalog are pushed; this is the artifact downstream copies. The check requires podman. Install it in the release workflow, and fail a release run before any work when it is missing, because the gate runs after the operator image is pushed. The docker-run.sh wrapper cannot provide it: rootless podman does not run inside its unprivileged container. Assisted-by: Claude Code Co-Authored-By: Claude Code <noreply@anthropic.com> * feat: forbid a configurable list of moving tags Move the release's moving-tag policy out of a single hardcoded tag: - replace --forbid-next-tags with --forbid-tags <tags>, a comma-separated list of tag names or globs; make-release.sh passes "next", and "latest" can be added once the UDI (#24027) and header-rewrite-proxy references are version-tagged; - mention the flag in the usage error printed when --csv is missing; - read the origin correctly: an untagged reference means the implicit latest tag, an origin that is already a digest has no tag to forbid, and quotes or trailing whitespace no longer prevent a match; - reject an empty or blank --forbid-tags value instead of silently disabling the check. Tested: :next fails with "next" and passes with "latest"; the reverse for :latest; quoted origins with trailing whitespace are matched; an untagged origin is caught by "latest"; digest origins are not matched by globs; an empty or blank list fails; the 7.125.0 CSV passes with "next" and fails with "next,latest" and with "la*"; the 7.124.0 CSV still reports four forbidden origins; a CSV without '# tag:' lines still fails when the flag is set. Assisted-by: Claude Code Co-Authored-By: Claude Code <noreply@anthropic.com> * fix: cover every pinned origin and quoted origins addDigests.sh deduplicated relatedImages entries with a substring match, so an origin whose entry name was a prefix of another was dropped from the list, and with it its "# tag:" line: tool:next was skipped when tool:next-patch had already been recorded. Compare the entry name exactly. The checker removed surrounding double quotes but not single quotes, so '# tag: 'image:next'' produced the tag next' and escaped matching. Remove a matching pair of either quote. Assisted-by: Claude Code Co-Authored-By: Claude Code <noreply@anthropic.com> * ci: describe the next catalog check accurately Dev Spaces replaces the upstream images with downstream ones when it builds its bundle, so the check on the next catalog is a check of what the next channel ships, not a gate on the images Dev Spaces deploys. Assisted-by: Claude Code Co-Authored-By: Claude Code <noreply@anthropic.com> * fix(release): retry the image inspection and gate podman on the OLM files A registry can fail the pinned-image inspection transiently, for example a blip while the release pushes the images. The inspection is read-only and idempotent, so retry it up to three times, five seconds apart, and report the cause of the last failure. The podman preflight ran unconditionally, but addDigests() - and with it the pinned-image check - only runs with --release-olm-files. The manual flow documented in build/scripts/release/RELEASE.md does not pass that flag, so a maintainer without podman failed before any release work for a gate that would not run. Check podman only when the gate will run. Assisted-by: Claude Code Co-Authored-By: Claude Code <noreply@anthropic.com> --------- Co-authored-by: Claude Code <noreply@anthropic.com>
1 parent 7e94947 commit a93dcb0

5 files changed

Lines changed: 268 additions & 4 deletions

File tree

‎.github/workflows/release-next-catalog-and-operator-image.yaml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright (c) 2019-2023 Red Hat, Inc.
2+
# Copyright (c) 2019-2026 Red Hat, Inc.
33
# This program and the accompanying materials are made
44
# available under the terms of the Eclipse Public License 2.0
55
# which is available at https://www.eclipse.org/legal/epl-2.0/
@@ -124,6 +124,8 @@ jobs:
124124
username: ${{ secrets.QUAY_USERNAME }}
125125
password: ${{ secrets.QUAY_PASSWORD }}
126126
registry: quay.io
127+
- name: Install podman
128+
run: sudo apt-get install -y podman
127129
- name: Build catalog source
128130
run: |
129131
${GITHUB_WORKSPACE}/build/scripts/release/editors-definitions.sh update-manager-yaml \
@@ -133,6 +135,10 @@ jobs:
133135
--index-json-url "https://raw.githubusercontent.com/eclipse-che/che-dashboard/main/packages/devfile-registry/air-gap/index.json"
134136
make update-dev-resources
135137
${GITHUB_WORKSPACE}/build/scripts/release/addDigests.sh -s $(make csv-path CHANNEL=next) -t next
138+
# Check the images the next channel ships before the next-digest bundle and catalog
139+
# are published. Dev Spaces replaces these with downstream images, so this is not a
140+
# downstream gate.
141+
${GITHUB_WORKSPACE}/build/scripts/release/checkPinnedImages.sh --csv $(make csv-path CHANNEL=next)
136142
${GITHUB_WORKSPACE}/build/scripts/release/release-catalog.sh \
137143
--channel next \
138144
--image-tool docker \

‎.github/workflows/release.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,13 @@ jobs:
8383
uses: actions/setup-python@7f4fc3e22c37d6ff65e88745f38bd3157c663f7c # v4.9.1
8484
with:
8585
python-version: 3.9
86-
- name: Install operator courier, yq and base32 wrapper
86+
- name: Install yq, semver, podman and base32 wrapper
8787
run: |
8888
python -m pip install --upgrade pip
8989
pip install yq
9090
pip install semver
91-
sudo apt-get -y -q install
91+
# the release gate checks the pinned images with podman, which this runner lacks
92+
sudo apt-get -y -q install podman
9293
# get base32 util from che-release project
9394
wget https://raw.githubusercontent.com/eclipse/che-release/master/utils/base32
9495
# copy base32 python-based helper script into dir that's accessed from PATH (so it's accessible to this and other called scripts)

‎build/scripts/release/addDigests.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ do
9696
RELATED_IMAGE="{ name: \"${relatedImageName}\", image: \"${dest}\", tag: \"${source}\"}"
9797
if [[ -z ${RELATED_IMAGES} ]]; then
9898
RELATED_IMAGES="${RELATED_IMAGE}"
99-
elif [[ ! ${RELATED_IMAGES} =~ ${relatedImageName} ]]; then
99+
elif ! grep -qF "name: \"${relatedImageName}\"" <<< "${RELATED_IMAGES}"; then
100100
RELATED_IMAGES="${RELATED_IMAGES}, ${RELATED_IMAGE}"
101101
fi
102102

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2019-2026 Red Hat, Inc.
4+
# This program and the accompanying materials are made
5+
# available under the terms of the Eclipse Public License 2.0
6+
# which is available at https://www.eclipse.org/legal/epl-2.0/
7+
#
8+
# SPDX-License-Identifier: EPL-2.0
9+
#
10+
# Contributors:
11+
# Red Hat, Inc. - initial API and implementation
12+
#
13+
# Checks that every image referenced by the CSV's RELATED_IMAGE_* variables can be pinned with
14+
# an OpenShift PinnedImageSet (machineconfiguration.openshift.io/v1). Each value must be a
15+
# digest reference accepted by the API, and must pass `podman manifest inspect` - the command
16+
# the machine config daemon runs to prefetch the set.
17+
#
18+
# The case this check exists for is a single OCI image manifest. It is well formed and
19+
# pullable, but `podman manifest inspect` fails on it with rc=125 ("Treating single images as
20+
# manifest lists is not implemented"). Because the prefetch is all-or-nothing per node, one
21+
# such image silently disables the whole set.
22+
#
23+
# make-release.sh calls this after addDigests.sh, on the digest-pinned stable CSV, with
24+
# --forbid-tags next: addDigests.sh records the tag each digest was pinned from as a commented
25+
# `# tag:` line, and an image that came from a moving tag is rebuilt and removed behind the
26+
# pinned digest, which breaks workspaces. The argument is a comma-separated list of tag names or
27+
# glob patterns; stable releases pass `next` today and can add `latest` once those references
28+
# are version-tagged. The next catalog keeps moving tags by design and does not pass the flag.
29+
#
30+
# Usage: checkPinnedImages.sh --csv <CSV> [--authfile <file>] [--forbid-tags <tags>]
31+
#
32+
# Each inspection is retried up to three times, five seconds apart, because a registry can fail
33+
# transiently; the inspection is read-only, so retrying it is safe.
34+
#
35+
# Requires podman and the python-yq (kislyuk) implementation. Set CONTAINERS_REGISTRIES_CONF to
36+
# check pre-release images through a mirror.
37+
38+
set -Eeuo pipefail
39+
40+
# IMAGE_RE is the CEL rule on spec.pinnedImages[*].name (openshift/api, ImageDigestFormat),
41+
# with the digest expression inlined. In words, a pinnable reference looks like:
42+
#
43+
# host[:port]/[namespace/]name@sha256:<64 lowercase hex characters>
44+
#
45+
# - host: dot-separated labels, so at least one dot. A dotless host, such as localhost:5000,
46+
# is not accepted here nor by the API.
47+
# - port: optional, 2 to 5 digits.
48+
# - namespace: optional, at most one segment of up to 61 characters.
49+
# - name: letters, digits, '_', '.' and '-'; it may be empty.
50+
# - digest: no tag before the '@', and exactly 64 lowercase hex characters after 'sha256:'.
51+
#
52+
# Do not tighten any part of it: the API accepts an empty namespace segment and an empty name,
53+
# so rejecting those here would reject references the cluster accepts.
54+
IMAGE_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}$'
55+
MAX_REFERENCE_LENGTH=447
56+
57+
die() {
58+
echo "[ERROR] $*" >&2
59+
exit 1
60+
}
61+
62+
CSV=""
63+
AUTHFILE=""
64+
FORBID_TAGS=""
65+
FORBID_TAGS_GIVEN=false
66+
67+
while [[ $# -gt 0 ]]; do
68+
case "$1" in
69+
--csv)
70+
[[ $# -ge 2 ]] || die "--csv requires a value"
71+
CSV="$2"
72+
shift 2
73+
;;
74+
--authfile)
75+
[[ $# -ge 2 ]] || die "--authfile requires a value"
76+
AUTHFILE="$2"
77+
shift 2
78+
;;
79+
--forbid-tags)
80+
[[ $# -ge 2 ]] || die "--forbid-tags requires a value"
81+
FORBID_TAGS="$2"
82+
FORBID_TAGS_GIVEN=true
83+
shift 2
84+
;;
85+
-h | --help)
86+
sed -n '/^# Usage:/,/^$/s/^# \{0,1\}//p' "$0"
87+
exit 0
88+
;;
89+
*) die "unknown argument: $1 (see --help)" ;;
90+
esac
91+
done
92+
93+
[[ -n "${CSV}" ]] || die "usage: $(basename "$0") --csv <CSV> [--authfile <file>] [--forbid-tags <tags>]"
94+
[[ -r "${CSV}" ]] || die "${CSV} cannot be read"
95+
[[ -z "${AUTHFILE}" || -r "${AUTHFILE}" ]] || die "${AUTHFILE} cannot be read"
96+
command -v podman >/dev/null 2>&1 || die "podman is not installed"
97+
command -v yq >/dev/null 2>&1 || die "yq is not installed; the python-yq (kislyuk) implementation is required"
98+
yq --version 2>/dev/null | grep -q mikefarah && die "yq is the mikefarah implementation; the python-yq (kislyuk) implementation is required"
99+
100+
# A throwaway store, because an image already present locally makes `podman manifest inspect`
101+
# resolve offline and hide a bad reference.
102+
STORE=$(mktemp -d "${TMPDIR:-/tmp}/checkPinnedImages.XXXXXX")
103+
trap 'rm -rf "${STORE}"' EXIT
104+
mkdir -p "${STORE}/root" "${STORE}/run"
105+
106+
# The env list is read with python-yq, so quoting, comments, folded scalars and key order are the
107+
# YAML parser's problem rather than this script's. Fail on an entry that cannot be pinned by value:
108+
# valueFrom, a missing, empty or multi-line value.
109+
RELATED_ENVS='.spec.install.spec.deployments[]?
110+
| .spec.template.spec
111+
| (.containers[]?, .initContainers[]?)
112+
| .env[]?
113+
| select((.name // "") | startswith("RELATED_IMAGE_"))'
114+
115+
related_count=$(yq -r "[${RELATED_ENVS}] | length" "${CSV}") ||
116+
die "could not parse the RELATED_IMAGE_* variables of ${CSV}"
117+
118+
if [[ "${related_count}" == "0" ]]; then
119+
die "no RELATED_IMAGE_* variables found in ${CSV}"
120+
fi
121+
122+
value_from=$(yq -r "[${RELATED_ENVS} | select(.valueFrom != null)] | length" "${CSV}") ||
123+
die "could not parse the RELATED_IMAGE_* variables of ${CSV}"
124+
if [[ "${value_from}" != "0" ]]; then
125+
die "a RELATED_IMAGE_* value uses valueFrom in ${CSV}"
126+
fi
127+
128+
invalid=$(yq -r "[${RELATED_ENVS} | select((.value | type) != \"string\" or .value == \"\" or (.value | test(\"\\n\")))] | length" "${CSV}") ||
129+
die "could not parse the RELATED_IMAGE_* variables of ${CSV}"
130+
if [[ "${invalid}" != "0" ]]; then
131+
die "a RELATED_IMAGE_* value is empty or multi-line in ${CSV}"
132+
fi
133+
134+
refs=$(yq -r "${RELATED_ENVS} | .value" "${CSV}") ||
135+
die "could not read the RELATED_IMAGE_* values of ${CSV}"
136+
137+
forbidden_origins=""
138+
if [[ "${FORBID_TAGS_GIVEN}" == true ]]; then
139+
# addDigests.sh keeps the source tag as a commented line, so a digest alone does not say
140+
# whether the image is rebuilt behind it. Without those lines the rule cannot work, so fail
141+
# instead of passing every image.
142+
grep -qE '^[[:space:]]*#[[:space:]]*tag:' "${CSV}" ||
143+
die "--forbid-tags needs the '# tag:' origin lines that addDigests.sh writes; none found in ${CSV}"
144+
145+
IFS=',' read -r -a forbidden_tags <<< "${FORBID_TAGS}"
146+
valid_patterns=()
147+
for pattern in "${forbidden_tags[@]}"; do
148+
pattern="${pattern#"${pattern%%[![:space:]]*}"}"
149+
pattern="${pattern%"${pattern##*[![:space:]]}"}"
150+
if [[ -n "${pattern}" ]]; then
151+
valid_patterns+=("${pattern}")
152+
fi
153+
done
154+
if (( ${#valid_patterns[@]} == 0 )); then
155+
die "--forbid-tags needs at least one tag name or pattern"
156+
fi
157+
158+
origins=$(grep -E '^[[:space:]]*#[[:space:]]*tag:' "${CSV}" |
159+
sed -e 's|^[[:space:]]*#[[:space:]]*tag:[[:space:]]*||' | sort -u || true)
160+
161+
while IFS= read -r origin; do
162+
origin="${origin#"${origin%%[![:space:]]*}"}"
163+
origin="${origin%"${origin##*[![:space:]]}"}"
164+
# Remove a matching pair of surrounding quotes, single or double.
165+
origin="${origin#[\"\']}"
166+
origin="${origin%[\"\']}"
167+
if [[ -z "${origin}" ]]; then
168+
continue
169+
fi
170+
# An origin that is already a digest reference has no tag to forbid.
171+
if [[ "${origin}" == *"@sha256:"* ]]; then
172+
continue
173+
fi
174+
# An untagged reference resolves to the implicit latest tag.
175+
last_segment="${origin##*/}"
176+
if [[ "${last_segment}" == *:* ]]; then
177+
tag="${last_segment##*:}"
178+
else
179+
tag="latest"
180+
fi
181+
for pattern in "${valid_patterns[@]}"; do
182+
# shellcheck disable=SC2053 # the pattern intentionally supports globs
183+
if [[ "${tag}" == ${pattern} ]]; then
184+
forbidden_origins+="${origin}"$'\n'
185+
break
186+
fi
187+
done
188+
done <<< "${origins}"
189+
fi
190+
191+
AUTHARGS=()
192+
[[ -n "${AUTHFILE}" ]] && AUTHARGS=(--authfile "${AUTHFILE}")
193+
194+
failures=0
195+
forbidden=0
196+
while IFS= read -r ref; do
197+
[[ -n "${ref}" ]] || continue
198+
199+
if (( ${#ref} > MAX_REFERENCE_LENGTH )) || [[ ! "${ref}" =~ ${IMAGE_RE} ]]; then
200+
echo "[FAIL] ${ref}"
201+
echo " not a digest reference accepted by the PinnedImageSet API (expected host/path@sha256:<64 hex>)"
202+
failures=$((failures + 1))
203+
continue
204+
fi
205+
206+
inspected=false
207+
for attempt in 1 2 3; do
208+
if output=$(podman --log-level error --root "${STORE}/root" --runroot "${STORE}/run" \
209+
manifest inspect "${AUTHARGS[@]}" "${ref}" 2>&1); then
210+
inspected=true
211+
break
212+
fi
213+
# A registry can fail transiently, for example a blip while the release pushes the images.
214+
# The inspection is read-only, so retrying it is safe.
215+
(( attempt < 3 )) && sleep 5
216+
done
217+
if [[ "${inspected}" != true ]]; then
218+
# The single-manifest error embeds the whole manifest JSON; keep the head and the tail,
219+
# where the cause is.
220+
output="${output//$'\n'/ }"
221+
(( ${#output} > 300 )) && output="${output:0:90} ... ${output: -180}"
222+
echo "[FAIL] ${ref}"
223+
echo " podman manifest inspect failed after 3 attempts: ${output}"
224+
failures=$((failures + 1))
225+
fi
226+
done < <(sort -u <<<"${refs}")
227+
228+
if [[ -n "${forbidden_origins}" ]]; then
229+
while IFS= read -r origin; do
230+
[[ -n "${origin}" ]] || continue
231+
echo "[FAIL] ${origin}"
232+
echo " pinned from a tag listed in --forbid-tags, which can move and leave the digest behind"
233+
forbidden=$((forbidden + 1))
234+
done <<< "${forbidden_origins}"
235+
fi
236+
237+
if (( failures > 0 || forbidden > 0 )); then
238+
summary=""
239+
(( failures > 0 )) && summary="${failures} image(s) failed the pinned-image check"
240+
(( forbidden > 0 )) && summary="${summary:+${summary}; }${forbidden} image(s) were pinned from a forbidden tag"
241+
die "${summary}"
242+
fi
243+
244+
echo "[INFO] every image can be pinned with a PinnedImageSet"

‎build/scripts/release/make-release.sh‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,13 @@ addDigests() {
196196
echo "[INFO] addDigests :: Pin images to digests"
197197
. "${OPERATOR_REPO}/build/scripts/release/addDigests.sh" -t "${RELEASE}" -s "${CSV_STABLE_PATH}" -o "${MANAGER_YAML}"
198198

199+
# Fail the release if an image cannot be pinned with an OpenShift PinnedImageSet. This runs
200+
# after addDigests.sh, so it checks the final digest-pinned CSV, and before the digest commit
201+
# and every later step. The operator image has already been pushed by then; re-running with
202+
# FORCE_UPDATE rebuilds and republishes it.
203+
echo "[INFO] addDigests :: Check that every image can be pinned with a PinnedImageSet"
204+
bash "${OPERATOR_REPO}/build/scripts/release/checkPinnedImages.sh" --csv "${CSV_STABLE_PATH}" --forbid-tags next
205+
199206
echo "[INFO] addDigests :: Ensure license header"
200207
make license "${CSV_STABLE_PATH}"
201208
make license "${MANAGER_YAML}"
@@ -269,6 +276,12 @@ prepareCommunityOperatorsUpdate() {
269276
}
270277

271278
run() {
279+
if [[ $RELEASE_OLM_FILES == "true" ]]; then
280+
# The pinned-image gate runs after the operator image is pushed, so fail before any release
281+
# work when podman is missing.
282+
command -v podman >/dev/null 2>&1 || { echo "[ERROR] podman is not installed. Abort."; exit 1; }
283+
fi
284+
272285
if [[ $CHECK_RESOURCES == "true" ]]; then
273286
echo "[INFO] Check if resources are up to date"
274287
. ${OPERATOR_REPO}/build/scripts/check-resources.sh

0 commit comments

Comments
 (0)