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

+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) |
| `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-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 |
| `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 |
@@ -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
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
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
`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
`app` is restarted; after `stop` or `destroy` it proxies to whatever later listens on 127.0.0.1:58801. Launch no
the app keeps the previous anon key until its expiry; after `rotate-secrets` a signed-in browser keeps its pre-rotation access
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.
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'
# 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 \
-c 'show logging_collector; show log_directory; show log_destination;'
# secrets in the container log and in the in-container files that output names (counts only, the secret
# never on argv: grep reads the pattern from a process substitution)
-c 'show logging_collector; show log_directory; show log_destination; show data_directory;'
# secrets in the container log, in the in-container log files and in pg_stat_statements (counts only, the
# secret never on argv: grep reads the pattern from a process substitution)
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 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
```
`<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`,
`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
API keys), with the owner's go; scan again afterwards. The old values stay in the log until the volume is recreated
and in the pre-rotate backup of `backups/`, so scan for them too.
anything else. After the owner's go: when `pg_stat_statements` holds a value, run `select pg_stat_statements_reset();`
as `supabase_admin` (same `psql` line), then `pnpm db:trial rotate-secrets`, which renews both scanned secrets
(`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