Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(minikube): harden bootstrap and local image evidence

Alfredo Lopez516b5ead7aea
diff --git a/scripts/e2e/minimal-bootstrap-contract.sh b/scripts/e2e/minimal-bootstrap-contract.sh
new file mode 100644
index 000000000..ef8518563
--- /dev/null
+++ b/scripts/e2e/minimal-bootstrap-contract.sh
@@ -0,0 +1,14 @@
+#!/usr/bin/env bash
+# Shared, dependency-free contracts for the self-hosted minimal bootstrap.
+# Keep this file Bash 3.2-compatible: it is sourced by the macOS README path.
+
+clerum_canonical_email() {
+ printf '%s' "$1" | LC_ALL=C tr '[:upper:]' '[:lower:]'
+}
+
+clerum_initial_setup_link_is_active() {
+ [ "${1:-}" = "active" ] &&
+ [ "${2:-}" = "initial_setup" ] &&
+ [ -n "${3:-}" ] &&
+ [ "${4:-}" = "true" ]
+}
diff --git a/scripts/e2e/seed-e2e-data.sh b/scripts/e2e/seed-e2e-data.sh
index 8ec6f4c53..2be889589 100755
--- a/scripts/e2e/seed-e2e-data.sh
+++ b/scripts/e2e/seed-e2e-data.sh
@@ -62,6 +62,8 @@ source "${SCRIPT_DIR}/load-dotenv.sh"
dotenv_load_canonical_root "${REPO_ROOT}"
# shellcheck source=scripts/e2e/admin-credentials.sh
source "${SCRIPT_DIR}/admin-credentials.sh"
+# shellcheck source=scripts/e2e/minimal-bootstrap-contract.sh
+source "${SCRIPT_DIR}/minimal-bootstrap-contract.sh"
# ─── Config (all overridable) ──────────────────────────────────────────
CONTEXT="${CONTEXT:-$(kubectl config current-context)}"
@@ -107,8 +109,13 @@ if [ -z "${ADMIN_EMAIL:-}" ]; then
ADMIN_EMAIL="[email protected]"
fi
fi
-if [ "$SEED_PROFILE" = "minimal" ] && [ -z "${E2E_DEV_LOGIN_EMAIL:-}" ]; then
- DEV_EMAIL="$ADMIN_EMAIL"
+if [ "$SEED_PROFILE" = "minimal" ]; then
+ ADMIN_EMAIL="$(clerum_canonical_email "$ADMIN_EMAIL")"
+ DEV_EMAIL="$(clerum_canonical_email "$DEV_EMAIL")"
+ if [ "$DEV_EMAIL" != "$ADMIN_EMAIL" ]; then
+ printf '%s\n' " ERROR — SEED_PROFILE=minimal requires the Desktop identity email (${DEV_EMAIL}) to equal the bootstrap admin email (${ADMIN_EMAIL}); refusing to create an unlinked ordinary member" >&2
+ exit 1
+ fi
if [ -z "${E2E_DEV_LOGIN_NAME:-}" ]; then
DEV_NAME="admin"
fi
@@ -508,22 +515,26 @@ perform_initial_setup() {
}
verify_minimal_operator_bootstrap() {
- local admin_count status source desktop_user_id
+ local admin_count admin_id status source desktop_user_id link_admin_id
ADMIN_GET_BODY=""
admin_get "$CAPI_BASE/admin/control-admins" "GET /admin/control-admins"
- admin_count="$(echo "$ADMIN_GET_BODY" | jq -r --arg username "$ADMIN_USERNAME" --arg email "${ADMIN_EMAIL,,}" \
+ admin_count="$(echo "$ADMIN_GET_BODY" | jq -r --arg username "$ADMIN_USERNAME" --arg email "$ADMIN_EMAIL" \
'[.admins[]? | select(.username == $username and ((.email // "") | ascii_downcase) == $email)] | length')"
if [ "$admin_count" != "1" ]; then
die "Minimal bootstrap did not produce exactly one admin '$ADMIN_USERNAME' with email '$ADMIN_EMAIL'"
fi
- status="$(echo "$ADMIN_GET_BODY" | jq -r --arg username "$ADMIN_USERNAME" --arg email "${ADMIN_EMAIL,,}" \
+ admin_id="$(echo "$ADMIN_GET_BODY" | jq -r --arg username "$ADMIN_USERNAME" --arg email "$ADMIN_EMAIL" \
+ '.admins[] | select(.username == $username and ((.email // "") | ascii_downcase) == $email) | .id // empty')"
+ status="$(echo "$ADMIN_GET_BODY" | jq -r --arg username "$ADMIN_USERNAME" --arg email "$ADMIN_EMAIL" \
'.admins[] | select(.username == $username and ((.email // "") | ascii_downcase) == $email) | .gfsOperatorLink.status // "missing"')"
- source="$(echo "$ADMIN_GET_BODY" | jq -r --arg username "$ADMIN_USERNAME" --arg email "${ADMIN_EMAIL,,}" \
+ source="$(echo "$ADMIN_GET_BODY" | jq -r --arg username "$ADMIN_USERNAME" --arg email "$ADMIN_EMAIL" \
'.admins[] | select(.username == $username and ((.email // "") | ascii_downcase) == $email) | .gfsOperatorLink.source // "missing"')"
- desktop_user_id="$(echo "$ADMIN_GET_BODY" | jq -r --arg username "$ADMIN_USERNAME" --arg email "${ADMIN_EMAIL,,}" \
+ desktop_user_id="$(echo "$ADMIN_GET_BODY" | jq -r --arg username "$ADMIN_USERNAME" --arg email "$ADMIN_EMAIL" \
'.admins[] | select(.username == $username and ((.email // "") | ascii_downcase) == $email) | .gfsOperatorLink.desktopUserId // empty')"
- if [ "$status" != "active" ] || [ "$source" != "initial_setup" ] || [ -z "$desktop_user_id" ]; then
- die "Minimal bootstrap is incomplete: expected one active initial_setup Desktop link for '$ADMIN_EMAIL' (status=$status source=$source desktopUserId=${desktop_user_id:-missing}); refusing ordinary-user fallback"
+ link_admin_id="$(echo "$ADMIN_GET_BODY" | jq -r --arg username "$ADMIN_USERNAME" --arg email "$ADMIN_EMAIL" \
+ '.admins[] | select(.username == $username and ((.email // "") | ascii_downcase) == $email) | .gfsOperatorLink.controlAdminId // empty')"
+ if ! clerum_initial_setup_link_is_active "$status" "$source" "$desktop_user_id" "$([ "$link_admin_id" = "$admin_id" ] && printf true || printf false)"; then
+ die "Minimal bootstrap is incomplete: expected one active initial_setup Desktop link for '$ADMIN_EMAIL' (status=$status source=$source desktopUserId=${desktop_user_id:-missing} controlAdminId=${link_admin_id:-missing}); refusing ordinary-user fallback"
fi
ok "Initial admin '$ADMIN_USERNAME' has active initial_setup Desktop operator link (desktopUserId=${desktop_user_id:0:8}…)"
}
@@ -644,6 +655,7 @@ ensure_seed_user_and_team() {
local email="$1"
local name="$2"
local team_name="${name} team"
+ email="$(clerum_canonical_email "$email")"
ADMIN_GET_BODY=""
admin_get "$CAPI_BASE/admin/users?$(jq -rn --arg q "$email" '$q|@uri' | sed 's/^/q=/')" \
diff --git a/scripts/minikube/full-setup.sh b/scripts/minikube/full-setup.sh
index 1713c40a2..858526e4a 100755
--- a/scripts/minikube/full-setup.sh
+++ b/scripts/minikube/full-setup.sh
@@ -40,6 +40,8 @@ PROJECT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)"
source "${PROJECT_DIR}/scripts/e2e/load-dotenv.sh"
# shellcheck source=scripts/e2e/admin-credentials.sh
source "${PROJECT_DIR}/scripts/e2e/admin-credentials.sh"
+# shellcheck source=scripts/e2e/minimal-bootstrap-contract.sh
+source "${PROJECT_DIR}/scripts/e2e/minimal-bootstrap-contract.sh"
# ── Color helpers ──────────────────────────────────────────────────────
RED='\033[0;31m'
@@ -1429,7 +1431,7 @@ else
# second ordinary member/team. `[email protected]` would leak the internal
# code name onto a product surface (the Desktop member list) — evenfire
# branding belongs here (docs/concepts/code-names.md).
- : "${ADMIN_EMAIL:[email protected]}"
+ ADMIN_EMAIL="$(clerum_canonical_email "${ADMIN_EMAIL:[email protected]}")"
SEED_USER_DEFAULT_EMAIL="$ADMIN_EMAIL"
SEED_USER_DEFAULT_NAME="admin"
fi
@@ -1438,12 +1440,12 @@ else
# process/.env E2E override silently mint a second ordinary Desktop user;
# only the explicitly named seed override is considered, and the guard
# below still requires it to equal ADMIN_EMAIL.
- SEED_USER_EMAIL="${CLERUM_SEED_USER_EMAIL:-${SEED_USER_DEFAULT_EMAIL}}"
+ SEED_USER_EMAIL="$(clerum_canonical_email "${CLERUM_SEED_USER_EMAIL:-${SEED_USER_DEFAULT_EMAIL}}")"
else
SEED_USER_EMAIL="${CLERUM_SEED_USER_EMAIL:-${CLERUM_TEST_USER_EMAIL:-${E2E_DEV_LOGIN_EMAIL:-${SEED_USER_DEFAULT_EMAIL}}}}"
fi
SEED_USER_NAME="${E2E_DEV_LOGIN_NAME:-${SEED_USER_DEFAULT_NAME}}"
- if [ "$SEED_PROFILE" = "minimal" ] && [ "${SEED_USER_EMAIL,,}" != "${ADMIN_EMAIL,,}" ]; then
+ if [ "$SEED_PROFILE" = "minimal" ] && [ "$SEED_USER_EMAIL" != "$ADMIN_EMAIL" ]; then
err "SEED_PROFILE=minimal requires the Desktop identity email (${SEED_USER_EMAIL}) to equal the bootstrap admin email (${ADMIN_EMAIL}); refusing to create an unlinked ordinary member"
exit 1
fi
diff --git a/scripts/minikube/t2-common.sh b/scripts/minikube/t2-common.sh
index 6a4bda636..ab21e64cf 100755
--- a/scripts/minikube/t2-common.sh
+++ b/scripts/minikube/t2-common.sh
@@ -324,13 +324,21 @@ source = payload.get("imageSource") or payload.get("source") or payload.get("mod
tag = payload.get("imageTag") or payload.get("tag") or ""
# Local builds are identified by the per-image digests in the manifest and
# intentionally have no registry tag. GHCR manifests still require a tag.
+images = payload.get("images")
if source not in {"local", "ghcr"} or (source == "ghcr" and not tag):
raise SystemExit("missing")
+if source == "local":
+ import re
+ if not isinstance(images, dict) or not images:
+ raise SystemExit("local-images")
+ digest = re.compile(r"^sha256:[0-9a-fA-F]{32,64}$")
+ if any(not isinstance(name, str) or not name or not isinstance(value, str) or not digest.fullmatch(value) for name, value in images.items()):
+ raise SystemExit("local-digests")
print(source + "\t" + tag)
PY
)"; then
T2_NEXT_COMMAND="MINIKUBE_PROFILE=$T2_PROFILE make minikube-setup-local"
- t2_fail IMAGE_MANIFEST_MISMATCH 'image manifest is invalid or has no source/tag'
+ t2_fail IMAGE_MANIFEST_MISMATCH 'image manifest is invalid or incomplete for its image source'
fi
local manifest_source manifest_tag
IFS=$'\t' read -r manifest_source manifest_tag <<< "$manifest_values"
diff --git a/scripts/tests/test-minikube-full-setup.sh b/scripts/tests/test-minikube-full-setup.sh
index 9133b0130..418f1e5c4 100755
--- a/scripts/tests/test-minikube-full-setup.sh
+++ b/scripts/tests/test-minikube-full-setup.sh
@@ -525,6 +525,7 @@ assert_minimal_seed_is_setup_first_and_link_fail_closed() {
if printf '%s\n' "$minimal_block" | grep -Fq 'perform_initial_setup' && \
printf '%s\n' "$minimal_block" | grep -Fq 'login_admin_only' && \
printf '%s\n' "$minimal_block" | grep -Fq 'verify_minimal_operator_bootstrap' && \
+ grep -Fq 'clerum_initial_setup_link_is_active' "$seed" && \
grep -Fq 'refusing ordinary-user fallback' "$seed"; then
pass "minimal seed consumes setup before login and fails closed without an active initial_setup link"
else
@@ -532,6 +533,44 @@ assert_minimal_seed_is_setup_first_and_link_fail_closed() {
fi
}
+assert_minimal_bootstrap_contract_runs_on_system_bash() {
+ local contract="$REPO_ROOT/scripts/e2e/minimal-bootstrap-contract.sh"
+ local output
+ if ! /bin/bash -n "$contract" "$REPO_ROOT/scripts/e2e/seed-e2e-data.sh" "$REPO_ROOT/scripts/minikube/full-setup.sh"; then
+ fail "minimal bootstrap scripts are not parseable by the system Bash"
+ return
+ fi
+ output="$(/bin/bash -c '
+ set -e
+ source "$1"
+ [ "$(clerum_canonical_email "[email protected]")" = "[email protected]" ]
+ clerum_initial_setup_link_is_active active initial_setup desktop-id true
+ ! clerum_initial_setup_link_is_active revoked initial_setup desktop-id true
+ ! clerum_initial_setup_link_is_active active revoked desktop-id true
+ ! clerum_initial_setup_link_is_active active initial_setup "" true
+ printf ok
+ ' bash "$contract")"
+ if [ "$output" = "ok" ] && \
+ ! grep -Eq '\$\{[A-Za-z_][A-Za-z0-9_]*,,\}' "$REPO_ROOT/scripts/e2e/seed-e2e-data.sh" "$REPO_ROOT/scripts/minikube/full-setup.sh"; then
+ pass "minimal bootstrap canonicalization and link contract run on system Bash 3.2"
+ else
+ fail "minimal bootstrap still contains a Bash-4 lowercase expansion or contract failure"
+ fi
+}
+
+assert_minimal_seed_rejects_a_divergent_identity() {
+ local seed="$REPO_ROOT/scripts/e2e/seed-e2e-data.sh"
+ local output rc=0
+ output="$(CONTEXT=clerum-test SEED_PROFILE=minimal \
+ ADMIN_EMAIL='[email protected]' E2E_DEV_LOGIN_EMAIL='[email protected]' \
+ ADMIN_PASSWORD='test-password-only' /bin/bash "$seed" 2>&1)" || rc=$?
+ if [ "$rc" -ne 0 ] && grep -Fq 'requires the Desktop identity email' <<<"$output"; then
+ pass "minimal seeder rejects a Desktop identity that differs from the bootstrap admin"
+ else
+ fail "minimal seeder accepted a divergent Desktop identity (rc=$rc output=$output)"
+ fi
+}
+
assert_minimal_setup_requires_admin_identity_email() {
if grep -Fq 'SEED_PROFILE=minimal requires the Desktop identity email' \
"$REPO_ROOT/scripts/minikube/full-setup.sh" && \
@@ -1137,6 +1176,8 @@ assert_bootstrap_seed_deferral_flag_resolves_for_local_minimal
assert_bootstrap_seed_deferral_rejects_non_local_or_e2e_modes
assert_minimal_seed_is_setup_first_and_link_fail_closed
assert_minimal_setup_requires_admin_identity_email
+assert_minimal_bootstrap_contract_runs_on_system_bash
+assert_minimal_seed_rejects_a_divergent_identity
assert_an_unknown_image_source_is_a_hard_error
assert_ghcr_mode_moves_only_the_render_dir
assert_ghcr_mode_with_skip_uis_renders_the_no_uis_ghcr_overlay
diff --git a/scripts/tests/test-minikube-t2-scenarios.sh b/scripts/tests/test-minikube-t2-scenarios.sh
index fc823d8d1..304c05d08 100755
--- a/scripts/tests/test-minikube-t2-scenarios.sh
+++ b/scripts/tests/test-minikube-t2-scenarios.sh
@@ -143,10 +143,22 @@ expect_code IMAGE_MANIFEST_MISMATCH stale-image stale-image \
bash -c 'source "$1"; T2_IMAGE_SOURCE=local; T2_IMAGE_TAG=old; t2_image_check' bash "$COMMON"
local_manifest="$tmp/local-image-manifest.json"
-printf '{"imageSource":"local","imageTag":"","images":{"clerum/control-api:test":"sha256:local"}}\n' >"$local_manifest"
+printf '{"imageSource":"local","imageTag":"","images":{"clerum/control-api:test":"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"}}\n' >"$local_manifest"
env "${repo_env[@]}" T2_IMAGE_MANIFEST="$local_manifest" T2_IMAGE_SOURCE=local T2_IMAGE_TAG= \
bash -c 'source "$1"; T2_IMAGE_SOURCE=local; T2_IMAGE_TAG=""; t2_image_check' bash "$COMMON"
+empty_local_manifest="$tmp/empty-local-image-manifest.json"
+printf '{"imageSource":"local","imageTag":"","images":{}}\n' >"$empty_local_manifest"
+expect_code IMAGE_MANIFEST_MISMATCH empty-local empty-local \
+ env "${repo_env[@]}" T2_IMAGE_MANIFEST="$empty_local_manifest" T2_IMAGE_SOURCE=local T2_IMAGE_TAG= \
+ bash -c 'source "$1"; T2_IMAGE_SOURCE=local; T2_IMAGE_TAG=""; t2_image_check' bash "$COMMON"
+
+not_built_local_manifest="$tmp/not-built-local-image-manifest.json"
+printf '{"imageSource":"local","imageTag":"","images":{"clerum/control-api:test":"NOT_BUILT"}}\n' >"$not_built_local_manifest"
+expect_code IMAGE_MANIFEST_MISMATCH not-built-local not-built-local \
+ env "${repo_env[@]}" T2_IMAGE_MANIFEST="$not_built_local_manifest" T2_IMAGE_SOURCE=local T2_IMAGE_TAG= \
+ bash -c 'source "$1"; T2_IMAGE_SOURCE=local; T2_IMAGE_TAG=""; t2_image_check' bash "$COMMON"
+
ghcr_manifest="$tmp/ghcr-image-manifest.json"
printf '{"imageSource":"ghcr","imageTag":""}\n' >"$ghcr_manifest"
expect_code IMAGE_MANIFEST_MISMATCH tagless-ghcr tagless-ghcr \