chore(memory): BDR-112 db:trial one-factor owner grant, contract and plan
This commit is contained in:
1 parent
45d74536f5
commit
3189a1917d
4 files changed
+113
No files matched your search
@@ -910,3 +910,11 @@ Owner brief « R0 — Autorisation des trois dernières corrections graphiques
|
||||
**Why coherent**: trial GoTrue SITE_URL / API_EXTERNAL_URL / redirect allowlist already = http://192.168.1.100:5194 (set at create and rotation from trial_host); a 127.0.0.1 app origin mismatches GoTrue links.
|
||||
**Trade-off**: app proxies signed-in sessions to the trial gateway; reachable by every device of the private network. Firewall not changed (ENVIRONMENTS.md §3 owner action). Playwright LAN tests still gated by arbitration 2 (environment check before any LAN test): this decision covers manual use of the app only.
|
||||
**Apply**: every later trial session starts the app on 192.168.1.100 unless owner says otherwise; same for `pnpm dev` (already LAN by scripts/dev-env.sh).
|
||||
|
||||
## BDR-112 — db:trial owner grant needs one verified TOTP factor (narrows BDR-083 to non-trial stacks) (2026-11-11)
|
||||
**Decision** (owner 2026-11-11 « Modification de la règle MFA »): db:trial stack only, one verified TOTP factor suffices for owner grant, as for admin and practitioner; second factor optional backup.
|
||||
**Narrows** BDR-083 Shape "first owner: enrol 2 factors first, role assigned last by operator" → db:trial carve-out only. Every other stack (production included), V1-2 §5.6/§5.7.1/§5.7.7 procedure text, IDENTITY.md recommendation: unchanged until distinct study + owner authorisation.
|
||||
**Kept**: verified TOTP before owner/admin (count before typed confirmation + recount `>= :need` inside grant tx, `\gset` zero rows → rollback); catalogue rights need has_verified_totp (+ admin for editor/publisher); aal2 in RPCs/policies; SQL untouched; no bypass.
|
||||
**Where**: scripts/db-trial.sh grant_platform_role `local need=1` (owner branch need=2 dropped), harness 375/0 (0 factors refused, 1 granted, 2 granted, tx recount 0 refused); SUPABASE.md §5.2; V1-2 §5.7.1 step 2 dated note + §5.6 pointer. Commit 45d7453; contract .claude/tasks/contracts/2026-11-11-trial-owner-one-factor-2050.md; verifier CONFORME 7/7, security PASS, 3-lens challenge folded.
|
||||
**Alternatives**: keep 2 for owner (rejected by owner: trial friction); change SQL/production rule (forbidden without study).
|
||||
**Trade-off**: one-factor owner losing device → no second path; recovery = V1-2 §5.7.7 by hand at trial db, or new account via `grant` (SUPABASE.md §5.2).
|
||||
@@ -549,3 +549,4 @@ R5.4: `draft/{labels,changelog,review_report,drawing,overlay,app_review,svg_comp
|
||||
- db:trial closure: code review + 2 fresh re-reviews fixed (d3bdbbe f2cbf68 953ae41). Strict absent match broke on real docker: inspect -f prints '\n' on stdout before stderr error; fresh re-review caught it, stub now splits streams. GATE 0 MET, harness 372/0, plan read-only: create would proceed. Stopped before create, owner go pending.
|
||||
- db:trial first create 2026-11-11 at 255dd67 (owner go): 6 containers, net, 2 volumes as planned, loopback ports only, DEV and sandbox unchanged, 17 migrations, equine draft equal. Interrupted at check 3: TR_PW in db container log, image migrate.sh ALTER USER logged during init. LRN-123..126 written. Owner decision pending.
|
||||
- db:trial TR_PW leak 2026-11-11: owner-ordered one-off rotation (5 roles, auth/storage/rest recreated, old pw refused, services ok, DEV/sandbox unchanged); fix 5f63d22 -c log_statement=none on server cmdline (harness 373/0, control 372/1, verifier CONFORME, security PASS); LRN-127. Real proof pending: create on fresh volume.
|
||||
- db:trial MFA rule 2026-11-11 (owner): owner grant with 1 verified TOTP on trial only (45d7453, harness 375/0, verifier CONFORME, security PASS), BDR-112 narrows BDR-083; production rule unchanged. App on LAN 192.168.1.100:5194 (BDR-111). Accounts owner@trial.local, praticien@trial.local created by owner, 1 verified factor each, no role yet.
|
||||
@@ -0,0 +1,60 @@
|
||||
# CONTRACT — trial-owner-one-factor
|
||||
- date: 2026-11-11 | flow: feat | branch: feature/v1-2-anatomical-sheets
|
||||
- status: active
|
||||
|
||||
## REQUEST (verbatim — IMMUTABLE)
|
||||
FAUNOSTEO — Modification de la règle MFA
|
||||
|
||||
Je souhaite modifier la décision concernant le nombre de facteurs TOTP.
|
||||
|
||||
Un seul facteur TOTP enrôlé et vérifié doit suffire pour les comptes owner, admin et praticien.
|
||||
|
||||
Un deuxième facteur reste facultatif comme méthode de secours.
|
||||
|
||||
Vérifie où la règle des deux facteurs obligatoires pour owner est appliquée (scripts db:trial, contrats, tests et règles de sécurité).
|
||||
|
||||
Adapte cette règle si elle est spécifique à la pile d'essai, tout en conservant :
|
||||
- L'obligation d'un TOTP vérifié avant l'attribution des rôles privilégiés.
|
||||
- Le niveau AAL2 exigé pour les opérations sensibles.
|
||||
- Les contrôles d'autorisation existants.
|
||||
- L'absence de contournement du MFA.
|
||||
|
||||
Ne modifie pas les règles de production sans étude et autorisation distinctes.
|
||||
|
||||
Teste, fais vérifier et documente le changement avant de reprendre les commandes grant.
|
||||
|
||||
Ne touche ni à DEV ni à la sandbox automatisée. Ne recrée aucun compte et ne réinitialise aucune donnée.
|
||||
|
||||
## CLARIFICATIONS
|
||||
Q: where is the two-factor owner rule applied? / A: (investigation, main loop) enforced only by scripts/db-trial.sh (`need=2` for owner in grant_platform_role) and pinned by scripts/db-trial-check.sh; the SQL (`private.assign_platform_role`, `private.has_verified_totp`) requires one verified factor on the session path and none on the operator path, never two; the contract docs/development/V1-2_ANATOMICAL_SHEETS.md §5.7.1, §5.7.2, §5.7.7 state "two factors on two devices before the first grant on any stack" as an operator procedure (covers production); docs/development/IDENTITY.md calls it a recommendation; apps/app/e2e/shell/admin.spec.ts A0 and packages/supabase/tests/sandbox/seed-owner-mfa.sandbox.ts enrol two factors as a scenario (they do not require two; sandbox suites, untouched).
|
||||
Q: production rule? / A: unchanged (owner: no production rule change without a distinct study and authorisation): V1-2 §5.7 keeps its text; a dated note scopes the db:trial exception; IDENTITY.md untouched.
|
||||
|
||||
## ACCEPTANCE CRITERIA
|
||||
1. scripts/db-trial.sh grants `owner` with one verified TOTP factor, as `admin`: no factor count of 2 remains in grant_platform_role; the factor count before the typed confirmation and the recount inside the grant transaction (`>= :need`, `\gset` fails on zero rows) both stay, with need = 1.
|
||||
CHECK: cd /home/bchanot/Documents/faunosteo-v1-2 && f=scripts/db-trial.sh && ! grep -qE 'need=2|\|\| need=' "$f" && grep -q 'local need=1' "$f" && grep -q '>= :need' "$f" && grep -q 'factor_count "\$1"' "$f" && grep -q 'confirm "grant \$2"' "$f" && echo ONE_FACTOR_OK
|
||||
EXPECT: ONE_FACTOR_OK
|
||||
EVIDENCE: MET exit=0 marker-found :: ONE_FACTOR_OK
|
||||
2. The harness pins it: owner with 0 verified factors refused ("owner needs 1", nothing granted, no role SQL); owner with 1 factor granted with `-v need=1`; owner with 2 factors still granted (optional backup); the in-transaction recount falling to 0 refuses, nothing granted; admin and catalogue-right cases unchanged; the whole harness passes.
|
||||
CHECK: cd /home/bchanot/Documents/faunosteo-v1-2 && grep -q 'owner needs 1' scripts/db-trial-check.sh && grep -q -- '-v role=owner -v need=1' scripts/db-trial-check.sh && ! grep -q 'need=2' scripts/db-trial-check.sh && bash scripts/db-trial-check.sh </dev/null > /tmp/claude-1000/-home-bchanot-Documents-faunosteo/463d8810-0112-4b67-92e4-aa3c30af6089/scratchpad/gate-harness-mfa.txt 2>&1 ; tail -n 1 /tmp/claude-1000/-home-bchanot-Documents-faunosteo/463d8810-0112-4b67-92e4-aa3c30af6089/scratchpad/gate-harness-mfa.txt
|
||||
EXPECT: db-trial-check: ALL PASS
|
||||
EVIDENCE: MET exit=0 marker-found :: db-trial-check: ALL PASS
|
||||
3. Kept unchanged: every SQL file, the catalogue-right checks (`private.has_verified_totp` before sheet_editor / reviewer / publisher), aal2 in the app and RPCs, the operator-path audit row; no MFA bypass added.
|
||||
CHECK: cd /home/bchanot/Documents/faunosteo-v1-2 && [ -z "$(git diff --name-only HEAD -- supabase apps packages crates scripts/db-sandbox.sh)" ] && [ "$(git diff -U0 HEAD -- scripts/db-trial.sh | grep -cE '^[-+].*(has_verified_totp|is_platform_admin|log_event|assign_platform_role)')" -eq 0 ] && echo KEPT_OK
|
||||
EXPECT: KEPT_OK
|
||||
EVIDENCE: MET exit=0 marker-found :: KEPT_OK
|
||||
4. bash -n and shellcheck clean, no new directive.
|
||||
CHECK: cd /home/bchanot/Documents/faunosteo-v1-2 && bash -n scripts/db-trial.sh && bash -n scripts/db-trial-check.sh && shellcheck -x scripts/db-trial.sh scripts/db-trial-check.sh && [ "$(git diff -U0 HEAD -- scripts | grep -c '^+.*shellcheck disable')" -eq 0 ] && echo LINT_OK
|
||||
EXPECT: LINT_OK
|
||||
EVIDENCE: MET exit=0 marker-found :: LINT_OK
|
||||
5. Docs: SUPABASE.md §5.2 (grant row, first-use step 1) and the script's `account` hint say one verified factor for owner and admin, a second optional as backup; V1-2_ANATOMICAL_SHEETS.md carries a dated note (owner 2026-11-11) that the db:trial stack takes one factor for the owner grant while the rule for every other stack (production included) is unchanged pending a distinct study and authorisation; IDENTITY.md unchanged.
|
||||
CHECK: cd /home/bchanot/Documents/faunosteo-v1-2 && ! grep -q 'two for owner' docs/development/SUPABASE.md && ! grep -q 'enrol two TOTP' docs/development/SUPABASE.md && grep -q '2026-11-11' docs/development/V1-2_ANATOMICAL_SHEETS.md && [ -z "$(git diff --name-only HEAD -- docs/development/IDENTITY.md)" ] && ! grep -q 'two factors for the owner account' scripts/db-trial.sh && echo DOCS_OK
|
||||
EXPECT: DOCS_OK
|
||||
EVIDENCE: MET exit=0 marker-found :: DOCS_OK
|
||||
6. Scope: only scripts/db-trial.sh, scripts/db-trial-check.sh, docs/development/SUPABASE.md, docs/development/V1-2_ANATOMICAL_SHEETS.md change; the untracked ChatGPT review file kept.
|
||||
CHECK: cd /home/bchanot/Documents/faunosteo-v1-2 && [ -z "$(git diff --name-only HEAD | grep -vxE 'scripts/db-trial\.sh|scripts/db-trial-check\.sh|docs/development/SUPABASE\.md|docs/development/V1-2_ANATOMICAL_SHEETS\.md|\.claude/tasks/.*')" ] && [ -f faunosteo-v1-2-6-revue-ux-chatgpt.md ] && echo SCOPE_OK
|
||||
EXPECT: SCOPE_OK
|
||||
EVIDENCE: MET exit=0 marker-found :: SCOPE_OK
|
||||
7. No secret, no DEV or sandbox action, no account or data change (harness = fake Docker only).
|
||||
|
||||
## FILE SCOPE
|
||||
scripts/db-trial.sh (grant_platform_role ~1719-1747, its comment ~1696-1700, the account hint ~1693), scripts/db-trial-check.sh (grant cases ~1211-1242 and ~1312-1323), docs/development/SUPABASE.md (§5.2 grant row ~867, first-use ~874), docs/development/V1-2_ANATOMICAL_SHEETS.md (§5.7.1 step 2 dated note, §5.6 pointer)
|
||||
@@ -0,0 +1,44 @@
|
||||
# PLAN — db:trial owner grant with one verified TOTP factor
|
||||
|
||||
Contract: .claude/tasks/contracts/2026-11-11-trial-owner-one-factor-2050.md
|
||||
|
||||
## Facts (investigated)
|
||||
- scripts/db-trial.sh `grant_platform_role` (≈1719-1747): `local need=1 factors count`, then `[ "$2" != owner ] || need=2`; `factor_count` before the typed confirmation; the grant transaction recounts verified TOTP factors (`>= :need`) and `\gset` fails on zero rows → ON_ERROR_STOP → rollback; operator path `private.assign_platform_role(null, …)` + `private.log_event` audit row.
|
||||
- SQL never requires two: `private.assign_platform_role` checks `has_verified_totp` (≥1) for a non-null actor only; aal2 lives in the RPCs and policies. Nothing SQL changes.
|
||||
- The two-factor rule elsewhere: V1-2_ANATOMICAL_SHEETS.md §5.7.1 (≈416 "two factors on two devices before the first grant on any stack"), §5.7.2 (≈551, ≈591), §5.7.7 (≈688, ≈699); IDENTITY.md ≈189 (recommendation). Production/operator procedure: unchanged.
|
||||
- Harness stub (db-trial-check.sh ≈258-264): `txn-factors` file = the count the transaction finds; `< need` → "no rows returned for \gset", exit 3.
|
||||
|
||||
## Changes
|
||||
1. scripts/db-trial.sh
|
||||
- `grant_platform_role`: drop the owner branch; `local need=1 factors count` stays (owner and admin both need one). Keep `-v need="$need"` and `>= :need` (the recount stays in the transaction). Messages unchanged in shape ("$1 holds $count verified TOTP factor(s), $2 needs $need: …").
|
||||
- [challenge] SQL comment inside the grant heredoc (≈1736-1737) "when one went away since the check, no row comes back" → "when fewer than :need remain since the check, no row comes back" (comment line only).
|
||||
- Comment above `factor_count` (≈1696-1700): "Owner needs two verified TOTP factors, admin one" → one verified factor for owner and admin (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).
|
||||
- `cmd_account` hint (≈1693): "(two factors for the owner account)" → "(one factor; a second one is an optional backup)".
|
||||
2. scripts/db-trial-check.sh
|
||||
- ≈1213-1216: `set_factors 0`; owner refused: "owner needs 1" + "nothing was granted"; no role SQL ran. Rename the check names accordingly ("grant owner with no factor: refused (one needed), nothing assigned").
|
||||
- [challenge: placement] Do NOT add the success case right after the zero-factor refusal (its grant SQL would stay in the stub stdin and break the `no_role_assigned` checks at ≈1220/1223). Add it right after the existing `set_factors 1` at ≈1236 and BEFORE the admin grant at ≈1237: `fresh_stdin; fresh_log; trial_tty 'grant owner' grant owner@trial.test owner`, check granted ("owner granted to owner@trial.test", rc 0) and `log_has "-v email=owner@trial.test -v role=owner -v need=1 -v operator="`; then `fresh_stdin` before the existing admin case so the admin checks stay as they are.
|
||||
- ≈1217 `set_factors 2` and the following owner cases stay (wrong phrase, piped phrase, unreadable factors, failing role SQL, granted with factors shown): owner with two factors still granted (the optional backup case).
|
||||
- ≈1234: `need=2` → `need=1`.
|
||||
- ≈1316-1322: `echo 0 > txn-factors` (the transaction finds none: count 1 or 2 before, 0 inside) → nothing granted; check name "count then 0"; then `echo 1 > txn-factors` → granted ("one factor still there in the transaction: granted").
|
||||
- No other check changes; no new helper; no shellcheck directive.
|
||||
3. docs/development/SUPABASE.md §5.2
|
||||
- grant row (≈867): "two for owner, one for admin" → "one for owner and for admin (owner decision 2026-11-11; a second factor is an optional backup)".
|
||||
- first-use step 1 (≈874): "enrol two TOTP factors" → "enrol one TOTP factor (a second is an optional backup)", plus one sentence [challenge]: 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`.
|
||||
4. docs/development/V1-2_ANATOMICAL_SHEETS.md [challenge: anchor]: the dated note goes right after §5.7.1 step 2 (≈551-552, "the future owner signs in, enrols two TOTP factors on two devices…"), the procedure db:trial cites (script comment, audit reason "V1-2 contract 5.7.1", SUPABASE.md, TRIAL_STACK.md); the §5.6 sentence at ≈415-416 ("The owner enrols two factors on two devices before the first grant on any stack.") gets only a short pointer "(db:trial exception: §5.7.1)". Note text: "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." No other contract line changes.
|
||||
|
||||
## Edge cases
|
||||
- Zero factors / no account / unreadable count: refused before the confirmation (unchanged paths).
|
||||
- A factor removed between the check and the transaction: recount `>= 1` → zero rows → rollback (pinned by the txn-factors=0 case).
|
||||
- Admin, catalogue rights (has_verified_totp, is_platform_admin for editor/publisher), sanitised factor names: unchanged.
|
||||
|
||||
## Precondition (orchestrator, owner-approved 2026-11-11)
|
||||
The harness refuses while the trial ports (58xxx, 5194) listen. Before dispatch the orchestrator stops the app and runs `pnpm db:trial stop` (data kept); after the gates it runs `pnpm db:trial start` and the app on 192.168.1.100. The executor never stops or starts anything; grants resume only after ALL PASS.
|
||||
|
||||
## Tests
|
||||
- `bash -n`, `shellcheck -x` on both scripts.
|
||||
- `bash scripts/db-trial-check.sh </dev/null` (fake Docker, ≈2.5 min; the real trial stack's ports must be free: if the harness refuses for a port in use, report BLOCKED, never stop anything).
|
||||
|
||||
## Disposition
|
||||
- [challenge] BDR-083 (ratified 2026-10-28, decisions.md:611) says "first owner: enrol 2 factors first, role assigned last by operator", no stack carve-out: narrowed for db:trial only by a new BDR at CAPITALIZE (owner decision 2026-11-11); production and every other stack keep BDR-083 as is.
|
||||
- `need` stays (fixed at 1) for the in-transaction recount and the stub's txn-factors emulation: the smaller diff.
|
||||
- honors BDR-107..110 (trial stack design) by changing only the trial script's operator gate; honors the owner's "no production rule change" by leaving SQL, IDENTITY.md and the §5.7 procedure text intact with a scoped note; no in-force BDR requires two factors on the trial stack (the rule was a V1-2 §5.7.1 procedure line applied by the script).
|
||||
Reference in new issue
Block a user