Skip to content

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

TypeScript

fix(minikube): apply PR 367 review corrections

Alfredo Lopez6359a8efe6a0
diff --git a/docs/testing/minikube-t2-runbook.md b/docs/testing/minikube-t2-runbook.md
index 0278edc82..bc5105b46 100644
--- a/docs/testing/minikube-t2-runbook.md
+++ b/docs/testing/minikube-t2-runbook.md
@@ -10,7 +10,8 @@ The contract is local-development-only. It requires a clean development
branch descended from the current `origin/dev`, a generated profile owned by
that worktree and `HEAD`, and an explicit Kubernetes context for that profile.
It refuses protected branches, production/GKE/Cloudflare contexts, shared
-profiles, and ambiguous ownership.
+profiles, ambiguous ownership, and Kubernetes contexts whose cluster endpoint
+does not resolve to a local Minikube address.
Run the read-only preflight first:
@@ -117,5 +118,9 @@ raw logs. Run the public-boundary contract before committing:
make minikube-t2-public-boundary
```
+The boundary check fails if its base ref cannot be resolved, scans committed,
+staged, working-tree, and non-ignored untracked files, and rejects credentialed
+or private PostgreSQL URLs as well as other sensitive runtime artifacts.
+
If ownership, scope, or redaction cannot be proved, stop and preserve the
reported code; do not widen the command to another cluster.
diff --git a/scripts/e2e/minikube-real-postgres.sh b/scripts/e2e/minikube-real-postgres.sh
index 169d1c5df..2772aa628 100755
--- a/scripts/e2e/minikube-real-postgres.sh
+++ b/scripts/e2e/minikube-real-postgres.sh
@@ -21,6 +21,7 @@ ADMIN_DSN=""
PG_USER=""
PG_PASSWORD=""
PG_DATABASE=""
+T1_REDACT_PASSWORD=""
T1_STATUS=NOT_RUN
T1_NEXT_COMMAND='repair the first reported Real PostgreSQL precondition, then re-run T1'
T1_TOTAL_TESTS=0
@@ -102,7 +103,7 @@ PY
sanitize_file() {
local file="$1"
[ -f "$file" ] || return 0
- T1_REDACT_PASSWORD="$PG_PASSWORD" python3 - "$file" <<'PY'
+ T1_REDACT_PASSWORD="${T1_REDACT_PASSWORD:-${PG_PASSWORD:-}}" python3 - "$file" <<'PY'
from pathlib import Path
import os
import re
@@ -139,7 +140,7 @@ run_suite() {
cat "$log_file" >&2 || true
cat "$json_file" >&2 || true
T1_NEXT_COMMAND='repair the first failing Real PostgreSQL suite, then re-run T1 on the same HEAD'
- die_t1 FAIL "Real PostgreSQL suite failed in $package"
+ die_t1 REAL_PG_SUITE_FAILED "Real PostgreSQL suite failed in $package"
fi
sanitize_file "$log_file"
sanitize_file "$json_file"
@@ -168,7 +169,7 @@ PY
T1_PENDING_TESTS=$((T1_PENDING_TESTS + pending_tests))
if [ "$success" -ne 1 ] || [ "$passed_files" -ne "$expected" ] || [ "$failed_tests" -ne 0 ]; then
T1_NEXT_COMMAND='repair the failed or incomplete Real PostgreSQL lane, then re-run T1'
- die_t1 FAIL "Real PostgreSQL reporter did not pass every suite in $package"
+ die_t1 REAL_PG_SUITE_FAILED "Real PostgreSQL reporter did not pass every suite in $package"
fi
if [ "$total_tests" -le 0 ] || [ "$passed_tests" -le 0 ] || [ "$pending_files" -ne 0 ] || [ "$pending_tests" -ne 0 ]; then
T1_NEXT_COMMAND='repair the test selection or database route; a T1 run cannot silently skip suites'
@@ -212,6 +213,7 @@ main() {
T1_NEXT_COMMAND="MINIKUBE_PROFILE=$T2_PROFILE make minikube-setup-local"
die_t1 REAL_PG_REQUIRED_BUT_UNAVAILABLE 'control-postgres Secret is incomplete'
fi
+ T1_REDACT_PASSWORD="$PG_PASSWORD"
LOCAL_PORT="$(choose_local_port)"
t2_kc -n "$PG_NAMESPACE" port-forward --address=127.0.0.1 svc/"$PG_SERVICE" "$LOCAL_PORT:5432" \
@@ -223,6 +225,12 @@ main() {
T1_NEXT_COMMAND='repair the profile-owned port-forward and re-run T1'
die_t1 REAL_PG_REQUIRED_BUT_UNAVAILABLE 'control-postgres port-forward did not become reachable'
fi
+ if ! kill -0 "$PORT_FORWARD_PID" >/dev/null 2>&1; then
+ sanitize_file "$T1_TMP_DIR/port-forward.log"
+ cat "$T1_TMP_DIR/port-forward.log" >&2 || true
+ T1_NEXT_COMMAND='repair the profile-owned port-forward and re-run T1'
+ die_t1 REAL_PG_REQUIRED_BUT_UNAVAILABLE 'control-postgres port-forward exited before the T1 lane started'
+ fi
ADMIN_DSN="$(printf '%s\0%s\0%s' "$PG_USER" "$PG_PASSWORD" "$LOCAL_PORT" | python3 -c '
from urllib.parse import quote
@@ -230,9 +238,9 @@ import sys
user, password, port = sys.stdin.buffer.read().split(b"\0")[:3]
print("postgresql://" + quote(user.decode(), safe="") + ":" + quote(password.decode(), safe="") + "@127.0.0.1:" + port.decode() + "/postgres", end="")
')"
- unset PG_USER PG_PASSWORD PG_DATABASE
run_suite control-api
run_suite gfs-controller
+ unset PG_USER PG_PASSWORD PG_DATABASE T1_REDACT_PASSWORD
unset ADMIN_DSN
T1_STATUS=PASS
t2_evidence_write T1 PASS "Real PostgreSQL suites passed; tests=$T1_TOTAL_TESTS passed=$T1_PASSED_TESTS pending=$T1_PENDING_TESTS"
@@ -244,4 +252,6 @@ print("postgresql://" + quote(user.decode(), safe="") + ":" + quote(password.dec
printf '[minikube-t1] T1 PASS: Real PostgreSQL executed against the verified local profile\n'
}
-main "$@"
+if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
+ main "$@"
+fi
diff --git a/scripts/minikube/t2-common.sh b/scripts/minikube/t2-common.sh
index 69318ccbc..5c4b1bfc0 100755
--- a/scripts/minikube/t2-common.sh
+++ b/scripts/minikube/t2-common.sh
@@ -220,6 +220,23 @@ t2_context_check() {
T2_NEXT_COMMAND='select the explicit Kubernetes context generated with the profile'
t2_fail DEVELOPMENT_SCOPE_REQUIRED "Kubernetes context is unavailable: $T2_CONTEXT"
fi
+ local endpoint host
+ endpoint="$(t2_kc config view --raw --minify -o jsonpath='{.clusters[0].cluster.server}' 2>/dev/null || true)"
+ if [ -z "$endpoint" ]; then
+ T2_NEXT_COMMAND='select a Kubernetes context with a resolvable local cluster endpoint'
+ t2_fail DEVELOPMENT_SCOPE_REQUIRED "Kubernetes context endpoint is unavailable: $T2_CONTEXT"
+ fi
+ host="${endpoint#*://}"
+ host="${host%%/*}"
+ host="${host%%:*}"
+ host="$(printf '%s' "$host" | tr '[:upper:]' '[:lower:]')"
+ case "$host" in
+ 127.0.0.1|192.168.*|*.minikube) ;;
+ *)
+ T2_NEXT_COMMAND='select the generated branch-owned Minikube context, not a remote cluster context'
+ t2_fail DEVELOPMENT_SCOPE_REQUIRED "Kubernetes context endpoint is not local: $host"
+ ;;
+ esac
}
t2_profile_status() {
@@ -513,6 +530,10 @@ t2_lock_acquire() {
if ! mkdir "$T2_LOCK_DIR" 2>/dev/null; then
local existing_pid
existing_pid="$(sed -n 's/^PID=//p' "$T2_LOCK_DIR/owner.env" 2>/dev/null | head -1 || true)"
+ if [[ ! "$existing_pid" =~ ^[0-9]+$ ]]; then
+ T2_NEXT_COMMAND='inspect the profile lock owner metadata and retry only after the lock is released'
+ t2_fail PROFILE_BUSY "profile $T2_PROFILE has a lock without a valid owner PID"
+ fi
if [ -n "$existing_pid" ] && kill -0 "$existing_pid" >/dev/null 2>&1; then
T2_NEXT_COMMAND="wait for PID $existing_pid to finish, then retry the same profile"
t2_fail PROFILE_BUSY "profile $T2_PROFILE is locked by PID $existing_pid"
diff --git a/scripts/tests/test-minikube-t2-contract.sh b/scripts/tests/test-minikube-t2-contract.sh
index 187a6864e..f6e1ae32d 100755
--- a/scripts/tests/test-minikube-t2-contract.sh
+++ b/scripts/tests/test-minikube-t2-contract.sh
@@ -20,7 +20,7 @@ for file in "$COMMON" "$PREFLIGHT" "$T2" "$T1" \
bash -n "$file"
done
-required_codes="DEVELOPMENT_SCOPE_REQUIRED PROFILE_OWNERSHIP_MISMATCH PROFILE_BUSY HEAD_MARKER_MISMATCH IMAGE_MANIFEST_MISMATCH BOOTSTRAP_REQUIRED SECRET_MISSING CONFIGMAP_MISSING POSTGRES_NOT_READY REAL_PG_REQUIRED_BUT_UNAVAILABLE ZERO_TESTS_EXECUTED PORT_FORWARD_CONFLICT"
+required_codes="DEVELOPMENT_SCOPE_REQUIRED PROFILE_OWNERSHIP_MISMATCH PROFILE_BUSY HEAD_MARKER_MISMATCH IMAGE_MANIFEST_MISMATCH BOOTSTRAP_REQUIRED SECRET_MISSING CONFIGMAP_MISSING POSTGRES_NOT_READY REAL_PG_REQUIRED_BUT_UNAVAILABLE REAL_PG_SUITE_FAILED ZERO_TESTS_EXECUTED PORT_FORWARD_CONFLICT"
for code in $required_codes; do
grep -Fq "$code" "$COMMON" "$PREFLIGHT" "$T2" "$T1"
done
@@ -29,6 +29,7 @@ grep -Fq 'kubectl --context=' "$COMMON"
grep -Fq 'CONTROL_API_REAL_PG_CONTEXT' "$T1"
grep -Fq 'CONTROL_API_REAL_PG_ADMIN_URL=' "$T1"
grep -Fq 'CONTROL_API_REAL_PG_REQUIRED=1' "$T1"
+grep -Fq 'T1_REDACT_PASSWORD="${PG_PASSWORD}"' "$T1" || grep -Fq 'T1_REDACT_PASSWORD="$PG_PASSWORD"' "$T1"
grep -Fq -- '--reporter=json' "$T1"
grep -Fq 'pending_tests' "$T1"
grep -Fq 'numTotalTests' "$T1"
@@ -66,16 +67,20 @@ if grep -Eq 'get secret .* -o (yaml|json)' "$COMMON" "$PREFLIGHT"; then
fi
grep -Fq 'clusterFingerprintRef' "$COMMON"
grep -Fq 'imageManifestRef' "$COMMON"
+grep -Fq 'cluster.server' "$COMMON"
+grep -Fq 'PUBLIC_BOUNDARY_BASE_UNRESOLVED' "$ROOT/scripts/tests/test-minikube-t2-public-boundary.sh"
if grep -Fq 'ADMIN_DSN=' "$COMMON" "$PREFLIGHT"; then
echo 'FAIL: preflight contains an admin DSN' >&2
exit 1
fi
tmp="$(mktemp -d "$TMP_ROOT/evenfire-t2-contract.XXXXXX")"
-cleanup() { rm -rf "$tmp"; }
+cleanup() {
+ rm -rf "$tmp"
+}
trap cleanup EXIT
T2_LOCK_ROOT="$tmp/locks" MINIKUBE_PROFILE=clerum-test-contract T2_CONTEXT=clerum-test-contract \
-T2_PROJECT_DIR="$ROOT" T2_BRANCH=codex/test T2_HEAD=0123456789abcdef \
+T2_PROJECT_DIR="$ROOT" T2_BRANCH=test/minikube-contract T2_HEAD=0123456789abcdef \
T2_ORIGIN_DEV=0123456789abcdef T2_MERGE_BASE=0123456789abcdef \
bash -c '
source "$1"
@@ -94,7 +99,7 @@ PROFILE=busy-profile
PID=$$
EOF
if T2_LOCK_ROOT="$tmp/locks" MINIKUBE_PROFILE=busy-profile T2_CONTEXT=busy-profile \
- T2_PROJECT_DIR="$ROOT" T2_BRANCH=codex/test T2_HEAD=0123456789abcdef \
+ T2_PROJECT_DIR="$ROOT" T2_BRANCH=test/minikube-contract T2_HEAD=0123456789abcdef \
T2_ORIGIN_DEV=0123456789abcdef T2_MERGE_BASE=0123456789abcdef \
bash -c 'source "$1"; t2_lock_acquire' bash "$COMMON" 2>"$tmp/busy.err"; then
echo 'FAIL: live profile owner was replaced' >&2
@@ -102,7 +107,50 @@ if T2_LOCK_ROOT="$tmp/locks" MINIKUBE_PROFILE=busy-profile T2_CONTEXT=busy-profi
fi
grep -Fq 'PROFILE_BUSY' "$tmp/busy.err"
+mkdir -p "$tmp/locks/empty-profile.lock"
+if T2_LOCK_ROOT="$tmp/locks" MINIKUBE_PROFILE=empty-profile T2_CONTEXT=empty-profile \
+ T2_PROJECT_DIR="$ROOT" T2_BRANCH=test/minikube-contract T2_HEAD=0123456789abcdef \
+ T2_ORIGIN_DEV=0123456789abcdef T2_MERGE_BASE=0123456789abcdef \
+ bash -c 'source "$1"; t2_lock_acquire' bash "$COMMON" 2>"$tmp/empty.err"; then
+ echo 'FAIL: an ownerless profile lock was reclaimed' >&2
+ exit 1
+fi
+grep -Fq 'PROFILE_BUSY' "$tmp/empty.err"
+
+redaction_file="$tmp/t1-redaction.log"
+redaction_secret='super-secret'
+printf '%s=%s\n' password "$redaction_secret" >"$redaction_file"
+env T2_PROJECT_DIR="$ROOT" bash -c \
+ 'source "$1"; T1_REDACT_PASSWORD="$3"; PG_PASSWORD="$3"; unset PG_PASSWORD; sanitize_file "$2"' \
+ bash "$T1" "$redaction_file" "$redaction_secret"
+grep -Fq '<password-redacted>' "$redaction_file"
+if grep -Fq "$redaction_secret" "$redaction_file"; then
+ echo 'FAIL: T1 redaction lost the password after PG_PASSWORD cleanup' >&2
+ exit 1
+fi
+
bash "$ROOT/scripts/tests/test-minikube-t2-public-boundary.sh"
+if T2_PUBLIC_BASE_REF=nonexistent-ref-for-contract \
+ bash "$ROOT/scripts/tests/test-minikube-t2-public-boundary.sh"; then
+ echo 'FAIL: public boundary accepted an unresolved base ref' >&2
+ exit 1
+fi
+
+public_repo="$tmp/public-repo"
+mkdir -p "$public_repo"
+git init -q -b dev "$public_repo"
+git -C "$public_repo" config user.email [email protected]
+git -C "$public_repo" config user.name boundary-test
+printf 'base\n' >"$public_repo/README.md"
+git -C "$public_repo" add README.md
+git -C "$public_repo" commit -q -m base
+public_base="$(git -C "$public_repo" rev-parse HEAD)"
+printf 'DATABASE_URL=%s://private-host:5432/db\n' postgresql >"$public_repo/runtime.txt"
+if T2_PUBLIC_ROOT="$public_repo" T2_PUBLIC_BASE_REF="$public_base" \
+ bash "$ROOT/scripts/tests/test-minikube-t2-public-boundary.sh"; then
+ echo 'FAIL: public boundary ignored a secret in an untracked file' >&2
+ exit 1
+fi
bash "$ROOT/scripts/tests/test-minikube-t2-scenarios.sh"
printf 'PASS: local Minikube T0/T1/T2 contract checks\n'
diff --git a/scripts/tests/test-minikube-t2-public-boundary.sh b/scripts/tests/test-minikube-t2-public-boundary.sh
index 6b4446a1c..8813e4a7d 100755
--- a/scripts/tests/test-minikube-t2-public-boundary.sh
+++ b/scripts/tests/test-minikube-t2-public-boundary.sh
@@ -4,7 +4,7 @@ set -euo pipefail
set +x
set +u
-ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd -P)"
+ROOT="${T2_PUBLIC_ROOT:-$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/../.." && pwd -P)}"
BASE="$T2_PUBLIC_BASE_REF"
if [ -z "$BASE" ]; then BASE=origin/dev; fi
TMP_ROOT="$TMPDIR"
@@ -14,12 +14,24 @@ tmp="$(mktemp "$TMP_ROOT/evenfire-public-boundary.XXXXXX")"
cleanup() { rm -f "$tmp"; }
trap cleanup EXIT
+if ! git -C "$ROOT" rev-parse --verify --quiet "$BASE^{commit}" >/dev/null 2>&1; then
+ printf 'PUBLIC_BOUNDARY_BASE_UNRESOLVED: %s\n' "$BASE" >&2
+ exit 1
+fi
+
{
- git -C "$ROOT" diff --no-color --unified=0 "$BASE...HEAD" 2>/dev/null || true
+ git -C "$ROOT" diff --no-color --unified=0 "$BASE...HEAD"
git -C "$ROOT" diff --no-color --unified=0
git -C "$ROOT" diff --cached --no-color --unified=0
} >"$tmp"
+git -C "$ROOT" ls-files --others --exclude-standard -z |
+while IFS= read -r -d '' path; do
+ [ -f "$ROOT/$path" ] || continue
+ printf '+++ b/%s\n' "$path"
+ sed 's/^/+/' "$ROOT/$path"
+done >>"$tmp"
+
python3 - "$tmp" <<'PY'
from pathlib import Path
import re
@@ -49,6 +61,7 @@ for line in diff.splitlines():
value = line[1:]
patterns = (
(r"postgres(?:ql)?://[^\s\"'<>:]+:[^\s\"'<>@]+@", "credentialed PostgreSQL URL"),
+ (r"(?i)postgres(?:ql)?://(?:[^\s\"'<>@]+@)?(?:localhost|127\.0\.0\.1|10\.[0-9.]+|192\.168\.[0-9.]+|172\.(?:1[6-9]|2[0-9]|3[01])\.[0-9.]+|[A-Za-z0-9.-]*(?:private|internal|local|cluster|postgres)[A-Za-z0-9.-]*)(?::[0-9]+)?(?:/|$)", "private PostgreSQL URL"),
(r"-----BEGIN (?:RSA |EC |OPENSSH )?PRIVATE KEY-----", "private key"),
(r"(?i)\bBearer\s+[A-Za-z0-9._~-]{24,}", "bearer token"),
(r"(?i)\b(?:api[_-]?key|password|secret|token|private[_-]?key)\s*[:=]\s*[\"']?(?![$<{`]|os\.environ|process\.env|secret_field|quote\()[^\s\"']{8,}", "credential assignment"),
diff --git a/scripts/tests/test-minikube-t2-scenarios.sh b/scripts/tests/test-minikube-t2-scenarios.sh
index 644290766..ae8497b6b 100755
--- a/scripts/tests/test-minikube-t2-scenarios.sh
+++ b/scripts/tests/test-minikube-t2-scenarios.sh
@@ -88,6 +88,23 @@ expect_code DEVELOPMENT_SCOPE_REQUIRED context-mismatch context-mismatch \
env "${repo_env[@]}" CONTROL_API_REAL_PG_CONTEXT=another-context \
bash -c 'source "$1"; t2_profile_scope' bash "$COMMON"
+fake_bin="$tmp/fake-bin"
+mkdir -p "$fake_bin"
+cat >"$fake_bin/kubectl" <<'EOF'
+#!/usr/bin/env bash
+case "$*" in
+ *"config current-context"*) exit 0 ;;
+ *"config view"*) printf '%s://%s:6443' https "${FAKE_ENDPOINT:-10.0.0.1}" ;;
+ *) exit 0 ;;
+esac
+EOF
+chmod +x "$fake_bin/kubectl"
+expect_code DEVELOPMENT_SCOPE_REQUIRED remote-context remote-context \
+ env "${repo_env[@]}" PATH="$fake_bin:$PATH" \
+ bash -c 'source "$1"; t2_context_check' bash "$COMMON"
+env "${repo_env[@]}" PATH="$fake_bin:$PATH" FAKE_ENDPOINT=127.0.0.1 \
+ bash -c 'source "$1"; t2_context_check' bash "$COMMON"
+
missing_profile_state="$(env "${repo_env[@]}" bash -c 'source "$1"; t2_mk(){ printf "%s" "Profile not found"; }; t2_profile_status; printf "%s" "$T2_PLAN_STATE"' bash "$COMMON")"
[ "$missing_profile_state" = full-bootstrap ] || fail "missing profile selected $missing_profile_state instead of full-bootstrap"