spec: platform mail submission, revision 5 — APPROVED (Fable round 3, no P1); P2s applied
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+48
−15
docs/superpowers/specs/2026-11-12-platform-mail-submission-design.md+48 −15
CI passed — run details
diff --git a/docs/superpowers/specs/2026-11-12-platform-mail-submission-design.md b/docs/superpowers/specs/2026-11-12-platform-mail-submission-design.md| index 19670410a..8dd3a0ccf 100644 |
| --- a/docs/superpowers/specs/2026-11-12-platform-mail-submission-design.md |
| +++ b/docs/superpowers/specs/2026-11-12-platform-mail-submission-design.md |
| @@ -1,6 +1,6 @@ |
| # Platform mail submission: instances send without holding a credential |
| -**Date:** 2026-11-12 · **Status:** draft, revision 4, not approved · |
| +**Date:** 2026-11-12 · **Status:** **APPROVED** (Fable 5.2, round 3, no P1; revision 5 applies its P2s) · |
| **Branch:** `design/platform-mail-submission` from `origin/main` `99df838cf` |
| · **Author:** Claude Opus 5.5, for Paul. |
| @@ -71,23 +71,23 @@ route that is not on its box, checks the sender's policy before sending, |
| and sends through SES with **one dedicated IAM user for the fleet**. That |
| user's key is readable only by the mailer. |
| -## 3. Decisions (proposed; none ruled) |
| +## 3. Decisions (approved by review; 7 and 9 ruled by Paul) |
| | # | Decision | Rejected | |
| |---|---|---| |
| | 1 | **Submission is a verb on the existing control socket,** mounted at both bind sites (flat `backend_exec.go:2557`, nested `prepare.go:298`) under its own condition, not under the `Timers`/`UpdatesReader` mount | A network SMTP relay with per-sender passwords, which still puts a credential in every instance. A second per-instance channel | |
| | 2 | **The mailer's credential is a single dedicated IAM user (`carlos-mailer-<region>`), not the box role.** Its key is in a root-written file readable only by the static user `carlos-mailer` (precedent: `/etc/carlos/relay-masters`). The mailer unit has `IPAddressDeny` for IMDS. **The box role gains nothing** | SES on the instance role. Every uid the IMDS gate admits gets the whole role, and the gate admits uid `carlos` by construction (`group-init.sh.tftpl:110-111`), so every flat exec child could send as any identity (round 1, P1-1) | |
| | 3 | **The mailer's peer rule is `instancectl`'s:** `SO_PEERCRED` uid `carlos` **and** pid equal to `carlos-edge.service`'s MainPID. The socket directory is in the instance units' `InaccessiblePaths`, as `/run/carlos-control` is | A uid-only check, which every flat exec child passes (round 1, P1-2) | |
| -| 4 | **The mailer refuses any `(account, app, host)` that is not a route on its own box,** read from the box's registry | Trusting the agent's stamp for any route anywhere | |
| +| 4 | **The mailer refuses any `(account, app, host)` that is not a route on its own box.** It reads this from the bucket's instance records (§5). Where a record names a box (`FleetBox`), that box must be this one. Where it does not, the record's region and pool must be this box's. **The check is therefore exact for fleet-assigned instances and region-and-pool-wide for the rest.** §6 states this | Trusting the agent's stamp for any route anywhere | |
| | 5 | **Every instance of a switched app sends as the app sender** (`SenderAppID`), as owned environments are counted today (`walk_environment.go`). Per-instance senders stay with #148, unbuilt | Inventing instance senders here (round 1, P1-3: nothing on main creates one) | |
| | 6 | **Attribution by SES `EmailTags`** (`account`, `app`, `sender`) on every send through the mailer. **Invariant: a tag is believed only from the mailer's own principal.** `SenderOfCaller` checks the caller first. Only when `ses:caller-identity` is `carlos-mailer-<region>` does it read the tags. Every other caller keeps today's path, and its tags are ignored. Any SMTP-credentialed tenant can set tags with an `X-SES-MESSAGE-TAGS` header (`sesv2/types/types.go:391`), so believing tags from anyone would let a tenant charge its bounces and complaints to another app. Enforced in that one function, with guard test 8.11. **Gated on the spike** (§9 item 1): that the tags arrive in `mail.tags` on Bounce, Complaint and Delivery events | Reading the tag before the caller (revision 2), which lets an unswitched app's sends be charged to a victim (round 2, P1-A). The caller identity alone, which is the same for every switched app (round 1, P1-3) | |
| | 7 | **No layout precondition. Ruled by Paul, 2026-11-12.** Decisions 2–4 make submission no worse than today on either layout (round 2, P2-1), and §6 states the residual | Revision 2's "switched apps nested only". It claimed nested tokens are invisible to flat siblings, but nested isolation is one-way: a flat child runs in the agent's unit with `ReadWritePaths=/data /run/carlos` (`carlos-edge.service:41,50`), and can read a nested instance's env file (`paths.go:43,56`) and dial its control socket (`paths.go:49`). As written, per app, it bought nothing and would have blocked on §9 item 2 | |
| | 8 | **Pause becomes a field on the sender record**, independent of `Provisioned`, **keeping today's pause kinds** (cap, rate, plan, manual: `mail.go:65-88`). Cap pauses lift at the day roll (`resumeStaleCapPause`), and the others do not. The console writes it (`carlos email pause`, and the automatic pauses), and the mailer reads it by etag. **While the app-level key still exists (§7.4's week), a pause also deactivates that key**, as today | Pause as IAM key state, which does not exist once the user is reaped (`SetSenderPaused` returns `ErrNotProvisioned`; `enforceMailLimits` returns early) | |
| | 9 | **The cap is enforced before the send, with a per-box counter** (§4.1 (a), ruled by Paul, 2026-11-12) | Counting only from events, after the send | |
| -| 10 | **The switch.** It is `carlos email submission on --app <a>`, with a `docs/site/cli.md` heading and a `parity/parity.tsv` row. It is **ordered**: the door refuses it unless every route of the app runs a build that has declared the `submit` transport (the app's manifest `mail = "submit"`). When on, no `<P>_SMTP_*` is delivered anywhere, `ReapEnvironment` runs for each existing owned environment's user, and `mintOwnedEnvironmentMail` checks the switch explicitly rather than relying on `Provisioned == nil`. **The precondition holds for as long as the switch is on, not only at the flip.** Adopting, rolling back to, or pinning a build whose manifest lacks the declaration is refused (`release.Manifest`, additive field, `release.go:55-60`). So is waking an older build. The build a route runs is read from its route record's live version. **Before §7.4's reap, `carlos email test --submit`** sends through the submit path per route, as proof rather than a declaration | Flipping before the apps can submit, which is an outage (round 1, P2-3) | |
| +| 10 | **The switch.** It is `carlos email submission on --app <a>`, with a `docs/site/cli.md` heading and a `parity/parity.tsv` row. It is **ordered**: the door refuses it unless every route of the app runs a build that has declared the `submit` transport (the app's manifest `mail = "submit"`). When on, no `<P>_SMTP_*` is delivered anywhere, `ReapEnvironment` runs for each existing owned environment's user, and `mintOwnedEnvironmentMail` checks the switch explicitly rather than relying on `Provisioned == nil`. **The precondition holds for as long as the switch is on, not only at the flip.** Adopting, rolling back to, or pinning a build whose manifest lacks the declaration is refused (`release.Manifest`, additive field, `release.go:55-60`). The refusal names its remedy: **switch submission off first**, which re-mints through `Enable`. Those refusals stop an older build ever becoming live, so waking is **not** refused, because a refused wake would turn a mail gap into a site outage. A wake that finds an undeclared build logs loudly instead The build a route runs is read from its route record's live version. **Before §7.4's reap, `carlos email test --submit`** sends through the submit path per route, as proof rather than a declaration | Flipping before the apps can submit, which is an outage (round 1, P2-3) | |
| | 11 | **`CARLOS_MAIL=submit` follows the bind,** not the switch and not mailer health: set when the switch is on and the control socket is bound (`ctl != nil`). Mailer health is what `503 MAILER_UNAVAILABLE` is for. A health probe at spawn would leave an instance with neither channel for its whole lifetime (round 2, P2-5). rastrillo fails loudly at boot when a switched app has neither `CARLOS_MAIL` nor SMTP variables. It is added to both `agentOwnedNames` (`backend_exec.go:2749`) and `moves.AgentOwnedVars` (`envreport.go:62`), which a test pins as a pair | Setting it from the switch alone, which leaves an app with no SMTP variables and no channel when a bind fails | |
| -### 4.1 The cap counter — for Paul |
| +### 4.1 The cap counter (ruled: (a)) |
| Every instance of a switched app is the app sender (decision 5), and its |
| instances are on many boxes. There are two options. |
| @@ -210,7 +210,9 @@ stays the stated upgrade path, with no app change needed. |
| bounds it to the box. Per-instance uids close this and the residual |
| above together. |
| - **A compromised agent** can send as any route on its box, within caps. |
| - It could already read every flat env file. |
| + It could already read every flat env file. Decision 4 bounds that |
| + agent to its own box only where instance records name a box. Otherwise |
| + it is bounded to the box's region and pool. |
| ## 7. Migration |
| @@ -220,7 +222,7 @@ stays the stated upgrade path, with no app change needed. |
| **Census cards** for `internal/host/units` and `infra/` (AGENTS.md). |
| 2. **Apps first:** re-pin rastrillo in the Oficina apps, declare |
| `mail = "submit"`, deploy. They keep sending over SMTP until the switch. |
| -3. **Flip the switch per app.** Its preconditions (decisions 7, 10, §5 |
| +3. **Flip the switch per app.** Its preconditions (decision 10, and §5's |
| tenants) are checked by the door. |
| 4. **Reap:** per-environment users via `ReapEnvironment`. The app-level |
| user is kept until a week of clean submission, then reaped by the walk |
| @@ -249,10 +251,12 @@ stays the stated upgrade path, with no app change needed. |
| (fake SES). |
| 6. **Header hygiene.** `Bcc:` and `X-SES-*` never reach SES. |
| 7. **Agent-owned variable.** A tenant-supplied `CARLOS_MAIL` is stripped. |
| - `CARLOS_MAIL` is set only when bound and the mailer is healthy. The |
| + `CARLOS_MAIL` is set when the switch is on and the control socket is |
| + bound, whatever the mailer's health (decision 11). The |
| `agentOwnedNames` and `AgentOwnedVars` pair is pinned. |
| -8. **The switch's preconditions.** A flat route, an undeclared build or an |
| - unassociated tenant each refuse the switch. |
| +8. **The switch's preconditions.** An undeclared build or an |
| + unassociated tenant each refuse the switch. A flat route does not |
| + (decision 7, as ruled). |
| 9. **The IMDS gate.** The mailer unit cannot reach IMDS. The box role has |
| no SES. `adopt_advice.go`'s parser cannot read negated sets |
| (`parseNftSkuids`), so this is a unit-file and IAM assertion, not an |
| @@ -267,7 +271,9 @@ stays the stated upgrade path, with no app change needed. |
| event from `carlos-mailer-<region>` is counted against the tagged |
| sender. |
| 12. **The precondition holds while on.** Adopting, rolling back to or |
| - pinning a build without the declaration is refused for a switched app. |
| + pinning a build without the declaration is refused for a switched app, |
| + and the refusal names "switch submission off first". Waking is never |
| + refused. |
| 13. **Pause kinds survive.** A cap pause lifts at the day roll; rate, plan |
| and manual pauses do not. During the overlap week, a pause |
| deactivates the app-level key. |
| @@ -284,10 +290,10 @@ stays the stated upgrade path, with no app change needed. |
| guard is correct either way. |
| - Which characters SES tag values accept, for sender ids containing |
| dots. |
| -2. **Which layout the Oficina apps' instances run in.** Decision 7 needs |
| - every route of a switched app nested. Find out what moves a route |
| - nested ("the layout pass moves the row nested", `backend_exec.go:272`) |
| - and whether Oficina's are. |
| +2. **Which layout the Oficina apps' instances run in.** Informational |
| + only, since decision 7 was cut. It sizes §6's residual for Oficina: |
| + nested routes are not readable by each other, and only flat ones widen |
| + it. |
| 3. **Has the tenant association backfill** (senders spec §4.2.1) landed? |
| 4. **Who changes the infra repo's IMDS gate, if anything.** The |
| decision-2 design needs no gate change, because the box role gains no |
| @@ -346,8 +352,35 @@ stays the stated upgrade path, with no app change needed. |
| | P2-6 pause kinds | Decision 8 and test 8.13 | |
| | §4.1 view | §4.1: recommendation changed to (a), with the true bound | |
| +**Round 3 (Fable 5.2, revisions 3 and 4, head `7929892c0`): APPROVE, no |
| +P1.** The review stops here (stopping rule 1). Revision 5 applies its P2s |
| +without reopening: |
| + |
| +| Finding | Answer | |
| +|---|---| |
| +| P2-a stale text (tests 8.7 and 8.8, §7.3, §9 item 2) | Corrected to the rulings and decision 11 | |
| +| P2-b "on this box" only where a record names one (uid family, wording) | Decision 4 and §6 state the exact and region-and-pool bounds | |
| +| P2-c a refused wake turns a mail gap into an outage | Decision 10: no wake refusal, a loud log instead; the rollback refusal names its remedy; test 8.12 | |
| + |
| +**Round history, for any handoff:** |
| +- Round 1: 3 P1s (two in the uid family, one in attribution). |
| +- Round 2: 1 P1 (attribution) and 6 P2s (two in the uid family). Rule 2 |
| + applied to both families. |
| +- Round 3: no P1. |
| + |
| +**Still needed before build:** the §9 item 1 SES spike, which gates |
| +decisions 6 and 9, and census cards for the build diff. |
| + |
| **P3 follow-up list** (not starting a round): |
| +- `carlos email test --submit`: how a per-route send is driven, given |
| + that only the agent can reach an instance's control socket. It also |
| + needs its CLI docs heading and parity row. |
| +- Where the agent reads the switch from (decision 11). |
| +- If the SES event carries the caller's full ARN, match on that rather |
| + than the bare name. |
| +- §11 sits before §10. |
| + |
| - Whether the cap counts messages or recipients (the console counts Send |
| events). |
| - The IAM backstop expressed as `identity/*` with a `ses:TenantName` |