carlos / platform Public

member backups: spec rev 6, §2b after Astra round 1 (#898)

Own-region only; durable job bound to account/app/host/incarnation;
an export worker operation; caps; a lifecycle rule on downloads/ in AWS
and MinIO; narrowly scoped presigned links never logged or emailed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev a604e10c4796d2d702d53c9e086e193073c4ed46 parent 3d2ac9c
2 files changed, +101 −30
  • docs/superpowers/notes/reviews/member-backups/CODEX-FINDINGS-member-backups-2b.md +29 −0
  • docs/superpowers/specs/2026-11-11-member-backups-design.md +72 −30

CI cancelled — superseded by a newer push — run details

diff --git a/docs/superpowers/notes/reviews/member-backups/CODEX-FINDINGS-member-backups-2b.md b/docs/superpowers/notes/reviews/member-backups/CODEX-FINDINGS-member-backups-2b.md
new file mode 100644
index 000000000..76951d5c8
--- /dev/null
+++ b/docs/superpowers/notes/reviews/member-backups/CODEX-FINDINGS-member-backups-2b.md
@@ -0,0 +1,29 @@
+1. **P1 — §2b Fetch / cross-region: the console lacks permission to sign the promised download.**
+ **Invariant: regional data authority.** The host role can read its own region’s data bucket; sibling-region grants cover writes to `moves/*`, not reads ([main.tf:172](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/infra/modules/region-host/main.tf:172), [group_iam.tf:42](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/infra/modules/region-host/group_iam.tf:42)). Existing forwarding returns sealed results through the deployment bucket; it does not delegate regional storage credentials ([apidbforward.go:617](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/console/apidbforward.go:617)). A usable presigned GET requires the signer’s permission to read that object: [https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html](https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html).
+ **Fix:** refuse cross-region browser downloads in slice 1b and retain the working CLI command. Supporting them requires an explicitly authorized regional signing protocol; do not silently broaden the console’s bucket access.
+
+2. **P1 — §2b Start / Fetch: the job-to-account authorization contract is missing.**
+ **Invariant: a member receives only their account’s database.** “Signed-in member” does not specify how a random job ID is bound to the authorized account, app, host and incarnation. Existing reads resolve membership and app ownership before reading the instance ([apicli.go:39](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/console/apicli.go:39), [apidb.go:203](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/console/apidb.go:203)); the worker checks the signed identity again ([agent.go:209](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/dbreads/agent.go:209)). That bracket ends during preparation, potentially hours before URL issuance.
+ **Fix:** persist the immutable account/app/host/incarnation/region binding with the job. Authorize status and URL issuance against that binding and current membership; refuse stale identity, deleted/recreated instances and mismatched route parameters. Derive the bucket/key server-side, never from browser input or an unrestricted result field. Preserve indistinguishable unauthorized/not-found responses. Require session and CSRF checks for start and URL-issuance POSTs; service credentials remain refused.
+
+3. **P2 — §2b Build / Shares: the reusable worker does not produce a restored-file stream.**
+ **Invariant: tenant database processing stays inside the sandbox.** The worker accepts only query and pull operations. Pull sends checked LTX files without restoring; query restores and emits SQL results ([worker.go:136](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/dbreads/worker.go:136), [worker.go:172](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/dbreads/worker.go:172), [worker.go:203](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/dbreads/worker.go:203)). Its network is disabled and its scratch is private ([carlos-dbread@.service:23](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/host/units/carlos-dbread@.service:23)).
+ **Fix:** specify a new operation and advertised capability. Reuse `RestoreLocal` and its integrity check, then release bounded database/archive bytes over the existing socket only after check B. A trusted agent uploads those bytes to its configured regional bucket. Keep credentials, networking and database decoding out of the opposite side of that boundary. Refuse old workers, disabled `dbreads` and host-claim configurations—the latter already cannot arm this runner ([dbreads.go:46](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/host/dbreads.go:46)).
+
+4. **P2 — §2b Hold / States: neither the expiry rule nor the 24-hour deletion guarantee exists.**
+ **Invariant: bounded retention of downloadable database copies.** Both regional bucket definitions enable versioning and expire noncurrent versions; current objects do not expire ([deployment-buckets/main.tf:90](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/infra/modules/deployment-buckets/main.tf:90), [region-remote-host/main.tf:32](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/infra/modules/region-remote-host/main.tf:32)). The existing one-day `db-reads/` rule is in the deployment bucket, not the data bucket. AWS expiration is asynchronous; versioned cleanup also requires noncurrent-version handling: [https://docs.aws.amazon.com/AmazonS3/latest/userguide/troubleshoot-lifecycle.html](https://docs.aws.amazon.com/AmazonS3/latest/userguide/troubleshoot-lifecycle.html). MinIO likewise requires explicit lifecycle configuration: [https://docs.min.io/aistor/reference/cli/mc-ilm-rule/mc-ilm-rule-add/](https://docs.min.io/aistor/reference/cli/mc-ilm-rule/mc-ilm-rule-add/).
+ **Fix:** define a logical `expires_at`, stop issuing URLs then, and cap each URL at the remaining lifetime. Describe physical deletion as asynchronous. Add prefix-scoped current-version, noncurrent-version, delete-marker and incomplete-upload cleanup to both AWS modules and the MinIO setup contract. Refuse enabling downloads without verified cleanup configuration.
+
+5. **P2 — §2b Start / States: request-scoped forwarding is not a durable background job.**
+ **Invariant: one bounded job survives browser disconnects and reaches a terminal state.** Current admission slots are released when the HTTP handler returns ([apidbforward.go:194](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/console/apidbforward.go:194)); disconnects cancel work ([apidbforward.go:617](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/console/apidbforward.go:617)). Worker election is keyed by request ID, so it does not prevent two different requests for the same instance ([agent.go:236](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/dbreads/agent.go:236)).
+ **Fix:** name the durable job store, atomic per-instance admission key, owner deadline and terminal-state rules. Make duplicate starts return the existing job. For slice 1b, prefer no automatic takeover: an unpicked or interrupted job expires into failure and requires a fresh attempt. Publish `ready` only after confirmed upload completion; reject late completion from an obsolete attempt. Specify state retention and failed-upload cleanup independently of archive expiry.
+
+6. **P2 — §2b Build / Refusals: existing caps do not bound archive generation or repeated-job cost.**
+ **Invariant: downloads cannot exhaust shared disk, workers or storage-request budgets.** Current reservations cover LTX input plus restored bytes, or LTX alone for pulls ([read.go:186](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/dbreads/read.go:186)). They reserve no additional archive file. Limits distinguish restored size, pull bytes and output bytes ([limits.go:46](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/dbreads/limits.go:46)). Planning accumulates listings without a file-count bound ([plan_from.go:30](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/dbdoor/plan_from.go:30)). One concurrent job per instance still permits repeated restores and jobs across many instances.
+ **Fix:** specify input, restored and archive byte caps; reserve every simultaneous scratch file or stream the archive. Bound planning files/pages, total job time, retries, account concurrency and start frequency. Share worker admission with CLI reads and exports. Poll known job keys at a bounded rate and stop at terminal state; do not list the downloads prefix for browser status.
+
+7. **P2 — §2b Fetch / §2 layout: the delivery contract assumes too much about presigned URLs.**
+ **Invariant: the download capability stays narrowly scoped and usable.** Existing database downloads deliberately avoid presigned URLs ([apidb.go:333](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/console/apidb.go:333)). The configured S3 endpoint is a process-wide storage endpoint, with no browser-reachability or HTTPS gate ([s3compat.go:37](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/s3compat/s3compat.go:37), [s3compat.go:66](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/member-backups/internal/s3compat/s3compat.go:66)). Presigned URLs are reusable bearer capabilities and can expire before 15 minutes when their signing credentials expire; membership revocation does not itself revoke an issued URL.
+ **Fix:** require a tested browser-reachable HTTPS endpoint and refuse unsupported configurations before starting work. Sign only the job’s exact GET, with attachment disposition; return the link through a non-cacheable response. Exclude signed URLs from logs, audit details, persistent status, analytics and email, and specify referrer protection. Document the bounded bearer-access window and audit URL issuance rather than claiming a completed download. Show an unavailable reason and the CLI command instead of an enabled primary download action when these requirements fail.
+
+NOT READY
\ No newline at end of file
diff --git a/docs/superpowers/specs/2026-11-11-member-backups-design.md b/docs/superpowers/specs/2026-11-11-member-backups-design.md
index f8a0d4838..5e17e2cc0 100644
--- a/docs/superpowers/specs/2026-11-11-member-backups-design.md
+++ b/docs/superpowers/specs/2026-11-11-member-backups-design.md
@@ -1,6 +1,6 @@
# Backups owners can see and check
-Status: rev 5, 2026-11-11 (D8 download job §2b, D9 UX pass and §2 layout; §2b awaits one Astra round). Rev 4.1: D7 recorded. Astra round 3 READY AFTER FIXES; its one fix (§9's backstop GETs) applied in rev 3.1. Fable 5.2's guidance (PROCEED WITH CHANGES, `FABLE-GUIDANCE-member-backups.md`) applied in rev 4, marked **(F-N)** (§17). Rev 4 changes product text and slicing, not the reviewed mechanisms. Paul's rulings D1-D5 (§11). Astra round 1
+Status: rev 6, 2026-11-11 (§2b rewritten after its Astra round 1, NOT READY, all 7 findings accepted; round 2 owed). Rev 5: D8 download job §2b, D9 UX pass and §2 layout. Rev 4.1: D7 recorded. Astra round 3 READY AFTER FIXES; its one fix (§9's backstop GETs) applied in rev 3.1. Fable 5.2's guidance (PROCEED WITH CHANGES, `FABLE-GUIDANCE-member-backups.md`) applied in rev 4, marked **(F-N)** (§17). Rev 4 changes product text and slicing, not the reviewed mechanisms. Paul's rulings D1-D5 (§11). Astra round 1
(`docs/superpowers/notes/reviews/member-backups/CODEX-FINDINGS-member-backups.md`)
was NOT READY with 3 P1s and 11 P2s; all 14 accepted (§14). Round 2
(`CODEX-FINDINGS-member-backups-R2.md`) was NOT READY with one new P1, two
@@ -225,34 +225,76 @@ Paul: "Is there a case for offering a download via the web console? This
would be via a background job that would have a 'preparing' state and I
guess sent a zip file?" Yes: the CLI command only helps people with a
terminal, and holding the file is the strongest proof the copy exists.
-
-- **Start.** Download a copy (POST, CSRF) creates a job for the instance.
- One job per instance at a time; admitted for the same people as
- `db pull` (any account member); every plan (D1).
-- **Build.** A box in the instance's region runs the job with the
- `dbreads` restore path: the identity bracket (§3), a pinned plan, the
- sandboxed restore worker, `integrity_check`, its size caps. It zips
- `db.sqlite3` and `manifest.json` (TXID, header time, SHA-256, platform
- version, `"files": "not_included"`).
-- **Hold.** The zip goes to the region's data bucket under
- `downloads/<job-id>.zip` (random id), deleted after 24 hours by bucket
- lifecycle. That bucket already holds this instance's replica, so no
- data leaves its trust zone. The console never holds the file.
-- **Fetch.** When ready, the button becomes "Download <file> (<size>)".
- Pressing it asks the console for a presigned GET valid for 15 minutes,
- issued only to a signed-in member at that moment, audited as
- `db-download`. The link is never emailed; the "ready" email links to
- the console page. Presigned GETs work on any S3-compatible store.
-- **States:** none, preparing (button disabled; "usually a minute or
- two"), ready (until the zip expires), failed (one line saying why, with
- the button back). Shown in the section head.
-- **Refused up front:** fleet-placed and pooled instances (as `db pull`),
- instances whose class has no copy, and a job over the size cap
- ("Too large to download here", pointing at the CLI). Another region's
- instance runs the job in its own region, as `db pull` forwarding does.
-- **Shares with 3b.** The nightly export is the same job with the
- owner's bucket as its destination; the two are built on one runner.
-- **Review.** This section gets one Astra round before its plan.
+Rev 6 applies Astra's §2b round 1 (`CODEX-FINDINGS-member-backups-2b.md`,
+NOT READY, 2 P1 + 5 P2, all accepted, marked **(D-N)**).
+
+**Refused up front in 1b:** instances in another region (the console can
+sign only for its own region's bucket, D-1; the CLI command stays);
+fleet-placed and pooled instances (as `db pull`); classes with no copy;
+deployments with host claims on, `dbreads` disabled, or workers older
+than the new operation (D-3); and any deployment whose download
+requirements below aren't verified (D-4, D-7). In each case the section
+shows the reason and the CLI command, never an enabled Download button.
+
+- **The job is a durable record (D-2, D-5).** The console stores it in
+ `console.db`: job id (random), account, app, host, region, the
+ instance's incarnation, who started it, state, `expires_at`, the
+ object key (derived server-side from the job id, never from browser
+ input), size, and a failure reason. One open job per instance, by an
+ atomic unique key; a second start returns the existing job. States:
+ `queued`, `preparing`, `ready`, `failed`, `expired`. A job not picked
+ up, or whose owner misses its deadline (20 minutes), fails; there is no
+ automatic takeover, and a fresh press starts a new job. `ready` is
+ written only after the upload is confirmed; a late completion from an
+ obsolete attempt is refused. Records are kept 7 days, then deleted.
+- **Who (D-2).** Start (POST), status (GET) and link issuance (POST) are
+ person-only, session plus CSRF, admitted for current members of the
+ job's account; service credentials are refused. Every request checks
+ the route's account/app/host against the job's binding and the
+ instance's current identity (a deleted or recreated instance makes the
+ job unusable). Unauthorised and not-found answer the same.
+- **Build (D-3).** A box in the region picks the job up through its
+ existing change-index scope, with a bounded poll of known job keys only.
+ The `dbreads` worker gets a new operation, `export`, advertised as a
+ capability: it restores with `RestoreLocal`, runs `integrity_check`
+ after check B, and streams the database plus `manifest.json` (TXID,
+ header time, SHA-256, platform version, `"files": "not_included"`)
+ over its existing socket. The worker keeps no network and no
+ credentials; the trusted agent zips the stream and uploads it to
+ `downloads/<job-id>.zip` in its own region's data bucket.
+- **Caps (D-6).** Input, restored and archive bytes each capped (the
+ archive is streamed, so no third scratch file); the planner's file cap
+ (§1); 20 minutes per job; no retries; at most 2 open jobs per account
+ and 10 starts per instance per day; worker slots shared with CLI reads
+ and the nightly export. Over a cap: `failed` with the reason, and the
+ CLI pointer.
+- **Expiry (D-4).** `expires_at` is 24 hours after `ready`; after it the
+ console issues no link and the job shows `expired`. Physical deletion is
+ asynchronous: a lifecycle rule on `downloads/` (current versions after 1
+ day, noncurrent versions and delete markers after 1 day, incomplete
+ multipart uploads after 1 day) is added to both AWS data-bucket modules
+ and to the MinIO setup contract. Downloads stay off until the
+ deployment reports the rule verified.
+- **Fetch (D-7).** Pressing the ready button POSTs for a link. The
+ console presigns only that job's exact GET, with
+ `response-content-disposition=attachment`, valid for the lesser of 15
+ minutes and the time left before `expires_at`, and returns it in a
+ `Cache-Control: no-store` response that the page follows with
+ `Referrer-Policy: no-referrer`. Signed URLs never appear in logs, audit
+ details, stored job state, analytics or email. The audit records the
+ issuance (`db-download-link`), not a completed download. A link is a
+ bearer capability for its lifetime and isn't revoked by a membership
+ change; the docs say so. Downloads need the storage endpoint to be
+ HTTPS and reachable by browsers, checked when the feature is enabled;
+ otherwise the section shows the CLI command.
+- **States on the page:** none (Download a copy), preparing (button
+ disabled; "usually a minute or two"; the page polls the job's status
+ at a bounded rate and stops at a terminal state), ready (Download
+ <file> (<size>), until `expires_at`), failed (the reason, button back),
+ expired (button back).
+- **Shares with 3b.** The nightly export uses the same `export` worker
+ operation, with the owner's bucket as the destination.
+- **Review.** Rev 6 needs Astra's §2b round 2 before its plan.
### 3. Restore tests published per box (durability §5.2's tenant half)
@@ -470,7 +512,7 @@ Not in this design's slices.
| Slice | What | Needs | Size |
|---|---|---|---|
| 1 | §1 door (with #893), §2 tab and CLI, the "get a copy" command; the test line reads "not shown yet" | nothing | small |
-| 1b | §2b download job (preparing, ready, zip, 24-hour hold, presigned fetch) | slice 1, one Astra round on §2b | medium |
+| 1b | §2b download job (durable job, export worker operation, 24-hour hold with lifecycle rule, presigned fetch, own region only) | slice 1, §2b review rounds | medium-large |
| 2a | §3 per-box records, the identity bracket, arming, the coverage target, operator alerts. Fixes today's fault where boxes erase each other's verdicts (F-4) | nothing | small-medium |
| 2b | §3 `copy_since` and the console reader, the test line, §4 operator view | 2a | medium |
| 3a | a narrow pull credential (§5a; D7) | nothing | small |