docs(supabase): db:trial operating guide
This commit is contained in:
1 parent
3b687a218e
commit
f7bf0c85cb
5 files changed
+144
-10
No files matched your search
@@ -821,6 +821,111 @@ set local role authenticated;
|
||||
select set_config('request.jwt.claims', '{"sub":"<user uuid>","role":"authenticated"}', true);
|
||||
```
|
||||
|
||||
### 5.2 Dedicated trial stack (`pnpm db:trial`)
|
||||
|
||||
A persistent stack for the owner's manual trials, apart from DEV and from the sandbox, which the
|
||||
automated suites keep using (`docs/development/TRIAL_STACK.md`, arbitrations A11 to A15). The script
|
||||
`scripts/db-trial.sh` and its checks exist; the stack is created only on the owner's go, one operation
|
||||
at a time, and never by a test.
|
||||
|
||||
| Container | Image | Port (127.0.0.1 only) | Data | Caps |
|
||||
|---|---|---|---|---|
|
||||
| `faunosteo_trial_db` | `supabase/postgres:17.11.0.004` | 58432 | volume `faunosteo_trial_db` (`PGDATA`) | 1 GiB, `shared_buffers` 128 MB, 512 pids |
|
||||
| `faunosteo_trial_auth` | `supabase/gotrue:v2.197.0` | 58999 | | 128 MiB, 256 pids |
|
||||
| `faunosteo_trial_rest` | `supabase/postgrest:v16.4` | 58300 | | 384 MiB, 256 pids |
|
||||
| `faunosteo_trial_storage` | `supabase/storage-api:v1.79.36` | 58500 | volume `faunosteo_trial_storage` (`/mnt`) | 256 MiB, 256 pids |
|
||||
| `faunosteo_trial_mail` | `supabase/mailpit:v1.31.3` | 58025 | | 64 MiB, 64 pids |
|
||||
| `faunosteo_trial_gateway` | `nginx:1.31-alpine` | 58801 | | 64 MiB, 64 pids |
|
||||
|
||||
Every container: network `faunosteo_trial_net`, `--cpus 1`, restart policy `no`. The app (`pnpm db:trial app`)
|
||||
runs Vite on `http://<trial host>:5194` with a 768 MiB Node heap; the trial host is the LAN address by default,
|
||||
`FAUNOSTEO_TRIAL_HOST=127.0.0.1` for host-only, decided again at each run (nothing to edit after a change of the LAN
|
||||
address). GoTrue's mail links carry the host of the moment GoTrue was started (`create`, `restore`,
|
||||
`rotate-secrets`). GoTrue's sign-up is closed and the gateway answers 403 on `/auth/v1/admin/`.
|
||||
|
||||
State: `~/.cache/faunosteo-trial` (or `FAUNOSTEO_TRIAL_DIR`), 700, refused inside any git work tree:
|
||||
`secrets.env` and the services' env files (600, written whole then renamed), `stack.conf` (images),
|
||||
`migrations.sha256` (applied files and their hashes), `backups/`. Keys are signed for the issuer `faunosteo-trial`
|
||||
and valid one year. Never run a bare `docker inspect` on a trial container: it prints the env-file values (database
|
||||
password, JWT secret, keys); use `docker inspect -f` with a named non-secret field. Every command but `plan` needs a
|
||||
reachable Docker daemon. `account`, `grant`, `restore` and `destroy` need a terminal: on a piped stdin they refuse
|
||||
before any Docker call. Their typed confirmations: `destroy` asks `faunosteo_trial`, `restore <backup>` asks
|
||||
`restore <backup>`, `grant <email> <right>` asks `grant <right>` for every right, catalogue rights included.
|
||||
|
||||
| Command | What it does |
|
||||
|---|---|
|
||||
| `plan` | read-only: the exact resources, each port free or taken, volume and backup places, memory, the refusals `create` would meet |
|
||||
| `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) |
|
||||
| `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 |
|
||||
| `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 |
|
||||
| `app` | the app, foreground; Ctrl+C stops Vite and waits for it, so 5194 is free on return; the stack keeps running |
|
||||
| `destroy` | inventory, typed confirmation `faunosteo_trial`, a backup of every trial volume checked as a restorable backup, then the containers, the network, the volumes and the live state files; backups kept. When that backup cannot be made or fails the check, it removes nothing and names the backup kept (or none), the exact `docker rm`, `docker network rm` and `docker volume rm` lines for what exists, then `pnpm db:trial destroy` to clear the state files; the script never runs those lines. With no trial resource left, it removes the live state files only |
|
||||
|
||||
First use, after the owner's go: `plan`, `create`, `assets`, then the two accounts.
|
||||
|
||||
1. Owner/admin account, for the administration trials: `account <email>`, `app`, sign in, enrol two TOTP
|
||||
factors in Mon compte > Sécurité, then `grant <email> owner`, `grant <email> admin`, then `grant <email>
|
||||
sheet_editor`, `sheet_reviewer` and `sheet_publisher`; sign in again and pass the step-up.
|
||||
2. Practitioner account: `account <email>`, `app`, enrol one TOTP factor, `grant <email> admin`, then `grant <email>
|
||||
sheet_editor` (refused before `admin`). This is a trial account, not a production practitioner profile: the
|
||||
technical `admin` role is there only because rule O1 activates `sheet_editor` for a platform admin (hence the
|
||||
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.
|
||||
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
|
||||
known, the script names the backup taken just before, and `restore <that backup>` returns to the previous secrets
|
||||
and data. Every backup holds the `secrets.env` of its time: restoring a backup taken before a `rotate-secrets`
|
||||
brings the old secrets back (the script says so before the confirmation). A restore needs the same Postgres image
|
||||
as the backup (recorded in its `stack.conf`).
|
||||
|
||||
No automated suite reaches this stack: `db-trial.sh` refuses a shell holding `SANDBOX_*` variables; the sandbox
|
||||
suites (`packages/supabase/tests/sandbox/target.ts`, imported by `stack.ts` and the shell Playwright config)
|
||||
accept only the sandbox's container, loopback ports and key issuer `db-sandbox`; the LAN Playwright config accepts
|
||||
port 5193 only; `e2e:avatar` and `e2e:sheet-assets` require the sandbox URL and issuer; `db-sandbox.sh` refuses a
|
||||
state folder holding the trial marker; every secret differs from the sandbox's. `bash scripts/db-trial-check.sh`,
|
||||
run by hand, proves these refusals and the script's Docker calls with stubs, no daemon reached; it is not a
|
||||
`pnpm check:all` stage because it reads the host's real ports and memory, and it refuses to run (exit 2) while the
|
||||
trial stack or app holds a port.
|
||||
|
||||
Identification of the target (owner 2026-11-10): the trial dev server (`apps/app/vite/trial.config.ts`, shared with
|
||||
`pnpm db:sandbox trial`) serves exactly one of the two stacks listed in `apps/app/vite/trial-targets.ts`. The exact
|
||||
gateway string picks it; the app port (with `--strictPort`), `VITE_SUPABASE_URL` and the anon key's `role` and
|
||||
`iss` must then match that same stack, and the db:trial gateway must answer `GET /__faunosteo_stack` with
|
||||
`faunosteo_trial`; anything else stops Vite before it listens, with no fallback to the sandbox, DEV or another
|
||||
local service. `db-trial.sh` checks, before acting: for `app` and `assets`, the gateway container published exactly
|
||||
on 127.0.0.1:58801 and its identity answer; for `account`, GoTrue published exactly on 127.0.0.1:58999; for
|
||||
`migrate`, Postgres exactly on 127.0.0.1:58432; and every key it hands over (Vite, the upload tool, GoTrue's admin
|
||||
API, Storage's env) must be signed with this stack's JWT secret for the issuer `faunosteo-trial` and the expected
|
||||
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
|
||||
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
|
||||
`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
|
||||
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`
|
||||
(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`.
|
||||
|
||||
## 6. Generated types
|
||||
|
||||
```bash
|
||||
|
||||
Reference in new issue
Block a user