feat(supabase): db:trial grants owner with one verified TOTP factor
Owner decision 2026-11-11: on the trial stack one verified factor suffices for owner as for admin, a second one optional. The count before the typed confirmation and the recount inside the grant transaction stay; SQL, aal2 and the rule for every other stack are unchanged.
This commit is contained in:
1 parent
0573d66864
commit
45d74536f5
4 files changed
+30
-18
No files matched your search
@@ -864,16 +864,17 @@ before any Docker call. Their typed confirmations: `destroy` asks `faunosteo_tri
|
||||
| `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 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 |
|
||||
| `grant <email> <right>` | `owner` / `admin`: the operator path of the V1-2 contract §5.7.1 (verified TOTP factors shown, one for owner and for admin (owner decision 2026-11-11; a second factor is an optional backup); 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.
|
||||
1. Owner/admin account, for the administration trials: `account <email>`, `app`, sign in, enrol one TOTP
|
||||
factor in Mon compte > Sécurité (a second is an optional backup), 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. With one factor, a lost device
|
||||
means the operator recovery of V1-2 §5.7.7 at the trial database, or a new account granted through `grant`.
|
||||
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
|
||||
|
||||
@@ -413,7 +413,8 @@ A1 to A6):
|
||||
(residual, §13). V1-2.5 records what removing a factor does to the
|
||||
account's other open sessions.
|
||||
- Loss of a factor: Supabase Auth issues no recovery codes. The owner enrols
|
||||
two factors on two devices before the first grant on any stack. Another
|
||||
two factors on two devices before the first grant on any stack (db:trial
|
||||
exception: §5.7.1). Another
|
||||
account that loses its factor keeps its `aal1` access (catalogue, rest of
|
||||
the application) and loses the administration until recovery.
|
||||
- Recovery is an operator procedure, never an application feature: no RPC,
|
||||
@@ -550,6 +551,11 @@ the reverse:
|
||||
API, email confirmed, and hands over the initial secret out of band;
|
||||
2. the future owner signs in, enrols two TOTP factors on two devices and
|
||||
verifies both; no role exists yet, so nothing is at stake in the window;
|
||||
(db:trial exception, owner, 2026-11-11: on the persistent trial stack of
|
||||
`pnpm db:trial` one verified TOTP factor suffices for the owner grant, as
|
||||
for admin; a second factor is an optional backup. This rule, for every
|
||||
other stack, production included, is unchanged until a distinct study and
|
||||
authorisation.)
|
||||
3. the operator checks, read-only, that the account has verified factors and
|
||||
that their names and creation times match what the owner did;
|
||||
4. only then the operator assigns the owner role from a privileged SQL
|
||||
|
||||
@@ -1210,10 +1210,10 @@ check "account: the body is a confirmed account" stdin_has '"email_confirm":true
|
||||
check "account: the state folder holds no file that is not 600" bash -c '[ -z "$(find "$1" -type f ! -perm 600)" ]' _ "$STATE_DIR"
|
||||
fresh_log; trial grant owner@trial.test root
|
||||
check "grant: an unknown right is refused before any call" refused_early "right:"
|
||||
set_factors 1
|
||||
set_factors 0
|
||||
fresh_stdin; fresh_log; trial_tty 'grant owner' grant owner@trial.test owner
|
||||
check "grant owner with one factor: refused (two needed), nothing assigned" bash -c '[ "$1" -ne 0 ] && grep -qF "owner needs 2" "$2" && grep -qF "nothing was granted" "$2"' _ "$RC" "$CASE/out"
|
||||
check "grant owner with one factor: no role SQL ran" no_role_assigned
|
||||
check "grant owner with no factor: refused (one needed), nothing assigned" bash -c '[ "$1" -ne 0 ] && grep -qF "owner needs 1" "$2" && grep -qF "nothing was granted" "$2"' _ "$RC" "$CASE/out"
|
||||
check "grant owner with no factor: no role SQL ran" no_role_assigned
|
||||
set_factors 2
|
||||
fresh_log; trial_tty no grant owner@trial.test owner
|
||||
check "grant owner, wrong phrase: nothing assigned" bash -c '[ "$1" -ne 0 ] && grep -qF "not confirmed" "$2"' _ "$RC" "$CASE/out"
|
||||
@@ -1231,9 +1231,13 @@ check "grant owner: the role SQL failing is told" bash -c '[ "$1" -ne 0 ] && gre
|
||||
rm -f "$CASE/stub/fail/grant-role"; fresh_stdin
|
||||
fresh_log; trial_tty 'grant owner' grant owner@trial.test owner
|
||||
check "grant owner: factors shown, operator path, audit row" bash -c '[ "$1" -eq 0 ] && grep -qF "Tablet | 2026-11-09 10:05 UTC" "$2" && grep -rlF "private.assign_platform_role(null, :'"'"'uid'"'"'::uuid" "$3" | grep -q . && grep -rlF "platform_role.operator_bootstrap" "$3" | grep -q .' _ "$RC" "$CASE/out" "$CASE/stub/stdin"
|
||||
check "grant owner: email, role and operator as psql variables" log_has "-v email=owner@trial.test -v role=owner -v need=2 -v operator="
|
||||
check "grant owner: email, role and operator as psql variables" log_has "-v email=owner@trial.test -v role=owner -v need=1 -v operator="
|
||||
check "grant owner: no secret in calls or output" secrets_absent "$STATE_DIR/secrets.env"
|
||||
set_factors 1
|
||||
fresh_stdin; fresh_log; trial_tty 'grant owner' grant owner@trial.test owner
|
||||
check "grant owner with one factor: granted, one factor suffices" bash -c '[ "$1" -eq 0 ] && grep -qF "owner granted to owner@trial.test" "$2"' _ "$RC" "$CASE/out"
|
||||
check "grant owner with one factor: need=1 passed as a psql variable" log_has "-v email=owner@trial.test -v role=owner -v need=1 -v operator="
|
||||
fresh_stdin
|
||||
fresh_log; trial_tty 'grant admin' grant practitioner@trial.test admin
|
||||
check "grant admin with one factor: granted, one factor suffices" bash -c '[ "$1" -eq 0 ] && grep -qF "admin granted to practitioner@trial.test" "$2"' _ "$RC" "$CASE/out"
|
||||
check "grant admin: role passed as a psql variable" log_has "-v email=practitioner@trial.test -v role=admin -v need=1 -v operator="
|
||||
@@ -1313,13 +1317,13 @@ set_factors 2; fresh_stdin; fresh_log; trial_tty 'grant owner' grant owner@trial
|
||||
SANITISED="left(regexp_replace(coalesce(nullif(f.friendly_name, ''), '(no name)'), '[^[:alnum:] ._-]', '?', 'g'), 40)"
|
||||
check "grant: SQL text check, the displayed name is sanitised in SQL (no newline, CR or ESC reaches the terminal)" bash -c 'grep -qF -- "$2" "$1"' _ "$(stdin_of grant-factors)" "$SANITISED"
|
||||
# 2: the transaction counts again.
|
||||
echo 1 > "$CASE/stub/answers/txn-factors"; fresh_stdin
|
||||
echo 0 > "$CASE/stub/answers/txn-factors"; fresh_stdin
|
||||
fresh_log; trial_tty 'grant owner' grant owner@trial.test owner
|
||||
check "grant owner: script handling of a failing grant session (stub emulates \\gset with zero rows, count 2 then 1): nothing granted" bash -c '[ "$1" -ne 0 ] && grep -qF "nothing was granted" "$2" && ! grep -qF "owner granted to owner@trial.test" "$2"' _ "$RC" "$CASE/out"
|
||||
check "grant owner: script handling of a failing grant session (stub emulates \\gset with zero rows, count 2 then 0): nothing granted" bash -c '[ "$1" -ne 0 ] && grep -qF "nothing was granted" "$2" && ! grep -qF "owner granted to owner@trial.test" "$2"' _ "$RC" "$CASE/out"
|
||||
check "grant owner: the transaction SQL counts the factors against :need" bash -c 'grep -q "mfa_factors" "$1" && grep -q ">= :need" "$1"' _ "$(stdin_of grant-role)"
|
||||
check "grant role: explicit begin and commit, never --single-transaction" bash -c 'f="$1"; [ "$(sed -n 2p "$f")" = "begin;" ] && [ "$(tail -n 1 "$f")" = "commit;" ] && ! grep -q -- "--single-transaction" "$2"' _ "$(stdin_of grant-role)" "$CASE/log"
|
||||
echo 2 > "$CASE/stub/answers/txn-factors"; fresh_stdin; fresh_log; trial_tty 'grant owner' grant owner@trial.test owner
|
||||
check "grant owner: two factors still there in the transaction: granted" bash -c '[ "$1" -eq 0 ] && grep -qF "owner granted to owner@trial.test" "$2"' _ "$RC" "$CASE/out"
|
||||
echo 1 > "$CASE/stub/answers/txn-factors"; fresh_stdin; fresh_log; trial_tty 'grant owner' grant owner@trial.test owner
|
||||
check "grant owner: one factor still there in the transaction: granted" bash -c '[ "$1" -eq 0 ] && grep -qF "owner granted to owner@trial.test" "$2"' _ "$RC" "$CASE/out"
|
||||
rm -f "$CASE/stub/answers/txn-factors"
|
||||
# 7: the e-mail is lowercased before any use.
|
||||
fresh_stdin; fresh_log; trial_tty 'grant sheet_reviewer' grant Foo@Example.com sheet_reviewer
|
||||
|
||||
+6
-5
@@ -1690,14 +1690,16 @@ cmd_account() {
|
||||
read_new_password password
|
||||
create_account "$email" "$password"
|
||||
say "account $email created and confirmed"
|
||||
echo "Next: pnpm db:trial app, sign in, enrol TOTP in Mon compte > Sécurité (two factors for the owner account), then pnpm db:trial grant"
|
||||
echo "Next: pnpm db:trial app, sign in, enrol TOTP in Mon compte > Sécurité (one factor; a second one is an optional backup), then pnpm db:trial grant"
|
||||
}
|
||||
|
||||
# Platform roles follow V1-2_ANATOMICAL_SHEETS.md §5.7.1: the account enrols its factors first, the
|
||||
# operator reads them (name, creation time) and confirms, then the role is assigned last through
|
||||
# the operator path (null actor, JWT-less session) and an audit row records the reason and the
|
||||
# operator. Owner needs two verified TOTP factors, admin one. The database counts them, here and
|
||||
# again inside the grant transaction; a factor name is sanitised in SQL before it reaches the terminal.
|
||||
# operator. Owner and admin each need one verified TOTP factor (owner decision 2026-11-11, db:trial
|
||||
# only; a second factor is an optional backup; the rule for other stacks is V1-2 §5.7.1, unchanged).
|
||||
# The database counts them, here and again inside the grant transaction; a factor name is sanitised
|
||||
# in SQL before it reaches the terminal.
|
||||
factor_count() { # email: verified TOTP factors of the account, or no_account
|
||||
sb_psql -t -A -v email="$1" <<'SQL'
|
||||
-- db-trial:grant-factor-count
|
||||
@@ -1718,7 +1720,6 @@ SQL
|
||||
}
|
||||
grant_platform_role() { # email role
|
||||
local need=1 factors count
|
||||
[ "$2" != owner ] || need=2
|
||||
count="$(factor_count "$1")" || die "the verified TOTP factors of $1 cannot be counted: nothing was granted"
|
||||
[ "$count" != no_account ] || die "no account $1 (pnpm db:trial account $1 first): nothing was granted"
|
||||
[[ "$count" =~ ^[0-9]+$ ]] || die "the verified TOTP factors of $1 cannot be counted: nothing was granted"
|
||||
@@ -1733,7 +1734,7 @@ grant_platform_role() { # email role
|
||||
-- db-trial:grant-role
|
||||
begin;
|
||||
select id::text as uid from auth.users where email = :'email' \gset
|
||||
-- The factors are counted again here: when one went away since the check, no row comes back,
|
||||
-- The factors are counted again here: when fewer than :need remain since the check, no row comes back,
|
||||
-- \gset fails, ON_ERROR_STOP ends the session and the transaction rolls back unfinished.
|
||||
select private.assign_platform_role(null, :'uid'::uuid, :'role'::public.platform_role)::text as role_id
|
||||
where (select count(*) from auth.mfa_factors f
|
||||
|
||||
Reference in new issue
Block a user