docs: gVisor flagship plan rev 2 (Astra round 1)
Explicit sandbox setting on demo boxes instead of auto, flagship set to systemd before the roll, bounded control-service peak and purge, full alert source, measured runsc containment across all templates, runbook checks carried into the flip. Per-demo disk bound cut to its own design.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+127
−72
docs/superpowers/plans/2026-11-16-gvisor-flagship-demos.md+127 −72
CI passed — run details
diff --git a/docs/superpowers/plans/2026-11-16-gvisor-flagship-demos.md b/docs/superpowers/plans/2026-11-16-gvisor-flagship-demos.md| index 09837cfff..89d4b38c8 100644 |
| --- a/docs/superpowers/plans/2026-11-16-gvisor-flagship-demos.md |
| +++ b/docs/superpowers/plans/2026-11-16-gvisor-flagship-demos.md |
| @@ -1,92 +1,147 @@ |
| -# gVisor on flagship demo boxes: plan |
| +# gVisor on flagship demo boxes: plan (rev 2) |
| -**Goal:** flagship demo boxes run anonymous demo code under gVisor (runsc), not the native systemd sandbox, and a new or replaced demo box cannot come up without it. |
| +**Goal:** flagship demo boxes run anonymous demo code under gVisor (runsc), not the native systemd sandbox. A demo box that isn't explicitly configured for one or the other admits no demos. |
| **Why now:** flagship demos have been live since 2026-11-11 under the native sandbox. gVisor was built for exactly this workload and has run on the dev demo box since 2026-11-11 (v0.34.47, witness PASS). Paul agreed on 2026-11-16 that we should have a plan. |
| -**Authorities (merged on main):** `docs/superpowers/specs/2026-11-08-gvisor-demos-design.md` (rev 5.5; §4.1 is the `auto` sequencing this plan completes), `docs/superpowers/runbooks/gvisor-demos.md` (dev rollout; the flagship section added here reuses its steps), `docs/superpowers/plans/2026-11-08-gvisor-demos.md`. |
| +**Authorities (merged on main):** `docs/superpowers/specs/2026-11-08-gvisor-demos-design.md` (rev 5.5; §4.1 sequences the default), `docs/superpowers/runbooks/gvisor-demos.md` (the dev rollout, whose checks slice 4 carries forward), `docs/superpowers/plans/2026-11-08-gvisor-demos.md`. |
| -**Evidence:** a Fable 5.2 audit of the gVisor path at 3793aa49 (2026-11-16; summary on discussion #1096). It found no path from the payload to root, other tenants or platform state. Its findings are labelled F1 to F10 below. |
| +**Evidence:** a Fable 5.2 audit of the gVisor path at 3793aa49 (2026-11-16; summary on discussion #1096; findings F1 to F10). It found no path from the payload to root, other tenants or platform state. |
| -**Scope:** demo boxes only. Shared pools are a separate, later plan: they need networked egress under gVisor and a cost ruling. The round limit is three reviews, stopping at the first round with no P1. |
| +**Review history:** round 1 (Astra) was NOT READY, with 4 P1s and 6 P2s, in `~/.cache/sec-review-20261116/reviews/G-R1-astra.md` on docs-t1. Rev 2 answers each finding; the dispositions are at the end. Round limit is three: stop at the first round with no P1. If round 3 still finds a P1, cut scope and take it to Paul. |
| -## Facts settled |
| - |
| -- **Architecture (F1):** `carlos-flagship-demo-box-1` is t4g.small, arm64 (checked 2026-11-16, profile keymail). That matches the only witnessed architecture, so the amd64 witness is not a blocker. Keep it on the list for any future amd64 demo box. |
| -- **Flagship demo box count:** one today. |
| +**Scope:** demo boxes only. Shared pools are a separate, later plan: they need networked egress under gVisor and a cost ruling. |
| -## Slice 1: demo-box hardening that matters TODAY (native and gVisor alike) |
| - |
| -These hold under the current native sandbox, so they ship first, whatever happens to gVisor. Anonymous traffic can trigger all three on flagship now. |
| +## Facts settled |
| -1. **F3: build output validated by streaming.** |
| - - **Problem:** `internal/demobuild/runner.go` `ValidateOutput` reads up to 32 MiB with `io.ReadAll` inside `carlos-instance-control` (`MemoryMax=64M`, up to 4 build slots). A source that links to about 32 MiB can OOM-kill the root control service. |
| - - **Fix:** run `elf.NewFile` over the open file (`ReaderAt`), and hash with `io.Copy` into sha256. Never hold the whole output in memory. |
| - - **Test:** a 32 MiB output validates with heap growth well under the cap; this is a benchmark-style assertion on `testing.AllocsPerRun`, or a bounded-reader fake. |
| -2. **F6: purge works on any tree.** |
| +- **Architecture (F1):** `carlos-flagship-demo-box-1` is t4g.small, arm64 (checked 2026-11-16, profile keymail), the only witnessed architecture. The amd64 witness is owed only if an amd64 demo box is ever added. |
| +- **One demo box, demos only:** the flagship demo box serves nothing but demos, so a demo-triggered disk or memory exhaustion there takes down the demo service on that box, not other tenants. That is why F5 is cut to its own design below. |
| +- **Where the setting lives:** `CARLOS_DEMO_BOX` and the demo tuple live in each demo box's root-owned `/etc/carlos/host.env`, preserved by the same per-box mechanism as `CARLOS_FLEET` (README "demo box settings"). `CARLOS_EXEC_SANDBOX` goes in the same file through the same mechanism. Slice 2's first task finds that producer for flagship. If it lives in an infra repo, that change needs scoped approval (AGENTS.md production infrastructure rule). |
| + |
| +## Sessions and finish lines |
| + |
| +Each slice is its own branch and its own session, and each ends when that slice merges. The handoff (`amadan branch handoff`) carries this plan's review history. Slice 4 is an operation, run in a #421 window by whoever holds the release lock (8a3d302), not a build session. |
| + |
| +## Slice 1: bound the root control service's memory (F3) and purge (F6) |
| + |
| +Both apply today under the native sandbox, so this slice ships first and protects flagship now. |
| + |
| +1. **F3: build output can OOM the root control service.** |
| + - **Problem:** |
| + - root reads a build output of up to 32 MiB (`internal/demobuild/runner.go` `ValidateOutput`, `io.ReadAll`); |
| + - it carries it as `BuildOutput.Binary []byte` (`internal/demobuild/job.go`); |
| + - it JSON-encodes it, as base64, into the control response (`internal/instancectl/demo_build.go`); |
| + - all of this happens inside `carlos-instance-control` (`MemoryMax=64M`), with up to 4 build slots. |
| + - **Fix: bound the peak rather than re-architecting the transport.** |
| + - Validate by streaming: `elf.NewFile` over the open file, and sha256 by `io.Copy`. |
| + - Admit one output transfer at a time, behind a process-wide semaphore of 1 held from read through response write; other finished builds wait their turn. |
| + - Raise the control service's `MemoryMax` to a measured figure covering one transfer (about 32 MiB raw, about 43 MiB base64, plus encoder buffers) on top of today's baseline. 192M is the starting estimate; the measured peak sets the final value. |
| + - Keep the size, ELF-segment and digest checks unchanged. |
| + - The output dir's cleanup stays where it is (`worker.go`), after the response is written. |
| + - **Tests:** a 32 MiB output, run through validation and response encoding, measures peak heap (`runtime.ReadMemStats` HeapInuse high-water, sampled) under the new cap. Four concurrent finished builds serialise and all succeed. The unit-text test pins the new `MemoryMax`. |
| + - **Why not stream the binary to the agent (fd passing):** it changes the client/upload contract across root and the agent, for a box class that runs only demos. It can be a follow-up if build concurrency grows. |
| +2. **F6: purge fails on deep or huge trees.** |
| - **Problem:** `internal/instancefs/dirs_linux.go` `removeAt` refuses depth > 64 and calls `Readdirnames(-1)`. |
| - - **Fix:** iterative, descriptor-relative removal with batched `Readdirnames(256)` and no depth refusal. |
| - - **Test:** a 200-deep tree and a 100k-entry directory purge completely, with bounded memory. |
| -3. **F5: per-demo disk bound.** |
| - - **Problem:** demo data and run dirs have no size bound. One demo can fill `/data` (the root volume) or `/run`. |
| - - **Fix:** a scanned cap is the smallest. The instance-control service measures a demo's data and run dirs at stop, and on a timer while running. Over a fixed cap (demo tier: 256 MiB data, 32 MiB run), it stops the demo and refuses wakes until the purge. |
| - - **Alternative, needs a ruling:** a per-demo loop-mounted filesystem. It's stronger but heavier; Astra or Paul decides. |
| - - **Test:** a demo writing past the cap is stopped and its wake refused with the existing over-limit response. |
| + - **Fix:** an iterative removal that holds at most 2 open directory descriptors. |
| + - It keeps a stack of name components, not fds, and re-resolves each directory from the purge root with `openat2(RESOLVE_BENEATH|RESOLVE_NO_SYMLINKS|RESOLVE_NO_MAGICLINKS)`. That is quadratic in depth, which is accepted. |
| + - It reads entries in batches of 256. |
| + - Path storage is bounded at 4096 components. Past that, purge reports "too deep" and leaves the tree for an operator. A tree of 4096 levels × 255-byte names cannot be built under the guest's limits anyway. |
| + - **Tests:** |
| + - a 1,000-deep tree purges with `RLIMIT_NOFILE` set to 16; |
| + - a 100k-entry directory purges with bounded memory; |
| + - a directory swapped for a symlink between batches is not followed; |
| + - an interrupted purge (error injected mid-walk) resumes and completes on retry. |
| + |
| +The census applies (`internal/demobuild`, `internal/instancefs`, `internal/instancectl` and `internal/host/units`). Release with the usual dev-first roll; the dev demo box witnesses one large build and one deep purge. |
| + |
| +## Slice 2: demo boxes must state their sandbox (F2), with an alert and a pinned argv (F7) |
| + |
| +1. **Explicit, not `auto`.** |
| + - A demo box (`CARLOS_DEMO_BOX=1`) whose `CARLOS_EXEC_SANDBOX` is unset or `auto` refuses demo admission and builds, and reports `sandbox: unset on a demo box` in its status. It must state `gvisor`, or `systemd` as an explicit, visible opt-out. |
| + - This replaces the design §4.1 `auto` flip. It does not depend on recognising a demo box before its configuration exists: an unconfigured box isn't a demo box and admits no demos. |
| + - **Downgrade safety:** the box keeps explicit `gvisor` in host.env, so an older aware release (protocol 1) honours it, and nothing ever relies on `auto`. |
| + - **Tests:** config table tests for demo box × {unset, auto, systemd, gvisor} × {aware, older floor}; the admission refusal end to end; and the status field. |
| +2. **Flagship sequencing (answers the "slice 2 activates early" finding).** |
| + - Before slice 2 rolls to flagship, set `CARLOS_EXEC_SANDBOX=systemd` explicitly in the flagship demo box's host.env through the producer, with a backup copy kept. That makes the slice-2 roll a no-op for the mode. |
| + - The roll then changes nothing until slice 4 flips that one line. Dev's demo box already says `gvisor`. |
| +3. **Alert.** |
| + - **Source:** each demo fleet's box reports at `fleets/<fleet>/status/boxes/`, with the fleet taken from the console's `CARLOS_DEMO_FLEET` (authoritative membership), read explicitly by a new alert signal. |
| + - **Fires** when the effective sandbox isn't `gvisor` on a demo box whose intended mode is `gvisor`. Intent is recorded in the console's demo settings when slice 4 flips; until then the rule is armed but expects `systemd`. |
| + - **Also fires** when the report is absent, unreadable or older than 3 heartbeat intervals, when gVisor reports blocked (not Ready), and when the mode is unset. |
| + - **Detached boxes** and a deliberate rollback, recorded by setting intent back to `systemd`, are quiet. |
| + - "Quiet" never counts as success: slice 4's witness also requires a fresh positive report. |
| + - **Tests:** rule registration, the incident lifecycle (open, resolve) and notification, through the existing alerts engine tests. |
| +4. **F7:** add `--platform=systrap` and an explicit `--directfs=` value (the value chosen in slice 3 step 1; until then the release's current default, written out) to the one argv constructor (`internal/execsandbox/command.go`), and to the `systemctl show` assertions derived from it. |
| + |
| +**Switch-on date:** the code is live on merge (it refuses unset demo boxes; flagship is explicit `systemd` first, so nothing changes there). The gVisor switch-on is slice 4's window. This branch must not merge until that window is booked with 8a3d302 (AGENTS.md stopping rule 5). |
| + |
| +## Slice 3: host-side runsc containment (F4) and diagnostics streams (F9) |
| + |
| +1. **F4: measure, then pin, in this order.** |
| + 1. Choose the `--directfs` value (it changes which host capabilities the gofer and sentry need). |
| + 2. On the disposable root runner (`root-runner`, its own approval scope), measure the minimal capability set and syscall needs for run, build, probe and the stop hooks together. The `instance-exit` hook needs `fchown`. The pinned gofer retains CHOWN, DAC_OVERRIDE, DAC_READ_SEARCH, FOWNER, FSETID and SYS_CHROOT, and runtime setup adds more: measure, don't guess. |
| + 3. Pin these in every gVisor template (`carlos-instance-gvisor@`, `carlos-demo-build-gvisor@`, `carlos-instance-gvisor-probe`) AND in the shared assertion set (`internal/execsandbox/hardening.go` `GVisorHardening`, consumed by `internal/instancectl/gvisorunit.go`): |
| + - `CapabilityBoundingSet=` (the measured set); |
| + - `IPAddressDeny=any` (no host IP traffic expected with `--network=none`; confirmed by witness); |
| + - `InaccessiblePaths=/etc/carlos` plus any other root secret path; |
| + - `NoNewPrivileges=yes`, if runsc tolerates it. |
| + 4. Witness the effective denial: from inside the unit's own context, an attempted host IP connect and a read of `/etc/carlos` both fail. Then witness the full dev runbook on the dev demo box (a separate approval scope from the root runner). |
| +2. **F9: separate the streams.** |
| + - **Problem:** pinned runsc passes its own stderr through to the guest, so `StandardError=journal` would also take the app's stderr away. |
| + - **Fix:** route runsc's own diagnostics with runsc's `--debug-log`/`--log` flags to a root-owned file or the journal. Keep guest stdout and stderr on the existing log socket. |
| + - Cap the listener (`internal/activator/loglistener.go`) before BOTH sinks: the tenant sink, which already has 1 MiB/minute and a ring (`internal/applog/sink.go`), and agent stdout, which today is uncapped. Bytes over the cap are still drained, and counted in a "dropped" line. |
| + - **Tests:** guest stdout and stderr both still reach the tenant log; a runsc error doesn't; a flood is drained and reported as dropped. |
| + |
| +Slice 3 is required before shared pools. For the demo flip, Paul decides at slice 4 whether it is required or waived. |
| + |
| +## Slice 4: flagship flip (an operation, in a #421 window) |
| -Census applies (`internal/demobuild`, `internal/instancefs` and `internal/instancectl` are root-binary code). It ships in the next release with the usual dev-first roll. |
| - |
| -## Slice 2: make gVisor the demo-box default (F2) and pin the argv (F7) |
| - |
| -1. **F2, the default.** |
| - - **Problem:** gVisor mode is a host.env line per box, and `auto` resolves to systemd everywhere (`internal/execsandbox/mode.go`, `AutoDemoGVisor = false`). A replacement demo box comes up native, and every "never fall back" check passes. |
| - - **Fix:** finish design §4.1. `auto` resolves to gVisor when the box is a demo box (the existing `demoBox` signal), and explicit `systemd` is the only opt-out. |
| - - **Tests:** `Parse`/`Resolve` table tests, with `auto` plus demo box giving gvisor, and `auto` plus a non-demo box giving systemd. |
| -2. **F2, the alert.** Add an alert when any demo box's sandbox status reports effective `systemd`. It goes through the existing fleet alerts engine (`internal/console` alerts), with no new channel. |
| -3. **F7, the pinned argv.** Add `--platform=systrap` and an explicit `--directfs=` value to the one argv constructor (`internal/execsandbox/command.go`), and to the `systemctl show` assertion, so a runsc lock bump can't change either silently. |
| - |
| -Census applies. This is a dormant default with a switch-on date: it switches on at the slice 4 window (AGENTS.md stopping rule 5). |
| +**Preconditions:** |
| +- Slices 1 and 2 are released and rolled to flagship, with the demo box's host.env saying `systemd` explicitly. |
| +- Slice 3 is released, or waived by Paul. |
| +- The dev witnesses the earlier rollout deferred are done on dev: |
| + - the claim finished by a person under gVisor; |
| + - two concurrent builds and two concurrent demos; |
| + - a roll that changes the runsc pin; |
| + - a rollback from gVisor to systemd. |
| -## Slice 3: host-side runsc containment (F4) and log volume (F9) |
| +**Steps:** in the window, with Paul's go and the version from 8a3d302, run the runbook's flagship-equivalent checks verbatim (runbook §"Prepare the release and approval" through §"Rollback", lines ~85-110), with the box name substituted. These include: |
| +- privileged acceptance on the current commit; |
| +- the five installed member hashes; |
| +- the Ready/probe result; |
| +- instance sandbox status; |
| +- full starter build and `Worker.Initialize`; |
| +- a fresh `X-Carlos-Version` receipt; |
| +- `/proc/net/dev` read INSIDE the guest, showing loopback only. |
| -1. **F4, host-side containment.** |
| - - **Problem:** `carlos-instance-gvisor@.service` runs runsc as root, with full capabilities and the host network. Its only backstop is `ProtectSystem=strict`. |
| - - **Fix:** measure on the dev demo box (the root runner) the smallest set runsc needs, then pin these in the unit and its unit-text test: |
| - - `CapabilityBoundingSet=` (that set); |
| - - `IPAddressDeny=any`; |
| - - `InaccessiblePaths=/etc/carlos`, plus any other root secrets path the audit names; |
| - - `NoNewPrivileges=yes`, if runsc tolerates it. |
| - - **Witness:** the dev runbook witness passes under the pinned unit. |
| -2. **F9, log volume.** |
| - - **Problem:** runsc and root hook stderr go into the tenant-visible log through a plain `io.Copy` with a line cap. |
| - - **Fix:** send runsc's own stderr to the journal, not the tenant log, and add a bytes-per-minute cap to the listener's tee, using the edge log pipeline's limits if they exist. |
| +Then flip host.env `systemd` to `gvisor` through the producer, record the intent in the console's demo settings, restart control and the agent, and check for a fresh positive sandbox report. |
| -Slice 3 is required before shared pools. For demo boxes it's recommended before the flip; if it slips, Paul decides whether the flip waits. |
| +**Witness demos are disposable:** create, update, wake and claim a throwaway demo. Its claim and deletion are not undone by a rollback, so never use a real visitor's demo. Record the account, region, resources and cleanup in the roll log. |
| -## Slice 4: flagship flip (an operation, not code) |
| +**Rollback:** follow the runbook's rollback: drain, prove the gVisor family is gone, set host.env back to `systemd`, record the intent, restart, and check for a fresh positive `systemd` report. The alert stays quiet because intent matches. |
| -**Preconditions:** |
| -- slices 1 and 2 are released and rolled to flagship; |
| -- slice 3 is released, or waived by Paul; |
| -- the runbook's dev witnesses not yet run are done on dev: |
| - - the claim finished by a person under gVisor (deferred since 11-09); |
| - - two concurrent builds and two concurrent demos; |
| - - a roll that changes the runsc pin; |
| - - a rollback from gVisor to systemd. |
| +## Cut: per-demo disk bound (F5) gets its own design |
| -**Steps** (one #421 window, Paul's go, version from 8a3d302): |
| -1. Runbook steps 1 to 3 on `carlos-flagship-demo-box-1`: |
| - - an aware release adopted, no update journal, guard files absent, and the recover unit matching; |
| - - each of the five runsc objects readable through the box's own store access. |
| -2. With slice 2 released, `auto` already resolves to gVisor. Remove any explicit `CARLOS_EXEC_SANDBOX=systemd` from host.env, keeping a backup copy. Restart control and the agent. |
| -3. Witness: |
| - - create a demo, update it (data kept), wake it from hibernation, finish a claim, take it down; |
| - - check `/proc/net/dev` shows loopback only; |
| - - check the sandbox status reports effective gvisor; |
| - - check the new alert is quiet. |
| -4. **Rollback:** set `CARLOS_EXEC_SANDBOX=systemd` in host.env, restart control and the agent, and the alert fires as expected. Write it down in the runbook before the window. |
| +- **Why not a scan:** the round-1 review showed a scanned cap cannot stop exhaustion. Unlinked open files and fast writes outrun it, and stopping outside the activator's fences is unsafe (`internal/instancectl/hardening.go:539`). |
| +- **What a real fix needs:** an enforced boundary. That means a per-demo or aggregate demo filesystem with reserved backing space, inode limits, mount, recovery and purge handling, survival across hibernation, readability during claim export, and native/gVisor parity. That is a design, not a plan task. |
| +- **Interim (no new code):** the flagship demo box runs only demos, so exhaustion is a demo-service outage on that box. The existing early disk alert (box staging disk) covers it. File the design as a follow-up on #1096. |
| ## Not in this plan |
| -- Shared pools under gVisor. |
| -- F8 (guest `noexec` parity) and F10 (fail-closed 503s during rolls). Both go on a follow-up list on #1096. |
| -- The amd64 witness, which is only needed if an amd64 demo box is ever added. |
| +- Shared pools. |
| +- F8 (guest `noexec` parity) and F10 (fail-closed 503s during rolls); both go on the #1096 follow-up list. |
| + |
| +## Round 1 dispositions |
| + |
| +| Finding | Disposition | |
| +|---|---| |
| +| P1 F3 OOM path | Accepted. Slice 1.1 bounds the peak (one-at-a-time transfer, measured cap, heap high-water test) instead of only streaming validation. | |
| +| P1 F5 scan insufficient | Accepted. Cut to its own design, with the interim reasoning stated. | |
| +| P1 slice 2 activates early | Accepted. Explicit `systemd` goes on flagship before the roll, and the flip is the slice 4 line change. | |
| +| P1 F2 fresh box / downgrade | Accepted. Explicit setting required on demo boxes, `auto` not relied on, admission refused when unset. | |
| +| P2 alert source and unknown state | Accepted (slice 2.3). | |
| +| P2 F6 descriptors | Accepted (slice 1.2: 2 fds, name stack, low-NOFILE test, interruption, symlink swap). | |
| +| P2 F4 scope | Accepted (slice 3.1: directfs first, all templates plus shared assertions, effective-denial witness, separate approval scopes). | |
| +| P2 F9 streams | Accepted (slice 3.2). | |
| +| P2 slice 4 evidence | Accepted (runbook checks verbatim, guest-side `/proc/net/dev`, disposable demos, full rollback). | |
| +| P2 sessions and switch-on | Accepted (sessions section; slice 2 waits for a booked window). | |