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

@@ -3603,6 +3603,18 @@ Measured on Docker 29.9.3: a failing `inspect -f` (absent resource or lost daemo
- M7: `cmd_start` checks `trial_host` before starting or recreating a container. - M7: `cmd_start` checks `trial_host` before starting or recreating a container.
- H: `lines_before_first` checks order; the rotation check asserts every silencing line; the tautological `! grep "already exists"` replaced by one that can fail; cases: stream split of the stub, plan, create, backup and status on stub-absent resources, create with the daemon lost after the first resource, restore with the daemon lost, start with no usable host. - H: `lines_before_first` checks order; the rotation check asserts every silencing line; the tautological `! grep "already exists"` replaced by one that can fail; cases: stream split of the stub, plan, create, backup and status on stub-absent resources, create with the daemon lost after the first resource, restore with the daemon lost, start with no usable host.
#### Closure second re-review fixes (2026-11-11)
- I-1: SUPABASE.md §5.2 post-create scan also counts `extensions.pg_stat_statements` per key; above 0: reset it as `supabase_admin`, then `rotate-secrets`, existing backups keep the text.
- m1: `check()` runs every check with stdin from `/dev/null`; the two `grep ... $(find ...)` checks (rotation SQL, account body) get `/dev/null` as an extra file.
- m2/m3: `refuse_inspect` states a reason alone (`container_running`'s two refusals); `inspect_refused` hint adds the Docker 29.9.3 wording note; SUPABASE.md records it.
- m4: `plan_images` prints "unknown (Docker daemon unreachable)" when the daemon is down.
- m5: `start_containers` calls `trial_host` before the first start when GoTrue's container is missing.
- m6: harness cases: the quoted answer and hints of `inspect_refused`, the "listing failed" way-out lines (stub hook `lost-after-archive`).
- m7/m8: SUPABASE.md: stale access token keeps getting 401 after rotation until refresh or sign-in; log scan defines `<log_path>`, labels each count, states both log-location cases.
- m9: `restore_extracted_note` names what was extracted when a volume is not empty or unreadable (stub `volume-ls-storage`).
- m10: `destroy_stop_line` prints `docker stop <running>` before the `docker rm` way-out line.
## Review record (orchestrator) ## Review record (orchestrator)
Each reviewer was a fresh subagent; each fix round went to a fresh executor; the orchestrator re-ran the checks Each reviewer was a fresh subagent; each fix round went to a fresh executor; the orchestrator re-ran the checks
+34 -10
View File
@@ -862,7 +862,7 @@ before any Docker call. Their typed confirmations: `destroy` asks `faunosteo_tri
| `backup` | refuses while the app runs; stops the stack a few seconds (and refuses when a container still runs after the stop), refuses when free space is below 110 % of the volumes, archives each volume read-only through a `--rm` helper with no network, then lists it back and compares its entry count with the volume's (an archive cut short is refused), copies the state files, writes checksums last, restarts; a failed backup keeps no folder (a folder without `SHA256SUMS` is listed as incomplete) | | `backup` | refuses while the app runs; stops the stack a few seconds (and refuses when a container still runs after the stop), refuses when free space is below 110 % of the volumes, archives each volume read-only through a `--rm` helper with no network, then lists it back and compares its entry count with the volume's (an archive cut short is refused), copies the state files, writes checksums last, restarts; a failed backup keeps no folder (a folder without `SHA256SUMS` is listed as incomplete) |
| `restore <backup>` | checksums, archives and the recorded database image checked first, typed confirmation `restore <backup>`, a backup of the current volumes, then the backup's volumes and secrets and the containers recreated; also rebuilds a destroyed stack | | `restore <backup>` | checksums, archives and the recorded database image checked first, typed confirmation `restore <backup>`, a backup of the current volumes, then the backup's volumes and secrets and the containers recreated; also rebuilds a destroyed stack |
| `rotate-keys` | a backup, then new anon and service keys signed with the same secret (one more year), Storage recreated and the gateway restarted; works on a stopped stack too (Storage is then recreated by the next `start`); the previous keys stay valid until their own expiry. Expired keys never block `start` or `rotate-keys`; `app`, `assets` and `account` refuse them and name `rotate-keys`; `status` reports them | | `rotate-keys` | a backup, then new anon and service keys signed with the same secret (one more year), Storage recreated and the gateway restarted; works on a stopped stack too (Storage is then recreated by the next `start`); the previous keys stay valid until their own expiry. Expired keys never block `start` or `rotate-keys`; `app`, `assets` and `account` refuse them and name `rotate-keys`; `status` reports them |
| `rotate-secrets` | a backup, then a new JWT secret, keys and role passwords set in one transaction as `supabase_admin` (values through psql variables, statement and error-statement logging off, a digest marker proving the commit); the new values wait in `secrets.next.env` (600) until the commit is known; every container recreated; access tokens signed with the old secret are refused, while refresh tokens and sessions stay valid (a browser refreshes and gets a token signed with the new secret; the script revokes no session, which is an owner decision not taken; to end sessions after a rotation, sign in again, then sign out: see the paragraph below the table), account passwords and TOTP factors stay | | `rotate-secrets` | a backup, then a new JWT secret, keys and role passwords set in one transaction as `supabase_admin` (values through psql variables, statement and error-statement logging off, a digest marker proving the commit); the new values wait in `secrets.next.env` (600) until the commit is known; every container recreated; access tokens signed with the old secret are refused, while refresh tokens and sessions stay valid (a signed-in browser keeps its pre-rotation access token and gets 401 from PostgREST, even after an app restart, until auth-js refreshes it near its expiry, up to 3600 s, or the user signs out and in again; the script revokes no session, which is an owner decision not taken; to end sessions after a rotation, sign in again, then sign out: see the paragraph below the table), account passwords and TOTP factors stay |
| `account <email>` | a confirmed account through GoTrue's admin API on 58999, password typed twice at a hidden prompt (12 characters min.); the address is lowercased | | `account <email>` | a confirmed account through GoTrue's admin API on 58999, password typed twice at a hidden prompt (12 characters min.); the address is lowercased |
| `grant <email> <right>` | `owner` / `admin`: the operator path of the V1-2 contract §5.7.1 (verified TOTP factors shown, two for owner, one for admin; typed confirmation `grant <right>`; `private.assign_platform_role(null, …)` and an audit row); a platform role already active is refused. Catalogue rights mirror `public.grant_catalog_right` in operator SQL (the RPC needs an owner session at aal2): a confirmed active account; a verified TOTP factor for every right but `catalog_reader`; `admin` held first for `sheet_editor` and `sheet_publisher` (the refusal names `pnpm db:trial grant <email> admin`); one active row per right; typed confirmation; the insert and an audit row `catalog_grant.operator_bootstrap` in one transaction; no platform role is granted implicitly. `granted_by` is the holder's own id (the column is NOT NULL and the operator has no profile), so the rights screen shows a self-grant; the audit row names the operator. A catalogue right already active exits 0 with nothing written | | `grant <email> <right>` | `owner` / `admin`: the operator path of the V1-2 contract §5.7.1 (verified TOTP factors shown, two for owner, one for admin; typed confirmation `grant <right>`; `private.assign_platform_role(null, …)` and an audit row); a platform role already active is refused. Catalogue rights mirror `public.grant_catalog_right` in operator SQL (the RPC needs an owner session at aal2): a confirmed active account; a verified TOTP factor for every right but `catalog_reader`; `admin` held first for `sheet_editor` and `sheet_publisher` (the refusal names `pnpm db:trial grant <email> admin`); one active row per right; typed confirmation; the insert and an audit row `catalog_grant.operator_bootstrap` in one transaction; no platform role is granted implicitly. `granted_by` is the holder's own id (the column is NOT NULL and the operator has no profile), so the rights screen shows a self-grant; the audit row names the operator. A catalogue right already active exits 0 with nothing written |
| `assets` | the equine drawings with `pnpm assets:upload` through the gateway (no overwrite, rerun = nothing to do), then every row confirmed with its object | | `assets` | the equine drawings with `pnpm assets:upload` through the gateway (no overwrite, rerun = nothing to do), then every row confirmed with its object |
@@ -917,12 +917,17 @@ API, Storage's env) must be signed with this stack's JWT secret for the issuer `
role. The identity answer is a static name, not authentication: the exact port, the container checks and the key role. The identity answer is a static name, not authentication: the exact port, the container checks and the key
signatures carry the rest. signatures carry the rest.
The absent sentences `db-trial.sh` recognises (`absent_answer`) were measured on Docker 29.9.3: a Docker upgrade
that rewords them makes every command refuse with "not the daemon's own 'absent' sentence", until `absent_answer` is
updated.
Limits: one host; no verification worker on this stack, so a draft submitted for verification stays waiting, and no avatar worker either, so a profile photo stays pending; the Limits: one host; no verification worker on this stack, so a draft submitted for verification stays waiting, and no avatar worker either, so a profile photo stays pending; the
historical sheet allows one working copy at a time; Mailpit is reachable on the host only; backups sit on the same historical sheet allows one working copy at a time; Mailpit is reachable on the host only; backups sit on the same
disk (copy them elsewhere by hand). `app` takes no lock: `stop`, `backup`, `migrate`, `destroy`, `restore`, `rotate-keys` or disk (copy them elsewhere by hand). `app` takes no lock: `stop`, `backup`, `migrate`, `destroy`, `restore`, `rotate-keys` or
`rotate-secrets` run in another terminal in the second before Vite listens on 5194 goes ahead. After `rotate-keys` `rotate-secrets` run in another terminal in the second before Vite listens on 5194 goes ahead. After `rotate-keys`
the app keeps the previous anon key until its expiry; after `rotate-secrets` its requests are refused (401) until the app keeps the previous anon key until its expiry; after `rotate-secrets` a signed-in browser keeps its pre-rotation access
`app` is restarted; after `stop` or `destroy` it proxies to whatever later listens on 127.0.0.1:58801. Launch no token and PostgREST answers 401 to it, even after the app restarts, until auth-js refreshes it near its expiry (up to
3600 s) or the user signs out and in again; after `stop` or `destroy` it proxies to whatever later listens on 127.0.0.1:58801. Launch no
other `db:trial` command while `app` is starting. other `db:trial` command while `app` is starting.
Proven only at the first `create` (the stub harness cannot prove them): the database init under a volume, the Proven only at the first `create` (the stub harness cannot prove them): the database init under a volume, the
@@ -944,20 +949,39 @@ docker exec <db> psql -X -h 127.0.0.1 -U supabase_admin -d postgres -At \
-c 'select rolname from pg_authid where rolpassword is not null order by 1' -c 'select rolname from pg_authid where rolpassword is not null order by 1'
# the server log: where it goes is read at that moment, not assumed # the server log: where it goes is read at that moment, not assumed
docker exec <db> psql -X -h 127.0.0.1 -U supabase_admin -d postgres -At \ docker exec <db> psql -X -h 127.0.0.1 -U supabase_admin -d postgres -At \
-c 'show logging_collector; show log_directory; show log_destination;' -c 'show logging_collector; show log_directory; show log_destination; show data_directory;'
# secrets in the container log and in the in-container files that output names (counts only, the secret # secrets in the container log, in the in-container log files and in pg_stat_statements (counts only, the
# never on argv: grep reads the pattern from a process substitution) # secret never on argv: grep reads the pattern from a process substitution)
for key in TR_PW TR_JWT_SECRET; do for key in TR_PW TR_JWT_SECRET; do
printf '%s in docker logs: ' "$key"
docker logs <db> 2>&1 | grep -cFf <(sed -n "s/^$key=//p" <secrets.env>) docker logs <db> 2>&1 | grep -cFf <(sed -n "s/^$key=//p" <secrets.env>)
docker exec <db> sh -c 'cat "$1"/*' _ <log_directory> | grep -cFf <(sed -n "s/^$key=//p" <secrets.env>) printf '%s in the log files: ' "$key"
docker exec <db> sh -c 'cat "$1"/*' _ <log_path> | grep -cFf <(sed -n "s/^$key=//p" <secrets.env>)
printf '%s in pg_stat_statements: ' "$key"
docker exec <db> psql -X -h 127.0.0.1 -U supabase_admin -d postgres -At \
-c 'select query from extensions.pg_stat_statements' | grep -cFf <(sed -n "s/^$key=//p" <secrets.env>)
done done
``` ```
`<log_path>` is the `log_directory` printed above when it is absolute, else `<data_directory>/<log_directory>`
(a relative `log_directory` is relative to `data_directory`, both printed by the `show` line). With
`logging_collector` off there are no log files: the container log is the only place and the second count does not
apply (a `cat` that prints "No such file" means a wrong path: that count is meaningless). `pg_stat_statements` is
the store `track_utility = off` protects: the image's ACL on `pg_stat_statements_reset` sits in schema `extensions`
(see the dump check above), so the view is `extensions.pg_stat_statements`; if the query answers "relation does not
exist", look up the schema with `select extnamespace::regnamespace from pg_extension where extname =
'pg_stat_statements'` and use it.
Every count must be 0 and the role list must be the five roles (`supabase_admin`, `postgres`, `authenticator`, Every count must be 0 and the role list must be the five roles (`supabase_admin`, `postgres`, `authenticator`,
`supabase_auth_admin`, `supabase_storage_admin`). A count above 0: stop, tell the owner, do not use the stack for `supabase_auth_admin`, `supabase_storage_admin`). A count above 0: stop, tell the owner, do not use the stack for
anything else. `rotate-secrets` is the command that renews both scanned secrets (`rotate-keys` renews only the two anything else. After the owner's go: when `pg_stat_statements` holds a value, run `select pg_stat_statements_reset();`
API keys), with the owner's go; scan again afterwards. The old values stay in the log until the volume is recreated as `supabase_admin` (same `psql` line), then `pnpm db:trial rotate-secrets`, which renews both scanned secrets
and in the pre-rotate backup of `backups/`, so scan for them too. (`rotate-keys` renews only the two API keys); scan again afterwards. What the old values leave behind depends on
where the log is. A log inside `PGDATA` (the log files under `data_directory`) lives in the volume: it stays until
the volume is recreated and is in every later backup's `db.tar`, the pre-rotate one included. A log in the
container's own filesystem is gone once the container is recreated, which `rotate-secrets` does. Existing backups
keep any text they already hold: scan the backups too, and delete by hand the ones that carry a secret you no longer
want (the script prunes nothing).
## 6. Generated types ## 6. Generated types
+50 -6
View File
@@ -46,7 +46,7 @@ trap cleanup EXIT
PASS=0 FAIL=0 PASS=0 FAIL=0
pass() { echo "PASS $1"; PASS=$((PASS + 1)); } pass() { echo "PASS $1"; PASS=$((PASS + 1)); }
fail() { echo "FAIL $1"; FAIL=$((FAIL + 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 SEED_REL=supabase/seed/anatomical-sheets/equine/draft
mkdir -p "$WORK/repo/scripts" "$WORK/repo/$SEED_REL/assets" "$WORK/repo/node_modules/.bin" \ 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 # 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 # 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). # 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 # 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 # 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: # 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 [ "$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 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. # 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 if printf '%s\n' "$@" | grep -q -- 'du -sk /volume'; then
printf '%s\n2\n' "$(cat "$st/answers/measure-kib" 2>/dev/null || echo 100)" printf '%s\n2\n' "$(cat "$st/answers/measure-kib" 2>/dev/null || echo 100)"
fi fi
if printf '%s\n' "$@" | grep -qx -- -cf; then 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 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: # 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). # 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: 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: 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: 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: 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: 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" 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 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" 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 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. # 6: passwords count their blanks.
fresh_log; trial_typed '12345678901'$'\n''12345678901' account long@trial.test 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" 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=() 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" echo "-- db:sandbox state guard"
new_case sandbox-guard; mkdir -p "$CASE/trialstate"; : > "$CASE/trialstate/.faunosteo-trial-state" new_case sandbox-guard; mkdir -p "$CASE/trialstate"; : > "$CASE/trialstate/.faunosteo-trial-state"
EXTRA=(FAUNOSTEO_SANDBOX_DIR="$CASE/trialstate"); sandbox down 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" ;; image) printf 'Error response from daemon: No such image: %s' "$2" ;;
esac 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 inspect_refused() { # kind name what answer: Docker's answer shown quoted, cut at 200 characters
local shown="${4:0:200}" 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 resource_exists() { # kind name: 0 exists, 1 absent, else die
local err status=0 field='{{.Name}}' 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 local out status=0
container_exists "$1" || return 1 container_exists "$1" || return 1
out="$(docker container inspect -f '{{.State.Running}}' "$1" 2>/dev/null)" || status=$? 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 case "$out" in
true) return 0 ;; true) return 0 ;;
false) return 1 ;; false) return 1 ;;
esac 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"; } volume_exists() { resource_exists volume "$1"; }
network_exists() { resource_exists network "$1"; } network_exists() { resource_exists network "$1"; }
@@ -579,6 +584,8 @@ start_containers() {
done done
ports_free "${todo[@]}" ports_free "${todo[@]}"
if [ "$missing" = yes ]; then write_env_files; ensure_network; fi 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 for name in "${todo[@]}"; do
if container_exists "$name"; then if container_exists "$name"; then
docker start "$name" >/dev/null docker start "$name" >/dev/null
@@ -826,7 +833,9 @@ plan_images() {
local image where local image where
echo "Images:" echo "Images:"
for image in "$IMAGE_DB" "$IMAGE_AUTH" "$IMAGE_REST" "$IMAGE_STORAGE" "$IMAGE_MAIL" "$IMAGE_GATEWAY"; do 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" printf ' %-46s %s\n' "$image" "$where"
done done
} }
@@ -1119,11 +1128,14 @@ new_backup_dir() { # label → a fresh folder (700)
( umask 077; mkdir -p "$BACKUPS"; mkdir "$dir" ) || die "cannot create $dir" ( umask 077; mkdir -p "$BACKUPS"; mkdir "$dir" ) || die "cannot create $dir"
printf '%s' "$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. # `docker volume create` succeeds on an existing name: a restore extracts into an empty volume only.
volume_is_empty() { # volume volume_is_empty() { # volume
local out local out
out="$(docker run --rm --name "$HELPER" --network none -v "$1:/volume:ro" --entrypoint sh "$IMAGE_DB" \ 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" ] [ -z "$out" ]
} }
# Size in KiB and entry count of a volume, by the helper (read-only, no network); the entries are # 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 for vol in "$VOL_DB" "$VOL_STORAGE"; do
if volume_exists "$vol"; then docker volume rm "$vol" >/dev/null; fi if volume_exists "$vol"; then docker volume rm "$vol" >/dev/null; fi
docker volume create --label faunosteo.stack=trial "$vol" >/dev/null 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" \ 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" --numeric-owner -xpf - -C /volume < "$dir/${vol#faunosteo_trial_}.tar"
done 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; } || { 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 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 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 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:" 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 container 'docker rm'
destroy_way_out_line network 'docker network rm' destroy_way_out_line network 'docker network rm'
destroy_way_out_line volume 'docker volume rm' destroy_way_out_line volume 'docker volume rm'