From 6ceced5c065eb0e5863ee6bdf42181f3243ece24 Mon Sep 17 00:00:00 2001 From: bchanot Date: Wed, 11 Nov 2026 19:54:42 +0100 Subject: [PATCH] chore(memory): TR_PW rotation, init log fix, LRN-127 --- .claude/memory/journal.md | 1 + .claude/memory/learnings.md | 8 +++ .claude/tasks/TODO.md | 4 +- .../2026-11-11-trial-init-log-leak-1907.md | 61 +++++++++++++++++++ 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 .claude/tasks/contracts/2026-11-11-trial-init-log-leak-1907.md diff --git a/.claude/memory/journal.md b/.claude/memory/journal.md index 9479f877..d9d6c0d5 100644 --- a/.claude/memory/journal.md +++ b/.claude/memory/journal.md @@ -548,3 +548,4 @@ R5.4: `draft/{labels,changelog,review_report,drawing,overlay,app_review,svg_comp ## 2026-11-11 - 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. diff --git a/.claude/memory/learnings.md b/.claude/memory/learnings.md index fd2f9fc7..69f3774a 100644 --- a/.claude/memory/learnings.md +++ b/.claude/memory/learnings.md @@ -878,3 +878,11 @@ Trap: substring tests like `*"no such"*` (meant for "No such container" / "no su Apply: never classify Docker errors by substring; exact whole-sentence match per kind on stderr, everything else refuses (see the inspect -f learning). Limit: wording of this client version only. + +## LRN-127 — Postgres image init logs role password: log_statement must be off on server command line (2026-11-11) +**Context**: db:trial first real create 2026-11-11 (255dd67). TR_PW found in `docker logs faunosteo_trial_db` line 379: `postgres@postgres LOG: statement: ALTER USER supabase_admin WITH PASSWORD '…'`. +**Cause** (demonstrated): image `supabase/postgres:17.11.0.004` init script `/docker-entrypoint-initdb.d/migrate.sh` sends role password as SQL text (lines 36/46/54/59) on init temp server; image `/etc/postgresql/postgresql.conf:545` has `log_statement = 'ddl'` → statement + password to stderr = container log. Our `/etc/postgresql.schema.sql` session `set log_statement='none'` runs after → too late. Per-role `log_statement=none` (image migration 20250205060043) also after. +**Fix** (5f63d22): `-c log_statement=none` appended to `exec docker-entrypoint.sh postgres ...` in DB_INIT. Entrypoint `_main` → `docker_temp_server_start "$@"` → `pg_ctl -o "$(printf '%q ' "$@")"` passes every arg after `postgres` to temp server and final server; command line (PGC_S_ARGV) beats postgresql.conf + auto.conf; no init script sets log_statement other than none (grep). Harness check db-trial-check.sh:726, positive control red 372/1 → green 373/0. Static proof only: real proof = create on fresh volume + container log scan (counts only, SUPABASE.md §5.2). Trade-off: DDL no longer logged on trial server. +**Not closed** (named, owner scope): failing init statement still logged (`log_min_error_statement = error`); migrate.sh puts password on psql argv during init; db-sandbox.sh same DB_INIT without flag; DEV CLI stack likely same log line. +**Remediation of exposed value**: one-off TR_PW rotation 2026-11-11 (owner): 5 roles one tx (local logging off), secrets.env, auth/storage/rest recreated by `pnpm db:trial start`; old pw refused on scram path (container network IP; 127.0.0.1 is trust, proves nothing), new ok ×5; db container frozen env keeps dead old value. +**Future application**: any self-hosted Postgres image with init scripts → set logging GUCs on server command line, never in init SQL; mandatory pre-production check in DEPLOY.md security prerequisites. Password probe must use non-trust pg_hba path + control with wrong password. diff --git a/.claude/tasks/TODO.md b/.claude/tasks/TODO.md index 50153d87..38ff096f 100644 --- a/.claude/tasks/TODO.md +++ b/.claude/tasks/TODO.md @@ -694,9 +694,9 @@ Order (BDR-071): P0 docs + decisions → V1-1 clients and animals → V1-2 sheet - [ ] Test anomaly A (owner 2026-11-09, separate from U1/U2): fictitious fingerprints `'a'.repeat(64)` from worker stand-ins (`packages/supabase/tests/sandbox/sheet-fixtures.ts:115` openRound, `sheets-concurrency.sandbox.ts:168`, `sheets-perf.sandbox.ts:169`); 7 published/deprecated sandbox versions fail `check_published`. Fix: real fingerprint through the core (as e2e `fingerprintOf`, `apps/app/e2e/support/catalogue.ts:88`); never weaken the publish gate or the reader check. Needs its own go. - [ ] Test anomaly B (owner 2026-11-09, separate from U1/U2): `packages/supabase/tests/sandbox/sheets-admin.sandbox.ts:181-195` creates the historical working copy and never archives it; slot taken → `admin.spec.ts:717` fails x4. Fix test independence and cleanup; the existing copy `8c315a12-20d4-4432-9db3-7cb88b27a5b4` stays untouched until the owner authorises. Linked: RR-13, the admin.spec confirmation line above. - [ ] Test anomaly C (owner 2026-11-09, separate from U1/U2): integrity failure invisible in catalogue cards; implemented as lot R4; failure shown, never hidden or bypassed. - - [ ] Dedicated persistent manual trial stack (owner 2026-11-09, D8; brief « Après R0 — Implémentation technique », contract .claude/tasks/contracts/2026-11-09-db-trial-stack-1809.md): [x] lot A suites' guard · [x] lot A2 trial dev server target (R13) · [x] lot B1 foundation · [x] lot B2 backups, restore, migrate, rotation · [x] lot B3 accounts, grants, drawings, app · [x] lot C docs · [x] reviews (verifier ECARTS owner-gated only, security PASS, code review + 2 re-reviews fixed: d3bdbbe, f2cbf68) · [x] first create 2026-11-11 at 255dd67 (owner go) · [ ] post-create checks: INTERRUPTED at check 3, TR_PW in the db container log (image migrate.sh), owner decision pending + - [ ] Dedicated persistent manual trial stack (owner 2026-11-09, D8; brief « Après R0 — Implémentation technique », contract .claude/tasks/contracts/2026-11-09-db-trial-stack-1809.md): [x] lot A suites' guard · [x] lot A2 trial dev server target (R13) · [x] lot B1 foundation · [x] lot B2 backups, restore, migrate, rotation · [x] lot B3 accounts, grants, drawings, app · [x] lot C docs · [x] reviews (verifier ECARTS owner-gated only, security PASS, code review + 2 re-reviews fixed: d3bdbbe, f2cbf68) · [x] first create 2026-11-11 at 255dd67 (owner go) · [ ] post-create checks: INTERRUPTED at check 3, TR_PW in the db container log (image migrate.sh); owner decided 2026-11-11 (rotation + fix, sub-item below); the app, its LAN routing and assets not run yet - shortcut: `pnpm db:trial app` takes no lock (scripts/db-trial.sh, comment above cmd_app): stop, backup, migrate, destroy, restore or rotate-* started in another terminal in the second before Vite listens on 5194 goes ahead. Upgrade: a dedicated app lock, shared by app and exclusive for those commands. - - [ ] init log leak: the image's /docker-entrypoint-initdb.d/migrate.sh runs `ALTER USER supabase_admin WITH PASSWORD '…'` while the init server logs statements, before /etc/postgresql.schema.sql (db container log line 379); fix for any future create, and decide the cleanup of the current container log + - [x] init log leak: the image's /docker-entrypoint-initdb.d/migrate.sh runs `ALTER USER supabase_admin WITH PASSWORD '…'` while the init server logs statements, before /etc/postgresql.schema.sql (db container log line 379). Owner 2026-11-11 « Correction minimale de la fuite TR_PW »: [x] one-off TR_PW rotation (5 roles, auth/storage/rest recreated, old password refused on scram, services ok; the db container log and frozen env keep the dead old value, allowed) · [x] fix 5f63d22 `-c log_statement=none` on the server command line (contract .claude/tasks/contracts/2026-11-11-trial-init-log-leak-1907.md, harness 373/0, control 372/1, verifier CONFORME, security PASS, LRN-127) · [ ] real proof: a create on a fresh volume with the log scan (needs its own go) · not closed, named in SUPABASE.md §5.2: init error statements, migrate.sh argv, db-sandbox.sh same DB_INIT - [ ] arbitration 1: narrow the file-wide `# shellcheck disable=SC2016` of db-trial-check.sh to its lines; a readable reason on every directive - [ ] arbitration 2: LAN Playwright environment check proves target, container or service, key issuer and no DEV fallback before connecting (5193 vs 5194 explained and checked) - [ ] arbitration 3: rotate-secrets revokes refresh tokens and handles old access JWTs, tested on the real stack before it is enabled, else it refuses with the limit documented diff --git a/.claude/tasks/contracts/2026-11-11-trial-init-log-leak-1907.md b/.claude/tasks/contracts/2026-11-11-trial-init-log-leak-1907.md new file mode 100644 index 00000000..81098005 --- /dev/null +++ b/.claude/tasks/contracts/2026-11-11-trial-init-log-leak-1907.md @@ -0,0 +1,61 @@ +# CONTRACT — trial-init-log-leak +- date: 2026-11-11 | flow: bugfix | branch: feature/v1-2-anatomical-sheets +- status: active + +## REQUEST (verbatim — IMMUTABLE) +FAUNOSTEO — Correction minimale de la fuite TR_PW (owner, 2026-11-11), part 3 and the scope lines that bind it: + +3. Empêcher que la fuite se reproduise + +Corriger uniquement la cause identifiée. + +Le script d'initialisation de l'image PostgreSQL écrit une instruction ALTER USER contenant le mot de passe pendant que log_statement est actif. + +Configurer PostgreSQL pour désactiver la journalisation des instructions dès le premier démarrage, avant l'exécution des scripts d'initialisation. + +Vérifier que la configuration est bien transmise au serveur temporaire d'initialisation utilisé par l'image. + +Ajouter un test ciblé et consigner ce risque comme point obligatoire de vérification pour toute future installation de production. + +Pas de refonte de l'infrastructure ni de campagne générale de durcissement. + +5. Périmètre + +Ne pas toucher maintenant aux autres sujets : Playwright LAN, destroy, révocation des sessions, durcissement général ou nettoyage des fichiers temporaires. + +Ne pas créer de comptes, importer d'assets, fusionner de branche ni déployer. + +Commits et push autorisés sur la branche de travail après vérification. + +Enregistrer simplement la cause, le correctif et la vérification à prévoir avant production. + +## CLARIFICATIONS +Q: where is the mandatory pre-production check recorded? / A: delegated — DEPLOY.md "Security prerequisites before deploying anything built from `develop`" (the production gate list), plus the trial's own record in docs/development/SUPABASE.md §5.2. +Q: also close adjacent paths (log_min_error_statement at init, migrate.sh's password in psql argv, db-sandbox.sh's identical DB_INIT)? / A: no — owner: "Corriger uniquement la cause identifiée", sandbox untouched; they are named as residual risks in the docs, not fixed. + +## ACCEPTANCE CRITERIA +1. The database container's command line hands `-c log_statement=none` to the image entrypoint after `postgres`, so that `docker_temp_server_start "$@"` passes it to the init temp server (and the final server): the `exec docker-entrypoint.sh postgres` line of DB_INIT in scripts/db-trial.sh carries it. + CHECK: cd /home/bchanot/Documents/faunosteo-v1-2 && grep -E "exec docker-entrypoint\.sh postgres( [^ ]+)* -c log_statement=none( |$)" scripts/db-trial.sh | grep -q . && echo INIT_FLAG_OK + EXPECT: INIT_FLAG_OK + EVIDENCE: MET exit=0 marker-found :: INIT_FLAG_OK +2. The fake-Docker harness carries a targeted check on the db container's `docker run` line asserting that flag on the entrypoint's `postgres` line (the first line of the `sh -c` script), and the whole harness passes. + CHECK: cd /home/bchanot/Documents/faunosteo-v1-2 && grep -q "log_statement=none" scripts/db-trial-check.sh && bash scripts/db-trial-check.sh /tmp/claude-1000/-home-bchanot-Documents-faunosteo/463d8810-0112-4b67-92e4-aa3c30af6089/scratchpad/gate-harness.txt 2>&1 && tail -n 1 /tmp/claude-1000/-home-bchanot-Documents-faunosteo/463d8810-0112-4b67-92e4-aa3c30af6089/scratchpad/gate-harness.txt + EXPECT: db-trial-check: ALL PASS + EVIDENCE: MET exit=0 marker-found :: db-trial-check: ALL PASS +3. Positive control: with the flag removed from DB_INIT (temporarily, on the working copy, then restored), the new check FAILS by name; the executor reports that red run (check name and FAIL line) and the restoration. +4. bash -n and shellcheck stay clean on both scripts (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 -- scripts | grep -c '^+.*shellcheck disable')" -eq 0 ] && echo LINT_OK + EXPECT: LINT_OK + EVIDENCE: MET exit=0 marker-found :: LINT_OK +5. The docs record the cause (the image's migrate.sh sends the password as SQL text on the init temp server while postgresql.conf sets log_statement = 'ddl'), the fix (`-c log_statement=none` on the server command line, passed to the init temp server by the entrypoint), and a mandatory pre-production verification (statement logging off from the first start, and the container log scanned for the password after init) for any self-hosted production database on this image; DEPLOY.md's security prerequisites list carries the verification. + CHECK: cd /home/bchanot/Documents/faunosteo-v1-2 && grep -q "log_statement=none" DEPLOY.md && grep -q "log_statement=none" docs/development/SUPABASE.md && 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 and DEPLOY.md change; db-sandbox.sh, migrations, seed, crates and apps untouched; 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|DEPLOY\.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 value, no new network exposure, no change to any other DB_INIT line or container option. + +## FILE SCOPE +scripts/db-trial.sh (DB_INIT exec line and the comment above DB_INIT), scripts/db-trial-check.sh (one targeted check next to the existing init logging checks, ~line 725), docs/development/SUPABASE.md (§5.2 trial paragraph on the init), DEPLOY.md (security prerequisites list)