From 6c36e2f22d03946f9d2c854c2f2c4bddbcb4d763 Mon Sep 17 00:00:00 2001 From: bchanot Date: Tue, 27 Oct 2026 13:52:05 +0100 Subject: [PATCH] docs(supabase): sandbox role prerequisite for the DEV restore check --- .claude/memory/journal.md | 4 ++++ .claude/memory/learnings.md | 5 +++++ docs/development/SUPABASE.md | 20 ++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index ee47ca0e..93ee4cd7 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -442,3 +442,7 @@ R5.4: `draft/{labels,changelog,review_report,drawing,overlay,app_review,svg_comp ## 2026-10-26 (V1-1.7 restore check closed before owner run) - 26 vs 28: my report double-counted (pg_reload_conf/pg_stat_statements_reset inside "7 GRANT"); log = 26. Rehearsal 2 sandbox, 4 variants, real exit codes; retained filtered TOC + single transaction, exit 0, rows + privileges identical. DEV D=21 → 29 exclusions expected. - §3.3 step 2/3b rewritten, replayed verbatim on sandbox. LRN-091. STOP: owner runs steps 0-4. + +## 2026-10-27 (V1-1.7 DEV preflight + backup + restore check, owner-authorized steps 0-3b) +- Preflight ok (vault 0, D=21, 28+15 lines = 2026-10-26, M1-M3 pending). pg_dump + storage tar ok outside Git, mode 600, dump sha256 kept. +- 3b run 1 exit 1: role supabase_functions_admin missing in sandbox. Owner authorized option A: NOLOGIN role sandbox only. Run 2 exit 0, empty log, 28+15 identical, scratch DB dropped, DEV unchanged. LRN-092. STOP: awaiting owner go for step 4. diff --git a/.claude/memory/learnings.md b/.claude/memory/learnings.md index ff3f8b43..06227084 100644 --- a/.claude/memory/learnings.md +++ b/.claude/memory/learnings.md @@ -634,3 +634,8 @@ Apply: any procedure on DEV → read CLI behaviour from installed binary; read-o Context: V1-1 restore check. LRN-090 (4) called 26 pg_restore errors "privilege refusals" and report double-counted them (28): wrong frame. Real: 26 TOC entries `postgres` cannot replay under `--no-owner` on same Supabase image: 18 DEFAULT ACL of supabase_admin/supabase_auth_admin, 5 vault ACL (grant option to self), ACL pg_reload_conf + pg_stat_statements_reset, COPY vault.secrets = data load fail, lossless only with vault empty. Each failing entry also carries other grants (service_role, anon). `--no-acl` loses app grants; `--exit-on-error` alone stops at COPY. Fix: `pg_restore --list` → exclude exact entries by anchored regex → count per kind must equal catalog prediction (D default ACL rows + 8) → `--use-list --single-transaction --exit-on-error` → exit 0, empty log, rows md5 + effective ACL (`acldefault`) identical. pg_dump drops ACL equal to default → compare effective, not stored. Expected count is per-instance: DEV D=21 vs sandbox 18 (supabase_functions schema). Apply: any restore check → real exit status from shell, every failing command classified (object, cause, data impact), conditions explicit (empty table), prefer filtered TOC with exit 0; derive expected exclusions from target catalog, never from rehearsal host; never widen pattern to go green. + +## LRN-092 | 2026-10-27 | Restore rehearsal on sandbox dump proves nothing about DEV-only objects; first real-dump run + +Context: V1-1 step 3b, first run on real DEV dump. Filtered TOC (29 = D+8) right, but exit 1: `GRANT USAGE ON SCHEMA supabase_functions` names cluster role `supabase_functions_admin`, absent in sandbox (roles are cluster-level, not in dump). Rehearsal on sandbox dump (LRN-091) could not see it. Fix: NOLOGIN no-privilege role in sandbox only → exit 0, empty log, 28+15 identical. +Apply: restore check on real dump before trusting rehearsal; roles named by ACL/owner entries must exist in target cluster (`--no-owner` needs name, not powers); never widen exclusions, fix the target; create minimal role, never copy login/CREATEROLE/password. diff --git a/docs/development/SUPABASE.md b/docs/development/SUPABASE.md index 639980e8..423bc80d 100644 --- a/docs/development/SUPABASE.md +++ b/docs/development/SUPABASE.md @@ -334,6 +334,16 @@ tar -tvf "$B/dev-before-v1-1-storage.tar" | grep -c '^-' # the volume's file c # 3b. The dump restores, on the isolated stack (never on the DEV server), with exit status 0: a scratch # database of the sandbox, restored in one transaction that stops at the first error, compared with # step 2, then dropped. `restore_check_v1_1` is the only database created or dropped here. +# Prerequisite, sandbox only: DEV owns the cluster role `supabase_functions_admin` (schema +# `supabase_functions`), a fresh sandbox does not, and the dump's ACL entries name it. Create +# it once there, NOLOGIN with no global privilege (what a no-owner replay needs); never on DEV: +docker exec -i faunosteo_dbsandbox_db sh -c 'PGPASSWORD="$POSTGRES_PASSWORD" psql -X -q -v ON_ERROR_STOP=1 -h 127.0.0.1 -U postgres -d postgres' <<'SQL' +do $$ begin + if not exists (select 1 from pg_roles where rolname = 'supabase_functions_admin') then + create role supabase_functions_admin nologin nosuperuser nocreaterole nocreatedb noreplication nobypassrls noinherit; + end if; +end $$; +SQL # The restore leaves out the D + 8 TOC entries `postgres` may not replay; the dump file itself stays # complete and unchanged (the list is a copy of its table of contents): # - D « DEFAULT ACL … supabase_admin | supabase_auth_admin »: default privileges for objects those @@ -392,6 +402,16 @@ data (2026-10-26, a 156 MB dump of the sandbox's `postgres` database at M3, - the filtered list with `--single-transaction --exit-on-error`: exit 0, empty log, the 28 lines and the 15 privilege lines identical. Retained. +First run on the real DEV dump (2026-10-27): the 29 expected entries were +left out (D = 21), and the restore stopped with exit 1 on +`GRANT USAGE ON SCHEMA supabase_functions TO postgres`: role +`supabase_functions_admin` missing from the sandbox (DEV: LOGIN, CREATEROLE, +`search_path=supabase_functions`, owns the `supabase_functions` objects). +With the NOLOGIN role above and nothing else changed: exit 0, empty log, the +28 and 15 lines identical, schema `supabase_functions` restored with its 2 +tables. The DEV role's login, CREATEROLE and password are not copied: no +privilege is exercised by a `--no-owner` replay. + A table whose stored ACL is the explicit owner-only one comes back with no ACL, the same privileges (pg_dump leaves out an ACL equal to the default): `privs.sql` therefore compares effective ACLs (`acldefault`). DEV differs