Skip to content

Commit 41f92ec

Browse files
fix(release): compare host-less image refs on digest alone (#3908)
Ports #3905 to `main`. Same fix, same tests, two cherry-picks, no conflicts. `main`'s copy of `hack/verify-promoted-packages.sh` was byte-identical to the buggy one, so the next promotion cut from here fails the way v1.6.2 just did: `normalized_refs()` gives a host-less ref a repository equal to its own tag, because `repo="${image%:*}"` is a no-op on a bare `tag@sha256:...` scalar with neither `/` nor `:` in it. `hack/lib/image-refs.sh` emits one of those per shape-3 split map, promotion rewrites exactly those tags, and the check then reports changed repositories at identical digests. It cost several rounds on v1.6.2 before the cause was clear, so it is worth not paying twice. Checked against `main`'s own tree rather than assumed from the 1.6 port. 13 host-less refs, same count as `release-1.6`: 12 pair one-to-one with a host-bearing ref at an identical digest, and the 13th is `packages/system/kuberture/values.yaml` (`tag:` only, no `repository:`, no `registry:`), which is genuinely digest-only and is the case the comment says must not be dropped. The narrowing the 1.6 review left open still does not exist here. Of 14 repository-bearing digest maps, exactly one has a slash-free `repository:` — kube-ovn's `global.images.kubeovn` — and `global.registry.address` gives it a shape-4 join that keeps its repository in the compared set. No map anywhere has an empty or non-string `registry:` sibling. `hack/lib/image-refs.sh` differs from `release-1.6`'s in comments only: 47 code lines either side and an empty diff once comments are stripped, same globs and same selectors, so the refs reaching the verifier are unchanged. Not modified here. Red phase checked both directions rather than inherited. Reverting the one line reddens the new split-map case on the digest-set assertion. Replacing `repo=""` with an outright `continue` for host-less refs flips which case fails: the split-map one goes green and `rejects a changed digest carried only by a repository-less image map` reddens at its exit-status assertion, because the verifier then exits 0 on a genuinely changed digest. That second direction is the one worth having a test for, since dropping host-less refs is the obvious-looking fix. Gate: the four promote bats suites individually green, `shellcheck -x --shell=sh` clean, `pre-commit` green. No Go, charts or generated files, so build, vet, test and `make generate` do not apply. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved promoted package validation for image references without explicit registries or repositories. * Promotion-only tag changes are now accepted when the image digest remains unchanged. * Digest changes continue to be detected and rejected correctly. * **Tests** * Added coverage for split image reference formats and repository-less image mappings. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 6935df8 + d87dffc commit 41f92ec

2 files changed

Lines changed: 143 additions & 1 deletion

File tree

‎hack/verify-promoted-packages.sh‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,44 @@ normalized_refs() {
206206
digest="${raw##*@}"
207207
image="${without_digest##*/}"
208208
if [ "$without_digest" = "$image" ]; then
209-
repo="${image%:*}"
209+
# No `/` anywhere ahead of the digest, so nothing in this ref names a
210+
# registry host or a repository path — it is a bare scalar sitting in
211+
# front of a digest, and the collector emits those by design. Shape 3
212+
# (`repository:` on one key, `tag: <tag>@sha256:<digest>` on another) is
213+
# the dominant shape in the tree, and shape 1's recursive descent sees
214+
# that `tag` scalar on its own, so every shape-3 map arrives here twice:
215+
# once correctly joined, once as the bare tag. hack/lib/image-refs.sh
216+
# documents that degeneracy and leaves host-less refs to its callers —
217+
# promote-retag.sh drops them through its ownership filter, and this
218+
# function had no equivalent. `${image%:*}` is then a no-op (a tag holds
219+
# no colon) and the TAG arrives as the repository. Promotion rewrites
220+
# exactly those tags, which is how a promotion that moved no container
221+
# bytes at all reported six changed "repositories" whose digests were
222+
# identical on both sides.
223+
#
224+
# Compare such a ref on its digest alone. The digest is the whole of the
225+
# container identity a host-less ref carries, and it is the only part
226+
# promotion must not move; the empty repository yields a leading `@`,
227+
# which no real repository name can produce, so these cannot collide with
228+
# a host-bearing entry. Where a repository name does exist behind one of
229+
# them — kube-ovn's `global.images.kubeovn`, whose host lives in
230+
# `global.registry.address` — the same image also arrives host-bearing
231+
# from shape 4, so a repository change stays visible through that entry.
232+
#
233+
# Dropping host-less refs outright would be wrong rather than merely
234+
# blunter: packages/system/kuberture/values.yaml carries an `image:` map
235+
# with a `tag:` and no `repository:`, so shape 1 is the only rule that
236+
# ever sees its digest. Skipping it would silently stop proving that
237+
# digest is unchanged — a hole in the very guard this branch repairs.
238+
#
239+
# Do NOT reach for promote-retag.sh's `${REGISTRY}/` ownership filter to
240+
# do this job. The verify job's REGISTRY names the private build registry
241+
# while both artifacts under comparison live on the public one, so that
242+
# filter drops every ref; and the emptiness guard above tests the RAW
243+
# collection rather than the filtered set, so the proof would then pass
244+
# by comparing two empty sets — failing open on the one invariant it
245+
# exists to establish.
246+
repo=""
210247
else
211248
repo="${without_digest%/*}/${image%:*}"
212249
fi

‎hack/verify-promoted-packages_test.bats‎

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,108 @@ EOF
365365
[ "$rc" -ne 0 ]
366366
grep -q 'promotion changed the container repository/digest set' "$tmp/err"
367367
}
368+
369+
# Shape 3 — `repository:` on one key, `tag: <tag>@sha256:<digest>` on another —
370+
# is the shape hack/lib/image-refs.sh itself calls the dominant one, and the one
371+
# no fixture above builds. The collector emits TWO entries for such a map: the
372+
# correctly joined repository@digest, plus shape 1's recursive scrape of the
373+
# bare `tag` scalar, which names no repository at all. Promotion rewrites
374+
# exactly that scalar, so normalization keeping it — treating the tag as the
375+
# repository — makes every clean promotion look as though it moved container
376+
# bytes. The single-string ref in _make_verify_fixture cannot reach that path:
377+
# it carries a registry host, so it normalizes through the other branch and its
378+
# own rc-to-stable rewrite passes either way. That is why the suite looked
379+
# covered while the dominant shape went untested.
380+
_write_split_map() {
381+
cat > "$1" <<EOF
382+
linstorCSI:
383+
image:
384+
repository: ghcr.io/cozystack/cozystack/linstor-csi
385+
tag: $2@sha256:eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee
386+
EOF
387+
}
388+
389+
# Same repository and the same digest on every side. ONLY the tag string moves,
390+
# which is exactly and only what promotion is meant to change.
391+
_add_split_map_package() {
392+
t="$1"
393+
mkdir -p "$t/release/system/linstor" "$t/artifact/system/linstor" \
394+
"$t/rc-artifact/system/linstor"
395+
_write_split_map "$t/release/system/linstor/values.yaml" v9.9.9
396+
_write_split_map "$t/artifact/system/linstor/values.yaml" v9.9.9
397+
_write_split_map "$t/rc-artifact/system/linstor/values.yaml" v9.9.9-rc.3
398+
}
399+
400+
@test "accepts a split-map tag rewritten from rc to stable" {
401+
tmp="$(_test_workspace)/fixture"
402+
_make_verify_fixture "$tmp"
403+
_add_split_map_package "$tmp"
404+
405+
rc=0
406+
MOCK_ARTIFACT="$tmp/artifact" MOCK_RC_ARTIFACT="$tmp/rc-artifact" MOCK_FLUX_LOG="$tmp/flux.log" \
407+
VERIFY_PACKAGES_WORKDIR="$tmp/work" \
408+
PATH="$tmp/bin:$PATH" \
409+
hack/verify-promoted-packages.sh 9.9.9 "$tmp/release" \
410+
> "$tmp/out" 2> "$tmp/err" || rc=$?
411+
if [ "$rc" -ne 0 ]; then
412+
echo "verification exited $rc" >&2
413+
cat "$tmp/err" >&2
414+
return "$rc"
415+
fi
416+
417+
grep -q "stable tags, identical package tree, and the rc artifact's container digests" "$tmp/out"
418+
}
419+
420+
# The property a blunter fix would break. packages/system/kuberture/values.yaml
421+
# carries an `image:` map with a `tag:` and no `repository:` — shape 2 wants a
422+
# `digest` key and shape 3 a `repository` key, so shape 1's scrape of the bare
423+
# tag scalar is the ONLY rule that ever sees that image's digest. Discarding
424+
# host-less refs rather than comparing them on their digest would silently stop
425+
# proving it unchanged, which is a hole in the same guard being repaired here.
426+
# Asserted from the rejecting direction, because that is the direction able to
427+
# go red: the digest moves and nothing else does, so the digest-set comparison
428+
# is the only leg that can fire — artifact and release tree stay byte-identical,
429+
# no rc string appears in the candidate, and the installer values match.
430+
_write_repository_less_map() {
431+
cat > "$1" <<EOF
432+
kuberture:
433+
image:
434+
tag: 0.1.1@sha256:$2
435+
EOF
436+
}
437+
438+
_add_repository_less_package() {
439+
t="$1"
440+
mkdir -p "$t/release/system/kuberture" "$t/artifact/system/kuberture" \
441+
"$t/rc-artifact/system/kuberture"
442+
_repoless_stable=1111111111111111111111111111111111111111111111111111111111111111
443+
_repoless_rc=2222222222222222222222222222222222222222222222222222222222222222
444+
_write_repository_less_map "$t/release/system/kuberture/values.yaml" "$_repoless_stable"
445+
_write_repository_less_map "$t/artifact/system/kuberture/values.yaml" "$_repoless_stable"
446+
_write_repository_less_map "$t/rc-artifact/system/kuberture/values.yaml" "$_repoless_rc"
447+
}
448+
449+
@test "rejects a changed digest carried only by a repository-less image map" {
450+
tmp="$(_test_workspace)/fixture"
451+
_make_verify_fixture "$tmp"
452+
_add_repository_less_package "$tmp"
453+
454+
rc=0
455+
MOCK_ARTIFACT="$tmp/artifact" MOCK_RC_ARTIFACT="$tmp/rc-artifact" MOCK_FLUX_LOG="$tmp/flux.log" \
456+
VERIFY_PACKAGES_WORKDIR="$tmp/work" \
457+
PATH="$tmp/bin:$PATH" \
458+
hack/verify-promoted-packages.sh 9.9.9 "$tmp/release" \
459+
> "$tmp/out" 2> "$tmp/err" || rc=$?
460+
461+
[ "$rc" -ne 0 ]
462+
grep -q 'promotion changed the container repository/digest set' "$tmp/err"
463+
# The rejection has to come from the digest set and not from a neighbouring leg
464+
# rejecting a tree this test never perturbed, or it would still pass with the
465+
# digest dropped from the comparison entirely. Counted rather than negated with
466+
# `!`, which suppresses errexit and would pass regardless.
467+
for _other in 'contain different files' 'differs from release tree' \
468+
'still carries rc image references' 'installer values differ'; do
469+
count="$(grep -c "$_other" "$tmp/err" || true)"
470+
[ "${count:-0}" -eq 0 ]
471+
done
472+
}

0 commit comments

Comments
 (0)