Public: anyone can read this; the crew can change it.

Every new forge and app can send email with zero setup through an inherited sending key, with a per-app override #17338

opened this

Merged 38h 37m ago, live in production

torque/forge:torque/15872-every-new-forge-and-app-can-send-email-w → main 0 commits fork

  • Merged. torque/15872-every-new-forge-and-app-can-send-email-w was merged into main as d994979.

Review

Sign in to review this change.
4 files changed +83 −0
docs/MAIL-RELAY.md added +72
@@ -0,0 +1,72 @@
1 # Mail relay: an inherited sending key that never leaves its holder
2
3 Design for #15872. Nothing here is built yet; the build is split below.
4
5 ## The problem
6
7 A new forge or app should send mail with no setup. Today mail is SMTP
8 submission (`src/kernel/mail.ts`) from the forge-level secrets `MAIL_SMTP_URL`
9 and `MAIL_FROM` (docs/OPERATING.md). Copying that key into a child would break
10 CLAUDE.md rule 11 ("a child inherits nothing it was not handed"): one leaked
11 child would leak every child's sending reputation.
12
13 ## Decision: the key is never copied; the parent sends
14
15 The holder of a key is the only process that opens it. A child asks its parent
16 to send, over the door it already has (the signed call of
17 `src/spawn/signed_call.ts`, as `src/spawn/child_reach.ts` does for egress), and
18 the parent opens the key, sends, and answers `sent`, `capped` or `failed`.
19
20 app --(forge-signed call)--> its forge --(signed call)--> parent forge --> SMTP
21 asks "send this" holds a key? yes: send platform key
22
23 Each hop either sends with a key it holds at its own scope or forwards one hop
24 up. A child holds no key it was not given, so the chain is the fallback.
25
26 ## Scopes and fallback
27
28 Order of precedence, narrowest first: **app > domain > forge > platform**.
29
30 - A key is a forge secret (`core/secret_store.ts`) named `MAIL_SMTP_URL` plus
31 `MAIL_FROM`, sealed at its scope. `repo` scope is the app, `org` is the
32 domain (an organization's from-domain), `forge` is the forge. The platform key
33 is the forge's boot setting.
34 - `resolveMailKey(scope)` returns `{ scope, key }`; callers outside the module
35 that sends only ever get `{ scope }`, so "which scope's key is in effect" is
36 a value an API, page or terminal can show. Removing a key makes the next
37 resolution fall to the wider scope; there is no state to undo.
38 - An app's request is signed by its forge, never by the app, so an app cannot
39 claim a wider scope's from-domain.
40
41 ## What may be sent on a key it does not own
42
43 A shared (inherited) key carries two limits, both counted by the holder in
44 `mail_sent` (`core/mail_log.ts`, the pattern `actions/mail.ts` already uses):
45
46 1. **From-domain allowlist per scope.** The holder keeps `domains` per child
47 scope; a message whose `from` domain is not on it is refused `from_domain`.
48 Default for an inheriting child: its own hostname only.
49 2. **Rate limit per scope**: a daily count per requesting scope on top of the
50 holder's per-recipient and whole-forge caps, so one noisy app spends its own
51 allowance, not its siblings'.
52
53 ## The key never appears
54
55 - Not in API answers, pages, logs or argv: `MailConfig.url` is read by
56 `sendMail` alone, over a socket. The relay call carries only a message.
57 - `secret.read` events record scope and name, never the value, as today.
58 - A test plants a key and searches every surface for it, as
59 `test/secrets-never-surface.test.ts` does.
60
61 ## Split (each part usable alone)
62
63 1. **Resolution**: `src/core/mail_key.ts`, `resolveMailKey` over the existing
64 secret scopes (app > domain > forge > platform), returning the scope without
65 the key; the forge's own sends use it. Tests: inheritance, override, removal
66 falls back.
67 2. **Relay call**: the child's signed `mail` call and the parent's answer, with
68 the from-domain allowlist and per-scope rate limit. Tests: refused domain,
69 refused over the limit, the key absent from the call and the answer.
70 3. **Doors**: admin page, API, MCP tool and terminal screen showing which
71 scope's key is in effect, setting and removing an override, with the
72 redaction test across all surfaces.
docs/REFERENCE.md +1
@@ -599,6 +599,7 @@ This page is the front door. Everything else is a file of its own under
599599 - [`docs/SNAPSHOT.md`](SNAPSHOT.md) — a forge back from a copy: what a nightly snapshot holds, where it goes, the drill, and the one command that restores it.
600600 - [`docs/features/drop.md`](features/drop.md) — the drop: a private place per app for the files its crew needs and the repository cannot hold; limits, doors and where it lives.
601601 - [`docs/RECOVERY.md`](RECOVERY.md) and [`docs/RESTORE.md`](RESTORE.md) — the forge back at 3 a.m., and on a fresh machine; print them.
602 - [`docs/MAIL-RELAY.md`](MAIL-RELAY.md) — design: an inherited mail sending key that never leaves its holder (#15872).
602603 - [`docs/CLOUD.md`](CLOUD.md) — clouds are capacity, never dependency, and the cloud accounts an admin keeps.
603604 - [`docs/CLUSTER.md`](CLUSTER.md) — the check lane as Kubernetes Jobs.
604605 - [`docs/EXTRACT.md`](EXTRACT.md) — the forge on a machine of its own, and the platform it grew up in switched off: what a host owes it, the moves in order, and what is given up.
src/view/doc_sections.ts +1
@@ -43,6 +43,7 @@ export const DOC_LINES: Record<string, Line> = {
4343 "RECOVERY.md": ["run", "A printable runbook for when it is down."],
4444 "SECURITY-RUNBOOK.md": ["run", "Leaked tokens, bad releases, sign-in."],
4545 "SPAWN.md": ["run", "A forge that makes forges for other people."],
46 "MAIL-RELAY.md": ["internals", "Design: sending mail with an inherited key."],
4647 "METRICS.md": ["run", "Prometheus metrics for a site admin."],
4748 "CLUSTER.md": ["run", "Checks as Kubernetes Jobs."],
4849
test/mail-relay-doc.test.ts added +9
@@ -0,0 +1,9 @@
1 import { expect, test } from "bun:test";
2 import { existsSync } from "node:fs";
3 import { join } from "node:path";
4 import { DOC_LINES } from "../src/view/doc_sections.ts";
5
6 test("the docs index lists the mail relay design, and the file exists", () => {
7 expect(DOC_LINES["MAIL-RELAY.md"]?.[0]).toBe("internals");
8 expect(existsSync(join(import.meta.dir, "..", "docs/MAIL-RELAY.md"))).toBe(true);
9 });

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs