fix(supabase): db:trial second re-review fixes

Post-create scan covers pg_stat_statements and labels each count; log path defined; rotate-secrets 401 window documented; plan shows image state unknown without a daemon; start_containers checks the app host before recreating GoTrue; truthful restore and destroy way-out messages; harness checks read stdin from /dev/null. Harness 372/0.
This commit is contained in:
bchanot committed 2026-11-11 14:36:12 +01:00
1 parent d3bdbbe0ba
commit f2cbf6814f
4 files changed
+121 -22

No files matched your search

+50 -6
View File
@@ -46,7 +46,7 @@ trap cleanup EXIT
PASS=0 FAIL=0
pass() { echo "PASS $1"; PASS=$((PASS + 1)); }
fail() { echo "FAIL $1"; FAIL=$((FAIL + 1)); }
check() { local name="$1"; shift; if "$@"; then pass "$name"; else fail "$name"; fi; }
check() { local name="$1"; shift; if "$@" </dev/null; then pass "$name"; else fail "$name"; fi; }
SEED_REL=supabase/seed/anatomical-sheets/equine/draft
mkdir -p "$WORK/repo/scripts" "$WORK/repo/$SEED_REL/assets" "$WORK/repo/node_modules/.bin" \
@@ -86,7 +86,8 @@ cat > "$WORK/bin/docker" <<'STUB'
# SIGTERM while it archives), append-on-rm (the file named inside gets a byte when a container is
# removed), term-on (an ERE: the first call whose argv line, or tag:<sql tag> for an exec, matches it
# sends the script a SIGTERM), answers/measure-kib (the volumes' measured size), answers/<tag>.seq (one line per call).
# answers/volume-ls (what `ls -A /volume` prints: a non-empty volume).
# answers/volume-ls (what `ls -A /volume` prints: a non-empty volume; volume-ls-storage: for that volume only).
# lost-after-archive: with fail/archive, the daemon is lost once the archive failed (as lost-now below).
# Every failing `inspect -f` (an absent resource of any of the four kinds, a lost daemon) writes a
# bare newline to stdout and the sentence to stderr, rc 1, as Docker 29.9.3 does (measured): the
# script must judge stderr alone. Docker's own wording per kind:
@@ -186,12 +187,19 @@ case "$sub" in
if [ "$name" = faunosteo_trial_helper ] && [ -f "$st/fail/helper" ]; then exit 1; fi
if [ "$input" -eq 1 ]; then [ ! -f "$st/fail/extract" ] || exit 1; save_stdin >/dev/null; fi
# Measure: 100 KiB and 2 entries ("." and "./content"), what the archive below lists.
if printf '%s\n' "$@" | grep -qx -- 'ls -A /volume'; then cat "$st/answers/volume-ls" 2>/dev/null || true; fi
if printf '%s\n' "$@" | grep -qx -- 'ls -A /volume'; then
vf="$st/answers/volume-ls"
if [[ "$*" == *faunosteo_trial_storage:* && -f "$vf-storage" ]]; then vf="$vf-storage"; fi
cat "$vf" 2>/dev/null || true
fi
if printf '%s\n' "$@" | grep -q -- 'du -sk /volume'; then
printf '%s\n2\n' "$(cat "$st/answers/measure-kib" 2>/dev/null || echo 100)"
fi
if printf '%s\n' "$@" | grep -qx -- -cf; then
[ ! -f "$st/fail/archive" ] || exit 3
if [ -f "$st/fail/archive" ]; then
if [ -f "$st/fail/lost-after-archive" ]; then : > "$st/lost-now"; fi
exit 3
fi
if [ -f "$st/term-in-archive" ]; then bash "$STUB_TERM"; fi
# A real (tiny) tar, so that the script's read-back has something to list. short-archive:
# the root entry only, exit 0 (an archive cut at a member boundary).
@@ -857,7 +865,7 @@ check "rotate-secrets: the final message does not claim sessions end" bash -c 'g
check "rotate-secrets: every value renewed" bash -c 'for k in TR_PW TR_JWT_SECRET TR_ANON_KEY TR_SERVICE_KEY; do [ "$(grep "^$k=" "$1")" != "$(grep "^$k=" "$2")" ] || exit 1; done' _ "$STATE_DIR/secrets.env" "$CASE/secrets.before-rotation"
check "rotate-secrets: a restorable, protected backup holding the previous secrets (no secrets.prev needed)" bash -c 'd=$(ls -d "$1"/*-pre-rotate* | tail -n 1); [ -n "$d" ] && [ "$(stat -c %a "$d")" = 700 ] && for f in db.tar storage.tar secrets.env stack.conf migrations.sha256 SHA256SUMS; do [ "$(stat -c %a "$d/$f")" = 600 ] || exit 1; done && cd "$d" && sha256sum --quiet -c SHA256SUMS && cmp -s secrets.env "$2"' _ "$STATE_DIR/backups" "$CASE/secrets.before-rotation"
check "rotate-secrets: values reach psql by environment names only" log_has 'docker exec -i -e PGPASSWORD -e PGAPPNAME -e NEW_PW -e NEW_JWT -e ROT_DIGEST faunosteo_trial_db psql -X -q -h 127.0.0.1 -U supabase_admin'
check "rotate-secrets: no rotation SQL text holds a secret, old or new" bash -c 'files=$(grep -lF -- "-- db-trial:rotate" $(find "$1" -type f)); [ -n "$files" ] && for f in $files; do grep -qF "set local log_min_error_statement = panic;" "$f" && grep -qF "app.trial_rotation" "$f" || exit 1; for s in "${@:2}"; do while IFS="=" read -r _ v; do [ -z "$v" ] || ! grep -qF -- "$v" "$f" || exit 1; done < "$s"; done; done' _ "$CASE/stub/stdin" "$STATE_DIR/secrets.env" "$CASE/secrets.before-rotation" "$CASE/secrets.before-lost" "$CASE/secrets.before-refusal"
check "rotate-secrets: no rotation SQL text holds a secret, old or new" bash -c 'files=$(grep -lF -- "-- db-trial:rotate" /dev/null $(find "$1" -type f)); [ -n "$files" ] && for f in $files; do grep -qF "set local log_min_error_statement = panic;" "$f" && grep -qF "app.trial_rotation" "$f" || exit 1; for s in "${@:2}"; do while IFS="=" read -r _ v; do [ -z "$v" ] || ! grep -qF -- "$v" "$f" || exit 1; done < "$s"; done; done' _ "$CASE/stub/stdin" "$STATE_DIR/secrets.env" "$CASE/secrets.before-rotation" "$CASE/secrets.before-lost" "$CASE/secrets.before-refusal"
check "rotate-secrets: six containers recreated, volumes kept" bash -c 'for n in db mail auth storage rest gateway; do grep -qx "docker rm faunosteo_trial_$n" "$1" && grep -q "^docker run -d --name faunosteo_trial_$n " "$1" || exit 1; done; ! grep -qF "docker volume rm" "$1"' _ "$CASE/log"
check "rotate-secrets: no leftover secrets.next.env, no secrets.prev.env" bash -c '[ ! -e "$1/secrets.prev.env" ] && [ ! -e "$1/secrets.next.env" ]' _ "$STATE_DIR"
check "rotate-secrets: new secrets absent from calls and output" secrets_absent "$STATE_DIR/secrets.env"
@@ -1316,7 +1324,7 @@ rm -f "$CASE/stub/answers/txn-factors"
fresh_stdin; fresh_log; trial_tty 'grant sheet_reviewer' grant Foo@Example.com sheet_reviewer
check "grant Foo@Example.com: the lowercased address is used everywhere" bash -c '[ "$1" -eq 0 ] && grep -qF -- "-v email=foo@example.com" "$2" && ! grep -qF "Foo@" "$2" "$3"' _ "$RC" "$CASE/log" "$CASE/out"
fresh_stdin; fresh_log; trial_typed "$PW"$'\n'"$PW" account Foo@Example.com
check "account Foo@Example.com: the body carries the lowercased address" bash -c '[ "$1" -eq 0 ] && grep -qF "\"email\":\"foo@example.com\"" $(find "$2" -type f) && ! grep -qF "Foo@" "$3"' _ "$RC" "$CASE/stub/stdin" "$CASE/out"
check "account Foo@Example.com: the body carries the lowercased address" bash -c '[ "$1" -eq 0 ] && grep -qF "\"email\":\"foo@example.com\"" /dev/null $(find "$2" -type f) && ! grep -qF "Foo@" "$3"' _ "$RC" "$CASE/stub/stdin" "$CASE/out"
# 6: passwords count their blanks.
fresh_log; trial_typed '12345678901'$'\n''12345678901' account long@trial.test
check "account: an 11-character password is refused" bash -c '[ "$1" -ne 0 ] && grep -qF "12 characters" "$2" && ! grep -q "^curl .*admin/users" "$3"' _ "$RC" "$CASE/out" "$CASE/log"
@@ -1574,6 +1582,42 @@ check "start with no usable app host: refused before any container is started or
EXTRA=()
echo "-- closure second re-review fixes (2026-11-11)"
# m4: a plan without a daemon does not call the images "not pulled yet".
new_case plan-down-images; : > "$CASE/stub/fail/daemon"; trial plan
check "plan with the daemon down: each of the six images is unknown, none 'not pulled yet'" bash -c '[ "$(grep -cF "unknown (Docker daemon unreachable)" "$1")" -eq 6 ] && ! grep -qF "not pulled yet" "$1"' _ "$CASE/out"
# m6/m3: a refused inspect shows Docker's answer, quoted, and both hints.
new_case inspect-shown; : > "$CASE/stub/fail/inspect-error"; trial create
check "an inspect error: the quoted Docker answer, the docker info hint and the wording hint" bash -c '[ "$1" -ne 0 ] && grep -qF "(answer '"'"'Error response from daemon: permission denied'"'"')" "$2" && grep -qF "(docker info)" "$2" && grep -qF "measured on Docker 29.9.3" "$2"' _ "$RC" "$CASE/out"
# m6/m10: the destroy way out when the listing fails, and when a container still runs.
new_case way-listing; trial create
: > "$CASE/stub/fail/archive"; : > "$CASE/stub/fail/lost-after-archive"
fresh_log; trial_tty faunosteo_trial destroy
check "destroy way out with the daemon lost after the failed archive: each kind prints its listing-failed line" bash -c '[ "$1" -ne 0 ] && for k in container network volume; do grep -qF "($k listing failed, Docker did not answer: inspect the faunosteo_trial ${k}s by hand)" "$2" || exit 1; done' _ "$RC" "$CASE/out"
new_case way-still-runs; trial create
: > "$CASE/stub/fail/stop-noop"; fresh_log; trial_tty faunosteo_trial destroy
check "destroy whose backup fails on a container that still runs: docker stop named before docker rm" bash -c '[ "$1" -ne 0 ] && grep -qF "still runs after the stop" "$2" && s=$(grep -nF " docker stop faunosteo_trial_db" "$2" | head -n 1 | cut -d: -f1) && r=$(grep -nF " docker rm faunosteo_trial_db" "$2" | head -n 1 | cut -d: -f1) && [ -n "$s" ] && [ -n "$r" ] && [ "$s" -lt "$r" ]' _ "$RC" "$CASE/out"
check "destroy whose backup fails on a container that still runs: nothing removed" no_removal
new_case way-stopped; trial create
echo 999999999999 > "$CASE/stub/answers/measure-kib"; fresh_log; trial_tty faunosteo_trial destroy
check "destroy way out with every container stopped: no docker stop line" bash -c '[ "$1" -ne 0 ] && grep -qF "no backup could be made" "$2" && ! grep -qF "docker stop faunosteo" "$2"' _ "$RC" "$CASE/out"
# m5: GoTrue's recreation reads the app host; backup's restart refuses before the first start.
new_case restart-host; trial create
rm -f "$CASE/stub/containers/faunosteo_trial_auth" "$CASE/stub/ports/faunosteo_trial_auth"
EXTRA=(FAUNOSTEO_TRIAL_HOST=8.8.8.8); fresh_log; trial backup
check "backup with GoTrue missing and no usable app host: the restart refuses before any container starts" bash -c '[ "$1" -ne 0 ] && grep -qF "must be loopback or a private address" "$2" && ! grep -qE "^docker (start|run -d|restart) " "$3"' _ "$RC" "$CASE/out" "$CASE/log"
EXTRA=()
# m9: a restore whose second volume fails says the first was extracted.
b2_stack restore-second
echo lost+found > "$CASE/stub/answers/volume-ls-storage"
fresh_log; trial_tty "restore $RN" restore "$RN"
check "restore: the storage volume not empty after the database volume was extracted says so" bash -c '[ "$1" -ne 0 ] && grep -qF "faunosteo_trial_storage is not empty after its creation: faunosteo_trial_db was extracted, faunosteo_trial_storage was not" "$2" && ! grep -qF "nothing was extracted" "$2"' _ "$RC" "$CASE/out"
echo "-- db:sandbox state guard"
new_case sandbox-guard; mkdir -p "$CASE/trialstate"; : > "$CASE/trialstate/.faunosteo-trial-state"
EXTRA=(FAUNOSTEO_SANDBOX_DIR="$CASE/trialstate"); sandbox down
+25 -6
View File
@@ -285,9 +285,14 @@ absent_answer() { # kind name: the daemon's wording, which differs by kind
image) printf 'Error response from daemon: No such image: %s' "$2" ;;
esac
}
refuse_inspect() { # kind name reason [extra hint]: the reason alone, for a path where Docker gave no sentence to quote
die "docker $1 inspect $2 $3: refused; check that the Docker daemon answers (docker info)${4:+, $4}"
}
# The absent sentences above were measured on Docker 29.9.3: a Docker that rewords them lands here.
inspect_refused() { # kind name what answer: Docker's answer shown quoted, cut at 200 characters
local shown="${4:0:200}"
die "docker $1 inspect $2 $3 (answer ${shown@Q}), not the daemon's own 'absent' sentence: refused; check that the Docker daemon answers (docker info)"
refuse_inspect "$1" "$2" "$3 (answer ${shown@Q}), not the daemon's own 'absent' sentence" \
"or that Docker's absent wording did not change (absent_answer, measured on Docker 29.9.3)"
}
resource_exists() { # kind name: 0 exists, 1 absent, else die
local err status=0 field='{{.Name}}'
@@ -302,12 +307,12 @@ container_running() { # 0 running, 1 stopped or absent, else die: an error is ne
local out status=0
container_exists "$1" || return 1
out="$(docker container inspect -f '{{.State.Running}}' "$1" 2>/dev/null)" || status=$?
[ "$status" -eq 0 ] || inspect_refused container "$1" "failed (exit $status) after it was found" "no answer kept"
[ "$status" -eq 0 ] || refuse_inspect container "$1" "failed (exit $status) after it was found"
case "$out" in
true) return 0 ;;
false) return 1 ;;
esac
inspect_refused container "$1" "returned an unexpected value" "$out"
refuse_inspect container "$1" "returned the unexpected value ${out:0:200}"
}
volume_exists() { resource_exists volume "$1"; }
network_exists() { resource_exists network "$1"; }
@@ -579,6 +584,8 @@ start_containers() {
done
ports_free "${todo[@]}"
if [ "$missing" = yes ]; then write_env_files; ensure_network; fi
# GoTrue's recreation reads the app host: a refusal must come before the first container starts.
if ! container_exists "$AUTH"; then trial_host >/dev/null; fi
for name in "${todo[@]}"; do
if container_exists "$name"; then
docker start "$name" >/dev/null
@@ -826,7 +833,9 @@ plan_images() {
local image where
echo "Images:"
for image in "$IMAGE_DB" "$IMAGE_AUTH" "$IMAGE_REST" "$IMAGE_STORAGE" "$IMAGE_MAIL" "$IMAGE_GATEWAY"; do
if docker image inspect -f '{{.Id}}' "$image" >/dev/null 2>&1; then where=present; else where='not pulled yet (create pulls it)'; fi
if [ "$PLAN_DAEMON" = no ]; then where='unknown (Docker daemon unreachable)'
elif docker image inspect -f '{{.Id}}' "$image" >/dev/null 2>&1; then where=present
else where='not pulled yet (create pulls it)'; fi
printf ' %-46s %s\n' "$image" "$where"
done
}
@@ -1119,11 +1128,14 @@ new_backup_dir() { # label → a fresh folder (700)
( umask 077; mkdir -p "$BACKUPS"; mkdir "$dir" ) || die "cannot create $dir"
printf '%s' "$dir"
}
restore_extracted_note() { # volume that failed: what the extraction loop had done before it
if [ "$1" = "$VOL_DB" ]; then echo "nothing was extracted"; else echo "$VOL_DB was extracted, $1 was not"; fi
}
# `docker volume create` succeeds on an existing name: a restore extracts into an empty volume only.
volume_is_empty() { # volume
local out
out="$(docker run --rm --name "$HELPER" --network none -v "$1:/volume:ro" --entrypoint sh "$IMAGE_DB" \
-c 'ls -A /volume')" || die "$1 cannot be read by the helper: nothing was extracted"
-c 'ls -A /volume')" || die "$1 cannot be read by the helper: $(restore_extracted_note "$1")"
[ -z "$out" ]
}
# Size in KiB and entry count of a volume, by the helper (read-only, no network); the entries are
@@ -1333,7 +1345,7 @@ cmd_restore() {
for vol in "$VOL_DB" "$VOL_STORAGE"; do
if volume_exists "$vol"; then docker volume rm "$vol" >/dev/null; fi
docker volume create --label faunosteo.stack=trial "$vol" >/dev/null
volume_is_empty "$vol" || die "$vol is not empty after its creation: nothing was extracted"
volume_is_empty "$vol" || die "$vol is not empty after its creation: $(restore_extracted_note "$vol")"
docker run --rm -i --name "$HELPER" --network none -v "$vol:/volume" --entrypoint tar "$IMAGE_DB" \
--numeric-owner -xpf - -C /volume < "$dir/${vol#faunosteo_trial_}.tar"
done
@@ -1357,9 +1369,16 @@ destroy_way_out_line() { # kind command
|| { echo " ($1 listing failed, Docker did not answer: inspect the faunosteo_trial $1s by hand)"; return 0; }
if [ -n "$names" ]; then echo " $2 ${names% }"; fi
}
# A container that still runs is stopped before it is removed: docker rm refuses it.
destroy_stop_line() {
local name names
names="$(for name in "${CONTAINERS[@]}"; do if container_running "$name"; then printf '%s ' "$name"; fi; done)" || return 0
if [ -n "$names" ]; then echo " docker stop ${names% } (first: these still run, docker rm refuses a running container)"; fi
}
destroy_way_out() { # kept backup folder, or empty
if [ -n "$1" ]; then echo "backup $(basename "$1") is kept."; else echo "no backup could be made."; fi
echo "Nothing was removed. To remove the stack yourself, run by hand:"
destroy_stop_line
destroy_way_out_line container 'docker rm'
destroy_way_out_line network 'docker network rm'
destroy_way_out_line volume 'docker volume rm'