Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(release): harden image-name validation, promotion-loop guard, and error messages
Jose Ramirez01f66e0f351c
diff --git a/scripts/ci/check-image-visibility.mjs b/scripts/ci/check-image-visibility.mjsindex 8d591092f..e82af2018 100644--- a/scripts/ci/check-image-visibility.mjs+++ b/scripts/ci/check-image-visibility.mjs@@ -15,9 +15,15 @@ const ACCEPT = ['application/vnd.docker.distribution.manifest.v2+json',].join(', ')+// A hung registry connection must not hang the job with no signal: 28 images+// are fetched sequentially (deliberately -- see the loop below), so one stuck+// connection would otherwise stall the whole guard with nothing in the logs+// to explain why.+const FETCH_TIMEOUT_MS = 15_000+async function token(image) {const url = `https://ghcr.io/token?scope=repository:${NAMESPACE}/${image}:pull&service=ghcr.io`- const res = await fetch(url)+ const res = await fetch(url, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) })if (!res.ok) return nullreturn (await res.json()).token}@@ -27,11 +33,18 @@ const failures = []for (const image of publishedImages()) {const t = await token(image.name)if (!t) {- failures.push(`${image.name}: no anonymous pull token (the package is private)`)+ // A 403/DENIED response with no token is returned both for a private+ // package and for one that never existed under this namespace at all --+ // GHCR does not distinguish the two cases in this response, so neither+ // does this message.+ failures.push(+ `${image.name}: no anonymous pull token was issued -- the package is private or does not exist`+ )continue}const res = await fetch(`https://ghcr.io/v2/${NAMESPACE}/${image.name}/manifests/latest`, {headers: { Authorization: `Bearer ${t}`, Accept: ACCEPT },+ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),})if (!res.ok) {failures.push(`${image.name}: manifests/latest returned HTTP ${res.status}`)diff --git a/scripts/release/images-manifest.mjs b/scripts/release/images-manifest.mjsindex 2bbb99785..fd4ebebf1 100644--- a/scripts/release/images-manifest.mjs+++ b/scripts/release/images-manifest.mjs@@ -30,6 +30,14 @@ function load() {}for (const image of parsed.images) {if (!image.name) throw new Error(`${MANIFEST_PATH}: an entry has no name`)+ // check-image-visibility.mjs interpolates image.name straight into GHCR+ // URLs, and promote-release-images.sh interpolates it into shell `crane`+ // refs -- both trusted consumers of a trusted in-repo file, but validating+ // the shape here once defends every consumer instead of relying on each+ // one to notice a malformed name on its own.+ if (!/^[a-z0-9][a-z0-9._-]*$/.test(image.name)) {+ throw new Error(`${MANIFEST_PATH}: ${image.name} is not a valid image name`)+ }if (typeof image.published !== 'boolean') {throw new Error(`${MANIFEST_PATH}: ${image.name} must set published explicitly`)}diff --git a/scripts/release/promote-release-images.sh b/scripts/release/promote-release-images.shindex 1e51760c3..d1b896f15 100755--- a/scripts/release/promote-release-images.sh+++ b/scripts/release/promote-release-images.sh@@ -59,10 +59,19 @@ for row in "${IMAGES[@]}"; do# Verify the INDEX we are about to promote is multi-arch. Existence alone# would let a single-platform copy through, which is the exact gap this# workstream exists to close.- platforms="$(crane manifest "$REGISTRY/$name@$digest" \- | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{- const m=JSON.parse(s).manifests||[];- console.log(m.map(x=>x.platform?.architecture).filter(a=>a&&a!=="unknown").sort().join(","))})')"+ #+ # Guarded the same way as the resolver call above: a bare assignment here+ # let a transient `crane manifest` failure or a node parse error abort the+ # WHOLE loop under `set -euo pipefail`, instead of marking just this one+ # image failed and continuing -- the opposite of the pattern one line up,+ # and it makes a partial-promotion state MORE likely, not less.+ if ! platforms="$(crane manifest "$REGISTRY/$name@$digest" \+ | node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{+ const m=JSON.parse(s).manifests||[];+ console.log(m.map(x=>x.platform?.architecture).filter(a=>a&&a!=="unknown").sort().join(","))})')"; then+ echo "::error::$name: could not verify the multi-arch manifest at $digest (crane manifest or the platform parse failed)"+ failed=1; continue+ fi# Subset match, not exact equality against "amd64,arm64": check-image-# visibility.mjs's guard already treats a third platform as still# multi-arch (it checks .includes for each of amd64/arm64), and an indexdiff --git a/scripts/release/resolve-release-images.mjs b/scripts/release/resolve-release-images.mjsindex 12c9ecc90..7c26970a9 100644--- a/scripts/release/resolve-release-images.mjs+++ b/scripts/release/resolve-release-images.mjs@@ -70,6 +70,24 @@ if (!revision) {)}+// A well-formed revision that simply is not an object in this checkout (a+// shallow clone, an unfetched ref, or a stray hand-edited annotation) makes+// BOTH --is-ancestor calls below throw -- with nothing to distinguish it from+// genuinely diverged history, this used to fall through to the "diverged+// history" message even though there was no comparison to make at all.+// Existence is checked first, and separately, so that message stays reserved+// for when it is actually true.+try {+ sh('git', ['cat-file', '-e', `${revision}^{commit}`])+} catch {+ die(+ `${image}: the published image records revision ${revision}, but this checkout has no such commit ` ++ `at all -- distinct from diverged history, where the commit exists yet neither side descends from ` ++ `the other. A shallow clone, an unfetched ref, or a stray hand-edited annotation could all cause ` ++ `this; fetch the missing commit (or its full history) into this checkout and retry.`+ )+}+try {sh('git', ['merge-base', '--is-ancestor', revision, tagSha])} catch {diff --git a/scripts/tests/test-images-manifest.sh b/scripts/tests/test-images-manifest.shindex 120b752c7..66822d4a4 100755--- a/scripts/tests/test-images-manifest.sh+++ b/scripts/tests/test-images-manifest.sh@@ -162,6 +162,46 @@ JSONrm -rf "$d"}+# check-image-visibility.mjs interpolates image.name straight into GHCR+# token/manifest URLs, and promote-release-images.sh interpolates it into+# shell `crane` refs -- a name with characters either of those would treat+# specially (path separators, whitespace, shell metacharacters) must be+# rejected at the one place both consumers read from, not discovered by+# either consumer individually.+#+# Same real-copy-into-a-throwaway-tree reasoning as+# assert_a_published_image_with_no_source_paths_is_rejected above.+assert_an_invalid_image_name_is_rejected() {+ local d; d="$(mktemp -d)"+ mkdir -p "$d/scripts/release" "$d/deploy"+ cp "$REPO_ROOT/scripts/release/images-manifest.mjs" "$d/scripts/release/"+ cat > "$d/deploy/images.json" <<'JSON'+{+ "images": [+ {+ "name": "widget/../evil",+ "path": "widget",+ "source_paths": ["widget/**"],+ "published": true,+ "deployed_to_minikube": false+ }+ ]+}+JSON+ local out rc+ out="$( cd "$d" && node -e '+ import("./scripts/release/images-manifest.mjs").catch(err => {+ console.log(err.message)+ process.exit(1)+ })' 2>&1 )" && rc=0 || rc=1+ if [ "$rc" -ne 0 ] && grep -qi "not a valid image name" <<< "$out"; then+ pass "an invalid image name is rejected at load time"+ else+ fail "expected a named failure about an invalid image name; got rc=$rc out='$out'"+ fi+ rm -rf "$d"+}+assert_unpublished_images_are_exactly_the_known_three() {local gotgot="$(node -e '@@ -514,6 +554,7 @@ assert_every_published_image_has_a_build_matrix_entryassert_every_local_image_maps_to_exactly_one_rowassert_pull_in_ghcr_mode_is_derived_not_storedassert_a_published_image_with_no_source_paths_is_rejected+assert_an_invalid_image_name_is_rejectedassert_unpublished_images_are_exactly_the_known_threeassert_matrix_fields_match_manifestassert_every_matrix_image_has_a_manifest_rowdiff --git a/scripts/tests/test-promote-release-images.sh b/scripts/tests/test-promote-release-images.shindex 97f55b175..e92be595b 100755--- a/scripts/tests/test-promote-release-images.sh+++ b/scripts/tests/test-promote-release-images.sh@@ -233,6 +233,115 @@ assert_a_single_arch_index_is_rejected() {rm -rf "$d"}+# A two-image manifest, real copies of the three release scripts, and one+# commit on a v0.2.0 tag -- same real-copy reasoning as make_repo above, just+# with two source dirs and two manifest rows so a per-image failure has a+# sibling to keep promoting.+make_repo_two_images() {+ local d=$1+ mkdir -p "$d/widget-a" "$d/widget-b" "$d/scripts/release" "$d/deploy"+ cp "$REPO_ROOT/scripts/release/images-manifest.mjs" "$d/scripts/release/"+ cp "$REPO_ROOT/scripts/release/resolve-release-images.mjs" "$d/scripts/release/"+ cp "$REPO_ROOT/scripts/release/promote-release-images.sh" "$d/scripts/release/"+ cp "$REPO_ROOT/scripts/release/release-coordinates.mjs" "$d/scripts/release/"+ cat > "$d/deploy/images.json" <<'JSON'+{+ "images": [+ {+ "name": "widget-a",+ "path": "widget-a",+ "source_paths": ["widget-a/**"],+ "published": true,+ "deployed_to_minikube": false+ },+ {+ "name": "widget-b",+ "path": "widget-b",+ "source_paths": ["widget-b/**"],+ "published": true,+ "deployed_to_minikube": false+ }+ ]+}+JSON+ ( cd "$d" && git init -q .+ echo one > widget-a/a.ts && echo one > widget-b/a.ts+ git add -A && git -c user.email=t@t -c user.name=t commit -qm one+ git tag v0.2.0 )+}++# make_stub_manifest_fails_for <dir> <revision> <failing-image-name>+# Like make_stub above, but `crane manifest` fails outright (rather than+# returning a payload) on the SECOND call made against one named image --+# simulating the transient registry failure or malformed response this guard+# exists to survive without aborting the whole run.+#+# `crane manifest "$REGISTRY/$name@$digest"` is called with the exact same+# arguments TWICE per image: once inside resolve-release-images.mjs (to read+# the revision annotation) and once more by promote-release-images.sh itself+# (the arch-verification line this case targets). A stub that fails on every+# call for the named image can't tell those two call sites apart -- proven by+# writing exactly that first and watching this case pass even with the+# arch-check guard reverted, because the resolver's own (already-guarded)+# manifest read failed first and never reached the line under test. Only+# failing the SECOND call isolates the arch-check's own crane invocation.+make_stub_manifest_fails_for() {+ local dir=$1 revision=$2 failing=$3+ mkdir -p "$dir/bin"+ cat > "$dir/bin/crane" <<STUB+#!/usr/bin/env bash+COPY_LOG="$dir/copy-log"+CALL_COUNT_FILE="$dir/$failing-manifest-calls"+case "\$1" in+ digest) echo "sha256:widgetdigest00000000000000000000000000000000000000000000000000" ;;+ manifest)+ case "\$2" in+ *"$failing@"*)+ n=\$(( \$(cat "\$CALL_COUNT_FILE" 2>/dev/null || echo 0) + 1 )); echo "\$n" > "\$CALL_COUNT_FILE"+ if [ "\$n" -eq 1 ]; then+ echo '{"annotations":{"org.opencontainers.image.revision":"$revision"},"manifests":[{"platform":{"architecture":"amd64"}},{"platform":{"architecture":"arm64"}}]}'+ else+ echo "crane stub: transient manifest fetch failure for $failing (call \$n)" >&2+ exit 1+ fi+ ;;+ *)+ echo '{"annotations":{"org.opencontainers.image.revision":"$revision"},"manifests":[{"platform":{"architecture":"amd64"}},{"platform":{"architecture":"arm64"}}]}'+ ;;+ esac+ ;;+ copy) echo "\$2 \$3" >> "\$COPY_LOG"; echo "copied \$2 -> \$3" ;;+ *) exit 1 ;;+esac+STUB+ chmod +x "$dir/bin/crane"+}++assert_an_arch_verification_failure_for_one_image_does_not_abort_the_loop() {+ local d; d="$(mktemp -d)"; make_repo_two_images "$d"+ local head; head="$( cd "$d" && git rev-parse HEAD )"+ # widget-b's `crane manifest` call fails outright; widget-a's succeeds.+ # Before this was guarded with the same `if ! ...; then failed=1; continue;+ # fi` shape as the resolver call one line up, this bare assignment aborted+ # the WHOLE loop under `set -euo pipefail` the instant widget-b's pipe+ # failed -- so a transient registry hiccup on one image would have silently+ # skipped promoting every image after it too, the opposite of the+ # continue-on-one-failure pattern the resolver call already follows.+ make_stub_manifest_fails_for "$d" "$head" "widget-b"+ local out rc+ out="$( cd "$d" && PATH="$d/bin:$PATH" DRY_RUN=true RELEASE_REF=v0.2.0 \+ bash scripts/release/promote-release-images.sh 2>&1 )" && rc=0 || rc=1+ if [ "$rc" -ne 0 ] \+ && grep -q 'would promote widget-a@' <<< "$out" \+ && ! grep -q 'would promote widget-b@' <<< "$out" \+ && grep -q 'widget-b:' <<< "$out"; then+ pass "an arch-verification failure for one image doesn't abort the loop; the other image still promotes, run still exits nonzero"+ else+ fail "expected widget-a promoted, widget-b named as failed, nonzero exit; got rc=$rc out='$out'"+ fi+ rm -rf "$d"+}+assert_every_defined_case_is_invoked() {# comm -23 over sorted lists -- same pattern as# test-resolve-release-images.sh and test-release-coordinates.sh.@@ -254,6 +363,7 @@ assert_the_real_promotion_copies_to_the_v_prefixed_tagassert_an_empty_image_list_fails_loudlyassert_stable_does_not_move_for_a_pre_releaseassert_a_single_arch_index_is_rejected+assert_an_arch_verification_failure_for_one_image_does_not_abort_the_loopassert_every_defined_case_is_invokedexit $FAILdiff --git a/scripts/tests/test-resolve-release-images.sh b/scripts/tests/test-resolve-release-images.shindex 1887c2995..9df638ac7 100755--- a/scripts/tests/test-resolve-release-images.sh+++ b/scripts/tests/test-resolve-release-images.sh@@ -58,21 +58,60 @@ assert_a_revision_that_is_an_ancestor_resolves() {}assert_a_non_ancestor_revision_is_rejected() {+ local d; d="$(mktemp -d)"; make_repo "$d"+ # A revision that genuinely shares no history with tagSha -- an orphan+ # branch in the SAME repo, so the commit really exists as an object (the+ # existence check added below must NOT fire) and the two are truly+ # unrelated (neither an ancestor nor a descendant of the other), unlike a+ # bogus SHA that is not an object at all (covered separately below).+ local default_branch unrelated+ default_branch="$( cd "$d" && git branch --show-current )"+ unrelated="$( cd "$d" && git checkout -q --orphan unrelated-history \+ && git -c user.email=t@t -c user.name=t commit -q --allow-empty -m unrelated \+ && git rev-parse HEAD )"+ ( cd "$d" && git checkout -q "$default_branch" )+ make_stub "$d" "sha256:abc" "$unrelated"+ # Check for the diverged-history guard's own wording, not just a nonzero+ # exit: an unrelated commit is also not an ancestor either direction, so if+ # the ancestor checks themselves were removed, the very next step (the+ # source-paths diff) would independently choke on an unrelated revision and+ # exit nonzero too. A bare rc-only assertion can't tell "the diverged-+ # history guard fired" apart from "something downstream happened to crash+ # instead."+ local out rc+ out="$( cd "$d" && PATH="$d/bin:$PATH" node "$REPO_ROOT/scripts/release/resolve-release-images.mjs" \+ --image control-api --source-paths 'control-api/**' --tag-sha HEAD 2>&1 )" && rc=0 || rc=1+ if [ "$rc" -ne 0 ] && grep -qi "diverged history" <<< "$out"; then+ pass "a revision that truly shares no ancestry with the release commit is rejected as diverged history"+ else+ fail "expected a named failure about diverged history; got rc=$rc out='$out'"+ fi+ rm -rf "$d"+}++# Distinct from the diverged-history case above: this revision is not an+# object in the checkout AT ALL (a shallow clone, an unfetched ref, or a+# stray hand-edited annotation), so before the git cat-file -e existence+# check was added, BOTH --is-ancestor calls threw here exactly the same way+# they do for genuinely diverged history, and the resolver misreported this+# as "diverged history" even though there was no comparison to make -- the+# annotation just names a commit this checkout has never heard of.+assert_a_revision_absent_from_the_checkout_is_rejected_with_an_accurate_message() {local d; d="$(mktemp -d)"; make_repo "$d"make_stub "$d" "sha256:abc" "0000000000000000000000000000000000000000"- # Check for the ancestor guard's own wording, not just a nonzero exit: the- # bogus revision below is also an unresolvable git object, so if the- # ancestor check itself were removed, the very next step (the source-paths- # diff) would independently choke on that same bogus revision and exit- # nonzero too. A bare rc-only assertion can't tell "the ancestor guard- # fired" apart from "something downstream happened to crash instead."- local out+ local out rcout="$( cd "$d" && PATH="$d/bin:$PATH" node "$REPO_ROOT/scripts/release/resolve-release-images.mjs" \--image control-api --source-paths 'control-api/**' --tag-sha HEAD 2>&1 )" && rc=0 || rc=1- if [ "$rc" -ne 0 ] && grep -qi "ancestor" <<< "$out"; then- pass "a revision that is not an ancestor of the release is rejected"+ # "has no such commit" is this guard's own wording. "shares no ancestry" is+ # the OLD diverged-history die message's distinguishing phrase -- its+ # absence here proves this hit the new existence check, not the ancestor+ # comparison (the new message names "diverged history" too, but only to+ # contrast against it, so grepping for that phrase alone can't tell the two+ # guards apart).+ if [ "$rc" -ne 0 ] && grep -qi "has no such commit" <<< "$out" && ! grep -qi "shares no ancestry" <<< "$out"; then+ pass "a revision absent from the checkout is rejected with an accurate message, not misattributed as diverged history"else- fail "expected a named failure about the revision not being an ancestor; got rc=$rc out='$out'"+ fail "expected a named 'has no such commit' failure without the diverged-history guard's wording; got rc=$rc out='$out'"firm -rf "$d"}@@ -215,6 +254,7 @@ assert_every_defined_case_is_invoked() {assert_a_revision_that_is_an_ancestor_resolvesassert_a_non_ancestor_revision_is_rejected+assert_a_revision_absent_from_the_checkout_is_rejected_with_an_accurate_messageassert_a_descendant_revision_is_rejected_with_accurate_adviceassert_a_source_change_after_the_revision_is_rejectedassert_a_missing_revision_annotation_fails_loudly