Mail relay: an inherited sending key that never leaves its holder
Design for #15872. Nothing here is built yet; the build is split below.
The problem
A new forge or app should send mail with no setup. Today mail is SMTP
submission (src/kernel/mail.ts) from the forge-level secrets MAIL_SMTP_URL
and MAIL_FROM (docs/OPERATING.md). Copying that key into a child would break
CLAUDE.md rule 11 ("a child inherits nothing it was not handed"): one leaked
child would leak every child's sending reputation.
Decision: the key is never copied; the parent sends
The holder of a key is the only process that opens it. A child asks its parent
to send, over the door it already has (the signed call of
src/spawn/signed_call.ts, as src/spawn/child_reach.ts does for egress), and
the parent opens the key, sends, and answers sent, capped or failed.
app --(forge-signed call)--> its forge --(signed call)--> parent forge --> SMTP asks "send this" holds a key? yes: send platform key
Each hop either sends with a key it holds at its own scope or forwards one hop up. A child holds no key it was not given, so the chain is the fallback.
Scopes and fallback
Order of precedence, narrowest first: app > domain > forge > platform.
- A key is a forge secret (
core/secret_store.ts) namedMAIL_SMTP_URLplusMAIL_FROM, sealed at its scope.reposcope is the app,orgis the domain (an organization's from-domain),forgeis the forge. The platform key is the forge's boot setting. resolveMailKey(scope)returns{ scope, key }; callers outside the module that sends only ever get{ scope }, so "which scope's key is in effect" is a value an API, page or terminal can show. Removing a key makes the next resolution fall to the wider scope; there is no state to undo.- An app's request is signed by its forge, never by the app, so an app cannot claim a wider scope's from-domain.
What may be sent on a key it does not own
A shared (inherited) key carries two limits, both counted by the holder in
mail_sent (core/mail_log.ts, the pattern actions/mail.ts already uses):
- From-domain allowlist per scope. The holder keeps
domainsper child scope; a message whosefromdomain is not on it is refusedfrom_domain. Default for an inheriting child: its own hostname only. - Rate limit per scope: a daily count per requesting scope on top of the holder's per-recipient and whole-forge caps, so one noisy app spends its own allowance, not its siblings'.
The key never appears
- Not in API answers, pages, logs or argv:
MailConfig.urlis read bysendMailalone, over a socket. The relay call carries only a message. secret.readevents record scope and name, never the value, as today.- A test plants a key and searches every surface for it, as
test/secrets-never-surface.test.tsdoes.
Split (each part usable alone)
- Resolution:
src/core/mail_key.ts,resolveMailKeyover the existing secret scopes (app > domain > forge > platform), returning the scope without the key; the forge's own sends use it. Tests: inheritance, override, removal falls back. - Relay call: the child's signed
mailcall and the parent's answer, with the from-domain allowlist and per-scope rate limit. Tests: refused domain, refused over the limit, the key absent from the call and the answer. - Doors: admin page, API, MCP tool and terminal screen showing which scope's key is in effect, setting and removing an override, with the redaction test across all surfaces.