From 333b3efc1e69022b33e1632d3e30ddc86df6960e Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 17:41:51 +0000 Subject: [PATCH] fix(supabase-kong): fail fast on bad declarative config instead of crash-looping Add make kong-config-check: renders kong.yml in a throwaway supabase-kong container with the node's real env and runs 'kong config parse', naming the known faults (empty DASHBOARD_PASSWORD, new keys aliased to legacy JWTs). supa-start runs it before bringing Kong up (SKIP_KONG_CONFIG_CHECK=1 bypasses). Strip CRs from the vendored kong-entrypoint.sh before exec so a Windows checkout with core.autocrlf=true no longer kills Kong on '#!/bin/sh\r'. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016aNs4mvJxQr1QT3NqGDt3Q --- pmoves/Makefile | 7 ++ pmoves/docker-compose.core.yml | 9 +- pmoves/docker-compose.yml | 9 +- ...larative-config-boot-failure-2026-08-18.md | 21 +++++ pmoves/scripts/supabase/kong_config_check.sh | 89 +++++++++++++++++++ 5 files changed, 133 insertions(+), 2 deletions(-) create mode 100755 pmoves/scripts/supabase/kong_config_check.sh diff --git a/pmoves/Makefile b/pmoves/Makefile index 716b35b71c..b98e8ecf33 100644 --- a/pmoves/Makefile +++ b/pmoves/Makefile @@ -775,6 +775,10 @@ SUPABASE_DB_HELPER ?= scripts/supabase/find_db_container.sh up-supabase: ## Start Supabase using selected runtime (SUPABASE_RUNTIME=cli|kong|compose) @$(MAKE) --no-print-directory supa-start +.PHONY: kong-config-check +kong-config-check: ## Pre-boot: render + parse Kong's declarative config in a throwaway container (catches crash-loop causes) + @$(DC) --profile supabase-local run --rm --no-deps -T --entrypoint /bin/sh supabase-kong -s < scripts/supabase/kong_config_check.sh + .PHONY: kong-routes-check KONG_ADMIN_URL ?= http://localhost:8001 KONG_CONTAINER ?= pmoves-supabase-kong-1 @@ -882,6 +886,9 @@ supa-start: ensure-env-shared ## Start Supabase stack for selected runtime (cli -e KONG_PG_PASSWORD=$${POSTGRES_PASSWORD:-$${SUPABASE_DB_PASSWORD:-postgres}} \ kong/kong:3.9.1 sh -c "kong migrations bootstrap --yes 2>/dev/null || true; kong migrations up --yes 2>/dev/null || true" >/dev/null 2>&1 || true; \ $(MAKE) --no-print-directory supa-bootstrap-db; \ + if [ "$${SKIP_KONG_CONFIG_CHECK:-0}" != "1" ]; then \ + $(MAKE) --no-print-directory kong-config-check || { echo "❌ Kong would crash-loop with this config; fix the error above (or SKIP_KONG_CONFIG_CHECK=1 to bypass)."; exit 1; }; \ + fi; \ $(DC) --profile supabase-local up -d --force-recreate supabase-postgrest supabase-gotrue supabase-kong supabase-realtime supabase-storage supabase-studio supabase-imgproxy supabase-meta supabase-edge-functions supabase-analytics supabase-vector supabase-pooler; \ fi @$(MAKE) --no-print-directory supa-status diff --git a/pmoves/docker-compose.core.yml b/pmoves/docker-compose.core.yml index 5a68ad0590..a74875dec8 100644 --- a/pmoves/docker-compose.core.yml +++ b/pmoves/docker-compose.core.yml @@ -635,7 +635,14 @@ services: - PARENT_SYSTEM=${PARENT_SYSTEM:-PMOVES.AI} - PARENT_VERSION=${PARENT_VERSION:-1.0.0-hardened} - PMOVES_NETWORKS=pmoves_api,pmoves_public - entrypoint: /home/kong/kong-entrypoint.sh + # Strip CRs before running the vendored entrypoint. PMOVES-supabase ships no + # .gitattributes, so a Windows checkout with core.autocrlf=true gives the + # script CRLF endings and `#!/bin/sh\r` cannot exec: Kong exits instantly and + # restart: unless-stopped loops it forever. Pre-boot check: make kong-config-check. + entrypoint: + - /bin/sh + - -c + - tr -d '\r' < /home/kong/kong-entrypoint.sh > /tmp/kong-entrypoint.sh && exec /bin/sh /tmp/kong-entrypoint.sh healthcheck: # NOTE: liveness only — `kong health` reports the Kong PROCESS, not whether # any routes are loaded. A route-less Kong passes this check while 404'ing diff --git a/pmoves/docker-compose.yml b/pmoves/docker-compose.yml index 37dc6211eb..50d6015f94 100644 --- a/pmoves/docker-compose.yml +++ b/pmoves/docker-compose.yml @@ -968,7 +968,14 @@ services: - PARENT_SYSTEM=${PARENT_SYSTEM:-PMOVES.AI} - PARENT_VERSION=${PARENT_VERSION:-1.0.0-hardened} - PMOVES_NETWORKS=pmoves_api,pmoves_public - entrypoint: /home/kong/kong-entrypoint.sh + # Strip CRs before running the vendored entrypoint. PMOVES-supabase ships no + # .gitattributes, so a Windows checkout with core.autocrlf=true gives the + # script CRLF endings and `#!/bin/sh\r` cannot exec: Kong exits instantly and + # restart: unless-stopped loops it forever. Pre-boot check: make kong-config-check. + entrypoint: + - /bin/sh + - -c + - tr -d '\r' < /home/kong/kong-entrypoint.sh > /tmp/kong-entrypoint.sh && exec /bin/sh /tmp/kong-entrypoint.sh healthcheck: # NOTE: liveness only — `kong health` reports the Kong PROCESS, not whether # any routes are loaded. A route-less Kong passes this check while 404'ing diff --git a/pmoves/docs/handoffs/supabase-kong-declarative-config-boot-failure-2026-08-18.md b/pmoves/docs/handoffs/supabase-kong-declarative-config-boot-failure-2026-08-18.md index 1d6b5d4e88..8402d1e2c4 100644 --- a/pmoves/docs/handoffs/supabase-kong-declarative-config-boot-failure-2026-08-18.md +++ b/pmoves/docs/handoffs/supabase-kong-declarative-config-boot-failure-2026-08-18.md @@ -170,3 +170,24 @@ entrypoint already implements the intended escape hatch; the data is what is wro Kong will keep crash-looping until fault 3 is cleared. The self-hosted `pmoves-supabase` MCP stays non-functional until then; the cloud `supabase@claude-plugins-official` plugin is **not** the substitute — it targets `mcp.supabase.com`, not this stack. + +--- + +## Follow-up 2026-11-25: fail fast instead of looping (4090 recurrence) + +The 4090 hit the same pattern (1,266 restarts in 22h). These faults live in each node's own +env files, so a fix on one node does nothing for the next. Two guards now stop a bad config +from ever reaching `restart: unless-stopped`: + +- **`make -C pmoves kong-config-check`** (`scripts/supabase/kong_config_check.sh`) renders + `kong.yml` in a throwaway `supabase-kong` container with the real env and mounts, then runs + `kong config parse`. It names faults 1 and 3 directly and prints the fix. `supa-start` + runs it before bringing Kong up; `SKIP_KONG_CONFIG_CHECK=1` bypasses it. +- **CRLF-safe entrypoint.** PMOVES-supabase has no `.gitattributes`, so a Windows checkout + with `core.autocrlf=true` gives `kong-entrypoint.sh` CRLF endings and `#!/bin/sh\r` cannot + exec. The compose entrypoint now strips CRs into `/tmp` before running it. A + `*.sh eol=lf` rule in the fork is still the durable fix. + +Not done: a compose-level `${DASHBOARD_PASSWORD:?}` guard. Compose interpolates every +service including profile-disabled ones, so it would break every `docker compose` command on +nodes that do not run Supabase. diff --git a/pmoves/scripts/supabase/kong_config_check.sh b/pmoves/scripts/supabase/kong_config_check.sh new file mode 100755 index 0000000000..d2bb1c188e --- /dev/null +++ b/pmoves/scripts/supabase/kong_config_check.sh @@ -0,0 +1,89 @@ +#!/bin/sh +# Pre-boot validation of the Supabase Kong declarative config. +# +# Runs INSIDE a throwaway supabase-kong container (see `make kong-config-check`), +# so it sees exactly the environment, mounts and image the real service gets. +# It renders kong.yml the same way kong-entrypoint.sh does, then asks Kong to +# parse it WITHOUT starting the gateway. +# +# Why: every known Kong crash-loop so far came from per-node env drift that +# nothing flagged before boot. Kong exits on a bad declarative config, Docker +# restarts it, and the loop runs silently (3,924 restarts on z890 2026-08-18, +# 1,266 in 22h on the 4090 2026-11-25). See +# docs/handoffs/supabase-kong-declarative-config-boot-failure-2026-08-18.md. +# +# Exit 0 = Kong will accept the config. Exit 1 = it will not; the message says why. + +ENTRYPOINT=/home/kong/kong-entrypoint.sh +fail=0 + +say_fail() { echo " ✗ $*" >&2; fail=1; } + +echo "=== Kong: pre-boot declarative config check ===" + +# --- Fault 1: empty dashboard password ------------------------------------- +# kong.yml declares basicauth password '$DASHBOARD_PASSWORD'; Kong refuses an +# empty one ("in 'password': length must be at least 1"). +if [ -z "${DASHBOARD_PASSWORD:-}" ]; then + say_fail "DASHBOARD_PASSWORD is empty on this node. Kong rejects an empty basic-auth password." + echo " fix: make -C pmoves secrets-rotate KEY=DASHBOARD_PASSWORD LEN=32" >&2 +fi + +# --- Fault 3: new-format keys aliased to the legacy JWTs -------------------- +# Each consumer declares both a legacy and a new key slot. Kong requires +# keyauth_credentials.key to be globally unique, so a copy is a hard refusal. +# Upstream's intended state for unmigrated installs is EMPTY (the entrypoint +# strips blank `- key:` lines). +dup_key() { + # $1 new-name $2 new-value $3 legacy-name $4 legacy-value + if [ -n "$2" ] && [ "$2" = "$4" ]; then + say_fail "$1 is a copy of $3. Kong rejects duplicate keyauth keys (uniqueness violation)." + echo " fix: set $1= (empty) in env.shared, then make -C pmoves secrets-funnel" >&2 + fi +} +dup_key SUPABASE_PUBLISHABLE_KEY "${SUPABASE_PUBLISHABLE_KEY:-}" SUPABASE_ANON_KEY "${SUPABASE_ANON_KEY:-}" +dup_key SUPABASE_SECRET_KEY "${SUPABASE_SECRET_KEY:-}" SUPABASE_SERVICE_KEY "${SUPABASE_SERVICE_KEY:-}" + +# --- CRLF line endings (Windows checkouts) ---------------------------------- +# PMOVES-supabase ships no .gitattributes, so core.autocrlf=true checks the +# entrypoint out with CRLF and `#!/bin/sh\r` cannot exec. The compose +# entrypoint now strips CRs before running it, so this is a warning only. +cr=$(printf '\r') +if grep -q "$cr" "$ENTRYPOINT" 2>/dev/null; then + echo " ! $ENTRYPOINT has CRLF line endings (Windows checkout). Compose strips them," >&2 + echo " but re-check out the submodule with core.autocrlf=false to clear this." >&2 +fi + +# --- Render + parse --------------------------------------------------------- +# Same render as the real boot, with the final `exec ... kong docker-start` +# swapped for a no-op so the gateway never starts here. +if [ ! -r "$ENTRYPOINT" ] || [ ! -r /home/kong/temp.yml ]; then + say_fail "kong.yml / kong-entrypoint.sh are not mounted. Is the PMOVES-supabase submodule populated?" + echo " fix: git submodule update --init PMOVES-supabase" >&2 + exit 1 +fi + +tr -d '\r' < "$ENTRYPOINT" \ + | sed 's|^exec /entrypoint.sh kong docker-start.*$|: # kong-config-check: start suppressed|' \ + > /tmp/kong-render.sh +if grep -q 'kong docker-start' /tmp/kong-render.sh; then + say_fail "kong-entrypoint.sh no longer ends in 'exec /entrypoint.sh kong docker-start'; upstream changed it. Update this check." + exit 1 +fi + +if ! sh /tmp/kong-render.sh; then + say_fail "rendering kong.yml failed (see output above)" + exit 1 +fi + +if kong config parse "$KONG_DECLARATIVE_CONFIG"; then + echo " ✓ Kong parses the rendered declarative config" +else + say_fail "Kong refused the rendered declarative config (error above). It would crash-loop on boot." +fi + +if [ "$fail" -ne 0 ]; then + echo "✗ kong-config-check failed; not starting supabase-kong." >&2 + exit 1 +fi +echo "✓ kong-config-check passed"