Repository navigation
feat(sbx): lease mode plan 1 — guest agent and image (level 1) - #706
Conversation
…wn_failed in End Adds the wire fields and passes them through the host. Nothing reads them yet. Lease and normalise_workspace are omitempty, so a request without them is byte-identical to today's. TeardownFailed is mapped from End to Result in runOverConn. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…ew_privs and a seccomp filter
ShimMain (argv[1] == "lease-shim") turns the root process it starts as
into the lease Exec identity on one locked OS thread: it empties the
capability bounding set, sets the groups and the resgid/resuid, sets
no_new_privs, and installs a seccomp filter that denies ptrace and
process_vm_{readv,writev} with EPERM. It kills the process on a foreign
audit arch or an amd64 x32 syscall number. Then it execs the argv with
HOME/USER/LOGNAME set. Off Linux it refuses.
The root tests run in CI's microvm-gates job under sudo, and that step
fails if the uid-drop test did not PASS. TestTheCIWorkflowsRunTheGates
now pins "TestShim". The shim's syscall.Exec is declared in the §3.5
spawn gate as a guest-side spawn.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…ss_vm_writev in test, rejects empty home/argv The inheritable capability set survives setresuid and execve, so it was empty only because the agent happened to start with it empty. The shim now clears it with capget/capset (v3) while still root. It leaves permitted and effective to setresuid: dropping them first on the shim thread aborts the process in the all-threads setgroups that follows. TestShimClearsAnInheritedCapabilitySet hands the shim CapInh 0x400 via AmbientCaps and asserts that the child sees 0. The seccomp test now also calls process_vm_writev, and parseShimArgs rejects an empty home and an empty argv[0] at the "args" step. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
… PID-1 reaper, lease latch A lease request runs a fresh bash -c through the lease shim, as the exec user, in its own cgroup (CgroupRoot/e<seq>, placed at clone time). After the command exits or times out, cgroup.kill and a 5 s wait for "populated 0" happen before End, so nothing it started outlives it. A wait4(-1) reaper started by the first lease request reaps the orphans. That first request also sets a latch, after which per-Exec requests are refused. A failed teardown sets End.TeardownFailed and makes the agent dead. NormaliseWorkspace is refused until Task 4. The per-Exec paths are unchanged. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…aborts the Exec, Close never waits on a running Exec
- Timeout or abort with a failed teardown now sends End{ExitCode:-1,
TeardownFailed:true} instead of a KindError (spec §3.1).
- A read return on the drained connection means the host closed it, and
the Exec is torn down as on a timeout.
- The reaper pointer is atomic, so Close stops it without taking the
lease mutex.
- c.dir is closed on the teardown-failure path.
- Comments at the latch and in Close.
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Paolo Dettori <[email protected]>
…out following symlinks or mounts Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…y, no setuid bits, guest kernel_release The init mounts cgroup2 at /sys/fs/cgroup, sets max_user_namespaces to 0 and starts the agent with --lease-cgroup-root /sys/fs/cgroup/moca-execs. assemble_rootfs appends the sbx (7000) / sbx-ws (7000) entries, refusing a tree that uses those ids or names for something else, and strips every setuid/setgid bit. Both boot paths probe the guest's uname -r into kernel_release and verify cgroup2, userns=0 and no setuid files with one per-Exec request (never lease: true). The manifest advertises features: ["lease-v1"], outside the hash. guest-agent dispatches the lease shim before flag parsing and takes -lease-cgroup-root/-lease-uid/-lease-gid/-lease-home. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…init failures, tighter tests The setuid/setgid strip now runs after install_egress_ca's chroot hooks and the gitconfig append, immediately before mkfs, so nothing can reintroduce a bit. The init's cgroup2 mount and max_user_namespaces write name their failure before exiting instead of dying silently under set -e. The identity clash tests grep for the clashing entry (uid and gid cases), and the Features test checks json.Marshal's error. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…, privilege Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Open /proc/1/mem for writing instead of reading it, replace su with a setuid scan and NoNewPrivs, migrate $BASHPID before starting the marker so an escape is caught in Run 2, add started-count positive controls and loud pgrep errors, mount onto /tmp/sbx-home, and require a kernel refusal from unshare -U. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…he cgroup tree, per-process start check util-linux mount refuses a non-root caller before any syscall, so assert CapEff is zero and call mount(2) directly for EPERM. Require "Permission denied" from the moca-execs write and mkdir so a broken cgroup layout (ENOENT) fails. Count each started process separately in the kill gate. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…procps The SBX0 rootfs has no pgrep/ps, so both probes now use one python3 /proc scanner (count and list modes, SCAN-ERROR on failure). The daemon marker must be reparented to PID 1, and CapEff/NoNewPrivs are read from the Exec shell's own status rather than awk's. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…002, nodev,nosuid workspace, devices removed, userns off at the first lease The vsock listener lacked SOCK_CLOEXEC, so every lease Exec inherited the agent's port-1024 listener. The shim now sets umask 0002 (spec §3.3). The first lease request, before the latch, remounts the workspace nodev,nosuid (keeping its other flags) and writes 0 to max_user_namespaces; normaliseWorkspace removes character and block devices instead of chowning them. Any failure leaves the latch unset. TestGateLeasePrivilege asserts the Exec's fd list and the workspace mount options. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…y, sbx account checked init no longer disables user namespaces (the agent does it at the first lease request, so per-Exec VMs keep them); check_lease_support checks the sysctl is writable and that /etc/passwd has the sbx line (grep, no getent). The manifest advertises lease-v1 only for VMM=firecracker: CHV mounts the workspace per Run. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…led by the agent Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Reviewed at f0dbf0b: guest agent lease path (shim, seccomp, per-Exec cgroup, reaper, latch, normalise), vsock listener CLOEXEC, build-snapshot.sh image changes, wire flags, manifest features, the new CI steps and KVM gates.
No blocking issues. I checked these and found them sound:
- The shim runs every privilege step on one locked thread: bounding set, inheritable caps, setgroups/setres[ug]id, no_new_privs, seccomp. Under CGO_ENABLED=0, Go's AllThreadsSyscall handles the setxid calls, and the new CI step covers that path.
- The seccomp filter checks the audit arch, kills x32 calls, and its jump offsets are right.
CLONE_INTO_CGROUPleaves no window outside the cgroup.cgroup.killruns, then waits forpopulated 0, all before End. The teardown_failed path still sends End and forces the drains off the pipes.- The reaper's early/registration window and the
stopLeaseordering inCloseare correct. normaliseWorkspacelstats, never follows symlinks, skips other devices, removes device nodes, and strips setuid/setgid.- The listener is SOCK_CLOEXEC and accepted conns use Accept4(SOCK_CLOEXEC), so a lease Exec inherits only fds 0-2.
check_lease_supportuses a per-Exec request, so no latch reaches the snapshot.lease-v1is advertised on Firecracker only.
Two suggestions (defence in depth, fine as plan-2 follow-ups) and one nit are inline.
Author: pdettori (MEMBER, maintainer)
Areas reviewed: Go (guestagent, vmpool), Shell (build-snapshot.sh + tests), CI (ci.yml), Docs (ADR-0048, lease spec)
Agent/IDE config (.claude/.vscode): none
Commits: 16 commits, all signed-off: yes
CI status: passing (all 17 checks, microvm-gates included)
| switch goarch { | ||
| case "amd64": | ||
| auditArch, x32 = unix.AUDIT_ARCH_X86_64, true | ||
| denied = []uint32{101, 310, 311} // ptrace, process_vm_readv, process_vm_writev |
There was a problem hiding this comment.
suggestion: Consider adding pidfd_getfd (438 on both amd64 and arm64) to the deny list. It lets a process copy an fd out of another process under the same PTRACE_MODE_ATTACH_REALCREDS check as ptrace. The uid split (and the agent being non-dumpable) already blocks it, but the filter's stated purpose is "cannot trace or read into another process of its uid", and pidfd_getfd belongs to that class. It costs one more JEQ.
There was a problem hiding this comment.
Fixed in a00db74. pidfd_getfd (438 on amd64 and arm64) is now on the deny list. TestSeccompFilterDeniesTheBuildArchSyscalls pins it against unix.SYS_PIDFD_GETFD. TestShimSeccompDeniesPtraceAndProcessVM now also calls pidfd_open on its own pid, then pidfd_getfd(fd 0), and asserts EPERM. Both tests failed on the rig before the filter change (RED: filter for amd64 never compares nr with pidfd_getfd (438) and output lacks "pidfd_getfd -1 1"). After it, the full root guestagent suite passes with -race (63 pass), and TestShim also passes with CGO_ENABLED=0.
| dir *os.File // O_PATH|O_DIRECTORY, for CLONE_INTO_CGROUP | ||
| } | ||
|
|
||
| func newExecCgroup(root string, seq uint64) (*execCgroup, error) { |
There was a problem hiding this comment.
suggestion: The per-Exec cgroup sets no pids.max or memory.max, and moca-execs has no subtree_control. Under per-Exec, a guest OOM or fork bomb only costs that one command's VM. In a lease VM, an OOM kill of PID 1 panics the guest and takes the whole lease with it, and a fork bomb can starve the agent of pids until cgroup.kill. Plan 2 could enable +pids +memory on the root and cap each e<seq> below guest RAM, or at least set oom_score_adj=-1000 on the agent. That gives teardown_failed/agent_dead a cleaner failure mode than a guest panic.
There was a problem hiding this comment.
Agreed, deferring this to plan 2 as you suggest. It belongs with the worker's lease state machine, because the cap has to be sized against guest RAM and the reclaim and teardown policy there (spec §6). I've recorded it as a plan-2 requirement:
- enable
+pids +memoryonmoca-execs; - cap each
e<seq>below guest RAM, with a pids.max; - set
oom_score_adj=-1000on the agent; - add a gate for both: a fork bomb, and an OOM inside a lease Exec, ending as teardown_failed/agent_dead rather than a guest panic.
|
|
||
| var end End | ||
| if req.HasStdin { | ||
| if req.Lease { |
There was a problem hiding this comment.
nit: 13 of the 16 commit subjects are over 72 characters (e.g. fix(guestagent): lease final review — CLOEXEC vsock listener, … is 146). This is advisory only, and a squash-merge with a short title would fix it.
There was a problem hiding this comment.
Acknowledged. I'll squash-merge this with a short title, feat(sbx): lease mode plan 1, guest agent and image, so main gets one subject under 72 characters.
pidfd_getfd copies an fd out of another process under the same PTRACE_MODE_ATTACH_REALCREDS check as ptrace, so it belongs in the filter's class (PR rossoctl#706 review). 438 on amd64 and arm64. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Follow-up review at a00db74 (incremental from f0dbf0b): pidfd_getfd (438, amd64+arm64) is now denied; the JEQ skip offsets still land on the shared ERRNO return, and both tests pin it (filter-level number check + in-shim EPERM on a self-targeted pidfd_getfd). The cgroup caps deferral to plan 2 and the squash-merge title both resolve the remaining items. No new findings. LGTM.
E16 (RESULTS.md, c8dba13): at 1-2% duty the arms do not separate up to 1,536 sessions; resident's only failures were the run-end egress wedge. Question 2 is now answered at the default point only; the freed rig time goes to the pycache gain-against-D and 256 MiB guest-RAM runs. E17b's guest side is merged (rossoctl/moca#706). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…_score_adj -1000 In a lease VM the agent is PID 1 and serves many Execs, so a guest OOM or a fork bomb in one Exec must cost that Exec, not panic the guest and take the lease with it (plan 1 review, rossoctl#706). - The first lease request enables +pids +memory in the cgroup root's parent and in the cgroup root. A failure refuses the request and leaves the latch unset, so lease service is refused rather than served uncapped; the next lease request retries. - Each e<seq> gets memory.max = MemTotal - max(64 MiB, MemTotal/8) (MemTotal from /proc/meminfo, read per Exec) and pids.max = 4096 before anything runs in it. An Exec whose caps cannot be written is refused. - The first lease request writes -1000 to the agent's oom_score_adj; a failure is logged, not fatal. The shim puts each Exec's back to 0 while still root, or every Exec process would inherit -1000 and an OOM would find nothing it may kill. The arithmetic and meminfo parsing are platform-neutral (lease_caps.go) and tested everywhere; the cgroupfs writes are Linux-only. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
…-in guest shape Building snapshots from third-party benchmark images hit faults in build-snapshot.sh that Moca's own sandbox image never shows: - The guest had no /dev/fd, /dev/stdin, /dev/stdout or /dev/stderr: the kernel's devtmpfs has none of them, so bash process substitution (`done < <(find ...)`) and tools reading /dev/stdin failed. init now links them to /proc/self/fd (each only if absent, never fatal), and check_dev_fd runs `cat <(echo fd-ok)` in the guest on both VMM arms. - init mounted an empty tmpfs on /var, hiding what an image keeps there (a prebuilt TeX format under /var/lib/texmf, say), with the read-only root keeping it from being rebuilt. /var is now an overlay: the image's /var underneath, a per-VM tmpfs on top (fallbacks: a copy into the tmpfs, then the old empty tmpfs; never fatal). check_var reads a file the image has under /var and writes one. - assemble_rootfs wrote $tree/sbin/init with `cat >`, which follows a symlink: Ubuntu-based images ship /sbin/init -> /lib/systemd/systemd (absolute), so the write opened the build host's own systemd as root. The directories written into must now resolve inside the tree, else the build refuses, and init and the agent are unlinked first. - The git identity check (#415) failed an image with no git at all. The guest now answers `no-git` and the check passes; git without an identity still fails. Opt-in flags, all off by default so a default build is unchanged: - --vcpus N (1-32): Firecracker's vcpu_count and Cloud Hypervisor's --cpus boot, recorded in the manifest as "vcpus" (outside the hash); restore takes the count from the snapshot. - --guest-home /tmp/DIR: a writable HOME for guest commands, made by init on the /tmp tmpfs (the default HOME=/ is on the read-only root). --guest-home-gitconfig also copies the image's root git config into it; opt-in, because a benchmark image can carry a root identity while its testbed refuses agent commits on purpose. - --skip-git-identity-check, for such an image; the skip is logged. - --verify-command CMD (with --verify-timeout-s N, 1-86400): what the verify step runs in the restored VM in place of `true`, as bash in /workspace mounted the way the worker mounts it. A nonzero exit publishes nothing; the last 16 KiB of output are logged. All of #706's lease-mode image changes are kept: the cgroup2 mount, the sbx identity, the agent's --lease-cgroup-root, check_lease_support on both arms (now after check_dev_fd and check_var), and the setuid strip as the last tree change before mkfs. Tests in build-snapshot.test.sh for each; P4-ON-P6.md documents the flags and the init changes. Changing init changes every snapshot built after it; existing snapshots keep working without the fixes until rebuilt. Refs #733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Sixteen ADRs still said Proposed although their decisions are in code on main. Each status line now names the merged PRs that implemented it and the date the core landed (format of ADR-0042), and notes what is still owed where only part is built: - 0028 (rossoctl#170, rossoctl#201, rossoctl#340; its KEDA transport removed by ADR-0041) - 0029 (rossoctl#171), 0030 (rossoctl#214), 0031 (rossoctl#214, rossoctl#225) - 0032 (rossoctl#249, rossoctl#350, as amended by MI1) - 0035 (rossoctl#251; ADR-0048 adds lease mode beside it) - 0036 (rossoctl#347), 0038 (rossoctl#458), 0039 (rossoctl#467), 0040 (rossoctl#481) - 0043 (rossoctl#560, rossoctl#588, rossoctl#600, rossoctl#615), 0044 (rossoctl#563), 0045 (rossoctl#620) - 0046 (phase 1: rossoctl#630, rossoctl#641, rossoctl#646; phase 2 owed) - 0047 (M1 and M3: rossoctl#704, rossoctl#713, rossoctl#717, rossoctl#765; M2 owed) - 0048 (rossoctl#706, rossoctl#763, rossoctl#802, rossoctl#808, rossoctl#814; off by default until the security review's lease sections are signed off) The README index follows, and its 0033 row, which still said Proposed after rossoctl#249 accepted the ADR, is corrected. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Paolo Dettori <[email protected]>
Summary
SBX0.3 lease mode, plan 1 of 5: the guest. This builds the guest half of the lease-mode design in #698 (spec
docs/specs/2026-11-08-sbx-lease-mode-design.md, ADR-0048): the guest agent and image can now serve lease requests, level 1. Nothing on the host uses this yet. The worker's lease state machine is plan 2. Per-Exec behaviour does not change.What a lease request does (spec §3.1–§3.3):
sbx/sbx-ws) through a small re-exec shim:no_new_privsis set;ptraceandprocess_vm_readv/writev;0002./sys/fs/cgroup/moca-execs, which is never delegated. When the Exec exits, times out or is aborted (the host closes the connection), the agent writescgroup.killand waits for the cgroup to empty before sendingEnd. If teardown doesn't finish within 5 s,Endcarriesteardown_failedand the agent stops serving.wait4(-1)reaper sits behind a lease-only latch. Once a VM serves a lease request it refuses per-Exec requests. Per-Exec requests never start the reaper./workspacenodev,nosuid;user.max_user_namespaces=0;normalise_workspace): it never follows symlinks, never crosses mounts, removes device nodes and strips setuid/setgid bits.SOCK_CLOEXEC. A lease Exec inherits only fds 0–2.Image (
build-snapshot.sh):cgroup2and passes--lease-cgroup-root;sbxaccount;mkfs;kernel_releasenow records the guest kernel, closing spec §16 item 2;"features": ["lease-v1"], on Firecracker only, because Cloud Hypervisor's per-Run virtiofs mount cannot serve lease;sbxaccount inside the booted guest, using a per-Exec request, so no lease latch is ever baked into a snapshot.Wire:
Request.lease,Request.normalise_workspaceandEnd.teardown_failedare allomitempty, so per-Exec frames are byte-identical.Testing
Hardware. On the SBX0 KVM host (Linux 6.8, guest kernel 6.18.51+), against a
lease-v1snapshot built from this branch: 18/18TestGate*pass.TestGateLeaseExecKillsProcesses,TestGateLeaseFreshShell, and the Exec half ofTestGateLeasePrivilege.TestGateCredentialNeverInGuestwas skipped, because it needs the egress CA private key in the test environment.Guest agent, as root, with
-race, on the rig. The fullinternal/guestagentsuite passes, including the lease, shim, seccomp, normalise, CLOEXEC, umask, remount and userns tests.CI. The
microvm-gatesjob gains two steps:TestShimruns again withCGO_ENABLED=0, which is the production setxid path.Both fail if every test skipped.
Local.
go test ./...,GOOS=linux go vet ./...,build-snapshot.test.sh(shell checks) and shellcheck all pass.Notes for reviewers
TestGateNoVMReusestill governs the pool.lease-v1.Plan series: 1 guest (this PR) → 2 worker lease state machine → 3 wire (proto, relay, control plane) → 4 clients + level-1 live smoke → 5 level 2. Plans 2–5 follow E17a (rossoctl/moca-experiments#21).
Assisted-By: Claude Code