Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(minikube): fail closed on image evidence and dry-run detection
Alfredo Lopeze270c994ec4c
diff --git a/scripts/minikube/pull-images.sh b/scripts/minikube/pull-images.shindex 1aedb0ce2..9c8cb84c6 100755--- a/scripts/minikube/pull-images.sh+++ b/scripts/minikube/pull-images.sh@@ -116,6 +116,15 @@ ok() { echo -e "${GREEN} OK${NC} -- $*"; }warn() { echo -e "${YELLOW} WARN${NC} -- $*"; }err() { echo -e "${RED} ERROR${NC} -- $*" >&2; }+validate_manifest_image_id() {+ local image="$1" image_id="$2"+ if [[ -z "${image_id}" || "${image_id}" == "NOT_PULLED" ||+ ! "${image_id}" =~ ^sha256:[0-9a-fA-F]{64}$ ]]; then+ err "IMAGE_MANIFEST_INVALID: docker inspect returned an invalid image ID for ${image}"+ return 1+ fi+}+validate_pull_integer MINIKUBE_PULL_PARALLELISM "${PULL_PARALLELISM}" 1 64validate_pull_integer MINIKUBE_IMAGE_PULL_RETRIES "${MINIKUBE_IMAGE_PULL_RETRIES}" 1 10validate_pull_integer MINIKUBE_IMAGE_PULL_DELAY_SECS "${MINIKUBE_IMAGE_PULL_DELAY_SECS}" 0 300@@ -187,10 +196,15 @@ if [ "$SKIP_UIS" = true ]; thenfiSTATUS_DIR="$(mktemp -d)"+MANIFEST_FILE="${PROJECT_DIR}/deploy/minikube/.image-manifest.json"+MANIFEST_TMP_FILE=""cleanup() {local status=$? cleanup_status=0trap - EXIT INT TERMrm -rf -- "$STATUS_DIR" || cleanup_status=$?+ if [ -n "${MANIFEST_TMP_FILE}" ]; then+ rm -f -- "${MANIFEST_TMP_FILE}" || cleanup_status=$?+ fidocker_cli_env_cleanup || cleanup_status=$?if [ "$status" -eq 0 ] && [ "$cleanup_status" -ne 0 ]; thenstatus="$cleanup_status"@@ -393,8 +407,36 @@ fi# recorded mode it falls back to the IMAGE_SOURCE env default (ghcr), which is# how a locally built cluster came to be reported as "25 of 28 images missing".# This writer only ever pulls, so the value is always "ghcr".-MANIFEST_FILE="${PROJECT_DIR}/deploy/minikube/.image-manifest.json"+# Resolve and validate every digest before opening the existing manifest. A+# failed inspect is inventory failure, not evidence that an image was absent;+# publishing NOT_PULLED or an empty value would create green evidence for a+# run whose acquisition cannot be verified.+MANIFEST_GHCR_REFS=()+MANIFEST_LOCAL_REFS=()+MANIFEST_SHAS=()+for f in "${STATUS_DIR}"/*.done; do+ [ -e "$f" ] || continue+ ghcr_ref="$(cut -f1 "$f")"+ local_ref="$(cut -f2 "$f")"+ manifest_inspect_status=0+ sha="$(docker_cli_run_public "inspect-image" \+ "$MINIKUBE_DOCKER_INFO_TIMEOUT_SECONDS" \+ docker inspect --format='{{.Id}}' "$ghcr_ref")" || manifest_inspect_status=$?+ if [ "$manifest_inspect_status" -ne 0 ]; then+ err "Could not inspect ${ghcr_ref} while generating the image manifest"+ exit "$manifest_inspect_status"+ fi+ validate_manifest_image_id "$ghcr_ref" "$sha" || exit 1+ MANIFEST_GHCR_REFS+=("$ghcr_ref")+ MANIFEST_LOCAL_REFS+=("$local_ref")+ MANIFEST_SHAS+=("$sha")+done+mkdir -p "$(dirname "$MANIFEST_FILE")"+MANIFEST_TMP_FILE="$(mktemp "${MANIFEST_FILE}.tmp.XXXXXX")" || {+ err "IMAGE_MANIFEST_INVALID: could not create a temporary manifest beside ${MANIFEST_FILE}"+ exit 1+}{echo "{"echo " \"generated\": \"$(date -u +%Y-%m-%dT%H:%M:%SZ)\","@@ -403,14 +445,9 @@ mkdir -p "$(dirname "$MANIFEST_FILE")"echo " \"imageTag\": \"${IMAGE_TAG}\","echo " \"images\": {"first=true- for f in "${STATUS_DIR}"/*.done; do- [ -e "$f" ] || continue- ghcr_ref="$(cut -f1 "$f")"- local_ref="$(cut -f2 "$f")"- sha="$(docker_cli_run_public "inspect-image" \- "$MINIKUBE_DOCKER_INFO_TIMEOUT_SECONDS" \- docker inspect --format='{{.Id}}' "$ghcr_ref" 2>/dev/null || echo "NOT_PULLED")"- for ref in "$ghcr_ref" "$local_ref"; do+ for image_index in "${!MANIFEST_SHAS[@]}"; do+ sha="${MANIFEST_SHAS[$image_index]}"+ for ref in "${MANIFEST_GHCR_REFS[$image_index]}" "${MANIFEST_LOCAL_REFS[$image_index]}"; doif [ "$first" = true ]; then first=false; else echo ","; fiprintf ' "%s": "%s"' "$ref" "$sha"done@@ -418,7 +455,18 @@ mkdir -p "$(dirname "$MANIFEST_FILE")"echo ""echo " }"echo "}"-} > "$MANIFEST_FILE"+} > "$MANIFEST_TMP_FILE"++if ! node -e 'JSON.parse(require("node:fs").readFileSync(process.argv[1], "utf8"))' \+ "$MANIFEST_TMP_FILE"; then+ err "IMAGE_MANIFEST_INVALID: generated manifest is not valid JSON"+ exit 1+fi+if ! mv -- "$MANIFEST_TMP_FILE" "$MANIFEST_FILE"; then+ err "IMAGE_MANIFEST_INVALID: could not publish the validated manifest"+ exit 1+fi+MANIFEST_TMP_FILE=""ok "Manifest: deploy/minikube/.image-manifest.json"echo ""diff --git a/scripts/minikube/with-t2-mutation-lock.sh b/scripts/minikube/with-t2-mutation-lock.shindex 3287d1959..75504e155 100755--- a/scripts/minikube/with-t2-mutation-lock.sh+++ b/scripts/minikube/with-t2-mutation-lock.sh@@ -12,13 +12,27 @@ shift# GNU Make executes recipe lines containing $(MAKE) during `make -n` so the# recursive make can print its own plan. Never let that dry-run escape hatch-# enter a mutating wrapper. Match the actual dry-run flags rather than looking-# for the letter `n`, because normal recursive builds carry --no-print-directory.-for make_flag in ${MAKEFLAGS:-}; do- case "${make_flag}" in- -n|n|--just-print|--dry-run) exit 0 ;;- esac-done+# enter a mutating wrapper. GNU Make may compact short flags into tokens such+# as `ns` or `rns`; inspect only flag-shaped tokens so `--no-print-directory`+# and variable assignments containing the letter n are not false positives.+t2_makeflags_is_dry_run() {+ local make_flag short_flags+ for make_flag in ${MAKEFLAGS:-}; do+ case "${make_flag}" in+ -n|n|--just-print|--dry-run|--recon) return 0 ;;+ --*|*=*) continue ;;+ esac+ short_flags="${make_flag#-}"+ if [[ "${short_flags}" =~ ^[a-zA-Z]+$ ]] && [[ "${short_flags}" == *n* ]]; then+ return 0+ fi+ done+ return 1+}++if t2_makeflags_is_dry_run; then+ exit 0+fiROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd -P)"T2_PROJECT_DIR="${T2_PROJECT_DIR:-${ROOT}}"diff --git a/scripts/tests/test-minikube-mutation-boundary.sh b/scripts/tests/test-minikube-mutation-boundary.shindex 64a1c8839..5912d3165 100755--- a/scripts/tests/test-minikube-mutation-boundary.sh+++ b/scripts/tests/test-minikube-mutation-boundary.sh@@ -2,6 +2,7 @@set -euo pipefailROOT="$(cd "$(dirname "$0")/../.." && pwd -P)"+MUTATION_WRAPPER="${ROOT}/scripts/minikube/with-t2-mutation-lock.sh"TMP_DIR="$(mktemp -d)"source "${ROOT}/scripts/tests/lib/minikube-fixture-repo.sh"@@ -70,12 +71,70 @@ run_child() {return "${status}"}+assert_makeflags_dry_run_matrix() {+ local flags label output status sentinel lock_root profile_root+ local dry_flags='n --no-print-directory|ns --no-print-directory|kn --no-print-directory|rns --no-print-directory|--dry-run|--just-print|--recon'+ local non_dry_flags='--no-print-directory|NAME=contains-n'++ IFS='|' read -r -a dry_cases <<<"${dry_flags}"+ for flags in "${dry_cases[@]}"; do+ label="$(printf '%s' "${flags}" | tr ' =-' '_')"+ sentinel="${TMP_DIR}/${label}.sentinel"+ lock_root="${TMP_DIR}/${label}.locks"+ profile_root="${TMP_DIR}/${label}.profiles"+ mkdir -p "${lock_root}" "${profile_root}"+ output=""; status=0+ MAKEFLAGS="${flags}" T2_PROJECT_DIR="${MINIKUBE_TEST_PROJECT_DIR}" \+ T2_PROFILE="${PROFILE}" T2_CONTEXT="${PROFILE}" \+ MINIKUBE_PROFILE="${PROFILE}" CONTROL_API_REAL_PG_CONTEXT="${PROFILE}" \+ T2_PROFILE_ROOT="${profile_root}" T2_LOCK_ROOT="${lock_root}" \+ SENTINEL="${sentinel}" \+ bash "${MUTATION_WRAPPER}" -- bash -c 'printf invoked >"${SENTINEL}"' \+ >"${TMP_DIR}/${label}.out" 2>&1 || status=$?+ output="$(cat "${TMP_DIR}/${label}.out")"+ if [ "${status}" -ne 0 ] || [ -e "${sentinel}" ] \+ || [ -n "$(find "${lock_root}" -mindepth 1 -print -quit)" ] \+ || [ -n "$(find "${profile_root}" -mindepth 1 -print -quit)" ]; then+ printf 'FAIL: MAKEFLAGS=%s did not stop before mutation: rc=%s output=%s\n' \+ "${flags}" "${status}" "${output}" >&2+ exit 1+ fi+ done++ IFS='|' read -r -a non_dry_cases <<<"${non_dry_flags}"+ for flags in "${non_dry_cases[@]}"; do+ label="non-dry-$(printf '%s' "${flags}" | tr ' =-' '_')"+ sentinel="${TMP_DIR}/${label}.sentinel"+ lock_root="${TMP_DIR}/${label}.locks"+ profile_root="${TMP_DIR}/${label}.profiles"+ mkdir -p "${lock_root}" "${profile_root}"+ output=""; status=0+ MAKEFLAGS="${flags}" T2_PROJECT_DIR="${MINIKUBE_TEST_PROJECT_DIR}" \+ T2_PROFILE="${PROFILE}" T2_CONTEXT="${PROFILE}" \+ MINIKUBE_PROFILE="${PROFILE}" CONTROL_API_REAL_PG_CONTEXT="${PROFILE}" \+ T2_PROFILE_ROOT="${profile_root}" T2_LOCK_ROOT="${lock_root}" \+ SENTINEL="${sentinel}" \+ bash "${MUTATION_WRAPPER}" -- bash -c 'printf invoked >"${SENTINEL}"' \+ >"${TMP_DIR}/${label}.out" 2>&1 || status=$?+ output="$(cat "${TMP_DIR}/${label}.out")"+ if [ "${status}" -eq 0 ] || [ -e "${sentinel}" ]; then+ printf 'FAIL: MAKEFLAGS=%s was treated as a dry-run: rc=%s output=%s\n' \+ "${flags}" "${status}" "${output}" >&2+ exit 1+ fi+ done++ printf 'PASS: compact and long GNU Make dry-run flags stop the real wrapper before profile or lock mutation\n'+}+run_child[[ "$(wc -l <"${LOG}" | tr -d ' ')" -eq 1 ]] || {echo 'FAIL: valid inherited lease did not reach the child boundary' >&2exit 1}+assert_makeflags_dry_run_matrix+if T2_PROJECT_DIR="${MINIKUBE_TEST_PROJECT_DIR}" T2_PROFILE="${PROFILE}" T2_CONTEXT="${PROFILE}" \T2_LOCK_ROOT="${LOCK_ROOT}" T2_LOCK_TOKEN=wrong-token \bash "${ROOT}/scripts/minikube/require-t2-mutation-lock.sh" >/dev/null 2>&1; thendiff --git a/scripts/tests/test-minikube-pull-images.sh b/scripts/tests/test-minikube-pull-images.shindex 2820a0ce7..ab89fd94b 100755--- a/scripts/tests/test-minikube-pull-images.sh+++ b/scripts/tests/test-minikube-pull-images.sh@@ -71,7 +71,19 @@ case "${1:-}" in;;tag) exit 0 ;;images) echo "sha256:aaaaaaaaaaaa"; exit 0 ;;- inspect) echo "sha256:aaaaaaaaaaaabbbbbbbbbbbbcccccccccccc"; exit 0 ;;+ inspect)+ if [ "${TEST_INSPECT_FAIL:-false}" = true ]; then+ exit 1+ fi+ if [ "${TEST_INSPECT_HANG:-false}" = true ]; then+ while :; do sleep 60; done+ fi+ if [ "${TEST_INSPECT_EMPTY:-false}" = true ]; then+ exit 0+ fi+ echo "sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"+ exit 0+ ;;*) exit 0 ;;esacSTUB@@ -153,12 +165,16 @@ run_puller_prepared() {TEST_FLAKY_COUNTER_DIR="${TEST_FLAKY_COUNTER_DIR:-}" \TEST_EMPTY_DOCKER_ENV="${TEST_EMPTY_DOCKER_ENV:-}" \TEST_IMAGE_LOAD_ALIAS_FAIL="${TEST_IMAGE_LOAD_ALIAS_FAIL:-}" \+ TEST_INSPECT_FAIL="${TEST_INSPECT_FAIL:-}" \+ TEST_INSPECT_HANG="${TEST_INSPECT_HANG:-}" \+ TEST_INSPECT_EMPTY="${TEST_INSPECT_EMPTY:-}" \MINIKUBE_IMAGE_TAG="${MINIKUBE_IMAGE_TAG:-}" \MINIKUBE_IMAGE_PULL_RETRIES="${MINIKUBE_IMAGE_PULL_RETRIES:-}" \MINIKUBE_IMAGE_PULL_DELAY_SECS="${MINIKUBE_IMAGE_PULL_DELAY_SECS:-}" \MINIKUBE_PULL_PARALLELISM="${MINIKUBE_PULL_PARALLELISM:-}" \TEST_HANG_PULL="${TEST_HANG_PULL:-}" \MINIKUBE_DOCKER_PULL_TIMEOUT_SECONDS="${MINIKUBE_DOCKER_PULL_TIMEOUT_SECONDS:-}" \+ MINIKUBE_DOCKER_INFO_TIMEOUT_SECONDS="${MINIKUBE_DOCKER_INFO_TIMEOUT_SECONDS:-}" \MINIKUBE_DOCKER_BUILD_TIMEOUT_SECONDS="${MINIKUBE_DOCKER_BUILD_TIMEOUT_SECONDS:-}" \T2_PROJECT_DIR="$d/repo" \T2_PROFILE=clerum-test T2_CONTEXT=clerum-test \@@ -450,6 +466,104 @@ assert_minikube_image_tag_overrides_the_pin() {rm -rf "$d"}+# Manifest publication must be transactional. Mutation coverage: restoring the+# old `|| echo NOT_PULLED` fallback or writing directly to MANIFEST_FILE makes+# this case either return success or destroy the known-good manifest.+assert_manifest_inspect_failure_preserves_previous_manifest() {+ local d out rc before after+ d="$(mktemp -d)"+ make_stubs "$d"+ copy_repo "$d" "$(recorded_manifest ghcr previous-good-tag)"+ before="$(cat "$d/repo/deploy/minikube/.image-manifest.json")"+ export TEST_INSPECT_FAIL=true MINIKUBE_IMAGE_TAG=inspect-fail-tag+ export MINIKUBE_IMAGE_PULL_RETRIES=1 MINIKUBE_IMAGE_PULL_DELAY_SECS=0+ out="$(run_puller_prepared "$d" --only=control-api)"; rc=$?+ unset TEST_INSPECT_FAIL MINIKUBE_IMAGE_TAG MINIKUBE_IMAGE_PULL_RETRIES MINIKUBE_IMAGE_PULL_DELAY_SECS+ after="$(cat "$d/repo/deploy/minikube/.image-manifest.json")"+ if [ "$rc" -ne 0 ] \+ && [ "$after" = "$before" ] \+ && ! grep -Fq 'NOT_PULLED' <<<"$out" \+ && ! grep -Fq 'published image(s) pulled at' <<<"$out"; then+ pass "docker inspect failure preserves the previous manifest and fails closed"+ else+ fail "docker inspect failure published false evidence: rc=$rc unchanged=$([ "$after" = "$before" ] && echo yes || echo no) out=$out"+ fi+ rm -rf "$d"+}++# A deadline is an inspect failure too. Mutation coverage: removing the+# inspect deadline or turning its status into NOT_PULLED makes this case pass+# without the required HARNESS_DEADLINE evidence and manifest preservation.+assert_manifest_inspect_deadline_preserves_previous_manifest() {+ local d out rc before after+ d="$(mktemp -d)"+ make_stubs "$d"+ copy_repo "$d" "$(recorded_manifest ghcr previous-good-tag)"+ before="$(cat "$d/repo/deploy/minikube/.image-manifest.json")"+ export TEST_INSPECT_HANG=true MINIKUBE_IMAGE_TAG=inspect-hang-tag+ export MINIKUBE_IMAGE_PULL_RETRIES=1 MINIKUBE_IMAGE_PULL_DELAY_SECS=0+ export MINIKUBE_DOCKER_INFO_TIMEOUT_SECONDS=1+ out="$(run_puller_prepared "$d" --only=control-api)"; rc=$?+ unset TEST_INSPECT_HANG MINIKUBE_IMAGE_TAG MINIKUBE_IMAGE_PULL_RETRIES \+ MINIKUBE_IMAGE_PULL_DELAY_SECS MINIKUBE_DOCKER_INFO_TIMEOUT_SECONDS+ after="$(cat "$d/repo/deploy/minikube/.image-manifest.json")"+ if [ "$rc" -ne 0 ] \+ && grep -Eq 'HARNESS_DEADLINE.*inspect-image' <<<"$out" \+ && [ "$after" = "$before" ] \+ && ! grep -Fq 'published image(s) pulled at' <<<"$out"; then+ pass "docker inspect deadline preserves the previous manifest and fails closed"+ else+ fail "docker inspect deadline did not preserve the manifest: rc=$rc unchanged=$([ "$after" = "$before" ] && echo yes || echo no) out=$out"+ fi+ rm -rf "$d"+}++assert_empty_manifest_inspect_output_fails_closed() {+ local d out rc before after+ d="$(mktemp -d)"+ make_stubs "$d"+ copy_repo "$d" "$(recorded_manifest ghcr previous-good-tag)"+ before="$(cat "$d/repo/deploy/minikube/.image-manifest.json")"+ export TEST_INSPECT_EMPTY=true MINIKUBE_IMAGE_TAG=inspect-empty-tag+ export MINIKUBE_IMAGE_PULL_RETRIES=1 MINIKUBE_IMAGE_PULL_DELAY_SECS=0+ out="$(run_puller_prepared "$d" --only=control-api)"; rc=$?+ unset TEST_INSPECT_EMPTY MINIKUBE_IMAGE_TAG MINIKUBE_IMAGE_PULL_RETRIES MINIKUBE_IMAGE_PULL_DELAY_SECS+ after="$(cat "$d/repo/deploy/minikube/.image-manifest.json")"+ if [ "$rc" -ne 0 ] \+ && [ "$after" = "$before" ] \+ && ! grep -Fq 'published image(s) pulled at' <<<"$out"; then+ pass "empty docker inspect output is rejected without changing the manifest"+ else+ fail "empty docker inspect output was accepted: rc=$rc unchanged=$([ "$after" = "$before" ] && echo yes || echo no) out=$out"+ fi+ rm -rf "$d"+}++assert_successful_manifest_contains_valid_digests_and_aliases() {+ local d out rc manifest problems+ d="$(mktemp -d)"+ out="$(run_puller "$d" --only=control-api)"; rc=$?+ manifest="$d/repo/deploy/minikube/.image-manifest.json"+ problems="$(node -e '+ const fs = require("node:fs")+ const path = process.argv[1]+ const j = JSON.parse(fs.readFileSync(path, "utf8"))+ const entries = Object.entries(j.images || {})+ const bad = entries.filter(([, id]) => !/^sha256:[0-9a-f]{64}$/.test(id))+ const keys = entries.map(([ref]) => ref)+ if (bad.length) console.log("invalid image id")+ if (entries.some(([, id]) => id === "NOT_PULLED")) console.log("NOT_PULLED")+ if (!keys.includes("ghcr.io/evenfire-ai/control-api:manifest-success-tag")) console.log("missing ghcr ref")+ if (!keys.includes("clerum/control-api:test")) console.log("missing local alias")+ ' "$manifest" 2>&1)"+ if [ "$rc" -eq 0 ] && [ -z "$problems" ] && [ -f "$manifest" ]; then+ pass "successful manifest publication records valid digests and GHCR/local refs"+ else+ fail "successful manifest publication was invalid: rc=$rc problems=$problems out=$out"+ fi+ rm -rf "$d"+}+# full-setup.sh:608 uses this file as a `find -newer` marker and warns loudly# when it is absent. Writing it is what keeps the ghcr path from looking like# "images were never built".@@ -831,6 +945,10 @@ assert_it_aliases_each_image_to_its_local_refassert_the_alias_honours_local_tag_and_local_nameassert_a_missing_tag_names_the_tag_and_the_overrideassert_minikube_image_tag_overrides_the_pin+assert_manifest_inspect_failure_preserves_previous_manifest+assert_manifest_inspect_deadline_preserves_previous_manifest+assert_empty_manifest_inspect_output_fails_closed+MINIKUBE_IMAGE_TAG=manifest-success-tag assert_successful_manifest_contains_valid_digests_and_aliasesassert_it_writes_the_image_manifest_consumers_readassert_a_transient_pull_failure_is_retried_until_it_succeedsassert_a_permanently_failing_pull_stops_after_the_retry_bound