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:
bchanot committed 2026-11-11 22:37:40 +01:00
1 parent 0573d66864
commit 45d74536f5
4 files changed
+30 -18

No files matched your search

+6 -5
View File
@@ -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