Repository navigation
fix(microvm,knative-server): microVM worker and snapshot-build fixes - #757
Conversation
The microVM worker sends the whole command to the guest agent in one request frame, which the guest protocol bounds at 32 KiB. A larger one was refused by WriteFrame on the write goroutine while the read loop waited for an answer the guest could never send, so the Exec hung to the caller's deadline with nothing in the worker's journal. runOverConn now encodes the request first and refuses one over a frame at once, with ErrCommandTooLarge naming stdin (which is split across frames and was never affected). A failed write also closes the connection, so no Exec waits on a guest that got no whole request. The guest agent is unchanged: no snapshot rebuild. The lease-mode request fields are carried as before. Tests run the real guest agent: a command just under a frame runs, 40 KiB is refused, 175 KiB of stdin passes. Refs rossoctl#733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…re says why
A worker whose chroot base is named after a long template id restored
vm-1 to vm-9 and then failed every restore with "API socket never
appeared". Firecracker was listening; the launcher could not dial it.
The API socket's host path is <chroot base>/firecracker/vm-N/root/run/
firecracker.socket, and with the chroot base /srv/sbx/jail/<worker id>
and a 31-character template id it passes sun_path from vm-10 on. The
cause was hard to see: the launcher discarded the jailer's stdout and
stderr, so the only error was the socket timeout.
- microvm-worker refuses at start an SH_CHROOT_BASE whose worst-case API
socket path does not fit, as it already did for the egress socket,
which only applied with egress on.
- The jailer's stdout and stderr (its own errors, before it execs, and
Firecracker's log) go to a 4 KiB tail buffer, quoted in the restore's
error ("jailer output: ..."). Like io.Discard it is not an *os.File,
so os/exec's pipes and copying goroutines are unchanged.
- SBX0's install-host.sh keys a worker's jail by 12 hex of the worker
id's sha256 (jail/j<hex>), and refuses an SBX_SRV deep enough to
overflow it before anything is written. The uninstall names the jail
it leaves. The README, runbook and design say so.
Tests: the launcher refuses a long base with egress off and on; a fake
jailer's error shows up in the restore error; the tail buffer keeps the
last bytes; the longest worker id fits, two workers keep separate
jails, and too deep an SBX_SRV is refused (install-host.test.sh, bash 5
and 3.2).
Refs rossoctl#733
Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…al it is A /turn answering 503 sandbox_unavailable covered unlike causes with one code and no log line: a full pool (clears by waiting), the session's sandbox briefly absent, and an empty tier or template (no worker of it attached), which never clears by waiting. A session that landed on a tier with no worker was answered 503 for minutes, and nothing in any log said why. - logTurnCapacity: one console.warn per 503 on the sync, SSE and detach paths, naming the error class, the session and its message; forLog keeps it on one line. - turnErrorMessage: the 503 body carries a `message`, the Error schema's existing operator-facing field. For the three pre-turn classes it is the class's own text, which names a pool, tier, template or sandbox id. A mid-turn host refusal's text is the worker host's admission arithmetic (its memory budget and commit level, rossoctl#452), so its body gets a fixed sentence and only the log keeps the host's figures; the same sentence replaces it in an SSE error frame after the first frame and in a detached turn's logged terminal (clientErrorText), which a later attach replays. A 500's text still never reaches the body. The status, the code and Retry-After are unchanged, so clients that retry keep working. Tests: the log line and the body message for 503, a host refusal's body free of the host's figures, none for 500 or 404. The HTTP reference and the harness OpenAPI document say so. Refs rossoctl#733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…a's own build-rootfs.sh refuses a tree missing any of REQUIRED_TOOLS (bash git rg gh python3 base64 file ls cat): the container tier's capabilities, right for Moca's own sandbox image. A sandbox template built from a benchmark image needs its own tools plus the guest agent's minimum, not Moca's whole toolchain, and no benchmark base image ships gh, so every one was refused. --require "T1 T2 ..." replaces the list with the caller's (each a bare tool name; a path or a dotted name is refused, exit 2). Without it the list is unchanged, so Moca's default sandbox image is checked as before. Tests: an image without gh builds when gh is not required; the default list still requires gh; a tool --require names is still required; a path is not a tool name. Refs rossoctl#733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[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 (rossoctl#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 rossoctl#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 rossoctl#733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
The PR's build-snapshot.sh changes added three shellcheck notes beyond upstream's own two: an unquoted `--cpus boot=$VCPUS` (SC2086; VCPUS is a checked integer, now quoted anyway) and two strings that are single-quoted on purpose (SC2016): the verify command's trailer, which the guest's shell expands, and the log's `true`, which names the default command. Those two carry a disable with the reason. The test that pins the cloud-hypervisor --cpus line matches the quoted form. Tests: shellcheck 0.11.0 reports only upstream's two existing notes; build-snapshot.test.sh PASS on bash 5. Refs rossoctl#733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Five well-scoped fixes with good tests, and CI is green on this head (17/17). One blocker: the branch conflicts with main (mergeable_state: dirty). A local git merge origin/main (3299cc9) conflicts in remote-worker/internal/vmpool/guestconn.go, remote-worker/internal/vmpool/errors.go and deploy/microvm/build-snapshot.sh, because of main's lease-timeout (guestError / guestTimedOut, ErrLeaseEnded, RefuseStaleMode) and balloon commits. The guestconn.go resolution is the delicate one: it has to keep main's &guestError{...} KindError return, which runLease depends on, next to this PR's pre-encoded sendRequest(rw, req, stdin). CI ran only against the old base dd0ce71, so please rebase and let CI run again.
Must-fix
- Rebase onto main and resolve the three conflicts; keep
guestErrorin guestconn.go.
Suggestions (inline)
- guestconn.go:37: in lease mode,
ErrCommandTooLargeends the lease asagent_dead, even though nothing reached the guest. - build-snapshot.sh:726: the symlink guard doesn't cover
/etc(passwd, group, gitconfig) or the CA directories, which are still written through the image's paths. - install-host.sh:107: re-installing an existing worker moves its jail to
j<hex>and orphans/srv/sbx/jail/<id>; the uninstall message names only the new one. - http-api.md:96 (nit): the "Error bodies are …" sentence doesn't list the new 503
message.
Author: webchang (MEMBER, maintainer)
Areas reviewed: Go (vmpool), TypeScript (knative-server), Shell (build-rootfs, build-snapshot, install-host + tests), Docs/OpenAPI
Agent/IDE config (.claude/.vscode): none
Commits: 6, all signed off
CI status: passing at 06b2bca (against base dd0ce71); dirty with main
Assisted-By: Claude Code
| return Result{}, fmt.Errorf("encode request: %w", err) | ||
| } | ||
| if len(req) > ga.MaxFrame { | ||
| return Result{}, fmt.Errorf("%w: %d bytes, the guest takes at most %d in one request; send large content as stdin", ErrCommandTooLarge, len(req), ga.MaxFrame) |
There was a problem hiding this comment.
suggestion: After the rebase, look at how this interacts with main's lease mode. runLease (lease.go, ~L639 on main) ends the lease with LeaseEndAgentDead for any runErr != nil && !guestTimeout. This refusal happens before a single byte is sent, so the agent and the VM are untouched, but a lease user who sends a >32 KiB command still loses the lease and its VM. Could ErrCommandTooLarge be exempted the way guestTimedOut is, or checked in execLease before Run? A test next to the lease-timeout ones would pin it.
| # following it. | ||
| local tree_real d | ||
| tree_real="$(realpath -e "$STAGE/rootfs-tree")" | ||
| for d in sbin usr/local/bin .moca-var; do |
There was a problem hiding this comment.
suggestion: Good catch on writing through /sbin/init. The same class of bug is still open for the tree's other writes. add_sbx_identity appends to $tree/etc/passwd and etc/group, the egress block does cat >>"$STAGE/rootfs-tree/etc/gitconfig", and install_egress_ca does cp into usr/local/share/ca-certificates or etc/pki/ca-trust/source/anchors. Each of these follows an absolute symlink in the image onto the build host, as root. Consider adding etc (and the CA dir in use) to this realpath loop, and rm -f plus rewrite, or refusing when one of those files is a symlink.
| # <base>/firecracker/vm-<up to 20 digits>/root/run/firecracker.socket (64 bytes after the base), and a | ||
| # worker id can be 52 (sbx_ + a 31-character template + _ + 12 hex). With the id, a long template's | ||
| # worker failed every restore from vm-10 on. The digest keeps two workers apart. | ||
| jail_dir() { |
There was a problem hiding this comment.
suggestion: Upgrade path: a worker installed before this change has SH_CHROOT_BASE=$SBX_SRV/jail/<id>. Re-running install-host.sh for it writes the new j<hex> base and leaves the old directory behind. After that, --uninstall names only the new one, so the operator is never told the old one exists. Could install (or uninstall) also mention $SBX_SRV/jail/<id> when it exists, or could RUNBOOK.md get an upgrade line?
| | 503 | `credential_unavailable`, `redis_unavailable` | Control plane or Redis fault. Has `Retry-After` for 503s | | ||
| | 500 | `internal_error` | Never carries error text | | ||
|
|
||
| Error bodies are `{error, sessionId?}`, plus a `message` on auth errors and on the `/runs` 501, and |
There was a problem hiding this comment.
nit: This sentence still says message appears only on auth errors and the /runs 501. With this PR, the 503 sandbox_unavailable body carries one too (the table row above, and turnErrorMessage).
clawgenti
left a comment
There was a problem hiding this comment.
Clawgenti Code Review
Summary
Five solid fixes. The one-frame command check uses > against the same ga.MaxFrame that WriteFrame/ReadFrame enforce, so there is no off-by-one. Both sun_path checks leave room for the terminator, and install-host's < 108 agrees with them. build-snapshot.sh now refuses to write through image symlinks, which is a real host-safety fix for Ubuntu-based images whose /sbin/init points at the build host's systemd. No must-fix issues. There are three findings inline, and one of them is a connection leak I reproduced on the new early-return path.
Author: webchang (MEMBER — maintainer)
Areas reviewed: Go (vmpool, microvm-worker), TypeScript (knative-server 503), Shell (build-rootfs, build-snapshot, install-host), Docs/OpenAPI
Agent/IDE config (.claude/.vscode): none
Commits: 6 commits, all signed-off: yes
CI status: passing
All checks pass. Ready for human review.
Verified by:
go vetandgofmt -loninternal/vmpoolandcmd/microvm-worker: clean.go test ./cmd/microvm-workerand the touched vmpool tests (Firecracker|RunOverConn|SendRequest|Egress|TailBuffer|Validate): ok.- build-rootfs.test.sh, build-snapshot.test.sh and install-host.test.sh: all pass.
- shellcheck on the three changed scripts adds no new findings over base.
- A throwaway Close-counting probe around
runOverConnshowed the leak. I deleted the probe afterwards.
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
| return Result{}, fmt.Errorf("encode request: %w", err) | ||
| } | ||
| if len(req) > ga.MaxFrame { | ||
| return Result{}, fmt.Errorf("%w: %d bytes, the guest takes at most %d in one request; send large content as stdin", ErrCommandTooLarge, len(req), ga.MaxFrame) |
There was a problem hiding this comment.
suggestion: This new early return for ErrCommandTooLarge comes before closeConn/defer closeConn() is registered (line 49). runOverConn owns rw: every other return closes it. firecrackerVM.Run (launcher_firecracker.go:1108) and the CHV path both dial a fresh vsock connection just for this call and never close it themselves, so each refused oversized command leaks one vsock fd on the worker. On the guest side, the agent's ServeConn stays blocked in ReadFrame, waiting inside a VM that is kept for the lease.
Probe: I wrapped a net.Pipe end in a conn that counts Close() calls. runOverConn returned ErrCommandTooLarge with 0 closes. (I deleted the probe.)
Suggested fix: call _ = rw.Close() before this return, or move the once/closeConn/defer closeConn() setup above the marshal-and-check block. Then extend TestRunOverConnRefusesACommandLargerThanOneFrameAtOnce to check that the guest end sees EOF.
| remove_shared_units | ||
| systemctl daemon-reload | ||
| log "left in place: $SBX_SRV/workspaces/$id and $SBX_SRV/jail/$id (workspace data; remove by hand when no sandbox needs it)" | ||
| log "left in place: $SBX_SRV/workspaces/$id and $(jail_dir "$id") (workspace data; remove by hand when no sandbox needs it)" |
There was a problem hiding this comment.
suggestion: uninstall_worker recomputes the jail as $(jail_dir "$id"), which is the new digest path. A worker installed before this PR has SH_CHROOT_BASE=$SBX_SRV/jail/<id> in its env file, and its jail is at that old path. After upgrading, --uninstall <id> logs /srv/sbx/jail/j<hex>, a directory that never existed, and says nothing about the real /srv/sbx/jail/<id>. An operator who follows the README/RUNBOOK advice to "remove it by hand" is pointed at the wrong path, and the old jail and its vm-N trees are left behind. Reinstalling such a worker also moves its jail without saying so.
Suggested fix: read SH_CHROOT_BASE from $SBX_ENV_DIR/workers/$id.env before that file is removed and log it, falling back to jail_dir only when the file is missing. Alternatively, record the jail dir in the manifest at install time.
| | 500 | `internal_error` | Never carries error text | | ||
|
|
||
| Error bodies are `{error, sessionId?}`, plus a `message` on auth errors and on the `/runs` 501, and | ||
| `turnId` on `turn_in_progress`. The 503 `Retry-After` is `KAGENTI_SYNC_SATURATION_RETRY_AFTER_S` |
There was a problem hiding this comment.
nit: The 503 row now says sandbox_unavailable carries a message. The sentence above it (line 96, "Error bodies are {error, sessionId?}, plus a message on auth errors and on the /runs 501…") was not updated, so the section now contradicts itself. turnErrorMessage in server.ts adds message to every non-empty /turn 503.
Suggested fix: add "and on the /turn 503 (sandbox_unavailable)" to that sentence.
Conflicts, each resolved keeping both sides: - remote-worker/internal/vmpool/errors.go: ErrCommandTooLarge beside ErrLeaseEnded and LeaseEndedError. - remote-worker/internal/vmpool/guestconn.go: both imports (encoding/json, errors); guestError and guestTimedOut kept, then guestRequest and the pre-encoded sendRequest. - deploy/microvm/build-snapshot.sh: the machine config's vcpu_count from $VCPUS, followed by main's free-page-reporting balloon. Refs rossoctl#733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
runOverConn owns the connection it is given, but its early return for ErrCommandTooLarge came before the deferred close: each refused command kept a vsock descriptor on the worker and left the guest agent blocked reading a request that never came. The size check now follows the deferred close. A test records Close on a wrapped pipe and checks the guest's read ends. Refs rossoctl#733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
runLease ended the lease (agent_dead) for any Run error but the guest's own timeout, so a lease Exec whose command was larger than the guest's one request frame lost the lease and its VM. Nothing reaches the guest for such a command, so it is exempted as the guest's timeout is: the caller gets ErrCommandTooLarge and the next Exec runs in the same VM. A test beside the lease timeout tests shows it. Refs rossoctl#733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
… out of it The /sbin/init fix covered the files the build replaces; the ones it appends to or copies into were still written through the image's symlinks: add_sbx_identity's etc/passwd and etc/group, the credential helper's etc/gitconfig, and install_egress_ca's CA file and directory. An absolute symlink there resolves on the build host, so a build as root wrote the host's file. A new tree_write_target checks each such file before it is written: its directory must resolve inside the tree (the deepest existing part is checked before mkdir -p makes the rest, since mkdir -p follows symlinks), and the file itself must not be a symlink. Tests run the script's own functions on trees whose etc, etc/passwd, etc/group, etc/gitconfig or CA directory is an absolute symlink out of the tree: the build refuses and the file outside is untouched. Refs rossoctl#733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…est-keyed path A worker installed before the jail path was keyed by a digest of the id has its jail at $SBX_SRV/jail/<id>. A reinstall wrote jail/j<hex> and left the old one, and --uninstall named a path that never existed for it. Both now remove that worker's own legacy jail once the worker is stopped, only that exact path (never a symlink, nor an id shaped like a current jail's name, which could be another worker's), and log it. The jailer's chroots hold hard links, so workspace data stays. The RUNBOOK's upgrade section says so; tests cover the reinstall, the uninstall, another worker's legacy jail and the jail-shaped id. Refs rossoctl#733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
The error-body summary named the message only on auth errors and the /runs 501; the /turn 503 sandbox_unavailable has one as well, as its table row already says. Refs rossoctl#733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
|
Thanks for both reviews. Every point is addressed in five new commits on top of a merge of main (lease mode included):
CI is green on the new head (5181204). The PRs stacked on this one will take it by merge. Assisted-By: Claude Code |
clawgenti
left a comment
There was a problem hiding this comment.
Summary
The Go changes match the PR body. The oversized-command refusal (ErrCommandTooLarge), closing the connection on refusal, keeping the lease, the jailer output tail and the socket-path length check all held up, and none showed a race under go test -race -count=3. The problems are in build-snapshot.sh. The new option checks can be bypassed with an embedded newline, and the bypass reaches the generated /sbin/init, a sed script and the manifest. One mkdir -p still follows image symlinks before the new realpath check runs.
Must-fix
--guest-home,--vcpusand--verify-timeout-sare checked withprintf | grep -Eq. grep matches line by line, so$'/tmp/h\nx'passes.GUEST_HOMEis then put unquoted into ased -iscript that writes init. A probe confirmed the grep bypass. Use bash[[ =~ ]]on the whole value instead.mkdir -pofusr/local/bin,sbin,var,tmp,workspaceand.moca-var(line 747) runs before the realpath check. An image whoseusr/localis an absolute symlink gets directories created on the build host, as root. A probe confirmedmkdir -pfollows the link.
The rest are suggestions and nits. See the inline comments.
Author: webchang (MEMBER — maintainer)
Areas reviewed: Go (vmpool, microvm-worker), Shell (build-snapshot, build-rootfs, install-host), TypeScript (knative-server), Docs/OpenAPI
Agent/IDE config (.claude/.vscode): none
Commits: 12 commits, all signed-off: yes
CI status: failing. proto / "Build and test remote-worker" failed on this head (run 43313497372, attempt 2). I could not fetch the job log. Locally on head, gofmt -l . and go vet ./... are clean. go test -race ./... passes except TestRestoreFoldsCloudHypervisorsOwnLogIntoTimeoutError, which also fails on main here because this sandbox can't exec from /tmp. Under -cpu 1,2,4, the untouched TestWorkspaceIdleNeverReclaimsALeasedRun flaked once (2s waitFor). That is a candidate for a slow runner. Please check the job log and re-run.
Verified by: go vet, gofmt, go test -race (head and main), -count=100 on the new tests, the deploy/microvm and deploy/sbx shell suites (pass), throwaway probes for the grep newline bypass and the mkdir -p symlink follow (probes deleted afterwards).
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
|
|
||
| # /tmp is the only writable tmpfs init mounts for every run (see assemble_rootfs), so a HOME | ||
| # anywhere else would be read-only or vanish; the pattern keeps it one plain directory path. | ||
| if [ -n "$GUEST_HOME" ] && ! printf '%s' "$GUEST_HOME" | grep -Eq '^/tmp(/[A-Za-z0-9._-]+)+$'; then |
There was a problem hiding this comment.
must-fix (injection): printf %s "$GUEST_HOME" | grep -Eq checks each line separately, so $'/tmp/home\n<payload>' passes (a probe confirmed it). The value is then put unquoted into sed -i "/^export PATH=/a mkdir -p $GUEST_HOME\\ ..." (around line 873). The extra line becomes either sed commands (GNU sed e runs a command on the build host) or extra lines in the guest's /sbin/init, which runs as PID 1. The -gitconfig branch also has no grep -qx check afterwards.
Suggested fix: [[ "$GUEST_HOME" =~ ^/tmp(/[A-Za-z0-9._-]+)+$ ]], which matches the whole string, and quote $GUEST_HOME in the lines written into init.
| exit 2 | ||
| fi | ||
|
|
||
| if ! printf '%s' "$VCPUS" | grep -Eq '^([1-9]|[12][0-9]|3[0-2])$'; then |
There was a problem hiding this comment.
suggestion: same newline bypass as above. $'4\n,"x":1' passes this check (a probe confirmed it). VCPUS then goes unescaped into the Firecracker /machine-config JSON, CH's --cpus and "vcpus": $VCPUS in manifest.json. --verify-timeout-s on line 316 has the same pattern.
Suggested fix: [[ "$VCPUS" =~ ^([1-9]|[12][0-9]|3[0-2])$ ]], and the same form for the timeout.
| @@ -631,14 +745,39 @@ assemble_rootfs() { | |||
| # so a failed build never corrupts the caller's base image. | |||
| cp -a "$ROOTFS/." "$STAGE/rootfs-tree/" | |||
| mkdir -p "$STAGE/rootfs-tree/usr/local/bin" "$STAGE/rootfs-tree/sbin" \ | |||
There was a problem hiding this comment.
must-fix (symlink): this mkdir -p runs before the realpath -e check below. If the image ships usr/local, sbin or .moca-var as an absolute symlink, mkdir -p follows it and creates directories on the build host as root, and only then does the build refuse. A probe with a symlinked usr/local showed bin created outside the tree. var, tmp and workspace are created here too but are not in the check list. The VAR_PROBE cd into var also follows a symlinked var.
Suggested fix: check each path, or its deepest existing parent, before running mkdir -p (as tree_write_target already does), and add var, tmp and workspace to the check. This matters because the commit says no tree file is written through a symlink.
| 'the sandbox host refused the command for lack of capacity; retry after Retry-After'; | ||
|
|
||
| /** | ||
| * An error's text as a client may read it in a frame (an SSE error frame after the first one, a |
There was a problem hiding this comment.
suggestion (not run, node deps not installed): the 503 body, the SSE error frame and the detached terminal now carry the fixed sentence. But the refusal text also goes through Pi's bash tool as isError tool content. harness/src/turn-stream.ts emits it as a tool_result frame with preview: clip(e.result), which reaches SSE clients and the detached-turn replay.
Suggested fix: either narrow the PR claim ("never reaches a client") to terminal frames, or redact the refusal message in the tool result as well.
| // A jailer (or a Firecracker) that fails says why on stdout/stderr; the restore's error carries | ||
| // the tail of it, instead of only the socket timeout. | ||
| func TestFirecrackerRestoreErrorCarriesTheJailerOutput(t *testing.T) { | ||
| base := shortdir.New(t, "fcout", len("/firecracker/vm-6/root/run/firecracker.socket")) |
There was a problem hiding this comment.
nit: need here is the vm-6 path length (45), but the new validate() checks the worst-case vm-<20 digits> path. With a longer TMPDIR, shortdir accepts the dir and NewFirecrackerLauncher then refuses it: 7 Firecracker tests failed locally with a 40-byte TMPDIR. This doesn't affect GitHub runners.
Suggested fix: size need from the worst-case path, for example len("/firecracker/vm-" + strings.Repeat("9", 20) + "/root/run/firecracker.socket"), here and at the other shortdir.New call sites.
|
Three notes to add to the reply above:
Assisted-By: Claude Code |
Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…ase VM id The launcher's validate checks the API and egress socket paths against the longest id nextIDLocked can mint (vm- plus 20 digits), but the tests that construct a launcher on a shortdir asked shortdir only for room for vm-6 or vm-42. With a long TMPDIR, shortdir accepted a directory that the launcher then refused, and the tests failed on path length instead of on what they test. Each such call site now passes the worst-case suffix, so a TMPDIR too long for it falls back to /tmp. Refs rossoctl#733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
… line by line --guest-home, --vcpus and --verify-timeout-s were checked with printf | grep -Eq, and grep matches each line separately: a value with an embedded newline passed when one of its lines matched. GUEST_HOME goes into the sed script that writes the guest's init, and VCPUS into the VMM's machine config and the manifest. The checks now use bash's [[ =~ ]], which matches the whole value. The check that the HOME insertion landed in init now runs with --guest-home-gitconfig too. Tests: each option with an embedded newline is refused with exit 2 before any build step, and no option check uses grep. Refs rossoctl#733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…makes it assemble_rootfs ran mkdir -p for usr/local/bin, sbin, tmp, var, workspace and .moca-var before its realpath check. mkdir -p follows symlinks, so an image whose usr/local (or sbin, or .moca-var) is an absolute symlink got directories created on the build host, as root, before the build refused; var, tmp and workspace were not checked at all, and the /var probe's cd followed a symlinked var. The check tree_write_target already did for files is now tree_dir_target: it checks the deepest existing part of a directory before mkdir -p makes the rest, and the directory itself once made. assemble_rootfs runs it for all six directories in place of its own mkdir -p and realpath loop, before anything else writes into the tree, and tree_write_target calls it for a file's directory. Tests run the loop from assemble_rootfs's own lines: on a plain tree all six directories are made; a symlink that stays inside the tree is accepted; each of usr/local, sbin, tmp, var, workspace and .moca-var as an absolute symlink out of the tree is refused with nothing created outside; a dangling absolute symlink is refused and nothing appears at its target. A shellcheck note on the previous commit's new literal pattern check is silenced the way the file's other literal patterns are. Refs rossoctl#733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…ot tool results The fixed sentence that replaces a host capacity refusal's text is used in the 503 body's message and in the terminal error frames (the SSE error frame and a detached turn's logged terminal). The refused command is also a failed tool call: Pi's bash tool returns the transport's error text as isError tool content, and the turn stream's tool_result frame carries a clipped preview of it, as for any tool result. clientErrorText's comment and the HTTP reference's SSE section now say which frames the rule covers. Refs rossoctl#733 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
ingpaolodettori-dev, review summary (must-fix)
Fixed in 3ee0acf (taken by merge, not rebase, so the reviewed commits keep their shas): the three conflicts were resolved keeping both sides. guestconn.go keeps main's ingpaolodettori-dev, inline threads1.
|
The note on X12 under base now says a client either sends a gate record showing commits refused (X5) or drops the skip, and that the build host's git identity check then needs git with an identity in the image, or no git at all once the build-snapshot change in rossoctl#757 is in. Refs rossoctl#737 Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
clawgenti
left a comment
There was a problem hiding this comment.
Summary
Since the last review (5181204), five commits landed: the option checks now use bash [[ =~ ]] on the whole value, a new tree_dir_target checks each tree directory before mkdir -p makes it, the Firecracker tests size their socket dirs for the worst-case VM id, and the clientErrorText doc now limits the host-refusal rule to terminal frames and the 503 body. All five previous findings are resolved. The newline cases are refused (I confirmed $'4\n' and $'4\nx' no longer match), var, tmp and workspace are now covered, and the grep -qx check runs on both HOME branches. The other reviewer's earlier points (rebase, the lease exemption for ErrCommandTooLarge, the /etc and CA writes, the legacy jail and the http-api.md sentence) are also addressed on this head. I found no new problems. One optional nit: the usage example in remote-worker/internal/shortdir/shortdir.go (line 41, not in this diff) still shows the vm-6 suffix the tests no longer use.
No new issues. Ready for human review once k8s-kind-e2e finishes.
Author: webchang (MEMBER — maintainer)
Areas reviewed: Shell (build-snapshot.sh and its tests), Go (vmpool Firecracker tests), TypeScript (knative-server doc comment), CI workflow
Agent/IDE config (.claude/.vscode): none
Commits: 17 commits, all signed-off: yes
CI status: pending. 16 of 17 checks pass. k8s-kind-e2e is still pending. Locally on head, shellcheck finds only the same SC2016/SC2329 notes as at 5181204 and nothing at warning level. go test ./internal/vmpool/ with a 38-byte TMPDIR passes the Firecracker tests that failed before. The one failure, TestRestoreFoldsCloudHypervisorsOwnLogIntoTimeoutError, comes from this sandbox's exec restriction and also happens on main.
Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).
ingpaolodettori-dev
left a comment
There was a problem hiding this comment.
Every item from our 06b2bca review is fixed, and so is every item from clawgenti's 5181204 review. The merge a56d502 is clean (--remerge-diff is empty).
- Option checks (newline bypass): fixed in 92c8d4d.
--guest-home,--vcpusand--verify-timeout-snow match the whole value with[[ =~ ]]. The HOME-insertion check runs with or without--guest-home-gitconfig. The tests cover embedded newlines for each of the three options. mkdir -pbefore the symlink check: fixed in 612a96c.tree_dir_targetresolves the deepest existing ancestor beforemkdir -pand stops at a dangling link. It then re-checks the directory once it exists.assemble_rootfsruns it for all six directories before the/varprobe. The tests cover an in-tree link, an out-of-tree link for each directory, and a dangling link, and check that nothing is created outside the tree.- shortdir sizing: fixed in 4f43821. All four call sites that build a launcher size for
vm-plus 20 digits. - Refusal text in
tool_result: resolved in fcd85c8 by narrowing the claim inclientErrorTextand http-api.md. Nit: the PR body's "What a client sees" bullet still says a refusal's text "never reaches a client", so it should get the same narrowing.
One nit is inline (carried over). CI: check, deploy-scripts and k8s-kind-e2e were still pending at this head. deploy-scripts runs the shell suites this push changes.
Assisted-By: Claude Code
| remove_shared_units | ||
| systemctl daemon-reload | ||
| log "left in place: $SBX_SRV/workspaces/$id and $SBX_SRV/jail/$id (workspace data; remove by hand when no sandbox needs it)" | ||
| log "left in place: $SBX_SRV/workspaces/$id and $(jail_dir "$id") (workspace data; remove by hand when no sandbox needs it)" |
There was a problem hiding this comment.
nit: This line still names $(jail_dir "$id"). For a worker that only ever had a legacy jail (now removed by remove_legacy_jail), that directory never existed. Log it only when [[ -d "$(jail_dir "$id")" ]], or say "if present".
…erminal frames, not tool results The fixed sentence that replaces a host capacity refusal's text (HOST_REFUSAL_MESSAGE) is used in the 503 body's `message` and in the terminal error frames (the SSE error frame and a detached turn's logged terminal). The refused command is also a failed tool call: Pi's bash tool returns the transport's error text as isError tool content, which the model reads (the capacity latch's design), and the turn stream's tool_result frame carries a clipped preview of it, as for any tool result. clientErrorText's comment and the HTTP reference's SSE section now say which frames the rule covers, so the reference no longer claims more than the code does. The error-body summary also names the /turn 503 sandbox_unavailable's `message`. No behaviour change (comments and the HTTP reference). (cherry picked from commit 5181204) (cherry picked from commit fcd85c8) Ports rossoctl#757 review fixes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
runOverConn owns the connection it is given, but its early return for ErrCommandTooLarge came before the deferred close: each refused command kept a vsock descriptor on the worker and left the guest agent blocked reading a request that never came. The size check now follows the deferred close. Test: TestRunOverConnClosesTheConnOnACommandTooLarge wraps one side of a pipe, counts Close, and checks that the guest's read returns. It fails with the fix reverted. Host-side (remote-worker). (cherry picked from commit 381d7c4) Ports rossoctl#757 review fixes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…ase VM id Each test that builds a Firecracker launcher on a shortdir passed the socket path of a short VM id, but the launcher's validate checks the longest API socket path an id nextIDLocked can mint (vm- plus 20 digits) could need. With a long TMPDIR the tests then failed on the launcher refusing its directory, not on the property under test. The four call sites (two in the collision tests, two in the egress tests) now pass the worst case, so a long TMPDIR costs a fallback to /tmp instead. Test-only. Host-side (remote-worker). (cherry picked from commit 4f43821) Ports rossoctl#757 review fixes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…mlinks, and checks whole option values The build runs as root on the host over a tree extracted from an image, so a path in it can be a symlink out of it (an absolute one resolves on the build host). - tree_write_target checks each file the build appends to or copies into before writing it (etc/passwd, etc/group, etc/gitconfig, the egress CA file and its directory): its directory must resolve inside the tree, the deepest existing part checked before mkdir -p makes the rest, and the file itself must not be a symlink. - tree_dir_target does that directory check, and assemble_rootfs runs it for every directory it makes or writes into (usr/local/bin, sbin, tmp, var, workspace, .moca-var) in place of its own mkdir -p and realpath loop, before anything else writes into the tree: mkdir -p follows symlinks, so an image whose usr/local, sbin or .moca-var was an absolute symlink got directories created on the build host before the build refused, and var, tmp and workspace were not checked at all. - --guest-home, --vcpus and --verify-timeout-s are checked with bash's [[ =~ ]], which matches the whole value: printf | grep -Eq checked each line separately, so a value whose first line was valid passed with a payload on the next (it reaches init, a sed script, the VMM's config and the manifest). The check that the HOME line landed in init now runs with --guest-home-gitconfig too. - Shellcheck notes on literal patterns are silenced as the file's others are, and --cpus's value is quoted. Tests (build-snapshot.test.sh; 41 checks fail with the fix reverted): the etc/passwd, etc/group, etc, etc/gitconfig, CA directory and CA file cases, each an absolute symlink out of the tree (refused, the file outside untouched); assemble_rootfs's own directory loop on scratch trees (a plain tree gets all six; a symlink inside the tree is accepted; each directory as an absolute symlink out of the tree, or a dangling one, is refused with nothing created outside); each option with an embedded newline is refused with exit 2 before any build step. Host-side (deploy/microvm, run as root on the KVM host). (cherry picked from commit 06b2bca) (cherry picked from commit ace1c43) (cherry picked from commit 92c8d4d) (cherry picked from commit 612a96c) Ports rossoctl#757 review fixes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…est-keyed path A worker's jail moved to <SBX_SRV>/jail/j<12 hex of the id>, so a reinstall and --uninstall only looked at the new path and left the worker's legacy <SBX_SRV>/jail/<id> behind, and the uninstall pointed the operator at the new path only. Both now remove that worker's own legacy jail once the worker is stopped, and log the path. Only that exact path is removed: never a symlink, nor an id shaped like a current jail's name, nor another worker's. The jailer's chroots hold hard links, so workspace data stays. The RUNBOOK's upgrade section says so. Tests (install-host.test.sh; fails with the fix reverted): the reinstall, the uninstall, another worker's legacy jail left alone, and a jail-shaped id. Host-side (deploy/sbx/install-host.sh). (cherry picked from commit ab347c1) Ports rossoctl#757 review fixes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
…ster id The comment moved with the size check in the previous port kept an internal tracking id; it now states the behaviour alone. Comment only. Host-side (remote-worker). Ports rossoctl#757 review fixes Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
The host agent stands on both parents: the template store and self-serve create (#766, with #760 and #756) and the template build tooling (#740's branch, with #757). No conflicts. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Rong Chang <[email protected]>
Conflicts: the sbx Go client, its tests, build-snapshot.sh and test_sandbox_v1_client.py take upstream's reviewed versions, a superset of webchang's (rossoctl#727, rossoctl#729, rossoctl#757, rossoctl#761, the build-snapshot PRs). packages/sandbox-relay/src/main.ts keeps webchang's per-client tokens beside upstream's set-mode tokens, and direct clients' Execs are normalized to per-exec like the harness's. sbx.py keeps the per-client-token environment line. Signed-off-by: Rong Chang <[email protected]>
Closes #733.
Five fixes, one commit each, all signed off:
ErrCommandTooLarge. A command larger than the guest's single request frame is refused with a clear error, instead of failing inside the guest./turn503 says which capacity refusal it is, and logs it.build-rootfs.sh --require, for an image that isn't Moca's own (it states which tools the image must already carry).build-snapshot.sh: fixes for third-party images, and an opt-in guest shape (vCPUs, guest HOME, git-identity check).Notes for review:
/var's permissions. The/varoverlay gives/varthe image's own permissions (usually root 0755), not tmpfs's 1777. So a lease-mode Exec (feat(sbx): lease mode plan 1 — guest agent and image (level 1) #706, uid 7000) can't create files at/var's top level, while world-writable subdirectories such as/var/tmpstill work.install-host.sh(this PR adds the jail key), so whichever merges second needs a rebase.Tests on the tip:
deploy/microvm/tests/build-snapshot.test.shon bash 5: 382 ok. Its bash 3.2 stop is the existing one reported in Deploy shell tests stop on macOS (BSD sed in #701's OIDC cases; two bash 3.2 stops) #720;build-rootfsandinstall-hosttests on bash 5 and bash 3.2;go vetandgo testforinternal/vmpoolandcmd/microvm-worker.20 files, +948 / -80.
Assisted-By: Claude Code