carlos / platform Public

mailer: unit, user, socket and the agent-only peer rule

Task 3 of the platform mail submission plan. carlos-mailer.service runs
`carlos mailer serve` as its own static user, socket-activated by
carlos-mailer.socket, which carlos-mailer-arm.path starts only once an
operator has written /etc/carlos-mailer/keys. The mailer admits a
connection only from uid carlos AND carlos-edge.service's MainPID
(instancectl's rule, reused through EdgeMainPIDPeer), checked in Accept
before a byte is read. GET /v1/health is its only route for now.

Bootstrap creates the user (privilegedPlan and sysusers) and the two
root-owned directories (tmpfiles). Every unit that hides
/run/carlos-control now hides -/run/carlos-mailer and -/etc/carlos-mailer
too, including the claim-bound template and the demo drop-in, which the
plan's unit list missed; a derived test pins the set. The box report
gains MailerArmed (G6 (b)): the socket exists and its health answers.

Census: Task 3 claims added, overlay re-proposed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev cec42acd897378faba9bc1f6478ae4a89d18eea0 parent f841527
45 files changed, +1,261 −31
  • commands.go +1 −0
  • docs/parity.md +1 −0
  • docs/site/cli.md +15 −0
  • docs/superpowers/notes/census-claims-platform-mail-submission.tsv +22 −0
  • docs/superpowers/notes/census-proposal-platform-mail-submission.md +48 −3
  • internal/host/agent.go +5 −0
  • internal/host/bootstrap.go +29 −1
  • internal/host/bootstrap_test.go +80 −0
  • internal/host/claimunit_template.go +1 −1
  • internal/host/dbreads_test.go +1 −1
  • internal/host/demo_policy_test.go +1 −1
  • internal/host/demo_units/demo.conf +1 −1
  • internal/host/host_test.go +6 −2
  • internal/host/mailerreport.go +42 −0
  • internal/host/mailerreport_test.go +85 −0
  • internal/host/units/carlos-dbread@.service +1 −1
  • internal/host/units/carlos-demo-build@.service +1 −1
  • internal/host/units/carlos-instance-cmd@.service +1 −1
  • internal/host/units/carlos-instance-gen@.service +1 −1
  • internal/host/units/carlos-instance-probe.service +1 −1
  • internal/host/units/carlos-instance-seed@.service +1 −1
  • internal/host/units/carlos-instance-sidecar@.service +1 −1
  • internal/host/units/carlos-instance-tty@.service +1 −1
  • internal/host/units/carlos-instance@.service +1 −1
  • internal/host/units/carlos-mailer-arm.path +18 −0
  • internal/host/units/carlos-mailer.service +62 −0
  • internal/host/units/carlos-mailer.socket +20 −0
  • internal/host/units_isolation_test.go +159 −3
  • internal/host/units_rootfs_test.go +5 −5
  • internal/instancectl/peer_linux.go +24 −0
  • internal/instancectl/peer_other.go +12 −0
  • internal/mailer/peer.go +63 −0
  • internal/mailer/server.go +107 −0
  • internal/mailer/server_linux_test.go +72 −0
  • internal/mailer/server_test.go +165 −0
  • internal/mailwire/mailwire.go +6 −0
  • internal/provision/platform_mail_submission_census_test.go +9 −0
  • internal/provision/testdata/plan14-root-reads-chain.tsv +1 −1
  • internal/provision/testdata/plan14-root-reads-platform-mail-submission.tsv +48 −2
  • internal/status/snapshot.go +13 −1
  • internal/status/snapshot_test.go +20 −0
  • mailer_cli.go +69 −0
  • mailer_cli_test.go +39 −0
  • parity/cli.tsv +1 −0
  • parity/parity.tsv +1 −0

CI cancelled — superseded by a newer push — run details

diff --git a/commands.go b/commands.go
index 27fe1d7a6..538b8ce32 100644
--- a/commands.go
+++ b/commands.go
@@ -129,6 +129,7 @@ func buildCommandRoot() *clireg.Node {
economicsCommand(),
storeCommand(),
relayCommand(),
+ mailerCommand(),
emailCommand(),
raw("logs", cust, runLogs),
raw("errors", cust, runErrors),
diff --git a/docs/parity.md b/docs/parity.md
index 496aefef8..591572c29 100644
--- a/docs/parity.md
+++ b/docs/parity.md
@@ -432,6 +432,7 @@ Discussion #742.
| release-keygen | box | `release-keygen` | | Mints signing keys; the private key stays local. |
| proof | box | `proof keygen`<br>`proof get`<br>`proof put`<br>`proof history` | | Dev proofs a box needs to adopt. |
| relay-box | box | `relay serve`<br>`relay keygen` | | Runs the relay, or mints a region master key. |
+| mailer-serve | box | `mailer serve` | | Runs the box-local mailer; the unit's entry point. |
| system-box | box | `system apply`<br>`system files`<br>`system guard-arm`<br>`system guard-exec`<br>`system floor-allows-prev`<br>`system exec-sandbox-allows-prev`<br>`system runsc-ensure`<br>`system install-channel`<br>`system host-env`<br>`system named-units`<br>`system db-worker`<br>`system journal-migrate`<br>`system group-maintenance`<br>`system edge trust-barrier`<br>`system edge trust-resume`<br>`system edge trust-status`<br>`system proxy-allows-prev`<br>`system box publish-record` | | Root oneshots and units on a box. |
| status-dry-run | box | `status [--dry-run]` | | A leak check against a fixture fleet, run locally. |
| devbox-serve | box | `devbox serve` | | The devbox service under systemd. |
diff --git a/docs/site/cli.md b/docs/site/cli.md
index 1826d00cb..2c686e799 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -3446,6 +3446,21 @@ agent refuses to wake isolated instances while the service reports another
build than its own, or none. Either way the reason in `carlos logs` ends
with `restart carlos-instance-control.service`.
+### carlos mailer
+
+The box-local mailer. An instance of an app switched to platform mail
+submission sends a message by `POST /v1/mail` on its own control socket;
+the agent stamps it with that socket's route and hands it to this process,
+which checks the sender's From, pause, daily cap and rate, and sends it
+through SES as the region's dedicated IAM user. No instance holds a sending
+credential.
+
+`carlos mailer serve` is what `carlos-mailer.service` runs, as its own user,
+`carlos-mailer`. Not for operators: there is nothing to type.
+`carlos-mailer.socket` listens only once an operator has written the key to
+`/etc/carlos-mailer/keys`, and the mailer admits only the agent's own main
+process.
+
### carlos instance-exec
The first thing an isolated instance unit runs. It reads the launch file
diff --git a/docs/superpowers/notes/census-claims-platform-mail-submission.tsv b/docs/superpowers/notes/census-claims-platform-mail-submission.tsv
index 0e491fe48..ec55b80ff 100644
--- a/docs/superpowers/notes/census-claims-platform-mail-submission.tsv
+++ b/docs/superpowers/notes/census-claims-platform-mail-submission.tsv
@@ -7,3 +7,25 @@
# none, and re-pins the root (.) envelope only, which census-propose takes
# without a claim. The planned claim, kept here for the reviewer:
# mail_cli.go:printEmailStatus: the `carlos email status` printer reads the pause from the reply's new optional `pause` block (kind, at), per sender too, and falls back to `active` and provisioned.pause_kind from an older console (emailPauseOf, a pure helper). apiEmailReply and apiEmailSender gain one optional field each. API mode only, run by a person against the console; no read of box state, no root read added
+#
+# Task 3 (mailer unit, user, socket, peer rule).
+internal/host/agent.go:statusLoop Task 3 (plan gap G6 (b)): the status tick also fills Probes.MailerArmed from mailerArmed(mailwire.MailerSocket, 2s): a stat of /run/carlos-mailer/mailer.sock and, only when it is a socket, GET /v1/health on it. The agent (carlos-edge.service, user carlos), not root; reported in the private BoxMetrics block only. The same six sites; no store request, no read of /etc/carlos-mailer (which uid carlos cannot traverse).
+internal/host/mailerreport.go:mailerArmed Task 3, new: the agent's MailerArmed probe. Stats the constant socket path and dials it for GET /v1/health with a 2 s timeout; true only on a 200. Runs in the agent as carlos, never as root; the path is a constant, in a root-owned 0750 root:carlos directory nothing a tenant or an app can write. Answers a bool into the private status block.
+internal/host/bootstrap.go:bootstrapWithGroup Task 3: the sysusers.d/carlos.conf it writes is now the constant sysusersConf, which adds "u carlos-mailer - \"CARLOS mailer\" - /usr/sbin/nologin" ahead of the existing "g carlos-sockets -" line, so the tmpfiles line naming group carlos-mailer resolves on a box whose confs arrive by a staged-tree refresh. Constant text, no input; no read added.
+internal/host/bootstrap.go:const tmpfilesConf Task 3: two constant lines, "d /run/carlos-mailer 0750 root carlos -" (the mailer's socket directory, beside /run/carlos-control and shaped like it) and "d /etc/carlos-mailer 0750 root carlos-mailer -" (the key directory, which uid carlos cannot traverse). Root creates two root-owned directories; no file inside either is created, owned or seeded (the key is the operator's, by hand). No input; no read added.
+internal/host/bootstrap.go:privilegedPlan Task 3: one more constant argv, useradd --system --user-group --no-create-home --shell /usr/sbin/nologin carlos-mailer, right after carlos's, behind runPrivileged's existing guard (user.Lookup of the argv's own last word). No input; no read added.
+internal/host/claimunit_template.go:const claimBoundTemplate Task 3: the InaccessiblePaths= line gains -/run/carlos-mailer -/etc/carlos-mailer, as every tenant template that hides /run/carlos-control now does (TestMailerPathsHiddenFromEveryTenantTemplate derives the set). Optional entries, so a box before tmpfiles ran still starts it. Only hides more; no bind source, Exec line, user or root read added.
+internal/host/demo_units/demo.conf:external Task 3: the restated InaccessiblePaths= line after the reset gains -/run/carlos-mailer -/etc/carlos-mailer, so a demo box's drop-in does not drop the mailer entries carlos-instance@ and carlos-instance-gen@ now carry. Optional entries; only hides more; no source or bind added.
+internal/host/units/carlos-dbread@.service:external Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added.
+internal/host/units/carlos-demo-build@.service:external Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added.
+internal/host/units/carlos-instance-cmd@.service:external Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional), the same line as the seed template (TestCmdTemplateEqualsSeedOutsideTheNamedLines). Only hides more; no read added.
+internal/host/units/carlos-instance-gen@.service:external Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added.
+internal/host/units/carlos-instance-probe.service:external Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional), so the probe proves what the tenants get. Only hides more; no read added.
+internal/host/units/carlos-instance-seed@.service:external Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added.
+internal/host/units/carlos-instance-sidecar@.service:external Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added.
+internal/host/units/carlos-instance-tty@.service:external Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added.
+internal/host/units/carlos-instance@.service:external Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added.
+internal/host/units/carlos-mailer-arm.path:external Task 3, new: [Path] PathExists=/etc/carlos-mailer/keys, Unit=carlos-mailer.socket, WantedBy=multi-user.target; enabled and armed by bootstrap like every .path. PID 1 watches a path in a root-owned 0750 root:carlos-mailer directory only root (the operator) writes; it starts a socket unit and reads nothing.
+internal/host/units/carlos-mailer.socket:external Task 3, new: ConditionPathExists=/etc/carlos-mailer/keys, ListenStream=/run/carlos-mailer/mailer.sock, SocketUser=carlos, SocketGroup=carlos, SocketMode=0600, Accept=no; not enabled, started only by the arming path. PID 1 binds a socket in a root-owned directory, as carlos-instance-control.socket does in /run/carlos-control. No read added.
+internal/host/units/carlos-mailer.service:external Task 3, new: runs /opt/carlos/carlos mailer serve as the static user carlos-mailer (never root), socket-activated, ConditionPathExists=/etc/carlos-mailer/keys, EnvironmentFile=-/etc/carlos/host.env (read by PID 1, as every carlos service's) with UnsetEnvironment=CARLOS_SECRETS_KEY, AWS_EC2_METADATA_DISABLED=true, IPAddressDeny=169.254.169.254/32 fd00:ec2::254/128, StateDirectory=carlos-mailer 0700, and the relay's hardening block with no ReadWritePaths. No root process reads anything new; the mailer reads its own key file and state.
+internal/status/snapshot.go:CollectBox Task 3: copies Probes.MailerArmed into BoxMetrics.MailerArmed (json mailer_armed, omitempty; private, like Layout) and counts it in the condition that builds Metrics; the same 28 sites, no read added.
diff --git a/docs/superpowers/notes/census-proposal-platform-mail-submission.md b/docs/superpowers/notes/census-proposal-platform-mail-submission.md
index 59cab5142..58e6f9b9f 100644
--- a/docs/superpowers/notes/census-proposal-platform-mail-submission.md
+++ b/docs/superpowers/notes/census-proposal-platform-mail-submission.md
@@ -1,11 +1,56 @@
# Census approval: platform-mail-submission
-Ruling `census-ruling-platform-mail-submission`. The independent reviewer approves or rejects every change below, 0 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
+Ruling `census-ruling-platform-mail-submission`. The independent reviewer approves or rejects every change below, 4 with a new disposition; nothing goes to the census owner (Paul, #280, 2026-10-26).
-Envelopes re-pinned: `.`.
+| unit | change | read sites | what changed |
+|---|---|---|---|
+| `internal/host/agent.go` `statusLoop` | body | unchanged (6) | Task 3 (plan gap G6 (b)): the status tick also fills Probes.MailerArmed from mailerArmed(mailwire.MailerSocket, 2s): a stat of /run/carlos-mailer/mailer.sock and, only when it is a socket, GET /v1/health on it. The agent (carlos-edge.service, user carlos), not root; reported in the private BoxMetrics block only. The same six sites; no store request, no read of /etc/carlos-mailer (which uid carlos cannot traverse). |
+| `internal/host/bootstrap.go` `bootstrapWithGroup` | body | unchanged (3) | Task 3: the sysusers.d/carlos.conf it writes is now the constant sysusersConf, which adds "u carlos-mailer - \"CARLOS mailer\" - /usr/sbin/nologin" ahead of the existing "g carlos-sockets -" line, so the tmpfiles line naming group carlos-mailer resolves on a box whose confs arrive by a staged-tree refresh. Constant text, no input; no read added. |
+| `internal/host/bootstrap.go` `const tmpfilesConf` | body | unchanged (7) | Task 3: two constant lines, "d /run/carlos-mailer 0750 root carlos -" (the mailer's socket directory, beside /run/carlos-control and shaped like it) and "d /etc/carlos-mailer 0750 root carlos-mailer -" (the key directory, which uid carlos cannot traverse). Root creates two root-owned directories; no file inside either is created, owned or seeded (the key is the operator's, by hand). No input; no read added. |
+| `internal/host/bootstrap.go` `privilegedPlan` | body | unchanged (1) | Task 3: one more constant argv, useradd --system --user-group --no-create-home --shell /usr/sbin/nologin carlos-mailer, right after carlos's, behind runPrivileged's existing guard (user.Lookup of the argv's own last word). No input; no read added. |
+| `internal/host/claimunit_template.go` `const claimBoundTemplate` | body | unchanged (1) | Task 3: the InaccessiblePaths= line gains -/run/carlos-mailer -/etc/carlos-mailer, as every tenant template that hides /run/carlos-control now does (TestMailerPathsHiddenFromEveryTenantTemplate derives the set). Optional entries, so a box before tmpfiles ran still starts it. Only hides more; no bind source, Exec line, user or root read added. |
+| `internal/host/demo_units/demo.conf` `external` | body | unchanged (1) | Task 3: the restated InaccessiblePaths= line after the reset gains -/run/carlos-mailer -/etc/carlos-mailer, so a demo box's drop-in does not drop the mailer entries carlos-instance@ and carlos-instance-gen@ now carry. Optional entries; only hides more; no source or bind added. |
+| `internal/host/units/carlos-dbread@.service` `external` | body | unchanged (1) | Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. |
+| `internal/host/units/carlos-demo-build@.service` `external` | body | unchanged (1) | Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. |
+| `internal/host/units/carlos-instance-cmd@.service` `external` | body | unchanged (1) | Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional), the same line as the seed template (TestCmdTemplateEqualsSeedOutsideTheNamedLines). Only hides more; no read added. |
+| `internal/host/units/carlos-instance-gen@.service` `external` | body | unchanged (1) | Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. |
+| `internal/host/units/carlos-instance-probe.service` `external` | body | unchanged (1) | Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional), so the probe proves what the tenants get. Only hides more; no read added. |
+| `internal/host/units/carlos-instance-seed@.service` `external` | body | unchanged (1) | Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. |
+| `internal/host/units/carlos-instance-sidecar@.service` `external` | body | unchanged (1) | Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. |
+| `internal/host/units/carlos-instance-tty@.service` `external` | body | unchanged (1) | Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. |
+| `internal/host/units/carlos-instance@.service` `external` | body | unchanged (1) | Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. |
+| `internal/status/snapshot.go` `CollectBox` | body | unchanged (28) | Task 3: copies Probes.MailerArmed into BoxMetrics.MailerArmed (json mailer_armed, omitempty; private, like Layout) and counts it in the condition that builds Metrics; the same 28 sites, no read added. |
+
+Envelopes re-pinned: `.`, `internal/host`, `internal/host/demo_units`, `internal/host/units`, `internal/instancectl`, `internal/mailer`, `internal/mailwire`, `internal/status`.
Review: a model from the other family than the author reads the branch's diff against main on the amadan.net remote (`origin` or `amadan`, whichever points at amadan.net) and gives a verdict for every unit and every re-pinned envelope above. For a unit, compare the change with its recorded disposition and basis below; for an envelope, read every changed function in the package and what it reaches. Reject if the change lets root open, run, query or follow anything it did not before from a path or input a tenant, an app or a box agent can create, write or name; if it weakens a check, refusal, validation, argument or environment the basis relies on; or if the diff cannot settle either. Otherwise approve. Record each verdict on #280 with the tip. A rejected unit goes back to the author to correct; nothing escalates to the census owner.
-Seal: `07b748a749084fdaf61c5087a6edfca8a79273962822ce551dd4d42b0d20c063` → `07b748a749084fdaf61c5087a6edfca8a79273962822ce551dd4d42b0d20c063`.
+Recorded dispositions, which each change must still satisfy:
+
+- `internal/host/agent.go` `statusLoop`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): the status tick's context carries the box's lifetime judge; read sites unchanged, offsets moved;rev3=census-ruling-rootfs-apps-2;basis=main's body as of the merge of origin/main 953b9fda (its later changes, regional box names and self-serve moves plan 1 among them, under main's own census rulings), where the tick fills rootfs_ready and rootfs_blocked from armedRootfs.Load().probe, which each tick runs NestedOK's checks and asks the control socket's GET /ready/rootfs (never the store); the same four direct sites;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Task 11 and #329 plan 3 Task 7: takes root's GET /egress reader and fills p.Egress = egressStatusProbe(egressStatus, routes, provision.PolicyReadStates()) and p.SizeCommittedMiB = sizeCommittedMiB(armedSizeSource.Load(), routes); the two added whole:Route sites are the tick's own registry list handed to those two units (decision rows), which read root's control socket and the activator's memory; no store request added; the four existing sites unchanged, offsets moved.;rev3=census-ruling-fleet-alerts-1;basis=the agent (carlos-edge.service, user carlos): the status tick passes os.Geteuid() to alertDeliveryProbe, which fills AlertDelivery.EngineBeat/EngineBeatWhy from engineBeatArmed (the env value and the euid only, no file access, root refused before the path is looked at), and fills Probes.DiskFullETAHours from diskETAProbe(&processDiskTrend, now), a Theil-Sen fit over the metrics loop's in-memory ring of disk readings; the same six sites, no read added, no store request added;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): the status tick's Probes gain HeldStreams: heldStreamsState(), which calls the edge's in-memory counters function (nil until the edge is ready). No file, bucket or registry access added.;rev3=census-ruling-stateless-replicas-3;basis=Fix round 1 Q20: read the detached in-memory replica snapshot source into Probes.ReplicaCopies on the existing five-minute tick. Existing six direct read sites unchanged. No additional bucket request, changed cadence or app lifecycle action.;rev3=census-ruling-agent-start-demo-3;basis=Report moved capability only when the serving edge reports readiness; report claim-seed support only with CARLOS_DEMO_CLAIM=1. Reads the explicit capability flag from the process environment; no new filesystem or registry read.;rev3=census-ruling-stateless-replicas-4-task5;basis=Task 5 fix round 1 (#511 R16 amendment): the status tick also fills Probes.ApplyFinished from systemApplyFinished(release.OptDir()), an Lstat of root's apply journal <opt>/system/router/journal.json in the root-owned, world-readable state directory: finished only when the journal is absent, any other answer unknown and so unfinished. Round 0: Probes.PrevRelease from prevReleaseOf (carlos.prev and carlos.prev.version, the files withMovesFields already reads). Reported in the private BoxMetrics block; no bucket request or cadence change.
+- `internal/host/bootstrap.go` `bootstrapWithGroup`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-region-ha-p3b;basis=Move bootstrapWith body here, retaining host.env, embedded unit reads and tmpfiles execution. Group live caller holds root mutation guard; skip automatic update/recovery units, preserve Restart=no/nftables drop-in and masks, and write separate root-owned /run/carlos-group-maintenance tmpfiles rule outside service ownership walk. No agent receipt read.;rev3=census-ruling-gvisor-demos;basis=Create the rootfs parent at 0700 and runtime root at 0755. Existing host.env/unit reads unchanged; workload templates remain unarmed.
+- `internal/host/bootstrap.go` `const tmpfilesConf`: authority, task A,C,G,J4. Basis: root-input;kept=A,C,G;scope=protected-decision-only
+- `internal/host/bootstrap.go` `privilegedPlan`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input
+- `internal/host/claimunit_template.go` `const claimBoundTemplate`: authority, task E2. Basis: PROPOSED E51: Root-only bound-unit template is held inside the claim renderer; ordinary bootstrap never enumerates or installs it.;rev3=census-ruling-instance-stop-execstop-528;basis=one line added after ExecStart=, ExecStop=-+/opt/carlos/carlos instance-stop $MAINPID (#528, Paul's option 2), plus TimeoutStopFailureMode=kill after TimeoutStopSec=20: PID 1 runs the platform binary's instance-stop as root (the + prefix) at a stop with $MAINPID, a value systemd supplies; instance-stop reads only that argument, /proc/self/cgroup and /proc/<MAINPID>/cgroup (kernel-written), and acts only through a pidfd on the unit's own main process (refused unless in the unit's own cgroup); no bind source, user, mount or tenant-writable path read added
+- `internal/host/demo_units/demo.conf` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-agent-start-demo-1;basis=Retains read-only /run and /var tmpfs overlays and all network/size restrictions. Resets InaccessiblePaths and restates /etc/carlos -/run/carlos-control so the hidden control directory need not exist during namespace setup; /etc/carlos remains required. No new source or bind.
+- `internal/host/units/carlos-dbread@.service` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-db-region-forward-1;basis=the db-read worker's units (written by root's ensureSystemUnits; carlos-dbread.socket bound by PID 1 and owned by carlos; carlos-dbread@.service runs as a DynamicUser with no network, its own PrivateTmp, /data, /var/lib, /opt/carlos and /run/carlos empty, /etc/carlos inaccessible): new
+- `internal/host/units/carlos-demo-build@.service` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-agent-start-demo-1;basis=New dynamic-UID compiler execution path with fixed argv, root-derived mounts, no network and bounded resources/termination.;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with a one-line comment
+- `internal/host/units/carlos-instance-cmd@.service` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-carlos-run;basis=the cmd unit template (applied by PID 1 as root; its process runs as carlos): extends the J4 seed pattern to the run role. The template equals the seed template outside named lines, and the template-equality test pins that. Root lays out a staged executable validated by the same refuseStagedExe the seed and generation paths use, then starts this unit, which runs as carlos with the instance's own reach. No new trust of registry, /data or agent-asserted content beyond the seed path;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment) so its stop starts only after the drain unit's stop has finished. Ordering only; no read added.
+- `internal/host/units/carlos-instance-gen@.service` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-instance-stop-execstop-528;basis=one line added after ExecStart=, ExecStop=-+/opt/carlos/carlos instance-stop $MAINPID (#528, Paul's option 2), plus TimeoutStopFailureMode=kill after TimeoutStopSec=20: PID 1 runs the platform binary's instance-stop as root (the + prefix) at a stop with $MAINPID, a value systemd supplies; instance-stop reads only that argument, /proc/self/cgroup and /proc/<MAINPID>/cgroup (kernel-written), and acts only through a pidfd on the unit's own main process (refused unless in the unit's own cgroup); no bind source, user, mount or tenant-writable path read added;rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment). Ordering only; no read added.
+- `internal/host/units/carlos-instance-probe.service` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-2;basis=one more BindReadOnlyPaths= line, so PID 1 opens one more bind source: /run/carlos-control/exe/_probe/box-addrs, bound to /opt/carlos/box-addrs, root's list of the box's own addresses, which RunProbe writes before every run (#367) in the root-only directory the unit already binds from; no tenant, app or agent input names or writes it;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service, so the probe proves what the tenants get (its new pts-private line); fix round 1 (Astra P2, roll order): one line outside the namespace block, Environment=CARLOS_PROBE_PTS_PRIVATE=1, a constant the unit sets for its own process (the probe, as carlos, in the namespace); it names no path, adds no bind source or Exec line, and root reads nothing new;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, inside the shared namespace block; plus one line outside it, Environment=CARLOS_PROBE_SYSCALL_FILTER=1, a constant the unit sets for its own process (the probe, as carlos); it names no path
+- `internal/host/units/carlos-instance-seed@.service` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment). Ordering only; no read added.
+- `internal/host/units/carlos-instance-sidecar@.service` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-instance-stop-execstop-528;basis=one line added after ExecStart=, ExecStop=-+/opt/carlos/carlos instance-stop $MAINPID (#528, Paul's option 2), plus TimeoutStopFailureMode=kill after TimeoutStopSec=20: PID 1 runs the platform binary's instance-stop as root (the + prefix) at a stop with $MAINPID, a value systemd supplies; instance-stop reads only that argument, /proc/self/cgroup and /proc/<MAINPID>/cgroup (kernel-written), and acts only through a pidfd on the unit's own main process (refused unless in the unit's own cgroup); no bind source, user, mount or tenant-writable path read added;rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment). Ordering only; no read added.
+- `internal/host/units/carlos-instance-tty@.service` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5, new: the binary tty template, carlos-instance-cmd@.service outside six named lines held by TestTTYTemplateEqualsCmdOutsideTheNamedLines: Description (tty), ExecStart/ExecStopPost instance-exec/instance-exit tty %I (the same root binary as every template), StandardInput=file:/run/carlos/logs/%I.tty.sock replacing the cmd StandardOutput socket (PID 1 opens it as root on the nosymfollow logs mount, as the cmd streams), StandardOutput=journal, StandardError=journal, and BindReadOnlyPaths sources tty-app/tty-live under /run/carlos-control/exe/%I (root-only exe layout, as cmd-app/cmd-live). Same namespace block byte for byte, runs as carlos. Task 6: POST /tty (handleOneShot(RoleTTY), claimAwareLegacy) starts it, after the role lock, the loaded-state refusal and refuseStagedExe; the tty-app/tty-live sources are laid out by ensureCmdExeAt(RoleTTY) and removed by removeCmdExe(RoleTTY) at /stop role=tty and /sweep;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment). Ordering only; no read added.
+- `internal/host/units/carlos-instance@.service` `external`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: one namespace-block line added after TemporaryFileSystem=/dev/mqueue:ro, TemporaryFileSystem=/dev/pts:ro (with its comment): PID 1 mounts an empty read-only tmpfs over the private /dev/pts, hiding the host devpts PrivateDevices= binds in; no bind source, Exec line, user or path read by root added; the block stays byte-identical across the binary templates (TestInstanceTemplatesShareOneNamespace);rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-instance-stop-execstop-528;basis=one line added after ExecStart=, ExecStop=-+/opt/carlos/carlos instance-stop $MAINPID (#528, Paul's option 2), plus TimeoutStopFailureMode=kill after TimeoutStopSec=20: PID 1 runs the platform binary's instance-stop as root (the + prefix) at a stop with $MAINPID, a value systemd supplies; instance-stop reads only that argument, /proc/self/cgroup and /proc/<MAINPID>/cgroup (kernel-written), and acts only through a pidfd on the unit's own main process (refused unless in the unit's own cgroup); no bind source, user, mount or tenant-writable path read added;rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment). Ordering only; no read added.
+- `internal/status/snapshot.go` `CollectBox`: legacy, task accepted-legacy. Basis: accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-rootfs-apps-2;basis=copies Probes.RootfsReady and RootfsBlocked into BoxMetrics (private, like Layout); the same 28 sites, no read added;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Task 11 and #329 plan 3 Task 7: copies Probes.Egress and Probes.SizeCommittedMiB into BoxMetrics (private, like Layout) and counts them in the condition that builds Metrics; the same 28 sites, no read added.;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3: comment only, the Hibernate count is left as is (display);rev3=census-ruling-regional-domains-447;basis=#447 Task 7: copies Probes.AliasesRead into BoxMetrics.AliasesRead (json aliases_read, omitempty) and counts it in the condition that builds Metrics; the same 28 sites, no read added;rev3=census-ruling-fleet-alerts-1;basis=copies Probes.DiskFullETAHours into BoxMetrics.DiskFullETAHours (json disk_full_eta_hours, omitempty; private, like Layout) and counts it in the condition that builds Metrics; the same 28 sites, no read added;rev3=census-ruling-edge-held-streams;basis=copies Probes.HeldStreams into BoxMetrics.HeldStreams (json held_streams, omitempty, additive) and counts it in the condition that builds Metrics; the same 28 sites, no read added.;rev3=census-ruling-stateless-replicas-3;basis=Fix round 1 Q20: carry already-supplied ReplicaCopies into a separate optional private BoxMetrics replica_copies field; allow copy evidence alone to create the metrics block. Upstreams retains address probes only. Existing 28 Route read sites unchanged; no filesystem, bucket, console or CLI read.;rev3=census-ruling-agent-start-demo-3;basis=Report claim-seed protocol capability only when explicitly configured and runtime moved readiness only when armed; dormant status keeps its original JSON shape. Census read-site delta: unchanged (28).;rev3=census-ruling-stateless-replicas-4-task5;basis=Task 5 (#511 R16 and its amendment): copies Probes.PrevRelease and Probes.ApplyFinished into BoxMetrics (json prev_release and apply_finished, omitempty; private, like Release) and counts them in the condition that builds Metrics; the same 28 sites, no read added.
+
+New dispositions, which census-propose wrote and the reviewer checks against the unit's reads and the diff:
+
+- new `internal/host/mailerreport.go:mailerArmed`: reads +file:Stat; written legacy, accepted-legacy, frozen
+- new `internal/host/units/carlos-mailer-arm.path:external`: reads +file:external; written legacy, accepted-legacy, frozen
+- new `internal/host/units/carlos-mailer.service:external`: reads +file:external; written legacy, accepted-legacy, frozen
+- new `internal/host/units/carlos-mailer.socket:external`: reads +file:external; written legacy, accepted-legacy, frozen
+
+Seal: `07b748a749084fdaf61c5087a6edfca8a79273962822ce551dd4d42b0d20c063` → `f949639f333c9a2e89bb120f64724ead4c55ee522914416b3ccc98bed460e49a`.
Overlay: `internal/provision/testdata/plan14-root-reads-platform-mail-submission.tsv`, appended to `internal/provision/testdata/plan14-root-reads-chain.tsv`.
diff --git a/internal/host/agent.go b/internal/host/agent.go
index b77c3e24b..98cfb7b2b 100644
--- a/internal/host/agent.go
+++ b/internal/host/agent.go
@@ -200,6 +200,7 @@ import (
"github.com/carlosframework/platform/internal/layout"
"github.com/carlosframework/platform/internal/lbhealth"
"github.com/carlosframework/platform/internal/lease"
+ "github.com/carlosframework/platform/internal/mailwire"
"github.com/carlosframework/platform/internal/metrics"
"github.com/carlosframework/platform/internal/moves"
"github.com/carlosframework/platform/internal/provision"
@@ -5068,6 +5069,10 @@ func statusLoop(reg *registry.Registry, svc *activator.Service, buildStates func
// The update-settings protocol this box enforces, and root's last
// decision per instance (settings spec §4.3). Private Metrics only.
fillUpdateProbes(&p, reg, release.OptDir())
+ // Whether this box's mailer is armed and answering (platform mail
+ // submission plan, gap G6 (b)): a stat, and a health call only when
+ // the socket exists. Private Metrics only.
+ p.MailerArmed = mailerArmed(mailwire.MailerSocket, mailerHealthTimeout)
// Each instance's egress read-back as root last asserted it, with
// the agent's own policy state where root has none (#328). Root's
// local socket and an in-memory map: no store request. Private
diff --git a/internal/host/bootstrap.go b/internal/host/bootstrap.go
index 08ad88e22..7920d6a25 100644
--- a/internal/host/bootstrap.go
+++ b/internal/host/bootstrap.go
@@ -52,6 +52,11 @@ const serviceUser = "carlos"
// dial sockets".
const socketsGroup = "carlos-sockets"
+// mailerUser is the box-local mailer's static user (platform mail
+// submission design, decision 2): its own uid, so the mailer's key is
+// readable by it and by nothing that runs as carlos.
+const mailerUser = "carlos-mailer"
+
// tmpfilesConf keeps /run/carlos across reboots (/run is tmpfs). Owned by the
// service user so the non-root units can bind their sockets there; group is
// the consumers group with SETGID so every socket an exec child binds inside
@@ -103,6 +108,15 @@ const tmpfilesConf = "d /data/.parked 2770 " + serviceUser + " " + serviceUser +
// so no carlos process can create, rename or replace anything in it;
// group carlos with search so the agent can connect.
"d /run/carlos-control 0750 root " + serviceUser + " -\n" +
+ // The box-local mailer's socket directory and key directory (platform
+ // mail submission design §5). Both root's, beside /run/carlos and
+ // /etc/carlos rather than under them, and both in every instance
+ // template's InaccessiblePaths. The socket directory is group carlos
+ // with search so the agent can dial; the key directory is group
+ // carlos-mailer, which uid carlos cannot traverse, so the key the
+ // operator writes into it is the mailer's alone.
+ "d /run/carlos-mailer 0750 root " + serviceUser + " -\n" +
+ "d /etc/carlos-mailer 0750 root " + mailerUser + " -\n" +
// The readiness probe's fixture (design §8.5, codex R11-1): a file
// root:carlos 0640 that an isolated instance must NOT be able to read.
// Written here, not by the control service, whose ProtectSystem=strict
@@ -113,6 +127,14 @@ const tmpfilesConf = "d /data/.parked 2770 " + serviceUser + " " + serviceUser +
// here, an empty listing inside the probe would prove nothing.
"f /dev/shm/carlos-probe 0644 root root - probe\n"
+// sysusersConf is etc/sysusers.d/carlos.conf. The mailer's user comes
+// first: tmpfiles' /etc/carlos-mailer line names its group, and a tmpfiles
+// line whose group does not resolve is dropped, so a box whose confs arrive
+// by a staged-tree refresh (no live useradd) gets the user from here,
+// before systemd-tmpfiles-setup runs.
+const sysusersConf = "u " + mailerUser + " - \"CARLOS mailer\" - /usr/sbin/nologin\n" +
+ "g " + socketsGroup + " -\n"
+
// journaldConfName is the journald drop-in every box gets (discussion #111).
//
// The name matches the one placed by hand on the flagship during the
@@ -171,6 +193,11 @@ const relayUnitName = "carlos-relay.service"
var enabledUnits = []string{"carlos-edge.service", relayUnitName, "carlos-adopt.timer", "carlos-adopt.path", "carlos-stage.path", "carlos-restart.path",
"carlos-system-update.path", "carlos-system-recover.service",
+ // The box-local mailer's arming path (platform mail submission design
+ // §5): armed like every .path, it starts carlos-mailer.socket only once
+ // an operator has written the key. The socket and the service are
+ // installed and never enabled on their own.
+ "carlos-mailer-arm.path",
// The isolated-exec mounts (design §3.2): the edge Requires= them.
"data-instances.mount", "run-carlos-instances.mount", "run-carlos-logs.mount",
// The root instance-control channel (design §5.2); socket-activated, so
@@ -623,7 +650,7 @@ func bootstrapWithGroup(root string, consumers []string, planJSON, group bool) e
// Before=systemd-tmpfiles-setup.service, so the group exists by the time
// the tmpfiles line is parsed, however the conf got there.
sysusersPath := filepath.Join(root, "etc", "sysusers.d", "carlos.conf")
- if err := os.WriteFile(sysusersPath, []byte("g "+socketsGroup+" -\n"), 0o644); err != nil {
+ if err := os.WriteFile(sysusersPath, []byte(sysusersConf), 0o644); err != nil {
return fmt.Errorf("write %s: %v", sysusersPath, err)
}
fmt.Fprintf(out, " wrote %s\n", sysusersPath)
@@ -747,6 +774,7 @@ func unitNames() ([]string, error) {
func privilegedPlan(consumers []string) [][]string {
plan := [][]string{
{"useradd", "--system", "--user-group", "--no-create-home", "--shell", "/usr/sbin/nologin", serviceUser},
+ {"useradd", "--system", "--user-group", "--no-create-home", "--shell", "/usr/sbin/nologin", mailerUser},
{"groupadd", "--system", socketsGroup},
{"chown", "-R", serviceUser + ":" + serviceUser, "/data"},
{"chown", "-R", serviceUser + ":" + socketsGroup, "/run/carlos"},
diff --git a/internal/host/bootstrap_test.go b/internal/host/bootstrap_test.go
new file mode 100644
index 000000000..0ca003b5f
--- /dev/null
+++ b/internal/host/bootstrap_test.go
@@ -0,0 +1,80 @@
+package host
+
+import (
+ "os"
+ "path/filepath"
+ "slices"
+ "strings"
+ "testing"
+)
+
+// The mailer's two directories (platform mail submission design §5): both
+// root's. The socket directory is group carlos with search, so the agent
+// can dial the socket; the key directory is group carlos-mailer, so uid
+// carlos cannot traverse it and the key in it is the mailer's alone.
+func TestTmpfilesMailerLines(t *testing.T) {
+ lines := strings.Split(tmpfilesConf, "\n")
+ for _, want := range []string{
+ "d /run/carlos-mailer 0750 root carlos -",
+ "d /etc/carlos-mailer 0750 root carlos-mailer -",
+ } {
+ if !slices.Contains(lines, want) {
+ t.Errorf("tmpfilesConf lacks %q", want)
+ }
+ }
+ // Nothing else in the conf names the mailer: no tmpfiles line may
+ // create, own or seed the key file. The operator writes it by hand.
+ for _, l := range lines {
+ if strings.Contains(l, "carlos-mailer/") {
+ t.Errorf("tmpfilesConf touches a path inside a mailer directory: %q", l)
+ }
+ }
+}
+
+// The sysusers snippet creates the mailer's user (and its group) before
+// the group line, so the tmpfiles line naming group carlos-mailer resolves
+// on a box whose confs arrive by a staged-tree refresh, with no live
+// useradd: systemd-sysusers runs before systemd-tmpfiles-setup, and a
+// tmpfiles line whose group does not resolve is dropped.
+func TestSysusersCreatesMailer(t *testing.T) {
+ root := t.TempDir()
+ if err := bootstrap(root, nil); err != nil {
+ t.Fatalf("bootstrap: %v", err)
+ }
+ b, err := os.ReadFile(filepath.Join(root, "etc", "sysusers.d", "carlos.conf"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ want := "u carlos-mailer - \"CARLOS mailer\" - /usr/sbin/nologin\ng carlos-sockets -\n"
+ if string(b) != want {
+ t.Fatalf("sysusers conf = %q, want %q", b, want)
+ }
+ // The tmpfiles conf bootstrap writes beside it names the group.
+ tf, err := os.ReadFile(filepath.Join(root, "etc", "tmpfiles.d", "carlos.conf"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !strings.Contains(string(tf), "d /etc/carlos-mailer 0750 root carlos-mailer -\n") {
+ t.Fatal("the staged tmpfiles conf lacks the key directory")
+ }
+}
+
+// A live bootstrap creates the mailer's user with the same guarded useradd
+// as carlos's, and before the tmpfiles conf that names its group is
+// written (privilegedPlan runs first on a live root).
+func TestPrivilegedPlanCreatesMailer(t *testing.T) {
+ plan := privilegedPlan(nil)
+ want := []string{"useradd", "--system", "--user-group", "--no-create-home", "--shell", "/usr/sbin/nologin", "carlos-mailer"}
+ i := slices.IndexFunc(plan, func(a []string) bool { return slices.Equal(a, want) })
+ if i < 0 {
+ t.Fatalf("privilegedPlan lacks %v: %v", want, plan)
+ }
+ if plan[0][len(plan[0])-1] != "carlos" || i != 1 {
+ t.Fatalf("the mailer's useradd is step %d, want 1, right after carlos's: %v", i, plan)
+ }
+ // runPrivileged's existence guard keys on the command's own last
+ // argument, so a box that already has the user re-runs cleanly.
+ if plan[i][0] != "useradd" || plan[i][len(plan[i])-1] != mailerUser {
+ t.Fatalf("the guard cannot see the subject: %v", plan[i])
+ }
+}
diff --git a/internal/host/claimunit_template.go b/internal/host/claimunit_template.go
index 748319fde..673218f50 100644
--- a/internal/host/claimunit_template.go
+++ b/internal/host/claimunit_template.go
@@ -32,7 +32,7 @@ TemporaryFileSystem=/var/cache:ro
TemporaryFileSystem=/var/lib:ro
TemporaryFileSystem=/opt/carlos:ro
BindReadOnlyPaths=/opt/carlos/carlos
-InaccessiblePaths=/etc/carlos /run/carlos-control
+InaccessiblePaths=/etc/carlos /run/carlos-control -/run/carlos-mailer -/etc/carlos-mailer
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
diff --git a/internal/host/dbreads_test.go b/internal/host/dbreads_test.go
index 542464139..e9c64e849 100644
--- a/internal/host/dbreads_test.go
+++ b/internal/host/dbreads_test.go
@@ -124,7 +124,7 @@ func TestDBReadUnitsCarryTheSandbox(t *testing.T) {
"DynamicUser=yes", "PrivateNetwork=yes", "RestrictAddressFamilies=AF_UNIX",
"TemporaryFileSystem=/data:ro /var/lib:ro /opt/carlos:ro /run/carlos:ro",
"BindReadOnlyPaths=/opt/carlos/carlos",
- "InaccessiblePaths=/etc/carlos -/run/carlos-control",
+ "InaccessiblePaths=/etc/carlos -/run/carlos-control -/run/carlos-mailer -/etc/carlos-mailer",
"PrivateTmp=yes", "MemoryMax=512M", "CPUQuota=100%", "TasksMax=16",
"LimitFSIZE=2147483648", "RuntimeMaxSec=20min",
"SystemCallFilter=@system-service", "NoNewPrivileges=yes", "CapabilityBoundingSet=", "ProtectProc=invisible",
diff --git a/internal/host/demo_policy_test.go b/internal/host/demo_policy_test.go
index 00ac9ed72..047c8ca24 100644
--- a/internal/host/demo_policy_test.go
+++ b/internal/host/demo_policy_test.go
@@ -25,7 +25,7 @@ func TestDemoPolicyRoundTrip(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- for _, want := range []string{"PrivateNetwork=yes", "TemporaryFileSystem=/run:ro /var:ro", "InaccessiblePaths=\nInaccessiblePaths=/etc/carlos -/run/carlos-control", "RestrictAddressFamilies=\nRestrictAddressFamilies=AF_UNIX", "IPAddressAllow=\n", "IPAddressDeny=any", "MemoryMax=268435456", "CPUWeight=50", "CPUQuota=50%", "IOWeight=50"} {
+ for _, want := range []string{"PrivateNetwork=yes", "TemporaryFileSystem=/run:ro /var:ro", "InaccessiblePaths=\nInaccessiblePaths=/etc/carlos -/run/carlos-control -/run/carlos-mailer -/etc/carlos-mailer", "RestrictAddressFamilies=\nRestrictAddressFamilies=AF_UNIX", "IPAddressAllow=\n", "IPAddressDeny=any", "MemoryMax=268435456", "CPUWeight=50", "CPUQuota=50%", "IOWeight=50"} {
if !strings.Contains(string(raw), want) {
t.Fatalf("missing %q in %s", want, raw)
}
diff --git a/internal/host/demo_units/demo.conf b/internal/host/demo_units/demo.conf
index 7dc3c8282..c67ef301b 100644
--- a/internal/host/demo_units/demo.conf
+++ b/internal/host/demo_units/demo.conf
@@ -7,5 +7,5 @@ IPAddressDeny=
IPAddressDeny=any
TemporaryFileSystem=/run:ro /var:ro
InaccessiblePaths=
-InaccessiblePaths=/etc/carlos -/run/carlos-control
+InaccessiblePaths=/etc/carlos -/run/carlos-control -/run/carlos-mailer -/etc/carlos-mailer
NetworkNamespacePath=
diff --git a/internal/host/host_test.go b/internal/host/host_test.go
index 803c2db38..862d0617f 100644
--- a/internal/host/host_test.go
+++ b/internal/host/host_test.go
@@ -82,6 +82,9 @@ var expectedUnits = []string{
"data-instances.mount",
"run-carlos-instances.mount",
"run-carlos-logs.mount",
+ "carlos-mailer-arm.path",
+ "carlos-mailer.service",
+ "carlos-mailer.socket",
}
// requireUnixSockets skips a test when the sandbox forbids unix-socket
@@ -1214,6 +1217,7 @@ func TestBootstrapPrivilegedPlanEnrollsConsumers(t *testing.T) {
// of consumer reach).
want := [][]string{
{"useradd", "--system", "--user-group", "--no-create-home", "--shell", "/usr/sbin/nologin", "carlos"},
+ {"useradd", "--system", "--user-group", "--no-create-home", "--shell", "/usr/sbin/nologin", "carlos-mailer"},
{"groupadd", "--system", "carlos-sockets"},
{"chown", "-R", "carlos:carlos", "/data"},
{"chown", "-R", "carlos:carlos-sockets", "/run/carlos"},
@@ -1226,8 +1230,8 @@ func TestBootstrapPrivilegedPlanEnrollsConsumers(t *testing.T) {
t.Errorf("privilegedPlan = %v, want %v", got, want)
}
// No consumers: same plan minus the usermod tail.
- if got := privilegedPlan(nil); !reflect.DeepEqual(got, want[:6]) {
- t.Errorf("privilegedPlan(nil) = %v, want %v", got, want[:6])
+ if got := privilegedPlan(nil); !reflect.DeepEqual(got, want[:7]) {
+ t.Errorf("privilegedPlan(nil) = %v, want %v", got, want[:7])
}
}
diff --git a/internal/host/mailerreport.go b/internal/host/mailerreport.go
new file mode 100644
index 000000000..5f399aad1
--- /dev/null
+++ b/internal/host/mailerreport.go
@@ -0,0 +1,42 @@
+package host
+
+import (
+ "context"
+ "io"
+ "net"
+ "net/http"
+ "os"
+ "time"
+)
+
+// mailerHealthTimeout bounds the status tick's mailer health call.
+const mailerHealthTimeout = 2 * time.Second
+
+// mailerArmed is the box report's MailerArmed (platform mail submission
+// plan, gap G6 (b)): the mailer's socket exists AND its GET /v1/health
+// answers 200 within timeout. The agent cannot look at the key itself:
+// /etc/carlos-mailer is 0750 root:carlos-mailer, which uid carlos cannot
+// traverse (design §5). The socket exists only once carlos-mailer-arm.path
+// has seen the key, and the health call fails while the mailer refuses to
+// start (no region, no loadable key), so the two together are the proxy.
+// The mailer's peer rule admits this call: it is the agent's main process.
+func mailerArmed(sock string, timeout time.Duration) bool {
+ fi, err := os.Stat(sock)
+ if err != nil || fi.Mode()&os.ModeSocket == 0 {
+ return false
+ }
+ client := &http.Client{Timeout: timeout, Transport: &http.Transport{
+ DisableKeepAlives: true,
+ DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
+ var d net.Dialer
+ return d.DialContext(ctx, "unix", sock)
+ },
+ }}
+ resp, err := client.Get("http://mailer/v1/health")
+ if err != nil {
+ return false
+ }
+ defer resp.Body.Close()
+ _, _ = io.Copy(io.Discard, io.LimitReader(resp.Body, 4<<10))
+ return resp.StatusCode == http.StatusOK
+}
diff --git a/internal/host/mailerreport_test.go b/internal/host/mailerreport_test.go
new file mode 100644
index 000000000..c7aded9b9
--- /dev/null
+++ b/internal/host/mailerreport_test.go
@@ -0,0 +1,85 @@
+package host
+
+import (
+ "net"
+ "net/http"
+ "os"
+ "path/filepath"
+ "testing"
+ "time"
+)
+
+// The box report's MailerArmed (plan gap G6 (b)): no socket is false; a
+// socket whose health answers 200 is true; a socket that accepts and never
+// answers, or answers something else, is false within the timeout.
+func TestBoxReportsMailerArmed(t *testing.T) {
+ dir, err := os.MkdirTemp("", "mar")
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { os.RemoveAll(dir) })
+
+ if mailerArmed(filepath.Join(dir, "absent.sock"), 200*time.Millisecond) {
+ t.Fatal("no socket: armed")
+ }
+ plain := filepath.Join(dir, "plain")
+ if err := os.WriteFile(plain, nil, 0o600); err != nil {
+ t.Fatal(err)
+ }
+ if mailerArmed(plain, 200*time.Millisecond) {
+ t.Fatal("a regular file at the socket path: armed")
+ }
+
+ serve := func(name string, h http.Handler) string {
+ sock := filepath.Join(dir, name)
+ ln, err := net.Listen("unix", sock)
+ if err != nil {
+ t.Fatal(err)
+ }
+ srv := &http.Server{Handler: h}
+ go srv.Serve(ln)
+ t.Cleanup(func() { srv.Close() })
+ return sock
+ }
+ ok := serve("ok.sock", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if r.URL.Path != "/v1/health" {
+ http.NotFound(w, r)
+ return
+ }
+ w.Write([]byte(`{"ok":true}`))
+ }))
+ if !mailerArmed(ok, 2*time.Second) {
+ t.Fatal("a healthy mailer: not armed")
+ }
+ sick := serve("sick.sock", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ http.Error(w, "no", http.StatusServiceUnavailable)
+ }))
+ if mailerArmed(sick, 2*time.Second) {
+ t.Fatal("a mailer answering 503: armed")
+ }
+
+ // A socket that accepts and never answers: what systemd's socket looks
+ // like while carlos-mailer.service refuses to start.
+ silent := filepath.Join(dir, "silent.sock")
+ ln, err := net.Listen("unix", silent)
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { ln.Close() })
+ go func() {
+ for {
+ c, err := ln.Accept()
+ if err != nil {
+ return
+ }
+ t.Cleanup(func() { c.Close() })
+ }
+ }()
+ start := time.Now()
+ if mailerArmed(silent, 300*time.Millisecond) {
+ t.Fatal("a silent socket: armed")
+ }
+ if time.Since(start) > 3*time.Second {
+ t.Fatalf("the health call outlived its timeout: %v", time.Since(start))
+ }
+}
diff --git a/internal/host/units/carlos-dbread@.service b/internal/host/units/carlos-dbread@.service
index 03284ae8a..263d21834 100644
--- a/internal/host/units/carlos-dbread@.service
+++ b/internal/host/units/carlos-dbread@.service
@@ -25,7 +25,7 @@ PrivateNetwork=yes
RestrictAddressFamilies=AF_UNIX
TemporaryFileSystem=/data:ro /var/lib:ro /opt/carlos:ro /run/carlos:ro
BindReadOnlyPaths=/opt/carlos/carlos
-InaccessiblePaths=/etc/carlos -/run/carlos-control
+InaccessiblePaths=/etc/carlos -/run/carlos-control -/run/carlos-mailer -/etc/carlos-mailer
PrivateTmp=yes
ProtectSystem=strict
ProtectHome=yes
diff --git a/internal/host/units/carlos-demo-build@.service b/internal/host/units/carlos-demo-build@.service
index 65ff1ab85..f03f3be01 100644
--- a/internal/host/units/carlos-demo-build@.service
+++ b/internal/host/units/carlos-demo-build@.service
@@ -34,7 +34,7 @@ StandardError=null
ProtectSystem=strict
ProtectHome=yes
TemporaryFileSystem=/data:ro /run:ro /var:ro /opt:ro /tmp:ro
-InaccessiblePaths=/etc/carlos -/run/carlos-control
+InaccessiblePaths=/etc/carlos -/run/carlos-control -/run/carlos-mailer -/etc/carlos-mailer
PrivateDevices=yes
TemporaryFileSystem=/dev/shm:ro /dev/mqueue:ro /dev/pts:ro
PrivateIPC=yes
diff --git a/internal/host/units/carlos-instance-cmd@.service b/internal/host/units/carlos-instance-cmd@.service
index a987dfeb5..31209d880 100644
--- a/internal/host/units/carlos-instance-cmd@.service
+++ b/internal/host/units/carlos-instance-cmd@.service
@@ -86,7 +86,7 @@ BindReadOnlyPaths=/opt/carlos/carlos
# connect from inside any instance's namespace is impossible outright,
# not merely refused by the peer check on the far end (final review,
# plan 2, item 3).
-InaccessiblePaths=/etc/carlos /run/carlos-control
+InaccessiblePaths=/etc/carlos /run/carlos-control -/run/carlos-mailer -/etc/carlos-mailer
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
diff --git a/internal/host/units/carlos-instance-gen@.service b/internal/host/units/carlos-instance-gen@.service
index 357b73447..2f6ca2a8b 100644
--- a/internal/host/units/carlos-instance-gen@.service
+++ b/internal/host/units/carlos-instance-gen@.service
@@ -78,7 +78,7 @@ BindReadOnlyPaths=/opt/carlos/carlos
# connect from inside any instance's namespace is impossible outright,
# not merely refused by the peer check on the far end (final review,
# plan 2, item 3).
-InaccessiblePaths=/etc/carlos /run/carlos-control
+InaccessiblePaths=/etc/carlos /run/carlos-control -/run/carlos-mailer -/etc/carlos-mailer
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
diff --git a/internal/host/units/carlos-instance-probe.service b/internal/host/units/carlos-instance-probe.service
index efe56e7f5..af994d5b4 100644
--- a/internal/host/units/carlos-instance-probe.service
+++ b/internal/host/units/carlos-instance-probe.service
@@ -70,7 +70,7 @@ BindReadOnlyPaths=/opt/carlos/carlos
# connect from inside any instance's namespace is impossible outright,
# not merely refused by the peer check on the far end (final review,
# plan 2, item 3).
-InaccessiblePaths=/etc/carlos /run/carlos-control
+InaccessiblePaths=/etc/carlos /run/carlos-control -/run/carlos-mailer -/etc/carlos-mailer
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
diff --git a/internal/host/units/carlos-instance-seed@.service b/internal/host/units/carlos-instance-seed@.service
index deb07691d..be7782e15 100644
--- a/internal/host/units/carlos-instance-seed@.service
+++ b/internal/host/units/carlos-instance-seed@.service
@@ -96,7 +96,7 @@ BindReadOnlyPaths=/opt/carlos/carlos
# connect from inside any instance's namespace is impossible outright,
# not merely refused by the peer check on the far end (final review,
# plan 2, item 3).
-InaccessiblePaths=/etc/carlos /run/carlos-control
+InaccessiblePaths=/etc/carlos /run/carlos-control -/run/carlos-mailer -/etc/carlos-mailer
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
diff --git a/internal/host/units/carlos-instance-sidecar@.service b/internal/host/units/carlos-instance-sidecar@.service
index b6f0f169c..cec22638c 100644
--- a/internal/host/units/carlos-instance-sidecar@.service
+++ b/internal/host/units/carlos-instance-sidecar@.service
@@ -105,7 +105,7 @@ BindReadOnlyPaths=/opt/carlos/carlos
# connect from inside any instance's namespace is impossible outright,
# not merely refused by the peer check on the far end (final review,
# plan 2, item 3).
-InaccessiblePaths=/etc/carlos /run/carlos-control
+InaccessiblePaths=/etc/carlos /run/carlos-control -/run/carlos-mailer -/etc/carlos-mailer
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
diff --git a/internal/host/units/carlos-instance-tty@.service b/internal/host/units/carlos-instance-tty@.service
index 79036d4c1..13a54b531 100644
--- a/internal/host/units/carlos-instance-tty@.service
+++ b/internal/host/units/carlos-instance-tty@.service
@@ -90,7 +90,7 @@ BindReadOnlyPaths=/opt/carlos/carlos
# connect from inside any instance's namespace is impossible outright,
# not merely refused by the peer check on the far end (final review,
# plan 2, item 3).
-InaccessiblePaths=/etc/carlos /run/carlos-control
+InaccessiblePaths=/etc/carlos /run/carlos-control -/run/carlos-mailer -/etc/carlos-mailer
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
diff --git a/internal/host/units/carlos-instance@.service b/internal/host/units/carlos-instance@.service
index 0a36229b9..cd041784b 100644
--- a/internal/host/units/carlos-instance@.service
+++ b/internal/host/units/carlos-instance@.service
@@ -105,7 +105,7 @@ BindReadOnlyPaths=/opt/carlos/carlos
# connect from inside any instance's namespace is impossible outright,
# not merely refused by the peer check on the far end (final review,
# plan 2, item 3).
-InaccessiblePaths=/etc/carlos /run/carlos-control
+InaccessiblePaths=/etc/carlos /run/carlos-control -/run/carlos-mailer -/etc/carlos-mailer
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
diff --git a/internal/host/units/carlos-mailer-arm.path b/internal/host/units/carlos-mailer-arm.path
new file mode 100644
index 000000000..d60ff8611
--- /dev/null
+++ b/internal/host/units/carlos-mailer-arm.path
@@ -0,0 +1,18 @@
+# Arms the box-local mailer (platform mail submission design §5) once an
+# operator has written its key. The key is armed by hand, never through
+# user_data, SSM or the bucket, so this unit is how a box with no key stays
+# inert: nothing listens until /etc/carlos-mailer/keys exists. Bootstrap
+# enables and starts every .path (armedUnits), so writing the key is the
+# operator's only step.
+#
+# /etc/carlos-mailer is 0750 root:carlos-mailer (tmpfiles): uid carlos
+# cannot traverse it, and only root writes it. PID 1 watches the path.
+[Unit]
+Description=carlos mailer arming (start the mailer socket once its key exists)
+
+[Path]
+PathExists=/etc/carlos-mailer/keys
+Unit=carlos-mailer.socket
+
+[Install]
+WantedBy=multi-user.target
diff --git a/internal/host/units/carlos-mailer.service b/internal/host/units/carlos-mailer.service
new file mode 100644
index 000000000..369aa2ff0
--- /dev/null
+++ b/internal/host/units/carlos-mailer.service
@@ -0,0 +1,62 @@
+# The box-local mailer (platform mail submission design §5): an instance of
+# a switched app submits a message on its own control socket, the agent
+# stamps it with the socket's route and forwards it here, and this process
+# checks the sender's policy and sends through SES as the region's
+# dedicated IAM user, carlos-mailer-<region>.
+#
+# It runs as its own static user, carlos-mailer, never as carlos: the key in
+# /etc/carlos-mailer/keys (0640 root:carlos-mailer, under a 0750 directory
+# uid carlos cannot traverse) is readable by this process alone. The box
+# role grants it nothing, and IMDS is denied to it twice: here by
+# IPAddressDeny, and in the SDK by AWS_EC2_METADATA_DISABLED and by building
+# every client from the static key (rootaws.LoadStaticConfig).
+#
+# host.env is read by PID 1 (EnvironmentFile), so this user needs no read
+# access to it; the secrets key it may hold is unset before exec.
+#
+# Socket-activated by carlos-mailer.socket, which carlos-mailer-arm.path
+# starts once the key exists. Not enabled on its own.
+[Unit]
+Description=carlos mailer (box-local SES submission for switched apps)
+Requires=carlos-mailer.socket
+After=carlos-mailer.socket network-online.target
+Wants=network-online.target
+ConditionPathExists=/etc/carlos-mailer/keys
+
+[Service]
+EnvironmentFile=-/etc/carlos/host.env
+UnsetEnvironment=CARLOS_SECRETS_KEY
+Environment=AWS_EC2_METADATA_DISABLED=true
+ExecStart=/opt/carlos/carlos mailer serve
+Restart=always
+RestartSec=5
+
+User=carlos-mailer
+Group=carlos-mailer
+StateDirectory=carlos-mailer
+StateDirectoryMode=0700
+IPAddressDeny=169.254.169.254/32 fd00:ec2::254/128
+
+NoNewPrivileges=yes
+ProtectSystem=strict
+ProtectHome=yes
+PrivateTmp=yes
+PrivateDevices=yes
+ProtectClock=yes
+ProtectHostname=yes
+ProtectKernelTunables=yes
+ProtectKernelModules=yes
+ProtectKernelLogs=yes
+ProtectControlGroups=yes
+ProtectProc=invisible
+RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
+RestrictNamespaces=yes
+RestrictRealtime=yes
+RestrictSUIDSGID=yes
+LockPersonality=yes
+MemoryDenyWriteExecute=yes
+SystemCallFilter=@system-service
+SystemCallErrorNumber=EPERM
+SystemCallArchitectures=native
+MemoryHigh=160M
+MemoryMax=256M
diff --git a/internal/host/units/carlos-mailer.socket b/internal/host/units/carlos-mailer.socket
new file mode 100644
index 000000000..c2f91d739
--- /dev/null
+++ b/internal/host/units/carlos-mailer.socket
@@ -0,0 +1,20 @@
+# The box-local mailer's socket (platform mail submission design §5). In
+# /run/carlos-mailer, a root-owned directory beside /run/carlos, never under
+# it, and hidden from every instance template by InaccessiblePaths, as
+# /run/carlos-control is. Owned by carlos so the agent can connect; the
+# mailer authenticates the peer process itself (decision 3: uid carlos AND
+# carlos-edge.service's MainPID), so a flat exec child of the agent, which
+# shares the uid, is still refused.
+#
+# Started by carlos-mailer-arm.path once the key exists. The condition keeps
+# a hand-run start on an unarmed box from listening.
+[Unit]
+Description=carlos mailer socket (agent to box-local mailer)
+ConditionPathExists=/etc/carlos-mailer/keys
+
+[Socket]
+ListenStream=/run/carlos-mailer/mailer.sock
+SocketUser=carlos
+SocketGroup=carlos
+SocketMode=0600
+Accept=no
diff --git a/internal/host/units_isolation_test.go b/internal/host/units_isolation_test.go
index 3b1b98f09..72f8d8c13 100644
--- a/internal/host/units_isolation_test.go
+++ b/internal/host/units_isolation_test.go
@@ -3,6 +3,7 @@ package host
import (
"os"
"path/filepath"
+ "slices"
"strings"
"testing"
@@ -373,7 +374,9 @@ func TestSameUIDAuditIsCoveredByTheTemplates(t *testing.T) {
for _, key := range []string{"TemporaryFileSystem=", "InaccessiblePaths="} {
if strings.HasPrefix(line, key) {
for _, p := range strings.Fields(strings.TrimPrefix(line, key)) {
- p = strings.TrimSuffix(p, ":ro")
+ // A "-" prefix makes a missing path a no-op, not a
+ // different path: the entry still hides it.
+ p = strings.TrimPrefix(strings.TrimSuffix(p, ":ro"), "-")
if path == p || strings.HasPrefix(path, p+"/") {
return true
}
@@ -389,7 +392,10 @@ func TestSameUIDAuditIsCoveredByTheTemplates(t *testing.T) {
}
for _, name := range names {
u := readUnit(t, name)
- if !strings.Contains(u, "User=carlos") {
+ // The audit is of uid carlos's units: User=carlos as a whole line.
+ // carlos-mailer.service runs as its own uid, which a tenant does
+ // not share, and its state directory is that uid's alone (0700).
+ if !slices.Contains(strings.Split(u, "\n"), "User=carlos") {
continue
}
for _, line := range strings.Split(u, "\n") {
@@ -417,7 +423,7 @@ func TestSameUIDAuditIsCoveredByTheTemplates(t *testing.T) {
}
}
// Credential inputs a carlos-group process reads (the second table).
- for _, cred := range []string{"/etc/carlos/relay-masters"} {
+ for _, cred := range []string{"/etc/carlos/relay-masters", "/etc/carlos-mailer/keys"} {
if !hidden(cred) {
t.Errorf("credential input %s is not hidden from tenants", cred)
}
@@ -649,3 +655,153 @@ func TestLitestreamUnitLogsWarningsOnly(t *testing.T) {
t.Error("carlos-litestream.service sets LogLevelMax=, which would drop litestream's errors")
}
}
+
+// The box-local mailer's socket and key directories (platform mail
+// submission design §5, decision 3) are hidden from every unit that hides
+// the root control channel: the set of units naming /run/carlos-control on
+// an active InaccessiblePaths= line is derived, never listed, so a new
+// tenant template that hides one and forgets the other fails here. Both
+// entries are "-"-prefixed: a box that has not yet run tmpfiles has neither
+// directory, and a missing non-optional target fails the unit's start,
+// which would fail every instance start on the fleet.
+//
+// Two renderings that are not unit files carry the control channel too:
+// the claim-bound template (dormant with claims) and the demo boxes'
+// drop-in, which resets InaccessiblePaths= on carlos-instance@ and
+// carlos-instance-gen@ and so would otherwise drop the mailer entries.
+func TestMailerPathsHiddenFromEveryTenantTemplate(t *testing.T) {
+ names, err := unitNames()
+ if err != nil {
+ t.Fatal(err)
+ }
+ bodies := map[string]string{"claimBoundTemplate": claimBoundTemplate, "demo_units/demo.conf": demoNetworkDropIn}
+ for _, name := range names {
+ bodies[name] = readUnit(t, name)
+ }
+ names = append(names, "claimBoundTemplate", "demo_units/demo.conf")
+ var carrying []string
+ for _, name := range names {
+ for _, line := range strings.Split(bodies[name], "\n") {
+ line = strings.TrimSpace(line)
+ if !strings.HasPrefix(line, "InaccessiblePaths=") {
+ continue
+ }
+ fields := strings.Fields(strings.TrimPrefix(line, "InaccessiblePaths="))
+ if !slices.Contains(fields, "/run/carlos-control") && !slices.Contains(fields, "-/run/carlos-control") {
+ continue
+ }
+ carrying = append(carrying, name)
+ for _, want := range []string{"-/run/carlos-mailer", "-/etc/carlos-mailer"} {
+ if !slices.Contains(fields, want) {
+ t.Errorf("%s hides /run/carlos-control but not %s: %q", name, want, line)
+ }
+ }
+ for _, f := range fields {
+ if strings.Contains(f, "carlos-mailer") && !strings.HasPrefix(f, "-") {
+ t.Errorf("%s: %s is not optional; a box before tmpfiles ran would fail every start", name, f)
+ }
+ }
+ }
+ }
+ // The nine templates the plan names, at least: a derivation that found
+ // none would pass vacuously.
+ for _, want := range []string{"carlos-instance@.service", "carlos-instance-cmd@.service", "carlos-instance-gen@.service",
+ "carlos-instance-seed@.service", "carlos-instance-sidecar@.service", "carlos-instance-tty@.service",
+ "carlos-instance-probe.service", "carlos-dbread@.service", "carlos-demo-build@.service",
+ "claimBoundTemplate", "demo_units/demo.conf"} {
+ if !slices.Contains(carrying, want) {
+ t.Errorf("%s does not hide /run/carlos-control on an active line", want)
+ }
+ }
+ // And no unit names the mailer's paths without the control channel's.
+ for _, name := range names {
+ for _, line := range strings.Split(bodies[name], "\n") {
+ line = strings.TrimSpace(line)
+ if strings.HasPrefix(line, "InaccessiblePaths=") && strings.Contains(line, "carlos-mailer") && !slices.Contains(carrying, name) {
+ t.Errorf("%s hides the mailer's paths but not the control channel", name)
+ }
+ }
+ }
+}
+
+// The mailer's three units, directive for directive where it matters (test
+// 8.9's unit-file half: the mailer cannot reach IMDS, runs as its own user,
+// and writes nothing but its state directory).
+func TestMailerUnitShape(t *testing.T) {
+ svc := unitDirectives(t, "carlos-mailer.service")
+ for _, want := range []string{
+ "Requires=carlos-mailer.socket",
+ "ConditionPathExists=/etc/carlos-mailer/keys",
+ "EnvironmentFile=-/etc/carlos/host.env",
+ "UnsetEnvironment=CARLOS_SECRETS_KEY",
+ "Environment=AWS_EC2_METADATA_DISABLED=true",
+ "ExecStart=/opt/carlos/carlos mailer serve",
+ "Restart=always",
+ "RestartSec=5",
+ "User=carlos-mailer",
+ "Group=carlos-mailer",
+ "StateDirectory=carlos-mailer",
+ "StateDirectoryMode=0700",
+ "IPAddressDeny=169.254.169.254/32 fd00:ec2::254/128",
+ "NoNewPrivileges=yes",
+ "ProtectSystem=strict",
+ "ProtectHome=yes",
+ "PrivateTmp=yes",
+ "PrivateDevices=yes",
+ "ProtectProc=invisible",
+ "RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX",
+ "RestrictNamespaces=yes",
+ "RestrictSUIDSGID=yes",
+ "MemoryDenyWriteExecute=yes",
+ "SystemCallFilter=@system-service",
+ "MemoryMax=256M",
+ } {
+ if !slices.Contains(svc, want) {
+ t.Errorf("carlos-mailer.service lacks %q", want)
+ }
+ }
+ for _, d := range svc {
+ switch {
+ case strings.HasPrefix(d, "ReadWritePaths="), strings.HasPrefix(d, "BindPaths="):
+ t.Errorf("carlos-mailer.service writes outside its state directory: %q", d)
+ case strings.HasPrefix(d, "User=") && d != "User=carlos-mailer":
+ t.Errorf("carlos-mailer.service runs as %q", d)
+ case strings.HasPrefix(d, "IPAddressAllow="):
+ t.Errorf("carlos-mailer.service re-allows addresses: %q", d)
+ case strings.HasPrefix(d, "AmbientCapabilities="), strings.HasPrefix(d, "CapabilityBoundingSet="):
+ t.Errorf("carlos-mailer.service takes capabilities: %q", d)
+ }
+ }
+ sock := unitDirectives(t, "carlos-mailer.socket")
+ for _, want := range []string{
+ "ConditionPathExists=/etc/carlos-mailer/keys",
+ "ListenStream=/run/carlos-mailer/mailer.sock",
+ "SocketUser=carlos",
+ "SocketGroup=carlos",
+ "SocketMode=0600",
+ "Accept=no",
+ } {
+ if !slices.Contains(sock, want) {
+ t.Errorf("carlos-mailer.socket lacks %q", want)
+ }
+ }
+ if slices.ContainsFunc(sock, func(d string) bool { return strings.HasPrefix(d, "WantedBy=") }) {
+ t.Error("carlos-mailer.socket is installed into a target; only carlos-mailer-arm.path starts it")
+ }
+ arm := unitDirectives(t, "carlos-mailer-arm.path")
+ for _, want := range []string{"PathExists=/etc/carlos-mailer/keys", "Unit=carlos-mailer.socket", "WantedBy=multi-user.target"} {
+ if !slices.Contains(arm, want) {
+ t.Errorf("carlos-mailer-arm.path lacks %q", want)
+ }
+ }
+ // The path unit is enabled and armed like every .path; the socket and
+ // the service are installed and never enabled on their own.
+ if !slices.Contains(enabledUnits, "carlos-mailer-arm.path") || !slices.Contains(armedUnits(enabledUnits), "carlos-mailer-arm.path") {
+ t.Error("carlos-mailer-arm.path is not enabled and armed")
+ }
+ for _, never := range []string{"carlos-mailer.socket", "carlos-mailer.service"} {
+ if slices.Contains(enabledUnits, never) {
+ t.Errorf("%s is enabled; only the arming path may start it", never)
+ }
+ }
+}
diff --git a/internal/host/units_rootfs_test.go b/internal/host/units_rootfs_test.go
index b55325bc4..ddf87f49e 100644
--- a/internal/host/units_rootfs_test.go
+++ b/internal/host/units_rootfs_test.go
@@ -66,11 +66,11 @@ func TestRootfsNamespaceRestatesTheBinaryBlock(t *testing.T) {
rfs[d] = true
}
dropped := map[string]string{
- "TemporaryFileSystem=/var/cache:ro": "the host's /var is not in an image root (probe root-image, mounts-allowlisted)",
- "TemporaryFileSystem=/var/lib:ro": "same",
- "InaccessiblePaths=/etc/carlos /run/carlos-control": "neither path exists in an image root (probe etc-carlos, control-unreachable)",
- "PrivateTmp=yes": "replaced by a tmpfs on /tmp (probe tmp-private)",
- "ProtectControlGroups=yes": "replaced by strict (probe cgroup-strict)",
+ "TemporaryFileSystem=/var/cache:ro": "the host's /var is not in an image root (probe root-image, mounts-allowlisted)",
+ "TemporaryFileSystem=/var/lib:ro": "same",
+ "InaccessiblePaths=/etc/carlos /run/carlos-control -/run/carlos-mailer -/etc/carlos-mailer": "none of these paths exists in an image root (probe etc-carlos, control-unreachable); the mailer's two are optional on the binary templates and absent here for the same reason",
+ "PrivateTmp=yes": "replaced by a tmpfs on /tmp (probe tmp-private)",
+ "ProtectControlGroups=yes": "replaced by strict (probe cgroup-strict)",
"BindReadOnlyPaths=-/run/systemd/resolve/resolv.conf:/etc/resolv.conf": "replaced by root's per-instance copy outside the block (probe dns)",
}
added := map[string]bool{
diff --git a/internal/instancectl/peer_linux.go b/internal/instancectl/peer_linux.go
index 6678a0218..50475715a 100644
--- a/internal/instancectl/peer_linux.go
+++ b/internal/instancectl/peer_linux.go
@@ -69,6 +69,30 @@ func productionPeerOK() func(net.Conn) error {
}
}
+// EdgeMainPIDPeer is this package's peer rule for another box-local
+// service to apply at its own accept: uid carlos AND carlos-edge.service's
+// MainPID (isolated-exec design §5.4). The box-local mailer uses it
+// (platform mail submission design, decision 3). It is productionPeerOK,
+// unchanged: a missing carlos user is fatal at start, and the MainPID is
+// asked of systemctl with the same cache and forced re-read.
+func EdgeMainPIDPeer() func(net.Conn) error { return productionPeerOK() }
+
+// EdgePeerRuleFor is EdgeMainPIDPeer's decision with the carlos uid and
+// the MainPID source supplied rather than looked up: the same SO_PEERCRED
+// read and the same edgePeer check. It exists so another package's tests
+// (the mailer's peer tests) exercise this rule over a real socket, as the
+// test process's own uid and pid, without a carlos user or systemd.
+func EdgePeerRuleFor(carlosUID int, mainPID func() (int, error)) func(net.Conn) error {
+ peer := &edgePeer{carlosUID: carlosUID, mainPID: mainPID, now: time.Now}
+ return func(conn net.Conn) error {
+ cred, err := peerCred(conn)
+ if err != nil {
+ return err
+ }
+ return peer.check(cred.Uid, cred.Pid)
+ }
+}
+
// systemdEdgeMainPID is carlos-edge.service's MainPID as systemd reports
// it now; 0 when the unit has none.
func systemdEdgeMainPID() (int, error) {
diff --git a/internal/instancectl/peer_other.go b/internal/instancectl/peer_other.go
index bcc138844..6b6017e58 100644
--- a/internal/instancectl/peer_other.go
+++ b/internal/instancectl/peer_other.go
@@ -10,6 +10,18 @@ import (
func productionPeerOK() func(net.Conn) error {
return func(net.Conn) error { return errors.ErrUnsupported }
}
+
+// EdgeMainPIDPeer refuses every peer off Linux: there is no SO_PEERCRED
+// and no systemd to name the edge's main pid.
+func EdgeMainPIDPeer() func(net.Conn) error {
+ return func(net.Conn) error { return errors.ErrUnsupported }
+}
+
+// EdgePeerRuleFor refuses every peer off Linux, as EdgeMainPIDPeer does.
+func EdgePeerRuleFor(int, func() (int, error)) func(net.Conn) error {
+ return func(net.Conn) error { return errors.ErrUnsupported }
+}
+
func activatedListener() (net.Listener, bool, error) { return nil, false, errors.ErrUnsupported }
func bindControlSocket(string) (net.Listener, error) { return nil, errors.ErrUnsupported }
func ProbeFixturesOK() error { return errors.ErrUnsupported }
diff --git a/internal/mailer/peer.go b/internal/mailer/peer.go
new file mode 100644
index 000000000..0e4d8b93e
--- /dev/null
+++ b/internal/mailer/peer.go
@@ -0,0 +1,63 @@
+package mailer
+
+import (
+ "errors"
+ "net"
+ "time"
+)
+
+// errNoPeerRule is the refusal a listener with no peer rule gives every
+// connection: a mailer that was not told who may dial it admits nobody.
+var errNoPeerRule = errors.New("no peer rule configured")
+
+// vettedListener runs the peer rule inside Accept, so a refused peer is
+// closed before net/http reads a byte from it (platform mail submission
+// design, decision 3). It is instancectl's vettedListener, copied rather
+// than shared so that package's body stays as it is.
+type vettedListener struct {
+ net.Listener
+ ok func(net.Conn) error
+ logf func(string, ...any)
+ now func() time.Time
+
+ // lastLog and suppressed hold the refusal log to one line a second: a
+ // refused peer reconnecting in a loop would otherwise flood the journal
+ // at its own rate. Accept runs on net/http's one accept goroutine, so
+ // these need no lock.
+ lastLog time.Time
+ suppressed int
+}
+
+func (v *vettedListener) Accept() (net.Conn, error) {
+ for {
+ c, err := v.Listener.Accept()
+ if err != nil {
+ return nil, err
+ }
+ check := v.ok
+ if check == nil {
+ check = func(net.Conn) error { return errNoPeerRule }
+ }
+ if err := check(c); err != nil {
+ v.logRefusal(err)
+ c.Close()
+ continue
+ }
+ return c, nil
+ }
+}
+
+func (v *vettedListener) logRefusal(err error) {
+ now := v.now()
+ if !v.lastLog.IsZero() && now.Sub(v.lastLog) < time.Second {
+ v.suppressed++
+ return
+ }
+ if v.suppressed > 0 {
+ v.logf("mailer: refused connection: %v (%d more refusals suppressed)", err, v.suppressed)
+ } else {
+ v.logf("mailer: refused connection: %v", err)
+ }
+ v.lastLog = now
+ v.suppressed = 0
+}
diff --git a/internal/mailer/server.go b/internal/mailer/server.go
new file mode 100644
index 000000000..e74d56556
--- /dev/null
+++ b/internal/mailer/server.go
@@ -0,0 +1,107 @@
+// Package mailer is the box-local mailer (platform mail submission design,
+// docs/superpowers/specs/2026-11-12-platform-mail-submission-design.md §5).
+// An instance of a switched app submits a message on its own control
+// socket; the agent stamps it with that socket's route and forwards it here
+// over /run/carlos-mailer/mailer.sock. The mailer admits only the agent's
+// main process (decision 3), checks the sender's policy, and sends through
+// SES as the region's dedicated IAM user.
+//
+// It runs as uid carlos-mailer, under carlos-mailer.service. It never
+// imports internal/mail: the wire types it shares with the console are in
+// internal/mailwire, which keeps internal/mail's IAM and SES walks out of
+// the root binary.
+package mailer
+
+import (
+ "context"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "net"
+ "net/http"
+ "os"
+ "strconv"
+ "time"
+)
+
+// Config is one mailer server.
+type Config struct {
+ // Listener is the socket systemd passed (ActivatedListener).
+ Listener net.Listener
+ // PeerOK decides each connection before a byte is read. Production
+ // passes instancectl.EdgeMainPIDPeer(): uid carlos AND the MainPID of
+ // carlos-edge.service. Nil refuses every connection.
+ PeerOK func(net.Conn) error
+ // Handler serves admitted connections. Nil serves NewHandler(nil).
+ Handler http.Handler
+ // Logf is the journal; nil discards.
+ Logf func(string, ...any)
+}
+
+// Serve serves cfg.Handler on cfg.Listener until ctx ends, with the peer
+// rule applied inside Accept. It returns nil when ctx ended it.
+func Serve(ctx context.Context, cfg Config) error {
+ if cfg.Listener == nil {
+ return errors.New("mailer: no listener")
+ }
+ logf := cfg.Logf
+ if logf == nil {
+ logf = func(string, ...any) {}
+ }
+ h := cfg.Handler
+ if h == nil {
+ h = NewHandler(nil)
+ }
+ vetted := &vettedListener{Listener: cfg.Listener, ok: cfg.PeerOK, logf: logf, now: time.Now}
+ srv := &http.Server{
+ Handler: h,
+ ReadHeaderTimeout: 5 * time.Second,
+ // A whole request, body included, is at most 14 MiB over a local
+ // socket; a peer that trickles it is cut off.
+ ReadTimeout: 30 * time.Second,
+ // Past the agent's own 60 s forward timeout: the answer to a slow
+ // SES call still reaches the agent before it gives up.
+ WriteTimeout: 90 * time.Second,
+ }
+ // One request per connection: the agent dials afresh for every message.
+ srv.SetKeepAlivesEnabled(false)
+ go func() {
+ <-ctx.Done()
+ srv.Close()
+ }()
+ err := srv.Serve(vetted)
+ if errors.Is(err, http.ErrServerClosed) || ctx.Err() != nil {
+ return nil
+ }
+ return err
+}
+
+// NewHandler is the mailer's routes: GET /v1/health, and POST /v1/send
+// when send is not nil.
+func NewHandler(send http.Handler) http.Handler {
+ mux := http.NewServeMux()
+ mux.HandleFunc("GET /v1/health", func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _ = json.NewEncoder(w).Encode(map[string]bool{"ok": true})
+ })
+ if send != nil {
+ mux.Handle("POST /v1/send", send)
+ }
+ return mux
+}
+
+// ActivatedListener is the one socket systemd passed: LISTEN_PID names
+// this process and LISTEN_FDS is 1, at fd 3. Anything else is an error,
+// and the mailer refuses to start: it never binds the path itself, so the
+// socket's owner and mode are always the socket unit's.
+func ActivatedListener(getenv func(string) string, pid int) (net.Listener, error) {
+ if getenv("LISTEN_PID") != strconv.Itoa(pid) {
+ return nil, errors.New("no socket from systemd (LISTEN_PID does not name this process); carlos-mailer.socket starts this")
+ }
+ if n := getenv("LISTEN_FDS"); n != "1" {
+ return nil, fmt.Errorf("LISTEN_FDS=%q, want 1", n)
+ }
+ f := os.NewFile(3, "mailer.sock")
+ defer f.Close()
+ return net.FileListener(f)
+}
diff --git a/internal/mailer/server_linux_test.go b/internal/mailer/server_linux_test.go
new file mode 100644
index 000000000..752231e03
--- /dev/null
+++ b/internal/mailer/server_linux_test.go
@@ -0,0 +1,72 @@
+//go:build linux
+
+package mailer
+
+import (
+ "errors"
+ "io"
+ "net/http"
+ "os"
+ "sync/atomic"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/instancectl"
+)
+
+// The peer rule is instancectl's (design decision 3): uid carlos AND the
+// MainPID of carlos-edge.service, read through SO_PEERCRED. These run the
+// real rule over a real socket with the test process standing in for the
+// agent: its own uid is "carlos" and its own pid is "the edge's MainPID",
+// or not, per case (test 8.3).
+
+func mainPIDIs(pid int) func() (int, error) { return func() (int, error) { return pid, nil } }
+
+// A uid-carlos process that is not the edge's main process (a flat exec
+// child of the agent, which shares the uid) is refused before a byte is read.
+func TestMailerPeerRefusesNonAgentPid(t *testing.T) {
+ var seen atomic.Int32
+ rule := instancectl.EdgePeerRuleFor(os.Getuid(), mainPIDIs(os.Getpid()+1))
+ sock, logs := serveOn(t, rule, countingHandler(&seen))
+ if got := rawExchange(t, sock); got != "" {
+ t.Fatalf("a non-agent pid read %q", got)
+ }
+ if seen.Load() != 0 || logs.n.Load() == 0 {
+ t.Fatalf("handler ran %d times, %d log lines", seen.Load(), logs.n.Load())
+ }
+}
+
+// Any other uid is refused, even as the edge's main pid.
+func TestMailerPeerRefusesOtherUid(t *testing.T) {
+ var seen atomic.Int32
+ rule := instancectl.EdgePeerRuleFor(os.Getuid()+1, mainPIDIs(os.Getpid()))
+ sock, _ := serveOn(t, rule, countingHandler(&seen))
+ if got := rawExchange(t, sock); got != "" || seen.Load() != 0 {
+ t.Fatalf("another uid was admitted: %q", got)
+ }
+}
+
+// With no MainPID (the edge restarting), everyone is refused.
+func TestMailerPeerRefusesWhenEdgeHasNoMainPID(t *testing.T) {
+ var seen atomic.Int32
+ rule := instancectl.EdgePeerRuleFor(os.Getuid(), func() (int, error) { return 0, errors.New("no unit") })
+ sock, _ := serveOn(t, rule, countingHandler(&seen))
+ if got := rawExchange(t, sock); got != "" || seen.Load() != 0 {
+ t.Fatalf("admitted with no MainPID: %q", got)
+ }
+}
+
+// The agent itself (uid carlos, the edge's MainPID) is admitted.
+func TestMailerPeerAdmitsAgent(t *testing.T) {
+ var seen atomic.Int32
+ rule := instancectl.EdgePeerRuleFor(os.Getuid(), mainPIDIs(os.Getpid()))
+ sock, _ := serveOn(t, rule, countingHandler(&seen))
+ resp, err := sockClient(sock).Get("http://mailer/v1/health")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer resp.Body.Close()
+ _, _ = io.Copy(io.Discard, resp.Body)
+ if resp.StatusCode != http.StatusOK || seen.Load() != 1 {
+ t.Fatalf("the agent got %d, handler ran %d times", resp.StatusCode, seen.Load())
+ }
+}
diff --git a/internal/mailer/server_test.go b/internal/mailer/server_test.go
new file mode 100644
index 000000000..6cc4ec01f
--- /dev/null
+++ b/internal/mailer/server_test.go
@@ -0,0 +1,165 @@
+package mailer
+
+import (
+ "context"
+ "errors"
+ "io"
+ "net"
+ "net/http"
+ "os"
+ "path/filepath"
+ "strings"
+ "sync/atomic"
+ "testing"
+ "time"
+)
+
+// shortSockDir is a directory short enough for a unix socket path.
+func shortSockDir(t *testing.T) string {
+ t.Helper()
+ dir, err := os.MkdirTemp("", "mlr")
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Cleanup(func() { os.RemoveAll(dir) })
+ return dir
+}
+
+// serveOn starts Serve on a fresh unix socket with peer and handler, and
+// returns the socket path and the log lines.
+func serveOn(t *testing.T, peer func(net.Conn) error, h http.Handler) (string, *logLines) {
+ t.Helper()
+ sock := filepath.Join(shortSockDir(t), "m.sock")
+ ln, err := net.Listen("unix", sock)
+ if err != nil {
+ t.Fatal(err)
+ }
+ logs := &logLines{}
+ ctx, cancel := context.WithCancel(context.Background())
+ done := make(chan error, 1)
+ go func() { done <- Serve(ctx, Config{Listener: ln, PeerOK: peer, Handler: h, Logf: logs.add}) }()
+ t.Cleanup(func() {
+ cancel()
+ if err := <-done; err != nil {
+ t.Errorf("Serve: %v", err)
+ }
+ })
+ return sock, logs
+}
+
+type logLines struct{ n atomic.Int32 }
+
+func (l *logLines) add(string, ...any) { l.n.Add(1) }
+
+func sockClient(sock string) *http.Client {
+ return &http.Client{Timeout: 5 * time.Second, Transport: &http.Transport{
+ DisableKeepAlives: true,
+ DialContext: func(ctx context.Context, _, _ string) (net.Conn, error) {
+ var d net.Dialer
+ return d.DialContext(ctx, "unix", sock)
+ },
+ }}
+}
+
+// countingHandler is NewHandler(nil) that counts the requests it saw.
+func countingHandler(n *atomic.Int32) http.Handler {
+ inner := NewHandler(nil)
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ n.Add(1)
+ inner.ServeHTTP(w, r)
+ })
+}
+
+// rawExchange dials sock, writes a whole request, and reads until EOF. A
+// refused peer reads EOF (or a reset) with no byte of an answer.
+func rawExchange(t *testing.T, sock string) string {
+ t.Helper()
+ c, err := net.Dial("unix", sock)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer c.Close()
+ _ = c.SetDeadline(time.Now().Add(5 * time.Second))
+ _, _ = io.WriteString(c, "GET /v1/health HTTP/1.1\r\nHost: mailer\r\nConnection: close\r\n\r\n")
+ b, err := io.ReadAll(c)
+ if err != nil && !errors.Is(err, io.EOF) && !strings.Contains(err.Error(), "reset") {
+ t.Fatalf("read: %v", err)
+ }
+ return string(b)
+}
+
+// A peer the rule refuses is closed at accept: it reads nothing, the
+// handler never runs, and the refusal is logged.
+func TestMailerServeRefusesBeforeReading(t *testing.T) {
+ var seen atomic.Int32
+ sock, logs := serveOn(t, func(net.Conn) error { return errors.New("not the agent") }, countingHandler(&seen))
+ if got := rawExchange(t, sock); got != "" {
+ t.Fatalf("a refused peer read %q", got)
+ }
+ if seen.Load() != 0 {
+ t.Fatal("the handler ran for a refused peer")
+ }
+ if logs.n.Load() == 0 {
+ t.Fatal("the refusal was not logged")
+ }
+}
+
+// No peer rule admits nobody.
+func TestMailerServeWithNoPeerRuleRefusesAll(t *testing.T) {
+ var seen atomic.Int32
+ sock, _ := serveOn(t, nil, countingHandler(&seen))
+ if got := rawExchange(t, sock); got != "" || seen.Load() != 0 {
+ t.Fatalf("a nil peer rule admitted a peer: %q", got)
+ }
+}
+
+// Refusals are logged at most once a second, with the suppressed count on
+// the next line.
+func TestMailerRefusalLogIsRateLimited(t *testing.T) {
+ var lines []string
+ clock := time.Unix(1_700_000_000, 0)
+ v := &vettedListener{logf: func(f string, a ...any) { lines = append(lines, f) }, now: func() time.Time { return clock }}
+ for range 5 {
+ v.logRefusal(errors.New("x"))
+ }
+ clock = clock.Add(1100 * time.Millisecond)
+ v.logRefusal(errors.New("x"))
+ if len(lines) != 2 || !strings.Contains(lines[1], "suppressed") {
+ t.Fatalf("log lines %q", lines)
+ }
+}
+
+func TestMailerHealth(t *testing.T) {
+ sock, _ := serveOn(t, func(net.Conn) error { return nil }, nil)
+ resp, err := sockClient(sock).Get("http://mailer/v1/health")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer resp.Body.Close()
+ b, _ := io.ReadAll(resp.Body)
+ if resp.StatusCode != http.StatusOK || strings.TrimSpace(string(b)) != `{"ok":true}` {
+ t.Fatalf("health = %d %q", resp.StatusCode, b)
+ }
+ // /v1/send is not served until it is given.
+ r2, err := sockClient(sock).Post("http://mailer/v1/send", "application/json", strings.NewReader("{}"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ r2.Body.Close()
+ if r2.StatusCode != http.StatusNotFound {
+ t.Fatalf("POST /v1/send with no send handler = %d, want 404", r2.StatusCode)
+ }
+}
+
+func TestActivatedListenerRefusesWithoutSystemdSocket(t *testing.T) {
+ env := func(m map[string]string) func(string) string { return func(k string) string { return m[k] } }
+ if _, err := ActivatedListener(env(nil), 42); err == nil {
+ t.Fatal("no LISTEN_PID: accepted")
+ }
+ if _, err := ActivatedListener(env(map[string]string{"LISTEN_PID": "41", "LISTEN_FDS": "1"}), 42); err == nil {
+ t.Fatal("another process's LISTEN_PID: accepted")
+ }
+ if _, err := ActivatedListener(env(map[string]string{"LISTEN_PID": "42", "LISTEN_FDS": "2"}), 42); err == nil {
+ t.Fatal("LISTEN_FDS=2: accepted")
+ }
+}
diff --git a/internal/mailwire/mailwire.go b/internal/mailwire/mailwire.go
index 3ee81f735..682577a5b 100644
--- a/internal/mailwire/mailwire.go
+++ b/internal/mailwire/mailwire.go
@@ -122,6 +122,12 @@ func DomainKey(acct, domain string) string {
return "accounts/" + acct + "/email/domains/" + domain + ".json"
}
+// MailerSocket is the box-local mailer's socket (carlos-mailer.socket). The
+// agent dials it to forward a stamped message, and to report whether the
+// box's mailer is armed. Its directory is root's and hidden from every
+// instance template.
+const MailerSocket = "/run/carlos-mailer/mailer.sock"
+
// The SES EmailTags the mailer puts on every send (decision 6). The console
// believes them only from the mailer's own principal (IsMailerCaller).
const (
diff --git a/internal/provision/platform_mail_submission_census_test.go b/internal/provision/platform_mail_submission_census_test.go
index 79437a39e..1af8458f1 100644
--- a/internal/provision/platform_mail_submission_census_test.go
+++ b/internal/provision/platform_mail_submission_census_test.go
@@ -28,6 +28,15 @@ func platformMailSubmissionWriteCensusInventory() []censusEntry {
{"internal/mail/walk.go", "claimUnserializedRotate", "reference", "id:Put", "77f02ea1bdece0db273af097dc73ac3713642ebbbaadd79a44c55e57b04cbb53"},
{"internal/mail/walk.go", "claimUnserializedCreateStandalone", "reference", "id:Put", "92114b16fe724b555700d14630ed86dd5fb6e67ec6ac1f2616baeb51ffb09542"},
{"internal/mail/walk_environment.go", "claimUnserializedEnableEnvironment", "reference", "id:Put", "6fe09f592c6a52faa7b5182eedbfd37fcc4a231490385ee6f9f41f7849b818de"},
+ // Task 3: three key-sites re-digested, kinds unchanged (lit:instances,
+ // the same literal path each already named). bootstrapWithGroup
+ // writes sysusers.d from the new constant sysusersConf (the
+ // carlos-mailer user line added); tmpfilesConf gains the two mailer
+ // directory lines; claimBoundTemplate's InaccessiblePaths= line gains
+ // -/run/carlos-mailer -/etc/carlos-mailer. No record write is added.
+ {"internal/host/bootstrap.go", "bootstrapWithGroup", "key-site", "lit:instances", "62fa76ad0fa812a0effc7c6add43ddcf54313450c13f20fbb2fee9d004488588"},
+ {"internal/host/bootstrap.go", "const tmpfilesConf", "key-site", "lit:instances", "d9849c0d887ce4c8698d67dfc9cf136f5b9922300b058fda6186d2fd4b42411a"},
+ {"internal/host/claimunit_template.go", "const claimBoundTemplate", "key-site", "lit:instances", "32d04a51e5edb785d3064a12532247d4fa2149fa490fcf4bff3499b8aecf52af"},
}
for _, r := range repins {
found := false
diff --git a/internal/provision/testdata/plan14-root-reads-chain.tsv b/internal/provision/testdata/plan14-root-reads-chain.tsv
index 77ad5b6de..cce7692ec 100644
--- a/internal/provision/testdata/plan14-root-reads-chain.tsv
+++ b/internal/provision/testdata/plan14-root-reads-chain.tsv
@@ -203,4 +203,4 @@ plan14-root-reads-edge-ppv2.tsv 44e5745a1d22ea2ddd6e73d775d87759afe7121666212b6e
plan14-root-reads-static-site-geo-962.tsv 5e8a72175700a3e60c1e283b133c1ee25e36f292e2e319f02a19138f15186376
plan14-root-reads-member-backups-drill-nodb.tsv 07b748a749084fdaf61c5087a6edfca8a79273962822ce551dd4d42b0d20c063
plan14-root-reads-spread-every-schedule-ticks.tsv 07b748a749084fdaf61c5087a6edfca8a79273962822ce551dd4d42b0d20c063
-plan14-root-reads-platform-mail-submission.tsv 07b748a749084fdaf61c5087a6edfca8a79273962822ce551dd4d42b0d20c063
+plan14-root-reads-platform-mail-submission.tsv f949639f333c9a2e89bb120f64724ead4c55ee522914416b3ccc98bed460e49a
diff --git a/internal/provision/testdata/plan14-root-reads-platform-mail-submission.tsv b/internal/provision/testdata/plan14-root-reads-platform-mail-submission.tsv
index 42d988ab9..96a7f60b6 100644
--- a/internal/provision/testdata/plan14-root-reads-platform-mail-submission.tsv
+++ b/internal/provision/testdata/plan14-root-reads-platform-mail-submission.tsv
@@ -1,3 +1,49 @@
# Census overlay platform-mail-submission, written by census-propose (#369). census-ruling-platform-mail-submission, approved on #280 before the merge; the approval card is docs/superpowers/notes/census-proposal-platform-mail-submission.md.
-# 0 body, 0 sites, 1 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
-@coverage . e08272a1ac6b2c889bb1dae89b06494228326ee5287c01d43ace8ef21e9562d2
+# 16 body, 0 sites, 8 envelope: each changed unit re-frozen at its existing disposition with its claim appended.
+# 4 new dispositions: 0 reads re-frozen at their disposition with the claim, 4 new units frozen accepted-legacy, 0 quiet units retired while they read nothing, 0 other.
+@legacy 589908d713736c8e6a9e3ff35f04288a44aa15643b899bdd3ec8e0b97d43d808 internal/host/agent.go statusLoop legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): the status tick's context carries the box's lifetime judge; read sites unchanged, offsets moved;rev3=census-ruling-rootfs-apps-2;basis=main's body as of the merge of origin/main 953b9fda (its later changes, regional box names and self-serve moves plan 1 among them, under main's own census rulings), where the tick fills rootfs_ready and rootfs_blocked from armedRootfs.Load().probe, which each tick runs NestedOK's checks and asks the control socket's GET /ready/rootfs (never the store); the same four direct sites;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Task 11 and #329 plan 3 Task 7: takes root's GET /egress reader and fills p.Egress = egressStatusProbe(egressStatus, routes, provision.PolicyReadStates()) and p.SizeCommittedMiB = sizeCommittedMiB(armedSizeSource.Load(), routes); the two added whole:Route sites are the tick's own registry list handed to those two units (decision rows), which read root's control socket and the activator's memory; no store request added; the four existing sites unchanged, offsets moved.;rev3=census-ruling-fleet-alerts-1;basis=the agent (carlos-edge.service, user carlos): the status tick passes os.Geteuid() to alertDeliveryProbe, which fills AlertDelivery.EngineBeat/EngineBeatWhy from engineBeatArmed (the env value and the euid only, no file access, root refused before the path is looked at), and fills Probes.DiskFullETAHours from diskETAProbe(&processDiskTrend, now), a Theil-Sen fit over the metrics loop's in-memory ring of disk readings; the same six sites, no read added, no store request added;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): the status tick's Probes gain HeldStreams: heldStreamsState(), which calls the edge's in-memory counters function (nil until the edge is ready). No file, bucket or registry access added.;rev3=census-ruling-stateless-replicas-3;basis=Fix round 1 Q20: read the detached in-memory replica snapshot source into Probes.ReplicaCopies on the existing five-minute tick. Existing six direct read sites unchanged. No additional bucket request, changed cadence or app lifecycle action.;rev3=census-ruling-agent-start-demo-3;basis=Report moved capability only when the serving edge reports readiness; report claim-seed support only with CARLOS_DEMO_CLAIM=1. Reads the explicit capability flag from the process environment; no new filesystem or registry read.;rev3=census-ruling-stateless-replicas-4-task5;basis=Task 5 fix round 1 (#511 R16 amendment): the status tick also fills Probes.ApplyFinished from systemApplyFinished(release.OptDir()), an Lstat of root's apply journal <opt>/system/router/journal.json in the root-owned, world-readable state directory: finished only when the journal is absent, any other answer unknown and so unfinished. Round 0: Probes.PrevRelease from prevReleaseOf (carlos.prev and carlos.prev.version, the files withMovesFields already reads). Reported in the private BoxMetrics block; no bucket request or cadence change.;rev3=census-ruling-platform-mail-submission;basis=Task 3 (plan gap G6 (b)): the status tick also fills Probes.MailerArmed from mailerArmed(mailwire.MailerSocket, 2s): a stat of /run/carlos-mailer/mailer.sock and, only when it is a socket, GET /v1/health on it. The agent (carlos-edge.service, user carlos), not root; reported in the private BoxMetrics block only. The same six sites; no store request, no read of /etc/carlos-mailer (which uid carlos cannot traverse). whole:Route@10554,whole:Route@12628,whole:Route@12909,whole:Route@6583,whole:Route@6610,whole:Route@7918 4dd7407a53e445f78e63f160bee068d835b26d5d8fd3300d389ba5dbcab26d5a
+@legacy 722920e1d095fe935962342d131ef5e8d5c97481b52b7ddc38dc214bf84ee9a5 internal/host/bootstrap.go bootstrapWithGroup legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p3b;basis=Move bootstrapWith body here, retaining host.env, embedded unit reads and tmpfiles execution. Group live caller holds root mutation guard; skip automatic update/recovery units, preserve Restart=no/nftables drop-in and masks, and write separate root-owned /run/carlos-group-maintenance tmpfiles rule outside service ownership walk. No agent receipt read.;rev3=census-ruling-gvisor-demos;basis=Create the rootfs parent at 0700 and runtime root at 0755. Existing host.env/unit reads unchanged; workload templates remain unarmed.;rev3=census-ruling-platform-mail-submission;basis=Task 3: the sysusers.d/carlos.conf it writes is now the constant sysusersConf, which adds "u carlos-mailer - \"CARLOS mailer\" - /usr/sbin/nologin" ahead of the existing "g carlos-sockets -" line, so the tmpfiles line naming group carlos-mailer resolves on a box whose confs arrive by a staged-tree refresh. Constant text, no input; no read added. file:Command@12045,file:ReadFile@564,file:ReadFile@7111 62fa76ad0fa812a0effc7c6add43ddcf54313450c13f20fbb2fee9d004488588
+@legacy aea72efedb3cc995ae9c791962e3e80f7dfe0b54d87da8c3ca13616baf7a433b internal/host/bootstrap.go privilegedPlan legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-platform-mail-submission;basis=Task 3: one more constant argv, useradd --system --user-group --no-create-home --shell /usr/sbin/nologin carlos-mailer, right after carlos's, behind runPrivileged's existing guard (user.Lookup of the argv's own last word). No input; no read added. data-literal@382 4f353dc38a329ff88fdec4bc2611c44b7ac483eee308b73f58100abc539707cc
+@legacy 72a9a01566413d03e47904622675de11f9728a7412ccd1c66164f6b269500437 internal/host/demo_units/demo.conf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-1;basis=Retains read-only /run and /var tmpfs overlays and all network/size restrictions. Resets InaccessiblePaths and restates /etc/carlos -/run/carlos-control so the hidden control directory need not exist during namespace setup; /etc/carlos remains required. No new source or bind.;rev3=census-ruling-platform-mail-submission;basis=Task 3: the restated InaccessiblePaths= line after the reset gains -/run/carlos-mailer -/etc/carlos-mailer, so a demo box's drop-in does not drop the mailer entries carlos-instance@ and carlos-instance-gen@ now carry. Optional entries; only hides more; no source or bind added. file:external@0 a9e9b766b8dc528c67e128622901f5e491c8abf247681c4e0a4479fbea5d25b9
+@legacy 6bab0f0242fccc13e611ddc073b997c7a82386167e4a44e8ca090ecd5b4bda1e internal/host/units/carlos-dbread@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-db-region-forward-1;basis=the db-read worker's units (written by root's ensureSystemUnits; carlos-dbread.socket bound by PID 1 and owned by carlos; carlos-dbread@.service runs as a DynamicUser with no network, its own PrivateTmp, /data, /var/lib, /opt/carlos and /run/carlos empty, /etc/carlos inaccessible): new;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. file:external@0 164adb03262f8252f1b73d0004e6ad69ff2ea9852eb73e087f1465852fb8d097
+@legacy f5333c9c43177dbd8ffbdfae39b59394bd9ca575e422d6e8b091c9c9b8784ff5 internal/host/units/carlos-demo-build@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-1;basis=New dynamic-UID compiler execution path with fixed argv, root-derived mounts, no network and bounded resources/termination.;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with a one-line comment;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. file:external@0 942401ebb30095e77b7c92f94353055af96e8f6e2c2b69c70d7c206e85c937ba
+@legacy f3942217776d50b0a050628fa7d62a8ac5877dcba08bf36d6212559911a03b48 internal/host/units/carlos-instance-cmd@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the cmd unit template (applied by PID 1 as root; its process runs as carlos): extends the J4 seed pattern to the run role. The template equals the seed template outside named lines, and the template-equality test pins that. Root lays out a staged executable validated by the same refuseStagedExe the seed and generation paths use, then starts this unit, which runs as carlos with the instance's own reach. No new trust of registry, /data or agent-asserted content beyond the seed path;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment) so its stop starts only after the drain unit's stop has finished. Ordering only; no read added.;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional), the same line as the seed template (TestCmdTemplateEqualsSeedOutsideTheNamedLines). Only hides more; no read added. file:external@0 f644399a0bb3dc17cda3e56624c091e60aebf903ea819667199274e227d7e2e1
+@legacy 978e29acf04dca41b8e04f83304ed372a086dc8d7ad3e121ebbff26b812d8803 internal/host/units/carlos-instance-gen@.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-instance-stop-execstop-528;basis=one line added after ExecStart=, ExecStop=-+/opt/carlos/carlos instance-stop $MAINPID (#528, Paul's option 2), plus TimeoutStopFailureMode=kill after TimeoutStopSec=20: PID 1 runs the platform binary's instance-stop as root (the + prefix) at a stop with $MAINPID, a value systemd supplies; instance-stop reads only that argument, /proc/self/cgroup and /proc/<MAINPID>/cgroup (kernel-written), and acts only through a pidfd on the unit's own main process (refused unless in the unit's own cgroup); no bind source, user, mount or tenant-writable path read added;rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment). Ordering only; no read added.;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. file:external@0 5a956385a2ff973e54d9964353b66a966e4395e221637126054f975a760fb704
+@legacy 3976639eb5e936c13a3b576884dd910ae16de6bd9fd0c91e6997f31e28c937dd internal/host/units/carlos-instance-probe.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-2;basis=one more BindReadOnlyPaths= line, so PID 1 opens one more bind source: /run/carlos-control/exe/_probe/box-addrs, bound to /opt/carlos/box-addrs, root's list of the box's own addresses, which RunProbe writes before every run (#367) in the root-only directory the unit already binds from; no tenant, app or agent input names or writes it;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service, so the probe proves what the tenants get (its new pts-private line); fix round 1 (Astra P2, roll order): one line outside the namespace block, Environment=CARLOS_PROBE_PTS_PRIVATE=1, a constant the unit sets for its own process (the probe, as carlos, in the namespace); it names no path, adds no bind source or Exec line, and root reads nothing new;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, inside the shared namespace block; plus one line outside it, Environment=CARLOS_PROBE_SYSCALL_FILTER=1, a constant the unit sets for its own process (the probe, as carlos); it names no path;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional), so the probe proves what the tenants get. Only hides more; no read added. file:external@0 70b0cca7daefaa4fc79f60acf26a16d8ac4b671faa3482243fe1cbfb97fcefb2
+@legacy c9806bb507bfaf1279b6508f30f0088386cffb8326b4aa0e31e5ec6d3ac0dc55 internal/host/units/carlos-instance-seed@.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment). Ordering only; no read added.;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. file:external@0 405798f682d1c2049786dd4202acb06b73e371f642a42b5efb7fc76af6718be7
+@legacy d3ddb6b0fb0df8d25decbef65730cff27308294850683e817a3e5333947870c8 internal/host/units/carlos-instance-sidecar@.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-instance-stop-execstop-528;basis=one line added after ExecStart=, ExecStop=-+/opt/carlos/carlos instance-stop $MAINPID (#528, Paul's option 2), plus TimeoutStopFailureMode=kill after TimeoutStopSec=20: PID 1 runs the platform binary's instance-stop as root (the + prefix) at a stop with $MAINPID, a value systemd supplies; instance-stop reads only that argument, /proc/self/cgroup and /proc/<MAINPID>/cgroup (kernel-written), and acts only through a pidfd on the unit's own main process (refused unless in the unit's own cgroup); no bind source, user, mount or tenant-writable path read added;rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment). Ordering only; no read added.;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. file:external@0 a3c88ea82548f46bbd8516fc4a9060bb5934273b60eb572647784a7ccfab528c
+@legacy 0a4d139cf9839189f90e09f4c57e29ddacc5eb320287a237770a080167db91df internal/host/units/carlos-instance-tty@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5, new: the binary tty template, carlos-instance-cmd@.service outside six named lines held by TestTTYTemplateEqualsCmdOutsideTheNamedLines: Description (tty), ExecStart/ExecStopPost instance-exec/instance-exit tty %I (the same root binary as every template), StandardInput=file:/run/carlos/logs/%I.tty.sock replacing the cmd StandardOutput socket (PID 1 opens it as root on the nosymfollow logs mount, as the cmd streams), StandardOutput=journal, StandardError=journal, and BindReadOnlyPaths sources tty-app/tty-live under /run/carlos-control/exe/%I (root-only exe layout, as cmd-app/cmd-live). Same namespace block byte for byte, runs as carlos. Task 6: POST /tty (handleOneShot(RoleTTY), claimAwareLegacy) starts it, after the role lock, the loaded-state refusal and refuseStagedExe; the tty-app/tty-live sources are laid out by ensureCmdExeAt(RoleTTY) and removed by removeCmdExe(RoleTTY) at /stop role=tty and /sweep;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment). Ordering only; no read added.;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. file:external@0 a316b14b25091ff3ed3dc2186378cc0b88bc23471d6ad45ede8302f278668034
+@legacy 1d51de12094b335de855b3620973b88ae3938185b243b820641dbd5adf48a875 internal/host/units/carlos-instance@.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: one namespace-block line added after TemporaryFileSystem=/dev/mqueue:ro, TemporaryFileSystem=/dev/pts:ro (with its comment): PID 1 mounts an empty read-only tmpfs over the private /dev/pts, hiding the host devpts PrivateDevices= binds in; no bind source, Exec line, user or path read by root added; the block stays byte-identical across the binary templates (TestInstanceTemplatesShareOneNamespace);rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-instance-stop-execstop-528;basis=one line added after ExecStart=, ExecStop=-+/opt/carlos/carlos instance-stop $MAINPID (#528, Paul's option 2), plus TimeoutStopFailureMode=kill after TimeoutStopSec=20: PID 1 runs the platform binary's instance-stop as root (the + prefix) at a stop with $MAINPID, a value systemd supplies; instance-stop reads only that argument, /proc/self/cgroup and /proc/<MAINPID>/cgroup (kernel-written), and acts only through a pidfd on the unit's own main process (refused unless in the unit's own cgroup); no bind source, user, mount or tenant-writable path read added;rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment). Ordering only; no read added.;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. file:external@0 348dd223f7f1bcd8cb2db90c7acb25f4cf3e9b29568c0b4b63ce13d6d1ab3af9
+@legacy 5a4d8a4a9ea0e00aa0186c84c18f49f5ae434c340651f4bbe636d3311cf39dfd internal/status/snapshot.go CollectBox legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-rootfs-apps-2;basis=copies Probes.RootfsReady and RootfsBlocked into BoxMetrics (private, like Layout); the same 28 sites, no read added;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Task 11 and #329 plan 3 Task 7: copies Probes.Egress and Probes.SizeCommittedMiB into BoxMetrics (private, like Layout) and counts them in the condition that builds Metrics; the same 28 sites, no read added.;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3: comment only, the Hibernate count is left as is (display);rev3=census-ruling-regional-domains-447;basis=#447 Task 7: copies Probes.AliasesRead into BoxMetrics.AliasesRead (json aliases_read, omitempty) and counts it in the condition that builds Metrics; the same 28 sites, no read added;rev3=census-ruling-fleet-alerts-1;basis=copies Probes.DiskFullETAHours into BoxMetrics.DiskFullETAHours (json disk_full_eta_hours, omitempty; private, like Layout) and counts it in the condition that builds Metrics; the same 28 sites, no read added;rev3=census-ruling-edge-held-streams;basis=copies Probes.HeldStreams into BoxMetrics.HeldStreams (json held_streams, omitempty, additive) and counts it in the condition that builds Metrics; the same 28 sites, no read added.;rev3=census-ruling-stateless-replicas-3;basis=Fix round 1 Q20: carry already-supplied ReplicaCopies into a separate optional private BoxMetrics replica_copies field; allow copy evidence alone to create the metrics block. Upstreams retains address probes only. Existing 28 Route read sites unchanged; no filesystem, bucket, console or CLI read.;rev3=census-ruling-agent-start-demo-3;basis=Report claim-seed protocol capability only when explicitly configured and runtime moved readiness only when armed; dormant status keeps its original JSON shape. Census read-site delta: unchanged (28).;rev3=census-ruling-stateless-replicas-4-task5;basis=Task 5 (#511 R16 and its amendment): copies Probes.PrevRelease and Probes.ApplyFinished into BoxMetrics (json prev_release and apply_finished, omitempty; private, like Release) and counts them in the condition that builds Metrics; the same 28 sites, no read added.;rev3=census-ruling-platform-mail-submission;basis=Task 3: copies Probes.MailerArmed into BoxMetrics.MailerArmed (json mailer_armed, omitempty; private, like Layout) and counts it in the condition that builds Metrics; the same 28 sites, no read added. registry:Alias@4543,registry:CertExpiresAt@3160,registry:CertExpiresAt@3396,registry:CertExpiresAt@4658,registry:DBPath@2495,registry:DBPath@2553,registry:DNSCheckedAt@3365,registry:DNSCheckedAt@4627,registry:DNSStatus@3139,registry:DNSStatus@3334,registry:DNSStatus@4597,registry:Hibernate@3853,registry:Host@2295,registry:Host@2437,registry:Host@2666,registry:Host@3280,registry:Host@3315,registry:Host@4578,registry:Kind@2473,registry:Kind@3807,registry:Platform@2152,registry:ServingVersion@2324,registry:ServingVersion@2447,registry:Socket@4066,registry:Version@2186,registry:Version@2305,whole:Route@1581,whole:RouteAlias@4440 b2a6b68d0c028970efee40812263bf1e4a6214b90c568d8275deb81b61ff1e66
+@legacy d6700cb69f36e6e7cb8fdf4f4b747269ba9bf6545143e4dd943acedc018bc4b1 internal/host/mailerreport.go mailerArmed legacy accepted-legacy accepted-legacy;rev3=census-ruling-platform-mail-submission;basis=Task 3, new: the agent's MailerArmed probe. Stats the constant socket path and dials it for GET /v1/health with a 2 s timeout; true only on a 200. Runs in the agent as carlos, never as root; the path is a constant, in a root-owned 0750 root:carlos directory nothing a tenant or an app can write. Answers a bool into the private status block. file:Stat@72 6fd83d5c27429d06864d02a141f7036c2f3e1e8e89366ad6d2a232d417420052
+@legacy 85d678c6a608ff70b7a60141d0efde911544f4b7aa9a7d9508f0e13cf2b7e724 internal/host/units/carlos-mailer-arm.path external legacy accepted-legacy accepted-legacy;rev3=census-ruling-platform-mail-submission;basis=Task 3, new: [Path] PathExists=/etc/carlos-mailer/keys, Unit=carlos-mailer.socket, WantedBy=multi-user.target; enabled and armed by bootstrap like every .path. PID 1 watches a path in a root-owned 0750 root:carlos-mailer directory only root (the operator) writes; it starts a socket unit and reads nothing. file:external@0 6b28c6282ee930560f859f20c752c65f0e550412b9c6ffb1fc10c292a3941a2a
+@legacy f99b76edb6264d669d69dee1931907a85d99256a5f891eda8be179f49c658492 internal/host/units/carlos-mailer.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-platform-mail-submission;basis=Task 3, new: runs /opt/carlos/carlos mailer serve as the static user carlos-mailer (never root), socket-activated, ConditionPathExists=/etc/carlos-mailer/keys, EnvironmentFile=-/etc/carlos/host.env (read by PID 1, as every carlos service's) with UnsetEnvironment=CARLOS_SECRETS_KEY, AWS_EC2_METADATA_DISABLED=true, IPAddressDeny=169.254.169.254/32 fd00:ec2::254/128, StateDirectory=carlos-mailer 0700, and the relay's hardening block with no ReadWritePaths. No root process reads anything new; the mailer reads its own key file and state. file:external@0 3f9bd1c2d6e1a4d5d1c72d0c24b000e122cc95290cca8b0d2e62d86576e2dd5f
+@legacy 486f70ac08ac5f675d91dc3b7bddf949c908db227e4596af5706df846c4fb32f internal/host/units/carlos-mailer.socket external legacy accepted-legacy accepted-legacy;rev3=census-ruling-platform-mail-submission;basis=Task 3, new: ConditionPathExists=/etc/carlos-mailer/keys, ListenStream=/run/carlos-mailer/mailer.sock, SocketUser=carlos, SocketGroup=carlos, SocketMode=0600, Accept=no; not enabled, started only by the arming path. PID 1 binds a socket in a root-owned directory, as carlos-instance-control.socket does in /run/carlos-control. No read added. file:external@0 275aae364c39e89bdf3d76d7e66aea9cf65b398ac0c16c087db353cfd5140c34
+internal/host/agent.go statusLoop legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): the status tick's context carries the box's lifetime judge; read sites unchanged, offsets moved;rev3=census-ruling-rootfs-apps-2;basis=main's body as of the merge of origin/main 953b9fda (its later changes, regional box names and self-serve moves plan 1 among them, under main's own census rulings), where the tick fills rootfs_ready and rootfs_blocked from armedRootfs.Load().probe, which each tick runs NestedOK's checks and asks the control socket's GET /ready/rootfs (never the store); the same four direct sites;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Task 11 and #329 plan 3 Task 7: takes root's GET /egress reader and fills p.Egress = egressStatusProbe(egressStatus, routes, provision.PolicyReadStates()) and p.SizeCommittedMiB = sizeCommittedMiB(armedSizeSource.Load(), routes); the two added whole:Route sites are the tick's own registry list handed to those two units (decision rows), which read root's control socket and the activator's memory; no store request added; the four existing sites unchanged, offsets moved.;rev3=census-ruling-fleet-alerts-1;basis=the agent (carlos-edge.service, user carlos): the status tick passes os.Geteuid() to alertDeliveryProbe, which fills AlertDelivery.EngineBeat/EngineBeatWhy from engineBeatArmed (the env value and the euid only, no file access, root refused before the path is looked at), and fills Probes.DiskFullETAHours from diskETAProbe(&processDiskTrend, now), a Theil-Sen fit over the metrics loop's in-memory ring of disk readings; the same six sites, no read added, no store request added;rev3=census-ruling-edge-held-streams;basis=the agent (/opt/carlos/carlos agent, carlos-edge.service, user carlos): the status tick's Probes gain HeldStreams: heldStreamsState(), which calls the edge's in-memory counters function (nil until the edge is ready). No file, bucket or registry access added.;rev3=census-ruling-stateless-replicas-3;basis=Fix round 1 Q20: read the detached in-memory replica snapshot source into Probes.ReplicaCopies on the existing five-minute tick. Existing six direct read sites unchanged. No additional bucket request, changed cadence or app lifecycle action.;rev3=census-ruling-agent-start-demo-3;basis=Report moved capability only when the serving edge reports readiness; report claim-seed support only with CARLOS_DEMO_CLAIM=1. Reads the explicit capability flag from the process environment; no new filesystem or registry read.;rev3=census-ruling-stateless-replicas-4-task5;basis=Task 5 fix round 1 (#511 R16 amendment): the status tick also fills Probes.ApplyFinished from systemApplyFinished(release.OptDir()), an Lstat of root's apply journal <opt>/system/router/journal.json in the root-owned, world-readable state directory: finished only when the journal is absent, any other answer unknown and so unfinished. Round 0: Probes.PrevRelease from prevReleaseOf (carlos.prev and carlos.prev.version, the files withMovesFields already reads). Reported in the private BoxMetrics block; no bucket request or cadence change.;rev3=census-ruling-platform-mail-submission;basis=Task 3 (plan gap G6 (b)): the status tick also fills Probes.MailerArmed from mailerArmed(mailwire.MailerSocket, 2s): a stat of /run/carlos-mailer/mailer.sock and, only when it is a socket, GET /v1/health on it. The agent (carlos-edge.service, user carlos), not root; reported in the private BoxMetrics block only. The same six sites; no store request, no read of /etc/carlos-mailer (which uid carlos cannot traverse). whole:Route@10554,whole:Route@12628,whole:Route@12909,whole:Route@6583,whole:Route@6610,whole:Route@7918 4dd7407a53e445f78e63f160bee068d835b26d5d8fd3300d389ba5dbcab26d5a
+internal/host/bootstrap.go bootstrapWithGroup legacy accepted-legacy accepted-legacy;rev3=census-ruling-region-ha-p3b;basis=Move bootstrapWith body here, retaining host.env, embedded unit reads and tmpfiles execution. Group live caller holds root mutation guard; skip automatic update/recovery units, preserve Restart=no/nftables drop-in and masks, and write separate root-owned /run/carlos-group-maintenance tmpfiles rule outside service ownership walk. No agent receipt read.;rev3=census-ruling-gvisor-demos;basis=Create the rootfs parent at 0700 and runtime root at 0755. Existing host.env/unit reads unchanged; workload templates remain unarmed.;rev3=census-ruling-platform-mail-submission;basis=Task 3: the sysusers.d/carlos.conf it writes is now the constant sysusersConf, which adds "u carlos-mailer - \"CARLOS mailer\" - /usr/sbin/nologin" ahead of the existing "g carlos-sockets -" line, so the tmpfiles line naming group carlos-mailer resolves on a box whose confs arrive by a staged-tree refresh. Constant text, no input; no read added. file:Command@12045,file:ReadFile@564,file:ReadFile@7111 62fa76ad0fa812a0effc7c6add43ddcf54313450c13f20fbb2fee9d004488588
+internal/host/bootstrap.go const tmpfilesConf authority A,C,G,J4 root-input;kept=A,C,G;scope=protected-decision-only;rev3=census-ruling-platform-mail-submission;basis=Task 3: two constant lines, "d /run/carlos-mailer 0750 root carlos -" (the mailer's socket directory, beside /run/carlos-control and shaped like it) and "d /etc/carlos-mailer 0750 root carlos-mailer -" (the key directory, which uid carlos cannot traverse). Root creates two root-owned directories; no file inside either is created, owned or seeded (the key is the operator's, by hand). No input; no read added. data-literal@1237,data-literal@1309,data-literal@1927,data-literal@21,data-literal@2328,data-literal@311,data-literal@810 d9849c0d887ce4c8698d67dfc9cf136f5b9922300b058fda6186d2fd4b42411a
+internal/host/bootstrap.go privilegedPlan legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-platform-mail-submission;basis=Task 3: one more constant argv, useradd --system --user-group --no-create-home --shell /usr/sbin/nologin carlos-mailer, right after carlos's, behind runPrivileged's existing guard (user.Lookup of the argv's own last word). No input; no read added. data-literal@382 4f353dc38a329ff88fdec4bc2611c44b7ac483eee308b73f58100abc539707cc
+internal/host/claimunit_template.go const claimBoundTemplate authority E2 PROPOSED E51: Root-only bound-unit template is held inside the claim renderer; ordinary bootstrap never enumerates or installs it.;rev3=census-ruling-instance-stop-execstop-528;basis=one line added after ExecStart=, ExecStop=-+/opt/carlos/carlos instance-stop $MAINPID (#528, Paul's option 2), plus TimeoutStopFailureMode=kill after TimeoutStopSec=20: PID 1 runs the platform binary's instance-stop as root (the + prefix) at a stop with $MAINPID, a value systemd supplies; instance-stop reads only that argument, /proc/self/cgroup and /proc/<MAINPID>/cgroup (kernel-written), and acts only through a pidfd on the unit's own main process (refused unless in the unit's own cgroup); no bind source, user, mount or tenant-writable path read added;rev3=census-ruling-platform-mail-submission;basis=Task 3: the InaccessiblePaths= line gains -/run/carlos-mailer -/etc/carlos-mailer, as every tenant template that hides /run/carlos-control now does (TestMailerPathsHiddenFromEveryTenantTemplate derives the set). Optional entries, so a box before tmpfiles ran still starts it. Only hides more; no bind source, Exec line, user or root read added. data-literal@27 32d04a51e5edb785d3064a12532247d4fa2149fa490fcf4bff3499b8aecf52af
+internal/host/demo_units/demo.conf external legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-1;basis=Retains read-only /run and /var tmpfs overlays and all network/size restrictions. Resets InaccessiblePaths and restates /etc/carlos -/run/carlos-control so the hidden control directory need not exist during namespace setup; /etc/carlos remains required. No new source or bind.;rev3=census-ruling-platform-mail-submission;basis=Task 3: the restated InaccessiblePaths= line after the reset gains -/run/carlos-mailer -/etc/carlos-mailer, so a demo box's drop-in does not drop the mailer entries carlos-instance@ and carlos-instance-gen@ now carry. Optional entries; only hides more; no source or bind added. file:external@0 a9e9b766b8dc528c67e128622901f5e491c8abf247681c4e0a4479fbea5d25b9
+internal/host/units/carlos-dbread@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-db-region-forward-1;basis=the db-read worker's units (written by root's ensureSystemUnits; carlos-dbread.socket bound by PID 1 and owned by carlos; carlos-dbread@.service runs as a DynamicUser with no network, its own PrivateTmp, /data, /var/lib, /opt/carlos and /run/carlos empty, /etc/carlos inaccessible): new;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. file:external@0 164adb03262f8252f1b73d0004e6ad69ff2ea9852eb73e087f1465852fb8d097
+internal/host/units/carlos-demo-build@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-agent-start-demo-1;basis=New dynamic-UID compiler execution path with fixed argv, root-derived mounts, no network and bounded resources/termination.;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with a one-line comment;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. file:external@0 942401ebb30095e77b7c92f94353055af96e8f6e2c2b69c70d7c206e85c937ba
+internal/host/units/carlos-instance-cmd@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-carlos-run;basis=the cmd unit template (applied by PID 1 as root; its process runs as carlos): extends the J4 seed pattern to the run role. The template equals the seed template outside named lines, and the template-equality test pins that. Root lays out a staged executable validated by the same refuseStagedExe the seed and generation paths use, then starts this unit, which runs as carlos with the instance's own reach. No new trust of registry, /data or agent-asserted content beyond the seed path;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment) so its stop starts only after the drain unit's stop has finished. Ordering only; no read added.;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional), the same line as the seed template (TestCmdTemplateEqualsSeedOutsideTheNamedLines). Only hides more; no read added. file:external@0 f644399a0bb3dc17cda3e56624c091e60aebf903ea819667199274e227d7e2e1
+internal/host/units/carlos-instance-gen@.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-instance-stop-execstop-528;basis=one line added after ExecStart=, ExecStop=-+/opt/carlos/carlos instance-stop $MAINPID (#528, Paul's option 2), plus TimeoutStopFailureMode=kill after TimeoutStopSec=20: PID 1 runs the platform binary's instance-stop as root (the + prefix) at a stop with $MAINPID, a value systemd supplies; instance-stop reads only that argument, /proc/self/cgroup and /proc/<MAINPID>/cgroup (kernel-written), and acts only through a pidfd on the unit's own main process (refused unless in the unit's own cgroup); no bind source, user, mount or tenant-writable path read added;rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment). Ordering only; no read added.;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. file:external@0 5a956385a2ff973e54d9964353b66a966e4395e221637126054f975a760fb704
+internal/host/units/carlos-instance-probe.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-2;basis=one more BindReadOnlyPaths= line, so PID 1 opens one more bind source: /run/carlos-control/exe/_probe/box-addrs, bound to /opt/carlos/box-addrs, root's list of the box's own addresses, which RunProbe writes before every run (#367) in the root-only directory the unit already binds from; no tenant, app or agent input names or writes it;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service, so the probe proves what the tenants get (its new pts-private line); fix round 1 (Astra P2, roll order): one line outside the namespace block, Environment=CARLOS_PROBE_PTS_PRIVATE=1, a constant the unit sets for its own process (the probe, as carlos, in the namespace); it names no path, adds no bind source or Exec line, and root reads nothing new;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, inside the shared namespace block; plus one line outside it, Environment=CARLOS_PROBE_SYSCALL_FILTER=1, a constant the unit sets for its own process (the probe, as carlos); it names no path;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional), so the probe proves what the tenants get. Only hides more; no read added. file:external@0 70b0cca7daefaa4fc79f60acf26a16d8ac4b671faa3482243fe1cbfb97fcefb2
+internal/host/units/carlos-instance-seed@.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment). Ordering only; no read added.;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. file:external@0 405798f682d1c2049786dd4202acb06b73e371f642a42b5efb7fc76af6718be7
+internal/host/units/carlos-instance-sidecar@.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: the same one namespace-block line, TemporaryFileSystem=/dev/pts:ro, as carlos-instance@.service; nothing else;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-instance-stop-execstop-528;basis=one line added after ExecStart=, ExecStop=-+/opt/carlos/carlos instance-stop $MAINPID (#528, Paul's option 2), plus TimeoutStopFailureMode=kill after TimeoutStopSec=20: PID 1 runs the platform binary's instance-stop as root (the + prefix) at a stop with $MAINPID, a value systemd supplies; instance-stop reads only that argument, /proc/self/cgroup and /proc/<MAINPID>/cgroup (kernel-written), and acts only through a pidfd on the unit's own main process (refused unless in the unit's own cgroup); no bind source, user, mount or tenant-writable path read added;rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment). Ordering only; no read added.;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. file:external@0 a3c88ea82548f46bbd8516fc4a9060bb5934273b60eb572647784a7ccfab528c
+internal/host/units/carlos-instance-tty@.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5, new: the binary tty template, carlos-instance-cmd@.service outside six named lines held by TestTTYTemplateEqualsCmdOutsideTheNamedLines: Description (tty), ExecStart/ExecStopPost instance-exec/instance-exit tty %I (the same root binary as every template), StandardInput=file:/run/carlos/logs/%I.tty.sock replacing the cmd StandardOutput socket (PID 1 opens it as root on the nosymfollow logs mount, as the cmd streams), StandardOutput=journal, StandardError=journal, and BindReadOnlyPaths sources tty-app/tty-live under /run/carlos-control/exe/%I (root-only exe layout, as cmd-app/cmd-live). Same namespace block byte for byte, runs as carlos. Task 6: POST /tty (handleOneShot(RoleTTY), claimAwareLegacy) starts it, after the role lock, the loaded-state refusal and refuseStagedExe; the tty-app/tty-live sources are laid out by ensureCmdExeAt(RoleTTY) and removed by removeCmdExe(RoleTTY) at /stop role=tty and /sweep;rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment). Ordering only; no read added.;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. file:external@0 a316b14b25091ff3ed3dc2186378cc0b88bc23471d6ad45ede8302f278668034
+internal/host/units/carlos-instance@.service external legacy accepted-legacy accepted-legacy;rev3=J4;basis=root-input;rev3=census-ruling-rootfs-apps-6;basis=rootfs Plan 6 Task 5: one namespace-block line added after TemporaryFileSystem=/dev/mqueue:ro, TemporaryFileSystem=/dev/pts:ro (with its comment): PID 1 mounts an empty read-only tmpfs over the private /dev/pts, hiding the host devpts PrivateDevices= binds in; no bind source, Exec line, user or path read by root added; the block stays byte-identical across the binary templates (TestInstanceTemplatesShareOneNamespace);rev3=census-ruling-instance-syscall-filter;basis=the tenant syscall filter (#527 Q5): three [Service] lines after SystemCallArchitectures=native (SystemCallFilter=@system-service; SystemCallFilter=~@keyring io_uring_setup io_uring_enter io_uring_register userfaultfd; SystemCallErrorNumber=ENOSYS), applied by PID 1 as a seccomp filter on the unit's own process as carlos; no bind source, Exec line, user, mount or path read by root added, with its comment, inside the shared namespace block (byte-identical across the binary templates);rev3=census-ruling-instance-stop-execstop-528;basis=one line added after ExecStart=, ExecStop=-+/opt/carlos/carlos instance-stop $MAINPID (#528, Paul's option 2), plus TimeoutStopFailureMode=kill after TimeoutStopSec=20: PID 1 runs the platform binary's instance-stop as root (the + prefix) at a stop with $MAINPID, a value systemd supplies; instance-stop reads only that argument, /proc/self/cgroup and /proc/<MAINPID>/cgroup (kernel-written), and acts only through a pidfd on the unit's own main process (refused unless in the unit's own cgroup); no bind source, user, mount or tenant-writable path read added;rev3=census-ruling-w6-ingress-drain;basis=adds Before=carlos-edge-drain.service (with a comment). Ordering only; no read added.;rev3=census-ruling-platform-mail-submission;basis=Task 3: InaccessiblePaths= gains -/run/carlos-mailer -/etc/carlos-mailer (optional). Only hides more; no read added. file:external@0 348dd223f7f1bcd8cb2db90c7acb25f4cf3e9b29568c0b4b63ce13d6d1ab3af9
+internal/status/snapshot.go CollectBox legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-rootfs-apps-2;basis=copies Probes.RootfsReady and RootfsBlocked into BoxMetrics (private, like Layout); the same 28 sites, no read added;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328 plan 2 Task 11 and #329 plan 3 Task 7: copies Probes.Egress and Probes.SizeCommittedMiB into BoxMetrics (private, like Layout) and counts them in the condition that builds Metrics; the same 28 sites, no read added.;rev3=census-ruling-rootfs-apps-3;basis=rootfs Plan 3: comment only, the Hibernate count is left as is (display);rev3=census-ruling-regional-domains-447;basis=#447 Task 7: copies Probes.AliasesRead into BoxMetrics.AliasesRead (json aliases_read, omitempty) and counts it in the condition that builds Metrics; the same 28 sites, no read added;rev3=census-ruling-fleet-alerts-1;basis=copies Probes.DiskFullETAHours into BoxMetrics.DiskFullETAHours (json disk_full_eta_hours, omitempty; private, like Layout) and counts it in the condition that builds Metrics; the same 28 sites, no read added;rev3=census-ruling-edge-held-streams;basis=copies Probes.HeldStreams into BoxMetrics.HeldStreams (json held_streams, omitempty, additive) and counts it in the condition that builds Metrics; the same 28 sites, no read added.;rev3=census-ruling-stateless-replicas-3;basis=Fix round 1 Q20: carry already-supplied ReplicaCopies into a separate optional private BoxMetrics replica_copies field; allow copy evidence alone to create the metrics block. Upstreams retains address probes only. Existing 28 Route read sites unchanged; no filesystem, bucket, console or CLI read.;rev3=census-ruling-agent-start-demo-3;basis=Report claim-seed protocol capability only when explicitly configured and runtime moved readiness only when armed; dormant status keeps its original JSON shape. Census read-site delta: unchanged (28).;rev3=census-ruling-stateless-replicas-4-task5;basis=Task 5 (#511 R16 and its amendment): copies Probes.PrevRelease and Probes.ApplyFinished into BoxMetrics (json prev_release and apply_finished, omitempty; private, like Release) and counts them in the condition that builds Metrics; the same 28 sites, no read added.;rev3=census-ruling-platform-mail-submission;basis=Task 3: copies Probes.MailerArmed into BoxMetrics.MailerArmed (json mailer_armed, omitempty; private, like Layout) and counts it in the condition that builds Metrics; the same 28 sites, no read added. registry:Alias@4543,registry:CertExpiresAt@3160,registry:CertExpiresAt@3396,registry:CertExpiresAt@4658,registry:DBPath@2495,registry:DBPath@2553,registry:DNSCheckedAt@3365,registry:DNSCheckedAt@4627,registry:DNSStatus@3139,registry:DNSStatus@3334,registry:DNSStatus@4597,registry:Hibernate@3853,registry:Host@2295,registry:Host@2437,registry:Host@2666,registry:Host@3280,registry:Host@3315,registry:Host@4578,registry:Kind@2473,registry:Kind@3807,registry:Platform@2152,registry:ServingVersion@2324,registry:ServingVersion@2447,registry:Socket@4066,registry:Version@2186,registry:Version@2305,whole:Route@1581,whole:RouteAlias@4440 b2a6b68d0c028970efee40812263bf1e4a6214b90c568d8275deb81b61ff1e66
+internal/host/mailerreport.go mailerArmed legacy accepted-legacy accepted-legacy;rev3=census-ruling-platform-mail-submission;basis=Task 3, new: the agent's MailerArmed probe. Stats the constant socket path and dials it for GET /v1/health with a 2 s timeout; true only on a 200. Runs in the agent as carlos, never as root; the path is a constant, in a root-owned 0750 root:carlos directory nothing a tenant or an app can write. Answers a bool into the private status block. file:Stat@72 6fd83d5c27429d06864d02a141f7036c2f3e1e8e89366ad6d2a232d417420052
+internal/host/units/carlos-mailer-arm.path external legacy accepted-legacy accepted-legacy;rev3=census-ruling-platform-mail-submission;basis=Task 3, new: [Path] PathExists=/etc/carlos-mailer/keys, Unit=carlos-mailer.socket, WantedBy=multi-user.target; enabled and armed by bootstrap like every .path. PID 1 watches a path in a root-owned 0750 root:carlos-mailer directory only root (the operator) writes; it starts a socket unit and reads nothing. file:external@0 6b28c6282ee930560f859f20c752c65f0e550412b9c6ffb1fc10c292a3941a2a
+internal/host/units/carlos-mailer.service external legacy accepted-legacy accepted-legacy;rev3=census-ruling-platform-mail-submission;basis=Task 3, new: runs /opt/carlos/carlos mailer serve as the static user carlos-mailer (never root), socket-activated, ConditionPathExists=/etc/carlos-mailer/keys, EnvironmentFile=-/etc/carlos/host.env (read by PID 1, as every carlos service's) with UnsetEnvironment=CARLOS_SECRETS_KEY, AWS_EC2_METADATA_DISABLED=true, IPAddressDeny=169.254.169.254/32 fd00:ec2::254/128, StateDirectory=carlos-mailer 0700, and the relay's hardening block with no ReadWritePaths. No root process reads anything new; the mailer reads its own key file and state. file:external@0 3f9bd1c2d6e1a4d5d1c72d0c24b000e122cc95290cca8b0d2e62d86576e2dd5f
+internal/host/units/carlos-mailer.socket external legacy accepted-legacy accepted-legacy;rev3=census-ruling-platform-mail-submission;basis=Task 3, new: ConditionPathExists=/etc/carlos-mailer/keys, ListenStream=/run/carlos-mailer/mailer.sock, SocketUser=carlos, SocketGroup=carlos, SocketMode=0600, Accept=no; not enabled, started only by the arming path. PID 1 binds a socket in a root-owned directory, as carlos-instance-control.socket does in /run/carlos-control. No read added. file:external@0 275aae364c39e89bdf3d76d7e66aea9cf65b398ac0c16c087db353cfd5140c34
+@coverage . 90e9af87273bc6003300b0ae91d6e615c0c9c900518c03837f34e9038a7bfec5
+@coverage internal/host 733290c0356d5508cf2ea4510d2b91806889243e8be2c8de5079ec1541142bf6
+@coverage internal/host/demo_units 3a34238356068c6176879f3ee189c81af8e08bfcc0246c5feba80d7169f7af6a
+@coverage internal/host/units 460478599582ed846a1b6c2d5273c8b2460dc40dcb2e82807a4d404d64c7a330
+@coverage internal/instancectl 50d4d80f1f1a86bbed67676f4e439eb79a08bb546ea85ff01a3b433925b9d984
+@coverage internal/mailer 3a1c42f8892a49d986a12078be8b5b8c7e69f066b265928b72eaaf3b6a19910d
+@coverage internal/mailwire 63e4ea297d1030ee6dc397f0a2a107f58b3ecff029513199b8e64489b2c454c1
+@coverage internal/status 7cdc110ec7df53cc754816f7333a90f665fb27a55caa7d2f4988fb7b02f8263f
diff --git a/internal/status/snapshot.go b/internal/status/snapshot.go
index 222022e9d..cf7dcf1c1 100644
--- a/internal/status/snapshot.go
+++ b/internal/status/snapshot.go
@@ -42,6 +42,9 @@ import (
// Probes carries everything CollectBox may not read from the registry —
// each nil means "unknown", and unknown publishes as null, never a guess.
type Probes struct {
+ // MailerArmed is whether this box's mailer answers its health check
+ // (platform mail submission plan, gap G6 (b)).
+ MailerArmed bool
DemoClaimSeedReady bool
DemoMovedReady bool
ConsoleProcesses []ConsoleProcess
@@ -655,6 +658,13 @@ type BoxMetrics struct {
// so it lives in this block and never reaches the public feed. Omitted
// when empty.
Updates map[string]HostUpdates `json:"updates,omitempty"`
+ // MailerArmed is true when this box's mailer socket exists and its
+ // GET /v1/health answered 200 within 2 s (platform mail submission
+ // plan, gap G6 (b)). The agent cannot read the key directory, which is
+ // the mailer's alone; the socket exists only once carlos-mailer-arm.path
+ // has seen the key, so it is the proxy. Absent (false) on every box
+ // with no key, and on every box from before the field.
+ MailerArmed bool `json:"mailer_armed,omitempty"`
// RouteVersions is host -> registry.Route.Version for every non-platform
// route this box carries with a Version the adopt pass has stamped
// (issue #78's staged_version chip) — a hostname-keyed map, which is
@@ -1207,7 +1217,8 @@ func CollectBox(routes []registry.Route, p Probes, now time.Time) Box {
len(routeVersions) > 0 || len(routeServing) > 0 || len(aliasReadings) > 0 || p.AliasesRead || len(p.Upstreams) > 0 || len(p.ReplicaCopies) > 0 ||
len(routeDBBytes) > 0 || p.Layout != nil || len(p.ConfigRefusals) > 0 || len(p.ReleaseRefusals) > 0 || len(p.ProofWaits) > 0 || p.Rollout != nil || p.ConfigGuard != "" ||
p.Alerts != nil || p.GeoIP != nil || p.HeldStreams != nil || len(p.BuildStates) > 0 || p.BuildStatesErr != "" ||
- p.DemoClaimSeedReady || p.DemoMovedReady || p.UpdateSettings != 0 || len(p.Updates) > 0 || len(p.Egress) > 0 || p.SizeCommittedMiB != nil {
+ p.DemoClaimSeedReady || p.DemoMovedReady || p.UpdateSettings != 0 || len(p.Updates) > 0 || len(p.Egress) > 0 || p.SizeCommittedMiB != nil ||
+ p.MailerArmed {
var capabilities []string
if p.DemoClaimSeedReady {
capabilities = append(capabilities, seeds.DemoClaimCapability)
@@ -1265,6 +1276,7 @@ func CollectBox(routes []registry.Route, p Probes, now time.Time) Box {
Egress: p.Egress,
SizeCommittedMiB: p.SizeCommittedMiB,
+ MailerArmed: p.MailerArmed,
}
}
diff --git a/internal/status/snapshot_test.go b/internal/status/snapshot_test.go
index 95aafe5a3..1ffac77ed 100644
--- a/internal/status/snapshot_test.go
+++ b/internal/status/snapshot_test.go
@@ -447,3 +447,23 @@ func TestDemoClaimSeedCapabilityConfigured(t *testing.T) {
t.Fatal("dormant claim changed status JSON")
}
}
+
+// MailerArmed (platform mail submission plan, gap G6 (b)) reaches the
+// private Metrics block, attaches it on its own, and never reaches the
+// public feed's FleetBox.
+func TestCollectBoxCarriesMailerArmed(t *testing.T) {
+ b := CollectBox(nil, Probes{MailerArmed: true}, time.Unix(1_700_000_000, 0))
+ if b.Metrics == nil || !b.Metrics.MailerArmed {
+ t.Fatalf("Metrics = %+v, want MailerArmed", b.Metrics)
+ }
+ if b := CollectBox(nil, Probes{}, time.Unix(1_700_000_000, 0)); b.Metrics != nil && b.Metrics.MailerArmed {
+ t.Fatal("an unarmed box reports armed")
+ }
+ raw, err := json.Marshal(b)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if !strings.Contains(string(raw), `"mailer_armed":true`) {
+ t.Fatalf("the box JSON lacks mailer_armed: %s", raw)
+ }
+}
diff --git a/mailer_cli.go b/mailer_cli.go
new file mode 100644
index 000000000..480192bb5
--- /dev/null
+++ b/mailer_cli.go
@@ -0,0 +1,69 @@
+package main
+
+import (
+ "context"
+ "fmt"
+ "log"
+ "os"
+ "os/signal"
+ "syscall"
+
+ "github.com/carlosframework/platform/internal/clireg"
+ "github.com/carlosframework/platform/internal/instancectl"
+ "github.com/carlosframework/platform/internal/mailer"
+)
+
+const mailerUsage = `usage: carlos mailer serve
+
+ serve run the box-local mailer (what carlos-mailer.service execs; not
+ typed by hand). It takes its socket from systemd and admits only
+ the agent's main process.`
+
+// mailerCommand is `carlos mailer`: the box-local mailer of the platform
+// mail submission design. Its one verb is the unit's entry point.
+func mailerCommand() *clireg.Node {
+ const box = clireg.BoxLocal
+ return &clireg.Node{
+ Name: "mailer",
+ Audience: box,
+ Children: []*clireg.Node{
+ noHint(skipGolden(raw("serve", box, runMailerServe), "starts the mailer server; it reads no arguments, -h included")),
+ },
+ Fallback: func(args, consumed []string) {
+ if len(args) > 0 {
+ switch args[0] {
+ case "-h", "--help", "help":
+ fmt.Println(mailerUsage)
+ return
+ }
+ }
+ fmt.Fprintln(os.Stderr, mailerUsage)
+ os.Exit(2)
+ },
+ }
+}
+
+// runMailerServe is carlos-mailer.service's ExecStart. It refuses to start,
+// with one line, when systemd passed no socket: the mailer never binds the
+// path itself.
+func runMailerServe(_ []string) {
+ ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
+ defer stop()
+ if err := mailerServe(ctx, os.Getenv, os.Getpid()); err != nil {
+ fmt.Fprintf(os.Stderr, "mailer serve: %v\n", err)
+ os.Exit(1)
+ }
+}
+
+func mailerServe(ctx context.Context, getenv func(string) string, pid int) error {
+ ln, err := mailer.ActivatedListener(getenv, pid)
+ if err != nil {
+ return err
+ }
+ return mailer.Serve(ctx, mailer.Config{
+ Listener: ln,
+ PeerOK: instancectl.EdgeMainPIDPeer(),
+ Handler: mailer.NewHandler(nil),
+ Logf: log.Printf,
+ })
+}
diff --git a/mailer_cli_test.go b/mailer_cli_test.go
new file mode 100644
index 000000000..5e4e07d38
--- /dev/null
+++ b/mailer_cli_test.go
@@ -0,0 +1,39 @@
+package main
+
+import (
+ "bytes"
+ "errors"
+ "os/exec"
+ "strings"
+ "testing"
+)
+
+// runMailerServeBinary runs `carlos mailer serve` from a scratch directory
+// with env added to carlosTestEnv's, and returns its exit code and stderr.
+func runMailerServeBinary(t *testing.T, env ...string) (int, string) {
+ t.Helper()
+ cmd := exec.Command(buildCarlos(t), "mailer", "serve")
+ cmd.Dir = t.TempDir()
+ cmd.Env = carlosTestEnv(t, append([]string{"LISTEN_PID=", "LISTEN_FDS="}, env...)...)
+ var stderr bytes.Buffer
+ cmd.Stderr = &stderr
+ err := cmd.Run()
+ var exit *exec.ExitError
+ if err != nil && !errors.As(err, &exit) {
+ t.Fatalf("run: %v", err)
+ }
+ return cmd.ProcessState.ExitCode(), stderr.String()
+}
+
+// With no socket from systemd the mailer refuses to start, with one line,
+// rather than binding the path itself.
+func TestMailerServeRefusesWithoutSocket(t *testing.T) {
+ code, stderr := runMailerServeBinary(t)
+ if code == 0 {
+ t.Fatal("mailer serve with no socket exited 0")
+ }
+ lines := strings.Split(strings.TrimSpace(stderr), "\n")
+ if len(lines) != 1 || !strings.Contains(lines[0], "LISTEN_PID") {
+ t.Fatalf("stderr = %q, want one line naming the missing socket", stderr)
+ }
+}
diff --git a/parity/cli.tsv b/parity/cli.tsv
index 8afcf425e..0398510f0 100644
--- a/parity/cli.tsv
+++ b/parity/cli.tsv
@@ -155,6 +155,7 @@ link status operator - - - - -
link unpublish operator - - - - -
links ls customer - - - - -
logs customer - - - - -
+mailer serve box-local - - - - -
move customer - - - - -
move abort customer - - - - -
move cut customer - - - - -
diff --git a/parity/parity.tsv b/parity/parity.tsv
index de8b436e3..345c5bd43 100644
--- a/parity/parity.tsv
+++ b/parity/parity.tsv
@@ -229,6 +229,7 @@ box-ops box box-local ops litestream ; ops restore-verify ; ops hibernate-verify
release-keygen box box-local release-keygen Mints signing keys; the private key stays local.
proof box box-local proof keygen ; proof get ; proof put ; proof history Dev proofs a box needs to adopt.
relay-box box box-local relay serve ; relay keygen Runs the relay, or mints a region master key.
+mailer-serve box box-local mailer serve Runs the box-local mailer; the unit's entry point.
system-box box box-local system apply ; system files ; system guard-arm ; system guard-exec ; system floor-allows-prev ; system exec-sandbox-allows-prev ; system runsc-ensure ; system install-channel ; system host-env ; system named-units ; system db-worker ; system journal-migrate ; system group-maintenance ; system edge trust-barrier ; system edge trust-resume ; system edge trust-status ; system proxy-allows-prev ; system box publish-record Root oneshots and units on a box.
status-dry-run box box-local status [--dry-run] A leak check against a fixture fleet, run locally.
devbox-serve box box-local devbox serve The devbox service under systemd.