spec: platform mail submission — instances send without holding a credential
Revision 1, for Paul's Oficina teams (Alta's runs block on it). A token-gated control-socket verb hands mail to a box-local mailer with its own uid; policy before the send; no IAM user per sender.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+195
−0
docs/superpowers/specs/2026-11-12-platform-mail-submission-design.md+195 −0
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| new file mode 100644 |
| index 000000000..e9a354be6 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-12-platform-mail-submission-design.md |
| @@ -0,0 +1,195 @@ |
| +# Platform mail submission: instances send without holding a credential |
| + |
| +**Date:** 2026-11-12 · **Status:** draft, revision 1, not reviewed · |
| +**Branch:** `design/platform-mail-submission` from `origin/main` `99df838cf` |
| +· **Author:** Claude Opus 5.5, for Paul. |
| + |
| +**Builds on:** `2026-09-15-tenant-email-senders-design.md` (senders, |
| +per-instance mode, and its §10, "What this leaves for the relay"), which |
| +decided: *"Extend the IAM-per-sender model now, and iterate towards a |
| +platform SMTP relay."* This is that iteration, in the shape the box |
| +already has. **Also:** `implementation/team-scoped-credentials.md` (owned |
| +environments, §3a's per-environment mail credentials, which this replaces |
| +for apps that switch), and the control channel |
| +(`internal/edge/purge.go`, `2026-08-23-scheduled-work-design.md` §7.2). |
| + |
| +**Stopping rule 5: who asks, what they get, when it switches on.** Paul, |
| +for Oficina. Alta creates one instance per app per team. Under §3a, each |
| +instance gets its own IAM user and SMTP key: 30 for Paul's first five |
| +teams, plus a relay identity per Calls instance. Paul, 2026-11-12: *"surely |
| +each instance doesn't need its own email sending credentials?"* He chose |
| +to **block Alta's team runs on this design** ("Happy to block"). So it |
| +switches on at Alta's first production run, and the Oficina apps are its |
| +first users. |
| + |
| +--- |
| + |
| +## 1. The problem |
| + |
| +Today a sending credential lives **inside the instance**. That is true at |
| +the app level (`carlos-mail-<acct>-<app>`, delivered as `<P>_SMTP_*` into |
| +the default bundle) and, since §3a, per owned environment |
| +(`carlos-mail-<acct>-<app>+e+<env>`). This has three costs. |
| + |
| +1. **One AWS IAM user per sender.** The account ceiling is 5,000 and not |
| + adjustable (senders spec §12). A team of six apps is six users, and a |
| + per-customer app is one per customer. |
| +2. **The credential is the authority.** Whoever reads `<P>_SMTP_PASS` can |
| + send as that sender, from anywhere, until the key is rotated. The cap |
| + is counted after the fact (senders spec §10: the relay "enforces the |
| + cap before the send rather than after"). |
| +3. **Per-instance credentials isolate less than they appear to.** On an |
| + exec-backed box, every instance runs as the agent's uid |
| + (`internal/activator/admintoken.go`: "every exec child shares the |
| + agent's uid — a sibling can read this file"). So a compromised instance |
| + can read a sibling's `<P>_SMTP_PASS` from its env file, just as it can |
| + read the sibling's admin token. The per-instance IAM user buys |
| + attribution and revocation. It does not stop a neighbour sending as you. |
| + Per-instance uids are "the actual fix" for both. |
| + |
| +## 2. The design in one paragraph |
| + |
| +**An instance submits a message on its control socket, and the platform |
| +sends it.** The agent already binds a local-only control channel for |
| +every exec-backed instance, token-gated by that instance's |
| +`CARLOS_ADMIN_TOKEN` (`backend_exec.go`, `edge.ListenControl`), and |
| +mounts verbs on it (`schedule.MountGated`, `instanceupdates.Mount`). A new |
| +verb, `POST /v1/mail`, takes one message. The agent knows which instance |
| +owns that socket, so the instance's identity comes from **where it |
| +dialled, not from a secret it presents**. It hands the message to a |
| +**box-local mailer** running as its own uid. Only the mailer can reach the |
| +SES credential. The mailer checks the sender's policy (From, cap, pause) |
| +**before** sending, sends through SES, and counts the send against the |
| +instance. **No instance holds a sending credential, and no sender needs |
| +an IAM user.** |
| + |
| +## 3. Decisions (proposed; none ruled) |
| + |
| +| # | Decision | Rejected | |
| +|---|---|---| |
| +| 1 | **Submission over the existing control socket**, as a token-gated verb beside the schedule and updates verbs | (a) A network SMTP relay with per-sender passwords (senders spec §10's sketch). It still puts a credential in every instance, and it needs its own listener, TLS and abuse surface. (b) A per-instance SMTP listener on the box. Every app would need to speak SMTP to a socket the agent vouches for, which is a second channel beside the one that already exists | |
| +| 2 | **The sending credential lives in a separate box unit, `carlos-mailer`, with its own uid.** The IMDS gate (`nft … meta skuid`, `scripts/harden-host.sh`, which `adopt_advice.go` reads) admits that uid, and the box role's SES permission is the only send authority | Giving the agent the credential. The agent shares its uid with every exec child, so any instance could read it (§1.3) | |
| +| 3 | **Policy is enforced before the send**: From must be an address the sender may use (the sender records of the senders spec §5), the daily cap is checked and decremented first, and a paused sender is refused | Counting after the fact, as today | |
| +| 4 | **Attribution per instance, without an IAM user.** Each submission is tagged with the instance's sender id (senders spec §5, `ScopeInstance`) and counted in `mail_sender_counts` | One IAM user per instance (§3a) | |
| +| 5 | **An app opts in per app, with a switch** (`carlos email submission on --app <a>`), mirroring per-instance mode (senders spec §6.3). When on, **no** `<P>_SMTP_*` is delivered to the default bundle or any owned environment, and the mail walk mints no per-environment users. The agent sets `CARLOS_MAIL=submit` in the instance's environment, agent-owned in both directions like `CARLOS_CONTROL_SOCKET` | Switching the fleet at once; inferring the mode from whether the socket exists | |
| +| 6 | **The app side is one library change.** rastrillo's `mail` package gains a `submit` transport, chosen when `CARLOS_MAIL=submit` is set, and used in place of SMTP. The Oficina apps get it from a rastrillo re-pin, with no app code changes | Each app learning a new API | |
| + |
| +## 4. The verb |
| + |
| +`POST /v1/mail` on the control socket. |
| +- **Headers:** `Authorization: Bearer <CARLOS_ADMIN_TOKEN>`. |
| +- **Body:** a JSON envelope `{ "from", "to": [..], "raw" }`, where `raw` |
| + is the RFC 5322 message, base64, at most 1 MiB. `from` must equal the |
| + message's `From:` header. |
| +- **Answers:** |
| + - `202` with a submission id: accepted and handed to the mailer. |
| + - `400`: malformed, or `from` ≠ `From:`. |
| + - `403 {"code":"FROM_NOT_ALLOWED"}`. |
| + - `429 {"code":"CAP_REACHED"}` or `{"code":"PAUSED"}`. |
| + - `503 {"code":"MAILER_UNAVAILABLE"}`: the instance retries. rastrillo's |
| + existing mail queues (Docs' and Sheets' `mailqueue.go`) already |
| + retry. |
| +- **Recipients:** at most 50 per message, to fit SES limits. Bcc is |
| + stripped from `raw` by the mailer, never the app. |
| +- **Not on this verb:** reading mail, bounces, events. Bounces and |
| + complaints keep their existing path (`events.go`). |
| + |
| +## 5. The mailer |
| + |
| +- **A systemd unit on every box, `carlos-mailer.service`,** with its own |
| + static user `carlos-mailer`. It listens on a root-owned unix socket that |
| + only the agent's uid may dial (`SO_PEERCRED` check, the pattern in |
| + `pty_linux.go` and `rolelaunch_root_linux.go`). |
| +- **The agent passes `(account, app, host)` with each message.** The |
| + mailer trusts that, because only the agent can dial it. The same-uid gap |
| + in §6 is the honest limit of that trust. |
| +- **The mailer reads sender records from the bucket** (the control plane), |
| + caching each with its etag, and enforces decision 3. |
| +- **The mailer sends with SES `SendRawEmail`,** using the box role. It |
| + sets the configuration set and SES tenant the senders spec already |
| + assigns (§5, `TenantARN`), so SES-side attribution and the per-tenant |
| + pause keep working. |
| +- **The box role's SES statement** is scoped to the platform's verified |
| + identities (`ses:FromAddress`/identity ARNs), the same scope the walk |
| + writes into per-sender policies today, and is reachable only by |
| + `carlos-mailer`'s uid at IMDS. |
| + |
| +## 6. What this does and does not protect |
| + |
| +- **No instance can obtain a sending credential.** That is strictly better |
| + than today, where every instance holds one. |
| +- **No instance can exceed its sender's cap or send while paused,** |
| + because both are checked before the send. |
| +- **An instance cannot send as another app's sender.** The agent decides |
| + identity from the socket, and the From check binds it to that sender's |
| + identities. |
| +- **Unchanged and stated: on an exec box, a compromised instance can still |
| + read a same-uid sibling's admin token and submit as that sibling.** It |
| + could do exactly that today with the sibling's SMTP password. Per-instance |
| + uids close both gaps together. Unit-backed tenants (`DynamicUser`) already |
| + have their own uids, if they have a control socket (§9 item 2). |
| +- **A compromised agent can send as anyone on its box, within caps.** It |
| + could already do that by reading every env file. |
| + |
| +## 7. Migration and what retires |
| + |
| +1. Build the mailer, the verb, and rastrillo's `submit` transport, with the |
| + switch defaulting to off. |
| +2. Turn the switch on for the Oficina apps (Paul's account `oficina`), then |
| + re-pin rastrillo and deploy. |
| +3. **App-level IAM users** for switched apps are reaped by the walk |
| + (`Teardown` for the user only, never the identity: senders spec §1's |
| + #147 warning). |
| +4. **Owned environments** of switched apps never get a mail identity, so |
| + Alta's team runs create no IAM users at all. |
| +5. Calls' TURN relay identities (§3a's other per-environment mint) are a |
| + separate design, but the same shape could serve: short-lived TURN |
| + credentials minted by the agent per request on the control socket. That |
| + is listed as a follow-up, not designed here. |
| + |
| +## 8. Tests and gates |
| + |
| +1. **No credential reaches an instance.** For a switched app, a rendered |
| + instance environment (default and owned) holds no `<P>_SMTP_*` and no |
| + AWS key. This is a golden test across `RenderEnv`. |
| +2. **Identity from the socket.** A message submitted on host A's socket is |
| + attributed to A, whatever the body says. A body claiming another sender |
| + is refused. |
| +3. **Before-send policy.** A wrong From gets `403`. Cap minus one sends and |
| + the cap answers `429`. A paused sender gets `429` with no SES call |
| + (fake SES). |
| +4. **The mailer dial gate.** Any uid other than the agent's is refused. |
| +5. **The IMDS gate.** On a hardened box, an exec child cannot reach IMDS |
| + and `carlos-mailer` can. This extends `adopt_advice.go`'s check. |
| +6. **The switch is agent-owned.** A tenant-supplied `CARLOS_MAIL` in |
| + `<host>.config.env` is removed when submission is off, as |
| + `CARLOS_CONTROL_SOCKET` is. |
| +7. **rastrillo `submit` transport.** It chooses `submit` only on |
| + `CARLOS_MAIL=submit`, retries `503`, and surfaces `403`/`429` as send |
| + errors, which the apps' queues already log. |
| + |
| +## 9. Open: facts to verify before build |
| + |
| +1. **Does the exec-child uid reach IMDS on production boxes today?** If |
| + the nft gate admits the agent's uid (shared by every exec child), then |
| + any instance can already obtain the box role. Adding SES send to that |
| + role would widen the hole, so decision 2 needs the gate to admit only |
| + `carlos-mailer` and whatever already needs it. |
| +2. **Unit-backed tenants:** is a control socket bound for them, or only |
| + for exec children (`backend_exec.go` says "every exec child")? The |
| + Oficina apps run as `binary` runtime instances, which the build must |
| + confirm are exec-backed. If unit tenants have no channel, they keep |
| + IAM-per-sender until it exists. |
| +3. **Customer fleets** (boxes in another AWS account, outbound-only): out |
| + of scope. They keep IAM-per-sender unless the mailer can use a |
| + cross-account role. That is a later decision. |
| +4. **SES `SendRawEmail` with a tenant:** confirm that the SES v2 call |
| + carries `TenantName` the way the senders spec's spike recorded for |
| + SMTP (§4.1). |
| + |
| +## 10. Out of scope |
| + |
| +- An SMTP listener for non-rastrillo apps. If a customer needs one, it is |
| + a shim in front of the same verb, designed when someone asks. |
| +- Inbound mail. |
| +- Calls' relay identities (§7.5). |