spec: platform mail submission, revision 3 — round 2 answered
Tags believed only from the mailer's principal (rule 2, third option); layout precondition cut and the true residual stated, for Paul's ruling; operator-armed mailer key with rotation; read-only bucket grants; pause kinds kept; precondition holds while on; cap recommendation now (a).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+119
−41
docs/superpowers/specs/2026-11-12-platform-mail-submission-design.md+119 −41
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 a84055a52..e0c65cdca 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 2, not approved · |
| +**Date:** 2026-11-12 · **Status:** draft, revision 3, not approved · |
| **Branch:** `design/platform-mail-submission` from `origin/main` `99df838cf` |
| · **Author:** Claude Opus 5.5, for Paul. |
| @@ -8,9 +8,16 @@ |
| 1 (`297b5a74a`) returned CHANGES REQUIRED, with 3 P1s, 6 P2s and 5 P3s. |
| P1-1 and P1-2 are one fault family, **"uid `carlos` does not separate the |
| agent (or the mailer's principal) from a tenant"**. P1-3 is "attribution, |
| -cap and pause need a home". Revision 2 answers all of them (Appendix A). |
| -Round 2 is due. If it finds another fault in the uid family, stopping rule |
| -2 sends the choice to Paul, and the simplest cut is §3 decision 7. |
| +cap and pause need a home". Revision 2 (`8997b3914`) answered them. |
| +Round 2: Fable 5.2 returned CHANGES REQUIRED with **one P1, in the |
| +attribution family**: a forged event tag. There were also six P2s, two of |
| +them in the uid family. Both families have now had findings two rounds |
| +running, so **stopping rule 2 applies to both.** Revision 3 does not write |
| +third fixes. For attribution it takes rule 2's third option: state the |
| +invariant, enforce it in one place, and guard it with a test (decision |
| +6). For the uid family it puts the choice to Paul (decision 7, §11). |
| +Round 3 is limited to this revision's diff and Paul's rulings. A fourth |
| +round needs Paul's go. |
| **Builds on:** `2026-09-15-tenant-email-senders-design.md` ("Extend the |
| IAM-per-sender model now, and iterate towards a platform SMTP relay", and |
| @@ -70,35 +77,34 @@ user's key is readable only by the mailer. |
| | 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 | |
| | 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. `sesevents.go`'s `SenderOfCaller` learns to read the tag **before** the caller identity, because with one sending principal the caller identifies nobody. **This is gated on a spike** (§9 item 1): that the tags arrive in `mail.tags` on Bounce, Complaint and Delivery events | The caller identity, which becomes the same for every app (round 1, P1-3) | |
| -| 7 | **The switch is refused for an app with any flat-layout route,** at the door and again at the agent's mount. Switched apps are nested only | Allowing flat routes, whose residual is the uid family. Optional: round 2 may show decisions 2–4 make flat routes no worse than today, and then Paul can lift it | |
| -| 8 | **Pause becomes a field on the sender record** (`Paused`, with reason and time), independent of `Provisioned`. The console writes it (`carlos email pause`, and the automatic bounce and complaint pauses), and the mailer reads it by etag | Pause as IAM key state, which does not exist once the user is reaped (`SetSenderPaused` returns `ErrNotProvisioned`; `enforceMailLimits` returns early) | |
| +| 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 | **Proposed: no layout precondition.** Decisions 2–4 make submission no worse than today on either layout (round 2, P2-1), and §6 states the residual. **Paul's call** under stopping rule 2 (§11 item 1) | 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. Where the counter lives is Paul's call** (§4.1) | 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` | Flipping before the apps can submit, which is an outage (round 1, P2-3) | |
| -| 11 | **`CARLOS_MAIL=submit` follows the outcome,** not the switch: set only when the control socket is bound (`ctl != nil`) **and** the mailer answers a health probe. 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 | |
| +| 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) | |
| +| 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 |
| -Every instance of a switched app is the app sender (decision 5), and the |
| -app's instances are on many boxes. So "before the send" needs a shared |
| -count. There are two options. |
| - |
| -- **(a) Per box, before the send; fleet-wide after event latency.** Each |
| - mailer keeps a durable daily counter per sender and refuses at the cap. |
| - Overshoot is bounded by **boxes holding the app × cap**, until SES |
| - events reach the console and it pauses the sender (decision 8). Simple, |
| - and needs no new coordination. |
| -- **(b) Leased from the bucket.** A per-sender, per-day counter object in |
| - the control-plane bucket, with CAS by etag (the senders spec's records |
| - already use one etag per object). A mailer leases an allowance (for |
| - example 20 sends), spends it locally, and returns what is left at |
| - expiry. Overshoot is bounded by **outstanding leases**, which is small. |
| - More work: a lease object, expiry, and contention under bursts. |
| - |
| -**Author's recommendation: (b).** The Oficina apps put every team's |
| -instances under one app sender, so (a)'s bound grows with the number of |
| -boxes. If Paul prefers to ship sooner, (a) with a low cap is acceptable, |
| -and (b) can replace it without an app change. |
| +Every instance of a switched app is the app sender (decision 5), and its |
| +instances are on many boxes. There are two options. |
| + |
| +- **(a) Per box, before the send; fleet-wide from events.** Each mailer |
| + keeps a durable daily counter per sender and refuses at the cap. The |
| + console still counts every send from SES events and sets the cap pause |
| + (decision 8), and §5's per-sender token bucket limits how fast any box |
| + sends. So **overshoot is roughly the per-sender rate × event latency, |
| + not boxes × cap.** It needs no new coordination, and the mailer needs |
| + only bucket reads. |
| +- **(b) Leased from the bucket.** A per-sender, per-day counter object |
| + with CAS by etag, from which mailers lease small allowances. Overshoot |
| + is bounded by outstanding leases. It costs a lease object, expiry, burst |
| + contention, and **bucket-write authority on the mailer.** |
| + |
| +**Recommendation, changed in revision 3: (a).** The cap is an abuse brake, |
| +not a billing limit, and round 2 showed that (a)'s true bound is set by |
| +rate × event latency. Revision 2 recommended (b) on a looser bound. (b) |
| +stays the stated upgrade path, with no app change needed. |
| ## 4. The verb |
| @@ -136,9 +142,26 @@ and (b) can replace it without an app change. |
| - **Its socket.** A root-owned socket directory in every instance unit's |
| `InaccessiblePaths`. |
| - **The peer rule** is decision 3. |
| -- **Its credential.** A root-written file, `0640 root:carlos-mailer`, |
| - holding one IAM user's key per region. The infra repo writes it, as it |
| - writes `relay-masters`. |
| +- **Its credential.** A root-owned file, `0640 root:carlos-mailer`, under |
| + a root-owned directory that uid `carlos` cannot traverse. It holds one |
| + IAM user's key per region. |
| + - **Delivery: armed by the operator by hand,** as `relay-masters` is |
| + (`variables.tf:304`, `bootstrap.go:267-269`). Revision 2 wrongly said |
| + the infra repo writes it. |
| + - **The key never passes through anything uid `carlos` can read.** Not |
| + `user_data` (readable from IMDS by flat children), not an SSM |
| + parameter the host role may read (`main.tf:519-527` records a key |
| + exposed that way), and not the bucket. |
| + - **Rotation:** IAM allows two keys per user. The procedure is to create |
| + the second key, arm it on every box in the region (the mailer reads |
| + both and uses the newer), confirm every box has it, then delete the |
| + old key. Each step is an operator runbook entry. |
| +- **What else the mailer's user may do: read only,** on the bucket keys |
| + for this region's sender records, domain records and instance records: |
| + `apps/*/*/email/senders/*`, the domain records, and the instance |
| + records. **"Route on this box" (decision 4) is read from the instance |
| + records in the bucket,** not the agent's `registry.db`, which lives in |
| + the agent's writable tree. **No bucket write** under §4.1 (a). |
| - **The send.** SES v2 `SendEmail` with `Content.Raw`, an explicit |
| `Destination` taken from the envelope, the sender's |
| `ConfigurationSetName`, `TenantName` when the sender has one, and |
| @@ -169,14 +192,20 @@ and (b) can replace it without an app change. |
| - **An instance can submit only as its own route.** The agent stamps the |
| route from the socket, and the mailer accepts only the agent's main |
| process and only routes on its box. |
| -- **Residual, stated.** On a box that also runs flat instances (any app, |
| - switched or not), a compromised flat instance can read a flat sibling's |
| - admin token and submit as that sibling, **on that box only**. That is |
| - the same reach it has today over that sibling's SMTP password. It cannot |
| - reach the mailer socket, the mailer's key, or IMDS's SES, because the |
| - box role has none. **Decision 7 keeps switched apps nested,** so their |
| - own tokens are invisible to flat siblings, and this residual covers |
| - unswitched apps only. |
| +- **Residual, stated.** On a box with any flat instance, a compromised |
| + flat instance can read **any** instance's admin token on that box, |
| + **nested or not** (nested isolation is one-way; see decision 7), and |
| + submit as that instance. **On that box only.** That is the same reach it |
| + has today over a neighbour's delivered SMTP password. It is better |
| + bounded than today: the sender's From, cap, pause and rate still apply, |
| + and nothing can be taken off the box. It cannot reach the mailer's |
| + socket (peer rule), the mailer's key, or SES through IMDS (the box role |
| + has none). |
| +- **Not closed:** a same-uid flat child that traces the agent process |
| + would pass the peer rule. No kernel setting in the repo prevents it, and |
| + it applies equally to the existing `instancectl` channel. Decision 4 |
| + 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. |
| @@ -227,7 +256,18 @@ and (b) can replace it without an app change. |
| nft-parse one. |
| 10. **rastrillo `submit` transport.** It is chosen only on |
| `CARLOS_MAIL=submit`, backs off on `429` per `Retry-After`, and |
| - retries `503`. |
| + retries `503`. It fails at boot when a switched app has neither |
| + channel. |
| +11. **Tags are believed only from the mailer** (decision 6's guard). An |
| + event whose caller is an app's IAM user, carrying another app's |
| + `account`/`app`/`sender` tags, is counted against the caller. The same |
| + 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. |
| +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. |
| ## 9. Open: facts to establish before build |
| @@ -237,6 +277,10 @@ and (b) can replace it without an app change. |
| - The SES v2 raw size limit and recipient limit. |
| - Whether the v2 raw path honours `X-SES-*` headers. |
| - The IAM action that v2 raw sends require. |
| + - Whether SES honours `X-SES-MESSAGE-TAGS` over SMTP. Decision 6's |
| + 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`) |
| @@ -246,6 +290,21 @@ and (b) can replace it without an app change. |
| decision-2 design needs no gate change, because the box role gains no |
| SES. Confirm. |
| +## 11. For Paul (stopping rule 2) |
| + |
| +1. **The uid family (decision 7).** Choose one: |
| + - **Cut the layout precondition, and state the residual** (§6). |
| + Submission is no worse than today on either layout, and better |
| + bounded. *Fable and the author recommend this.* |
| + - **Refuse at box level:** no switched app on a box with any flat row |
| + (`FlatLayoutChosen`, `backend_exec.go:268-273`). This is the only form |
| + that delivers "a flat sibling cannot submit as a switched app". It |
| + waits on moving Oficina's boxes nested (§9 item 2). |
| + - **Per-instance uids,** the real fix for this and the admin-token gap. |
| + A separate design, and out of scope here. |
| +2. **The cap counter (§4.1).** (a) per box (recommended) or (b) leased |
| + from the bucket. |
| + |
| ## 10. Out of scope |
| - An SMTP shim for non-rastrillo apps. |
| @@ -271,8 +330,27 @@ and (b) can replace it without an app change. |
| | P2-5 synchronous delivery, rate limit | §4 synchronous, §5 rate | |
| | P2-6 layout | §1.3, decision 7, §9 item 2 | |
| +**Round 2 (Fable 5.2, revision 2 `8997b3914`):** |
| + |
| +| Finding | Answer | |
| +|---|---| |
| +| P1-A forged tags (attribution family, second round) | Decision 6: the invariant, enforced in `SenderOfCaller`, with guard test 8.11 (rule 2, third option) | |
| +| P2-1 nested tokens readable by flat siblings (uid family, second round) | Decision 7 is cut as proposed, §6's residual is rewritten, and §11 item 1 goes to Paul | |
| +| P2-2 key delivery, wrong precedent, rotation (uid family) | §5 credential: operator-armed, never through a uid-carlos path, with a rotation runbook | |
| +| P2-3 the mailer cannot read sender records | §5: read-only bucket grants; "on this box" taken from the bucket's instance records | |
| +| P2-4 precondition only at the flip | Decision 10 and test 8.12; `carlos email test --submit` before the reap | |
| +| P2-5 the health probe's dead state | Decision 11: follows the bind; rastrillo fails loudly | |
| +| P2-6 pause kinds | Decision 8 and test 8.13 | |
| +| §4.1 view | §4.1: recommendation changed to (a), with the true bound | |
| + |
| **P3 follow-up list** (not starting a round): |
| +- Whether the cap counts messages or recipients (the console counts Send |
| + events). |
| +- The IAM backstop expressed as `identity/*` with a `ses:TenantName` |
| + condition on `carlos-*`, which makes the association backfill mandatory. |
| +- §4.1 is numbered ahead of §4. |
| + |
| - The raw size limit, now 10 MiB pending the spike. |
| - `429` back-off in the apps' queues. |
| - The CLI docs and parity row (decision 10). |