feat(supabase): V1-2.1 M4/M5 secure sheet access and review workflow
M4 20261028100000_sheet_access_hardening + M5 20261028110000_sheet_review_workflow (applied together; no unprotected window). Implements contract §5-§14. - Catalogue rights table + owner RPCs; has_mfa / has_aal2_session (live auth.sessions check); grant_active vs caller_has split; catalogue reader predicate; can_edit_sheet on the sheet_editor capability (F14). - AR-1 B: aal2 required on every platform role change, target verified factor, race-free last-owner guard (F18/F19); service_role loses table privileges on the catalogue + profiles/profile_roles and EXECUTE on the role RPCs (F12/F17). - Reviewed lifecycle: version provenance + review columns, content/freeze/ author triggers, rounds/comments/acknowledgments, save/submit/withdraw/ comment/acknowledge/decide, atomic publish_sheet_version(review_id) on the stored verdict, deprecate/archive/restore, species RPCs, equine working copy, uploads with the storage check (F7) + editor INSERT policy + 2 MiB bucket. F1-F3,F5,F6,F8,F9,F13,F15,F16 closed. Verdict is a fixture until M6 (V1-2.3). - O22: SQL business mirror removed, declared status check kept; pgTAP 011 and the Rust generator's SQL parts deleted, ledger retargeted. - Access layer sheets.ts (closed SheetFailure kinds); old client publish gate deleted; types regenerated; upload tool reads via get_sheet_asset_state. Tested on the throwaway sandbox only; DEV untouched. pgTAP 850 (real stack) / 122 (PGlite) green; real-GoTrue AR-1 B + F18 race green; fresh install and M3->M5 upgrade green; V1-1 regression green; rust:check, typecheck, lint, build, types drift clean. BDR-084, LRN-095.
This commit is contained in:
1 parent
9c13bae4bc
commit
77e5fa4cf5
33 files changed
+4613
-1617
No files matched your search
@@ -613,3 +613,16 @@ Alt: A (owner+admin only) rejected: leaves moderator/support weak path; C (accep
|
||||
Review (fresh challenger FATAL(4), all integrated, no ratified decision changed): grant needs target with verified factor; private fns: non-null actor = auth.uid() + aal2, null actor only without JWT; advisory lock both RPCs; DEV precondition before M4 = ENVIRONMENTS §3.6 hardening (public default JWT secret + demo service key + 54321 LAN → aal2 forgeable) + seed owner password changed + role holders listed; recovery reordered (ban, password set with owner, unban, enrol).
|
||||
Reserves: staff read policies (is_platform_admin) stay aal1, owner decision; stolen aal2 session residual; refused attempts not in audit table.
|
||||
Status: ratified; contract only, no code/migration/DEV change; V1-2.1 not authorised.
|
||||
|
||||
## BDR-084 — V1-2.1 M4/M5 secure SQL foundations (sandbox) (2026-10-28)
|
||||
- **Status**: implemented + tested on sandbox; DEV apply is an owner action (contract 16.11)
|
||||
V1-2.1 M4/M5 built + tested on sandbox (not DEV). Migrations `20261028100000_sheet_access_hardening` (M4), `20261028110000_sheet_review_workflow` (M5); applied together (M4 removes Step-4 unsafe write paths, M5 adds the reviewed workflow; no unprotected window).
|
||||
|
||||
Key design choices:
|
||||
- AR-1 B: `private.has_aal2_session()` = aal claim == `aal2` AND the token's `session_id` names a live `auth.sessions` row of the caller at aal2 (closes the stolen-token-after-downgrade window at once, not after jwt_expiry). GoTrue v2.197 probe confirmed: verify upgrades the SAME session to aal2, token carries `aal`+`session_id`+`amr`, exp-iat=3600.
|
||||
- Predicates split by caller vs stored actor: `grant_active(uid,kind)` (no assurance) for stored approvers/acknowledgers; `caller_has(kind)` = `grant_active(auth.uid())` + `has_mfa()` for the session. `can_edit_sheet` redefined on `caller_has('sheet_editor')` + caller==auth.uid() (F14).
|
||||
- F12/F17: `revoke all ... from service_role` on every catalogue table + profiles/profile_roles; role RPCs `EXECUTE` revoked from service_role. service_role stays a GoTrue-admin residual (§13), not a table writer.
|
||||
- F18 last-owner race: one `pg_advisory_xact_lock` in both RPCs and both private writers, guard counts active owners under the lock. Cross-revoke resolves safely (one 200, one refused; one owner remains).
|
||||
- O22 mirror removed: dropped `sheet_document_issues` + the 4 business-mirror helpers; kept `sheet_document_has_shape`, `check_sheet_version_document`, `unknown_assets`; added the declared status check `sheet_all_reviewed` (absent review_status = inherited = refused). pgTAP 011 + the SQL-mirror parts of the Rust `sheet_conformance` generator deleted; ledger retargeted.
|
||||
- Publish gate: `publish_sheet_version(review_id)` atomic; `guard_sheet_version_update` lets draft->published only with an approved round of same version+revision + passed verdict (no direct UPDATE publishes, even table owner). Verdict is a fixture until M6 (V1-2.3).
|
||||
- Reader column grants narrowed; editor needs only `revision` on versions; authors/provenance/fingerprint reach staff via RPCs (`get_sheet_version`).
|
||||
Reference in new issue
Block a user