fix(supabase): db:trial closure review fixes

Strict absent detection (stderr sentence per kind, measured on Docker 29.9.3), tri-state container_running, empty-volume check before restore, quieter DB init and rotation logging, backup/migrate refuse while the app runs, lock first in start/stop, truthful rotate-secrets and post-create checks. Stub reproduces Docker's stdout/stderr split. Harness 364/0.
This commit is contained in:
bchanot committed 2026-11-11 14:16:32 +01:00
1 parent a78da9f4e2
commit d3bdbbe0ba
5 files changed
+357 -54

No files matched your search

+41 -8
View File
@@ -858,11 +858,11 @@ before any Docker call. Their typed confirmations: `destroy` asks `faunosteo_tri
| `create` | after the Rust pipeline check of the equine seed (`pnpm r5:import-equine --check`): secrets, network, volumes, services, the branch's migrations, then `equine_draft.sql` only (never `seed.sql`); checks that the historical sheet is the only official one and that its draft equals `document.json` |
| `start` / `stop` | the same containers, data kept; `start` recreates a missing service container from `stack.conf` and `secrets.env` |
| `status` | containers, keys' expiry, migrations, equine sheet, accounts with roles, rights and verified factors, backups |
| `migrate` | a cold backup, then the branch's new migrations; refuses an applied file edited since, or a new file older than the last applied; a migrate that stops part-way names its backup |
| `backup` | stops the stack a few seconds, 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) |
| `migrate` | a cold backup, then the branch's new migrations; refuses while the app runs (it stops the stack), an applied file edited since, or a new file older than the last applied; a migrate that stops part-way names its backup |
| `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; sessions signed with the old secret end, 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 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 |
| `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 |
@@ -880,7 +880,14 @@ First use, after the owner's go: `plan`, `create`, `assets`, then the two accoun
grant asking `admin` first, as `grant_catalog_right` does); O1 is unchanged. A production practitioner
holds neither `admin` nor a catalogue editing right by default.
Rotation and recovery: `rotate-keys` before the keys expire (`status` shows the date); `rotate-secrets` to revoke.
Rotation and recovery: `rotate-keys` before the keys expire (`status` shows the date); `rotate-secrets` refuses the access tokens signed with the old secret (refresh tokens and sessions survive it).
Ending a session after a rotation: signing out in the app right after `rotate-secrets` does not end it. The app calls
`auth.signOut()` with auth-js's default scope `global`, which revokes every session of the account, but GoTrue refuses
the `/logout` call of a token signed with the old secret, and auth-js 2.117.3 ignores that 401 or 403 and only drops the
local session: the server session and its refresh token stay valid (a token refreshed with the new secret lasts up to
`jwt_exp`, 3600 s). To end the sessions, sign in again (the token is then signed with the new secret), then sign out:
that revokes all sessions of the account, other browsers included. The script revokes nothing itself (an owner
decision not taken).
If `rotate-secrets` loses psql, the marker the transaction wrote tells whether it committed and only the matching
file stays `secrets.env` (password probes prove nothing here: loopback connections are `trust` in this image); if a
rotation stops after the commit, `pnpm db:trial start` recreates the containers; if it stops before the commit is
@@ -910,9 +917,9 @@ 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.
Limits: one host; no verification worker on this stack, so a draft submitted for verification stays waiting; 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
disk (copy them elsewhere by hand). `app` takes no lock: `stop`, `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`
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
@@ -921,10 +928,36 @@ 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
`supabase_admin` password used by `rotate-secrets`, the pids caps, `tar` and `du` in the database image (checked by
`create` before anything is made), the image's default logging settings, the backup helper's `tar` restoring
ownership in the database image, `set local pgaudit.log` accepted by the image, loopback `trust` in its `pg_hba.conf`
ownership in the database image, `set local pgaudit.log` and `set local pg_stat_statements.track_utility` accepted by
the image, the init's session-level `set` lines (`log_statement`, `log_min_duration_statement`,
`log_min_error_statement`, `pgaudit.log`, `pg_stat_statements.track_utility`) accepted by it, whether the image's own
init runs an `ALTER USER supabase_admin ... PASSWORD` before the schema file (where the init's settings cannot help), loopback `trust` in its `pg_hba.conf`
(the rotation's commit marker relies on it), psql's echo of an error statement (a failing rotation statement must not print a
secret), and the grant and factor SQL, which the harness checks as text and which first
runs at the first real `grant`.
runs at the first real `grant`. Checks to make right after that first `create`, printing no value, only counts.
`<secrets.env>` is `$FAUNOSTEO_TRIAL_DIR/secrets.env` (default `~/.cache/faunosteo-trial/secrets.env`), `<db>` is
`faunosteo_trial_db`:
```bash
# roles holding a password: exactly the five the script sets (postgres is not a superuser in this image)
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)
for key in TR_PW TR_JWT_SECRET; do
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>)
done
```
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.
## 6. Generated types
+1 -1
View File
@@ -170,7 +170,7 @@ recreates a missing container; backups check free space, list each archive back
backup of what it would remove and names the manual removal commands; the stub harness is run by hand, not by
`check:all` (it reads the host's real ports). R13 (owner 2026-11-10): the shared trial dev server serves exactly
one of two listed stacks (`apps/app/vite/trial-targets.ts`), and `db-trial.sh` checks each operation's target and
every key it hands over (`SUPABASE.md` §5.2). Known limit: `app` takes no lock, so a `stop`, `destroy`, `restore`
every key it hands over (`SUPABASE.md` §5.2). Known limit: `app` takes no lock, so a `stop`, `backup`, `migrate`, `destroy`, `restore`
or rotation run in another terminal just before Vite listens goes ahead (`SUPABASE.md` §5.2). The tests of §5 that
create a stack under a test prefix were not run (owner brief: environment-free checks only); the stub harness
replaces them until the first `create`.