docs: hub learns the console's address from root's install of it (spec rev 1)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+274
−0
docs/superpowers/specs/2026-11-24-hub-console-address-from-install-design.md+274 −0
diff --git a/docs/superpowers/specs/2026-11-24-hub-console-address-from-install-design.md b/docs/superpowers/specs/2026-11-24-hub-console-address-from-install-design.md| new file mode 100644 |
| index 000000000..d5f4e3f61 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-24-hub-console-address-from-install-design.md |
| @@ -0,0 +1,274 @@ |
| +# The hub learns the console's address from root's install of it |
| + |
| +Status: draft rev 1 for design review, 2026-11-24. Branch |
| +`console-addr-from-install`. Direction chosen by Paul on 2026-11-24: the |
| +console install writes the address, and the hub reads it. The earlier |
| +`/proc` listener discovery (branch `hub-operator-console`, 7a2569892) was |
| +rejected by Codex with two P1s and is not revived here. |
| + |
| +## 1. The problem |
| + |
| +A tunnel hub forwards fleet boxes' console calls (`POST |
| +/api/fleet/replicas/…`, `/api/fleet/seeds/…`, `boxConsolePath`, |
| +`internal/edge/replicaconsole.go:134-145`) to the local console, carrying |
| +the boxes' fleet bearer tokens. `serveReplicaConsole` |
| +(`replicaconsole.go:97-131`) finds the console in one of two ways: |
| + |
| +1. `CARLOS_REPLICA_CONSOLE_ADDR`, read once at edge start in |
| + `enableTunnelsFromEnv` (`internal/edge/edge.go:5317-5324`) from the |
| + edge's `EnvironmentFile=-/etc/carlos/host.env` |
| + (`internal/host/units/carlos-edge.service`); |
| +2. otherwise, a scan of the route table for the one accountless |
| + `console`/`console.service` route on a loopback upstream or socket. |
| + |
| +On the flagship the console is app `console` in the ops account `bab`, so |
| +(2) finds nothing and every call answers `503 replica-console-missing` |
| +(`replicaconsole.go:128`). (1) would work, but the flagship hub's |
| +`host.env` is hand-managed: it is not built from parameters, so `carlos |
| +system host-env` does not reach it, and setting it means a session on the |
| +box. Paul does not want that to be how this is managed (AGENTS.md, |
| +"Operate via API and CLI"). |
| + |
| +Interim (2026-11-24, approved by Paul): the coordinator set |
| +`CARLOS_REPLICA_CONSOLE_ADDR=127.0.0.1:8090` in the flagship hub's |
| +`host.env`, with a comment marking it temporary, and restarted |
| +`carlos-edge`. §9 removes it. |
| + |
| +## 2. The trust argument |
| + |
| +The rule (`replicaconsole.go:16-26`): route records are not a tenancy |
| +boundary, since a legacy direct-S3 fleet box can write them, so no record |
| +field may choose, redirect or disable where the fleet tokens go. The new |
| +source must therefore be written by root from inputs only root and the |
| +operator control, and read by the edge in a way only root can satisfy. |
| + |
| +What makes `console.service` "the console" on a box, record-free: |
| + |
| +- **The unit is root's.** `console.service` is a root-owned unit under |
| + `/etc/systemd/system`, installed with the box (not by `internal/host/units`, |
| + and not by any record; console-as-an-app spec §4a). A tenant cannot create |
| + or name a system unit. |
| +- **Its binary comes from a release only the ops account can promote.** The |
| + ops account's builds stage to `<opt>/versions/<ver>/<app>`; every other |
| + account gets `<opt>/versions/<ver>/<acct>/<app>` (`VersionPath`, |
| + `internal/release/versions.go:53-61`). So a file at exactly |
| + `<opt>/versions/<ver>/console` was staged from `apps/bab/console`, whose |
| + channel pointers root verifies against the release key with account, app |
| + and channel bound in (`verifyPointer`, `internal/release/release.go:598`). |
| + The console refuses service-principal promotes of a control-plane app |
| + (console-as-an-app spec §6), so a person with ops membership, or the |
| + operator with the release key, is the only promoter. |
| +- **Its listen address comes from its unit configuration.** The console |
| + listens on `CONSOLE_ADDR`, default `127.0.0.1:8090` |
| + (`cmd/console/main.go:957`). Unit fragments and drop-ins are root-owned; |
| + environment files are trusted only if root-owned (§4). |
| + |
| +A record can still point adoption at a host or name `console.service` in |
| +`rt.Unit`, which decides which live link adoption repoints and which unit it |
| +restarts (`makeRestartRoute`, `internal/host/agent.go:5493`). It cannot change |
| +anything this design reads: the unit's `ExecStart`, the live link's target |
| +shape, or the unit's environment. If a record ever made `console.service` |
| +exec something other than an ops console build, the writer refuses (§4). |
| + |
| +**What the address proves, and what it does not.** The record says where |
| +root configured the console to listen. It does not prove who holds that port |
| +at the moment the edge dials: if the console is stopped, another process |
| +could bind `127.0.0.1:8090` and receive the next call's token (Codex's |
| +finding 1 on `hub-operator-console`). That residual is exactly today's |
| +`CARLOS_REPLICA_CONSOLE_ADDR`, which that review named the acceptable |
| +interim. On a platform hub the processes that can bind host loopback are |
| +root, the console's own user, `carlos` (the edge itself, which already |
| +handles every token in flight), and unit-backed tenants, which are |
| +operator-trusted by definition (`carlos-app@.service:5-14`: "never set it |
| +for a tenant you would not give a shell on the box"). Instances can bind, |
| +but their cgroup filter drops loopback traffic both ways |
| +(`IPAddressDeny=localhost`, `carlos-instance@.service:162`, |
| +`carlos-instance-rootfs@.service:237`), so the edge's connect never reaches |
| +them, and gVisor instances run `--network=none` |
| +(`internal/execsandbox/command.go:8`). Closing the residual entirely is a |
| +listener whose ownership survives a stop (a unix socket in the console |
| +unit's `RuntimeDirectory=`, or a systemd socket unit holding the port). That |
| +needs a console listener change and is §11's decision for Paul, not part of |
| +this fix. |
| + |
| +**`host.env`'s ownership.** On the flagship hub `/etc/carlos/host.env` is |
| +`carlos:carlos` 0600, not root's as the edge unit's comment says. systemd |
| +reads it as root, but `carlos` can write it, so the env var's trust today is |
| +"root or the edge's own user". That does not widen who sees the tokens, |
| +because the `carlos` process is the edge that forwards them. It does mean |
| +`host.env` is not a root-only anchor, and the new record must not inherit |
| +that: it is root-written, and the edge refuses one that is not root-owned |
| +(§5). |
| + |
| +## 3. What writes it, when |
| + |
| +A new step in root's adopt pass, `runAdoptUnderRootRelease` |
| +(`internal/host/agent.go:5997`), placed beside the named-units step |
| +(`agent.go:6181`): never fatal, on full and `-config-only` passes alike, so |
| +it runs hourly (`carlos-adopt.timer`) and on every config-sync trigger. It |
| +reads only: |
| + |
| +1. `systemctl show console.service -p LoadState,FragmentPath,DropInPaths,ExecStart,Environment,EnvironmentFiles,UnsetEnvironment,PassEnvironment`; |
| +2. the target of the live link `ExecStart` names, through |
| + `rootstate.ReadTrustedLink`; |
| +3. on a guarded box, the console guard marker through `consoleGuardHost` |
| + (`internal/host/unitops.go:195`); |
| +4. each listed environment file, through `rootstate.OpenTrustedFile`. |
| + |
| +It never reads the registry, a record or the bucket. |
| + |
| +It writes one record, `endpoint.json`, in a public root store |
| +`/var/lib/carlos-console-endpoint` (`rootstate.Open(dir, true, true)`, root |
| +0644, replaced atomically), the convention of `/var/lib/carlos-named-units` |
| +(`internal/host/namedunitsfetch.go:37`). It rewrites only when the bytes |
| +change, so the record carries no timestamp. |
| + |
| +```json |
| +{"schema":1,"state":"ok","addr":"127.0.0.1:8090","source":"default", |
| + "exec":"/opt/carlos/live/platform.carlosframework.com","build":"v0.41.0"} |
| +{"schema":1,"state":"refused","reason":"console.service loads /etc/carlos/host.env, which is not root-owned"} |
| +{"schema":1,"state":"absent"} |
| +``` |
| + |
| +`source` is `default`, `environment` or `environment-file:<path>`; `build` is |
| +the `<ver>` of the staged path. Only `ok` carries an address. |
| + |
| +## 4. How root derives the address |
| + |
| +The step decides `absent`, `refused` or `ok`, in order: |
| + |
| +- **absent:** `LoadState` is `not-found`. No console on this box. |
| +- **refused, ExecStart:** the unit has exactly one `ExecStart`, and its argv |
| + is one of exactly two shapes: `[<opt>/live/<host>, "serve"]`, or the |
| + guard's `[<opt>/system/guard/carlos, "system", "guard-exec", "console", |
| + <opt>/live/<host>, "serve"]` (`hostfloor.ConsoleGuardDropIn`, |
| + `internal/hostfloor/report.go:101`) with the guard marker naming that live |
| + link. Anything else (a wrapper, `env`, extra arguments) is refused. |
| +- **refused, binary:** the live link must resolve to exactly |
| + `<opt>/versions/<ver>/console` with a valid version (`ValidVersion`), a |
| + regular file. A tenant path (`versions/<ver>/<acct>/console`), any other |
| + app or an unreadable link is refused. |
| +- **refused, environment:** `PassEnvironment` or `UnsetEnvironment` naming |
| + `CONSOLE_ADDR`; an environment file that exists but fails the trusted open |
| + (not root-owned, group- or other-writable, a symlink); or a |
| + `CONSOLE_ADDR` line the parser does not accept (anything but |
| + `CONSOLE_ADDR=<value>`, optionally in one pair of matching quotes). A |
| + missing optional file (`-` prefix) is skipped, as systemd skips it. |
| +- **the value:** systemd's precedence. The last assignment in the |
| + environment files (in listed order) wins over the inline `Environment=`, |
| + whose last assignment wins over the default. The default is a constant |
| + moved out of `cmd/console` into a small shared package both binaries |
| + import, so the console and root cannot drift. |
| +- **refused, address:** the value must pass the edge's own |
| + `parseReplicaConsoleAddr` (`replicaconsole.go:39-56`): a literal loopback |
| + IP and a port. A wildcard (`:8090`, `0.0.0.0:8090`) or a host name is |
| + refused, naming `CARLOS_REPLICA_CONSOLE_ADDR` as the way to configure it. |
| +- otherwise **ok**. |
| + |
| +Exactly one unit name is consulted, so "more than one console" cannot arise |
| +from this source. A second console unit on a box is invisible to the step and |
| +keeps today's behaviour. |
| + |
| +## 5. How the edge reads it, and what wins |
| + |
| +The order is **env > record > the old route scan**: |
| + |
| +1. `CARLOS_REPLICA_CONSOLE_ADDR` set: as today, read once at start; the |
| + record is never opened. Tito and self-hosters are unchanged. |
| +2. Otherwise, on every replica call, the edge opens `endpoint.json` with |
| + `rootstate.OpenTrustedFile` plus `rootstate.CheckPublicConfig` |
| + (root:root, 0644, regular, one link), reads at most 4 KB, decodes one |
| + document with unknown fields refused, and requires `schema` 1, |
| + `state` `ok` and an `addr` that passes `parseReplicaConsoleAddr`. Then it |
| + forwards to that address with `newReplicaConsoleProxy` |
| + (`replicaconsole.go:64`), one proxy cached per address. |
| +3. Any other outcome (missing, not root's, malformed, oversized, `refused`, |
| + `absent`) is treated as no record: the edge logs the reason at most once |
| + per distinct reason and falls through to today's route scan, which on the |
| + flagship answers 503 as it does now. |
| + |
| +Reading per call means a new record takes effect on the next call, with no |
| +edge restart and no watcher. Replica calls are a few per box per minute, and |
| +the read is one small file; a cache keyed on the file's identity is allowed |
| +later if profiling asks for it. |
| + |
| +## 6. Fail-closed cases |
| + |
| +| Case | Record | Edge | |
| +|---|---|---| |
| +| No `console.service` | `absent` | route scan (today) | |
| +| Unit runs something other than an ops console build | `refused` | route scan (today) | |
| +| Untrusted env file, unparsable `CONSOLE_ADDR`, wildcard or non-loopback | `refused` with the reason | route scan (today) | |
| +| Record missing, not root's, malformed | — | route scan (today), reason logged once | |
| +| Console stopped but still installed | `ok` | dials, gets 502 (§2 residual) | |
| +| Console uninstalled or moved to another address | `absent`, or `ok` with the new address, from the next pass | until then the old address: 502 or §2's residual | |
| + |
| +No failure yields an address the edge would not have used before this |
| +change; the record only adds one, and only in state `ok`. |
| + |
| +## 7. Staleness |
| + |
| +The record is current as of the last root pass: at most an hour, sooner on |
| +any config-sync trigger. A console moves address only by an operator |
| +changing its root-owned unit, which is already box work; the next pass |
| +follows. Uninstalling the unit gives `absent` on the next pass. The stale |
| +window carries the same risk as a stale `CARLOS_REPLICA_CONSOLE_ADDR`, which |
| +has no expiry at all. |
| + |
| +## 8. Visibility |
| + |
| +The agent reads the record into the box heartbeat beside `named_units` |
| +(`internal/status/snapshot.go:877-880`), as `console_endpoint`, with which |
| +source the edge is using (env, record or route scan). `carlos system status` |
| +prints one line for a box whose console endpoint is `refused`, and for a box |
| +whose env and record disagree. Nobody needs a shell to see why a hub |
| +answers 503. |
| + |
| +## 9. Rollout |
| + |
| +1. Merge; it ships in the next release (everyone is on edge). Roll dev boxes, |
| + then the dev console, then flagship, per the README recipe. |
| +2. Dev hub: confirm `console_endpoint` reads `ok` and replica calls still |
| + succeed. Dev's accountless console route keeps the route scan as a |
| + backstop meanwhile. |
| +3. Flagship hub: confirm `console_endpoint` is `ok`, `127.0.0.1:8090`, with |
| + the edge reporting `source: env` (the interim line still wins). |
| +4. Remove the interim `CARLOS_REPLICA_CONSOLE_ADDR` line from the flagship |
| + hub's `host.env` and restart `carlos-edge`, by the same Paul-approved |
| + route the coordinator used to add it. Confirm the heartbeat shows |
| + `source: record` and the 503s stay gone. |
| +5. Update the comment at `replicaconsole.go:16-26`, the self-host docs (the |
| + env var stays the supported override) and the replica docs. |
| + |
| +## 10. Tests and census |
| + |
| +Tests (table-driven over a fake `systemctl show` and a temp opt tree): |
| +each `absent`/`refused`/`ok` row of §4, both `ExecStart` shapes, a tenant |
| +`versions/<ver>/<acct>/console` path, env precedence, an untrusted env file, |
| +a wildcard address, unchanged bytes not rewritten; the edge's precedence, |
| +every §6 row, a record change taking effect without a restart, a route row |
| +naming another `addr` having no effect while the record is `ok`; and a test |
| +that the console's default and root's are the one constant. |
| + |
| +Census: the writer (`internal/host`), the reader (`internal/edge`), the |
| +heartbeat field (`internal/status`) and the shared constant package are all |
| +in the root binary's scope. New root reads: `systemctl show`, a trusted link |
| +read under `<opt>/live`, the guard marker, and trusted opens of the unit's |
| +environment files. Card and Codex census review on the branch, per AGENTS.md. |
| + |
| +## 11. Decisions for Paul |
| + |
| +1. **The route scan.** Recommendation: keep it in this change as the |
| + fallback below the record, so a hub whose record is refused behaves as |
| + today; delete it in the next release once every platform hub reports |
| + `source: record` or `env`. It is the one remaining place route data |
| + chooses where tokens go. |
| +2. **Listener identity.** Accept §2's residual (identical to the env var |
| + today), or follow up with a console listener whose ownership survives a |
| + stop (a unit-owned unix socket, or a socket unit). |
| + |
| +## 12. Not in this spec |
| + |
| +Self-hosted consoles not staged by the root pass (the guide's downloaded |
| +binary) get `refused` and keep using the env var. A box with two console |
| +units. Any change to the console's listener. |