Skip to content

feat(microvm,sbx): from an image to a registered template; manifest hash v2 and the template record check - #771

Merged
pdettori merged 22 commits into
rossoctl:mainfrom
webchang:pr/i17-build-tooling
Nov 13, 2026
Merged

pdettori merged 22 commits into
rossoctl:mainfrom
webchang:pr/i17-build-tooling

Conversation

@webchang

@webchang webchang commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Closes #740. On main (ab8d10e): #757, which this branch used to stack on, is merged. Its own change is the commits on top of main (manifest hash v2, --source-name, the template record check, template-build.sh and template-register.sh, their review fixes, and merges of main).

What it does: tooling to go from an image to a registered template, with a manifest hash that covers the whole snapshot. Six signed-off commits:

  1. Manifest hash version 2 covers every manifest field and every snapshot file.
  2. build-rootfs.sh --source-name keeps the registry host out of the guest.
  3. The worker checks its template record at start (SH_TEMPLATE_RECORD).
  4. The docs: SH_TEMPLATE_RECORD's row in the variables table.
  5. template-build.sh and template-register.sh take an image to a registered template.
  6. A test fixture uses a neutral instance type in the manifest hash's field test.

Limits:

  • Without SH_TEMPLATE_RECORD, a v1 manifest still verifies, and v1 doesn't cover the vmstate or the memory file. So someone who can write the snapshot directory could swap the memory file and mark the manifest v1.
  • A follow-up: a minimum hash version (SH_MIN_HASH_VERSION, default 1, then 2 once templates are rebuilt), or requiring v2 whenever a template record is configured.
  • P4-ON-P6.md should say when v1 acceptance ends.

Tests on the tip:

  • go test for vmpool;
  • the template-build and template-register test suites, and build-snapshot.test.sh;
  • shellcheck adds no new findings.

16 files, +1,588 / -61, counted over the review range.

Assisted-By: Claude Code

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
A snapshot's manifest.json hashed only kernel, rootfs and agent. Every
other field, and vmstate and memfile, could change without the hash
noticing, so the hash could not serve as a build id.

build-snapshot.sh now writes "hash_version": 2. It records the sha256
of vmstate, memfile and Cloud Hypervisor's ch-config.json, copies the
image digest build-rootfs.sh recorded in the rootfs's
/etc/moca-rootfs-source as source_image_digest, and hashes one
"name:value" line per field and digest after a version header: image,
vmm, instance type, kernel release, guest RAM, vcpus, sorted
capabilities, built_at, the file digests, the egress CA and the source
image digest. The Go Manifest gains the same fields, and ComputeHash
follows the manifest's version.

The worker checks vmstate at every start. It re-reads the memory file
only with SH_VERIFY_MEMFILE=1 (Manifest.VerifyWith), since that is a
full read of the guest's RAM. A manifest without hash_version still
verifies under the old rule, so existing snapshots keep working until
they are rebuilt. An unknown version, or a field holding a line break,
is refused.

A golden digest is pinned on both sides (snapshot_test.go and
build-snapshot.test.sh), so the shell and Go line formats cannot drift
apart unnoticed.

Refs rossoctl#740

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…out of the guest

build-rootfs.sh records the image it exported in the rootfs's
/etc/moca-rootfs-source, which the guest's agent can read. A caller
pulling from a private registry passed the pull reference, so the
registry host reached every guest built from it.

--source-name NAME is the reference recorded as image= (default: the
pulled --image, as before); the digest= line stays the pulled image's.
template-build.sh passes the spec's registry-free reference there and
supplies the registry host at the pull only. An empty --source-name is
refused.

Refs rossoctl#740

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Nothing tied a worker's SH_SNAPSHOT_IMAGE to the record of what was
built for its template, so a worker could serve a snapshot other than
the one its template names.

SH_TEMPLATE_RECORD names the template record (schema
moca-sbx-template/1, written by template-build.sh). At start the worker
refuses to run when the record's manifest_hash, snapshot, guest RAM or
egress CA differ from its snapshot's manifest, when its worker differs
from SANDBOX_ID, or its id from SANDBOX_TEMPLATE when that is set. With
a version-2 manifest the record's image must be pinned by a digest
equal to the manifest's source_image_digest; a version-1 manifest has
none, so only that comparison is skipped, and the log says so. Every
mismatch is named. Unset: no check, as before.

Refs rossoctl#740

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
The row added with the template record check was wider than the table's
description column, so the formatter widened every row. A shorter row
says the same and leaves the other rows as they were.

Refs rossoctl#740

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…to a registered template

Adding a template was manual (RUNBOOK §5): build a snapshot by hand,
pick a worker id, edit SBX_WORKERS and SBX_TEMPLATES_FILE. Nothing
pulled by digest and checked it, probed the snapshot before publishing,
or named snapshots and workers so that a new image is a new version.

template-build.sh SPEC --kernel K, on the KVM host, takes a JSON template
spec (moca-sbx-template-spec/1: id, pinned image, guest size, guest
HOME and git identity options, egress, seed, probe, description, tools,
optional etc_hosts_sha256) and, each step failing the build:

1. checks the spec, and the free disk (SBX_MIN_FREE_GB);
2. pulls the image by digest and checks the digest it got;
3. runs build-rootfs.sh, requiring only the spec's tools plus the guest
   agent's minimum, then build-snapshot.sh with the spec's flags and a
   --verify-command that runs the seed and the probe in the restored VM:
   a failed probe publishes nothing;
4. writes the template record, $SBX_SRV/templates/<snapshot>.json
   (moca-sbx-template/1): the spec, the snapshot, its worker id and its
   manifest hash;
5. removes the rootfs tree and the pulled image.

The snapshot is <id>-<12 hex of the image digest> and its worker
sbx_<id>_<12 hex>, so a new image is a new snapshot and a new worker
while the old one drains. An existing snapshot with the same record is
not rebuilt (--force rebuilds).

--gate-record FILE (with --gate-commit SHA) checks the image builder's
gate record for the image: its gate passed, it names the spec's image
digest, the spec's source_record_digest is that digest, and for a spec
that skips the git identity check it shows commits refused. The
template record then carries the evidence and the gate record's sha256.
--registry HOST supplies the registry at the pull only: build-rootfs.sh
--source-name and the record keep the spec's host-free reference.
--egress-ca bakes the host's egress CA for a template with egress.

template-register.sh --env-file FILE RECORD [--apply], on the
operator's machine, adds the record's worker and template entry to
setup.sh's inputs; a template id already listed is a versioned update,
and the old worker stays until --retire WORKER drops it. --remove ID
drops a template and its worker. Without --apply it prints the setup.sh
to run.

make test-deploy runs the new tests.

Refs rossoctl#740

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
The field test only needs a value that differs from the base manifest's.

Refs rossoctl#740

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 12, 2026
…w PRs

Slide 30 charts the G50 window's cold round, the verify cache as first
built against fixed (runs/g50-1-d: per-instance request_to_active_s in
rounds batch-1 and batch-3; reads per start and the files re-hashed from
FINDINGS.md). The upstream table adds rossoctl#771-rossoctl#773 and the next slide names
the PRs after the host agent. Slide 8's first refusal says what
M7.spec_image checks: --image must match the image named in the spec.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
On Linux, `stat -f '%Lp'` succeeds (-f is filesystem status in GNU
stat) and prints no mode, so the BSD-first fallback never ran: chmod got
a non-mode and the test's mode check failed. GNU stat is tried first,
BSD stat second, in template-register.sh and its test.

Refs rossoctl#740

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Conflicts, both sides kept:
- remote-worker/cmd/microvm-worker/main.go: main now loads the manifest
  before vmpool.New (lease features); this branch's VerifyWith with
  SH_VERIFY_MEMFILE uses that one load instead of a second.
- remote-worker/internal/vmpool/snapshot_test.go: main's balloon feature
  test, and this branch's comment that Features is outside both hash
  versions.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 12, 2026

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Manifest hash v2, build-rootfs.sh --source-name, the worker's SH_TEMPLATE_RECORD check, and the new template-build.sh / template-register.sh onboarding pair. The Go side holds up: ComputeHash v2 matches build-snapshot.sh's write_manifest line for line, refuses line breaks on both sides, and both use C-locale capability sorting. The template record check names every mismatch. One suggestion: template-build.sh's "already built" shortcut ignores several build inputs (details inline). No must-fix findings.

Verified on head 842a1d9: go vet is clean and gofmt -l reports nothing for cmd/microvm-worker and internal/vmpool. go test ./cmd/microvm-worker/ passes. go test ./internal/vmpool/ has one failure, TestRestoreFoldsCloudHypervisorsOwnLogIntoTimeoutError (fork/exec …/fake-virtiofsd.py: permission denied). It fails the same way on main, so it comes from the review sandbox, not this PR. template-build.test.sh, template-register.test.sh and build-rootfs.test.sh all pass. The throwaway probe behind the inline comment has been deleted.

Author: webchang (MEMBER — maintainer)
Areas reviewed: Go (vmpool, microvm-worker), Shell (build-rootfs, build-snapshot, template-build/register, install-host), TypeScript (knative-server 503 messages), Docs
Agent/IDE config (.claude/.vscode): none
Commits: 14 commits, all signed-off: yes
CI status: passing (17/17)

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

}

# The spec's part of a record, for "already built": the same spec on the same snapshot.
spec_key() { jq -S '{id, image, guest_ram_mb, vcpus, egress, seed, probe, description, tools,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: The "already built" shortcut leaves out build inputs that change the snapshot.

spec_key compares {id, image, guest_ram_mb, vcpus, egress, seed, probe, description, tools, guest_home_gitconfig}, and the shortcut (L286-289) also checks the manifest hash and the CA. It never looks at --vmm, guest_home, skip_git_identity_check or etc_hosts_sha256. The snapshot name depends only on the id and the image digest, so changing any of those inputs reuses the old snapshot and exits 0.

A throwaway probe (this PR's test harness with the builders mocked) built once, then re-ran with each input changed:

vmm change (--vmm cloud-hypervisor) -> rc=0 builds=0: ==> already built: snapshot acme-widget-1234-aaaaaaaaaaaa ...
guest_home change                   -> builds=0: ==> already built ...
skip_git_identity_check true->false -> builds=0: ==> already built ...
etc_hosts_sha256 changed            -> rc=0 builds=0: ==> already built ...
positive control --force            -> builds=1

In the etc_hosts_sha256 case, the spec's own integrity check never runs at all. In the skip_git_identity_check case, the record still says skip_git_identity_check: true.

Suggested fix: add guest_home, skip_git_identity_check and etc_hosts_sha256 to spec_key, and compare --vmm against the manifest's vmm (or store it in the record). A test like the probe above would pin this behaviour.

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR adds manifest hash v2, which covers every field and digest and is fail-closed on an unknown version, a line break in a field, or any file or field drift. It also adds the template-record check at worker start, build-rootfs.sh --source-name, and the template-build/register scripts. The hash canonicalization is sound: the fields are in a fixed order with fixed names, each line is newline-terminated, and a CR or LF in a value is refused on both sides. Files are streamed, the Go and shell sides are pinned to a shared golden value, and v1 manifests still verify under the old rule. A v1 downgrade doesn't get past the record check today, because manifest_hash must match.

One must-fix: a root write that follows a symlink shipped by an untrusted image, in build-rootfs.sh. The suggestions: the record check never runs in any deployment, because nothing sets SH_TEMPLATE_RECORD; a v1 manifest should be refused when a record is given; and the "already built" short cut ignores --vmm, --kernel and --agent.

Rebase needed: this branch contains #757 at 06b2bca, not #757's current head 5181204. It is now dirty against main: git merge-tree origin/main pr771 conflicts in deploy/microvm/build-snapshot.sh, remote-worker/cmd/microvm-worker/main.go, remote-worker/internal/vmpool/{errors.go,guestconn.go,snapshot_test.go}. It needs a rebase on #757's latest or on main. The green CI is for the pre-conflict head, so the line-format golden test and the build-snapshot test should be re-checked after the rebase. I reviewed only this PR's own commits (620af76..842a1d9), not #757's.

Not raised as findings:

  • With SH_VERIFY_MEMFILE off, memfile is trusted by its digest only. That is documented.

  • Files are verified at start and read later by the launcher (a TOCTOU window). That is acceptable, since the dir is sealed root:root 0444/0555 and published by rename.

  • An unqualified image such as ubuntu@sha256:... gets no --registry prefix. The digest check still protects it.

  • --registry's regex accepts host:port, and an image's first component with : is treated as a host, which is correct.

  • template-register.sh's stat -c then stat -f order is correct for GNU and BSD.

  • Author: webchang (MEMBER — maintainer)

  • Areas reviewed: Go (vmpool manifest hash v2, microvm-worker template record check), shell (build-rootfs.sh, build-snapshot.sh write_manifest, template-build.sh, template-register.sh, tests), docs

  • Agent/IDE config: none

  • Commits: 7, all signed-off: yes

  • CI status: passing (on the pre-conflict head)

# Mount points init and the kernel need; an exported container tree may lack them.
mkdir -p "$OUT/dev" "$OUT/proc" "$OUT/sys"
printf 'image=%s\ndigest=%s\n' "$IMAGE" "$digest" >"$OUT/etc/moca-rootfs-source"
printf 'image=%s\ndigest=%s\n' "${SOURCE_NAME:-$IMAGE}" "$digest" >"$OUT/etc/moca-rootfs-source"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must-fix: this write follows a symlink the image ships. $OUT is the tree podman export extracted from an untrusted image, and this runs as root. If the image ships /etc/moca-rootfs-source -> /etc/sudoers (or /etc itself as a symlink to /etc), the redirect opens the build host's file and truncates it to image=...\ndigest=.... build-snapshot.sh already says "NEVER WRITE THROUGH THE IMAGE'S SYMLINKS" for the same reason. The bug is older than this PR, but this PR edits the line, and template-build.sh now sends third-party images (benchmark images) through it as a routine step. That makes it a host-compromise path. rm -f "$OUT/usr/local/bin/remote-worker" above has the same problem if usr/local/bin resolves outside the tree.

Fix: check that $OUT/etc (and $OUT/usr/local/bin) resolve inside $OUT, the way assemble_rootfs does with realpath -e, then rm -f the file before writing it so that a symlink is replaced rather than followed. Add a build-rootfs.test.sh case with an image fixture whose /etc/moca-rootfs-source is an absolute symlink.

// The image digest the rootfs was exported from (build-rootfs.sh's
// /etc/moca-rootfs-source, copied into a version-2 manifest as source_image_digest).
// A version-1 manifest does not carry it: the check is skipped, and says so in the log.
if man.SourceImageDigest != "" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: a version-1 manifest skips the image-digest comparison, and it does so quietly (main.go only logs it). template-build.sh only ever produces version-2 manifests, so a worker given SH_TEMPLATE_RECORD with a v1 manifest is in a state the tooling never creates. The likeliest causes are an old snapshot dir or a hand-edited manifest whose hash_version was dropped. The manifest_hash equality catches most of these today, but only by accident. If a record was ever written against a v1 hash, the image check is silently off. Since the record path is new, fail closed: when a record is given, refuse man.HashVersion != vmpool.HashVersionAll ("rebuild the template: its manifest predates hash version 2"). Then remove the "predates source_image_digest" log branch in main.go, and change TestTemplateRecordV1ManifestSkipsOnlyTheImage to expect a refusal.

}
// SH_TEMPLATE_RECORD: the template record this worker serves (template-build.sh's),
// checked against the snapshot and the worker's own identity. Unset: no check, as before.
if rec := get("SH_TEMPLATE_RECORD"); rec != "" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: nothing sets SH_TEMPLATE_RECORD, and nothing sets SANDBOX_TEMPLATE either. install-host.sh writes the worker env (RELAY_ADDR, SANDBOX_ID, SH_SNAPSHOT_DIR, SH_SNAPSHOT_IMAGE, ...) but has no record flag. template-build.sh's closing hint (install-host.sh <bundle> --snapshot ... --budget-mb ...) doesn't mention it, and neither does the RUNBOOK. So the "worker checks its template record at start" part of #740 is off in every deployment the new tooling produces. Even when someone sets SH_TEMPLATE_RECORD by hand, the id comparison is skipped because SANDBOX_TEMPLATE is never set. Either have install-host.sh write SH_TEMPLATE_RECORD=$SBX_SRV/templates/<snapshot>.json (and the template id) when that file exists, and add it to template-build.sh's hint, or say clearly in the PR and docs that wiring it is a follow-up.

CA_SHA="sha256:${CA_SHA%% *}"
fi

if [[ -z "$FORCE" && -f "$OUT/manifest.json" && -f "$RECORD" ]] &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: the "already built" short cut ignores the build inputs that are not in the spec, namely --vmm, --kernel and --agent. The snapshot name (<id>-<digest12>) doesn't include them either. Failure: you build with the default --vmm firecracker, then re-run with --vmm cloud-hypervisor (or a new guest kernel or agent) without --force. The script logs "already built" and exits 0, and the operator installs a CH worker against a Firecracker snapshot. The worker's start then fails, or the snapshot runs an old kernel or agent without anyone noticing. Fix: also require [[ "$(jq -r .vmm "$OUT/manifest.json")" == "$VMM" ]], and compare kernel_sha256 with sha256sum "$KERNEL". For the agent, either compare it too or document that --force is needed after an agent change.

Comment thread deploy/microvm/build-snapshot.sh Outdated

caps_json="$(printf '%s\n' "${MANIFEST_CAPABILITIES:-}" | sed '/^$/d' | awk '{printf "%s\"%s\"", sep, $0; sep=","}')"
caps_json="$(printf '%s\n' "${MANIFEST_CAPABILITIES:-}" | sed '/^$/d' | sort | awk '{printf "%s\"%s\"", sep, $0; sep=","}')"
caps_csv="$(printf '%s\n' "${MANIFEST_CAPABILITIES:-}" | sed '/^$/d' | sort | paste -sd, -)"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: sort here uses the build host's locale, but Go's ComputeHash sorts by byte (sort.Strings). The two agree for today's fixed probe list (lowercase ASCII). A locale-dependent collation is still a trap in a line that must match the Go side byte for byte: a mismatch makes every worker refuse the snapshot. Use LC_ALL=C sort on both the caps_json and caps_csv lines.

# makes a registry or a local tag that says otherwise fail here, not in a sandbox.
log "pulling $IMAGE"
PULLED=''
podman image exists "$PULL" || { podman pull "$PULL" >/dev/null && PULLED=1; }

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: set -e doesn't fire when the pull fails here. The failing podman pull sits on the left of && inside the group (I verified that set -euo pipefail; false || { false && X=1; } keeps going). The script then fails later, at podman image inspect, with podman's "image not known" instead of a clear "could not pull $PULL". Write it as if ! podman image exists "$PULL"; then podman pull "$PULL" >/dev/null || die "could not pull $PULL"; PULLED=1; fi.

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review on d4445a2. Since my last review (842a1d9), the only new commit is a merge, d4445a2, which brings in #757's current head (5181204: build-snapshot.sh's tree_write_target, the vmpool too-large-command fixes, install-host.sh's jail cleanup and the 503 docs). The rebase note from last time no longer applies: git merge-tree origin/main pr771 is clean now, and every CI check passes on this head, including microvm-gates, shellcheck, deploy-scripts and deploy-scripts-bash32. This PR's own commits (620af76..842a1d9) are unchanged, so I reviewed only the merge.

The findings from the last round are still open. None of them were changed by this merge:

  1. must-fix: deploy/microvm/build-rootfs.sh:133 still writes $OUT/etc/moca-rootfs-source as root without checking whether the untrusted image's /etc is a symlink. #757's new tree_write_target guards build-snapshot.sh's writes, but build-rootfs.sh never calls it. A throwaway probe (etc -> victim, then the same printf … >"$OUT/etc/moca-rootfs-source") wrote into victim/. I deleted the probe afterwards. mkdir -p "$OUT/dev" "$OUT/proc" "$OUT/sys" on line 131 follows symlinks in the same way. The existing thread on line 133 has the details.
  2. suggestion: nothing sets SH_TEMPLATE_RECORD yet (it is read only at remote-worker/cmd/microvm-worker/main.go:751), so the template-record check doesn't run in any deployment.
  3. suggestion: a version-1 manifest should be refused when a template record is given (template_record.go:68).
  4. suggestion: the "already built" short cut in template-build.sh ignores --vmm, --kernel and --agent.
  5. nit: the locale-dependent sort in write_manifest (build-snapshot.sh:2162-2163), and set -e not firing on a failed podman pull in template-build.sh.

I added no new inline comments. The existing threads cover each of these.

  • Author: webchang (MEMBER — maintainer)
  • Areas reviewed: the merge delta 842a1d9..d4445a2 (build-snapshot.sh, microvm-worker main.go, install-host.sh test), plus a re-check of the open findings on this PR's own files
  • Agent/IDE config (.claude/.vscode): none
  • Commits: 21 in the branch (7 of them this PR's own), all signed-off: yes
  • CI status: passing

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up at d4445a2. The new commit is only the #757 merge. Its two conflict resolutions (microvm-worker main.go uses a single LoadManifest before vmpool.New, and VerifyWith reuses that man; snapshot_test.go keeps both sides) look correct, and the remerge-diff shows nothing else. The branch now merges cleanly with main, and CI is green.

The six items from the 842a1d9 review are still open, because none of this PR's own files changed:

  1. must-fix: build-rootfs.sh:133 writes $OUT/etc/moca-rootfs-source through an image-shipped symlink as root (the same applies to the rm -f $OUT/usr/local/bin/remote-worker above it).
  2. When a record is given, a v1 manifest should be refused.
  3. Nothing sets SH_TEMPLATE_RECORD or SANDBOX_TEMPLATE.
  4. The template-build.sh "already built" short cut ignores --vmm, --kernel and --agent.
  5. nit: build-snapshot.sh caps sort should be LC_ALL=C sort.
  6. nit: a failed podman pull in template-build.sh is masked by &&.

…image's symlinks

build-rootfs.sh runs as root over an untrusted image's exported tree. The
provenance redirect into etc/moca-rootfs-source, the rm of
usr/local/bin/remote-worker and the mkdir of dev, proc and sys all
followed a symlink the image ships, so an absolute one changed the build
host's file. Each directory is now checked to resolve inside the tree
with cd -P, the deepest existing part before mkdir and the full path
after it, and a symlinked provenance file is refused. A refused tree is
removed, as a tree missing a required tool is. This is the approach
build-snapshot.sh's tree_write_target takes for its own writes.

build-rootfs.test.sh covers an absolute symlinked provenance file, /etc,
/usr/local/bin and /dev pointing out of the tree, and a relative /etc
symlink inside it that still builds.

Refs rossoctl#740

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…hash version 2

With SH_TEMPLATE_RECORD set, a version-1 manifest (or one with no
source_image_digest) skipped the record's image comparison and only said
so in the log. template-build.sh, which writes the records, only builds
version-2 manifests from a rootfs that records its image digest, so
either is a state the tooling never creates: an old snapshot directory or
a hand-edited manifest. The record check now refuses both, naming a
rebuild, and the worker's "predates source_image_digest" log line is
gone.

TestTemplateRecordV1ManifestSkipsOnlyTheImage becomes
TestTemplateRecordV1ManifestRefused, and
TestTemplateRecordManifestWithoutImageDigestRefused is new.

Refs rossoctl#740

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…s worker

Nothing set SH_TEMPLATE_RECORD or SANDBOX_TEMPLATE, so the worker's
template record check ran in no deployment the onboarding tools produce.
When template-build.sh wrote a record for the snapshot
($SBX_SRV/templates/<snapshot>.json), install-host.sh now writes both
into the worker env (the record's path and its template id). A record
that names another worker, or is not a moca-sbx-template/1 record, is
refused before anything is written. A snapshot without a record is
installed as before.

template-build.sh's closing hint, the RUNBOOK's worker step and the
SH_TEMPLATE_RECORD row say so. install-host.test.sh covers the wiring,
the other-worker and schema refusals, and a snapshot without a record.

Refs rossoctl#740

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…put it can

The short cut that skips a rebuild compared the spec's description,
image, sizing, seed, probe and tools, the manifest hash and the CA, but
not --vmm, --kernel, guest_home, skip_git_identity_check or
etc_hosts_sha256. Changing any of them reused the old snapshot and
exited 0, so an operator could install a Cloud Hypervisor worker on a
Firecracker snapshot, or a snapshot with an old kernel, and the spec's
/etc/hosts check never ran.

The VMM and the kernel's sha256 are now compared with the snapshot's
manifest, and guest_home, skip_git_identity_check and etc_hosts_sha256
are in the compared part of the spec (and the record now carries
guest_home and etc_hosts_sha256). The guest agent is built from source
by build-snapshot.sh and cannot be compared without a build: the header
and the "already built" line say --force is needed after an agent
change. template-build.test.sh changes each input in turn and checks it
rebuilds.

Refs rossoctl#740

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…byte

write_manifest sorted the probed capabilities with the build host's
locale, while vmpool's ComputeHash sorts them by byte (sort.Strings).
Both agree for today's lowercase ASCII probe list, but a locale that
collates differently would change the hashed capabilities line, and
every worker would refuse the snapshot. Both sorts (the JSON list and
the hashed line) now run under LC_ALL=C. build-snapshot.test.sh builds a
manifest under an en_US locale and checks the byte order.

Refs rossoctl#740

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
… pull fails

The pull sat on the left of && inside a || group, where set -e does not
fire, so a failed podman pull went on and failed later at podman image
inspect with podman's "image not known". It is now an if with
`podman pull ... || die "could not pull <ref>"`. template-build.test.sh
makes the mock pull fail and checks the build stops there, before the
inspect and the rootfs build.

Refs rossoctl#740

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…neutral directory name

Refs rossoctl#740

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@webchang

Copy link
Copy Markdown
Member Author

deploy/microvm/build-rootfs.sh:133 (must-fix)

"this write follows a symlink the image ships. $OUT is the tree podman export extracted from an untrusted image, and this runs as root."

Fixed in 486472d: build-rootfs.sh now changes nothing through the image's symlinks. Before the rm -f of usr/local/bin/remote-worker, the mkdir of dev, proc and sys, and the provenance write, each directory is checked with cd -P to resolve inside the tree. The check runs on the deepest existing part before mkdir -p and on the full path after it, the same way build-snapshot.sh's tree_write_target does. A symlinked etc/moca-rootfs-source is refused, not replaced. A refused tree is removed, like a tree that is missing a required tool. The rm -f only needs its directory checked, because it removes a symlink itself, never the symlink's target. New cases in build-rootfs.test.sh, under "the image's symlinks out of the tree are never written through": an absolute /etc/moca-rootfs-source symlink to a host file, /etc, /usr/local/bin and /dev each a symlink out of the tree, and a relative /etc symlink inside the tree, which still builds. Without the fix, the first four fail. 4c6c732 only renames a fixture directory in that test.

remote-worker/cmd/microvm-worker/template_record.go:68

"Since the record path is new, fail closed: when a record is given, refuse man.HashVersion != vmpool.HashVersionAll"

Fixed in da3b325: with a record, a manifest older than hash version 2 is refused ("rebuild the template: its manifest predates hash version 2"). So is a version-2 manifest with no source_image_digest, which is the same state the tooling never creates, and the image comparison is otherwise skipped for it. The "predates source_image_digest" log branch in main.go is removed. TestTemplateRecordV1ManifestSkipsOnlyTheImage is now TestTemplateRecordV1ManifestRefused, and TestTemplateRecordManifestWithoutImageDigestRefused is new. The SH_TEMPLATE_RECORD row in docs/reference/configuration.md says so.

remote-worker/cmd/microvm-worker/main.go:751

"nothing sets SH_TEMPLATE_RECORD, and nothing sets SANDBOX_TEMPLATE either."

Fixed in e9ca087: when $SBX_SRV/templates/<snapshot>.json exists, install-host.sh writes SH_TEMPLATE_RECORD (its path) and SANDBOX_TEMPLATE (the record's id) into the worker env. Two cases are refused before anything is written or systemd is touched: a record that names another worker than the bundle's, and a file that is not a moca-sbx-template/1 record. A snapshot without a record installs as before. template-build.sh's closing hint, the RUNBOOK's worker step and the configuration row now say so. Test: install-host.test.sh, "a snapshot's template record is wired into the worker env (SH_TEMPLATE_RECORD, SANDBOX_TEMPLATE); another worker's is refused".

deploy/sbx/template-onboarding/template-build.sh:286

"the "already built" short cut ignores the build inputs that are not in the spec, namely --vmm, --kernel and --agent."

Fixed in bb21ab9: the short cut now also requires the manifest's vmm to equal --vmm and its kernel_sha256 to equal the sha256 of --kernel. The guest agent is built from --agent's source inside build-snapshot.sh, so it can't be compared without a build. The script header and the "already built" line say that --force is needed after an agent change. Test: template-build.test.sh section 4b changes each input in turn and checks that it rebuilds.

deploy/sbx/template-onboarding/template-build.sh:267 (bot)

"add guest_home, skip_git_identity_check and etc_hosts_sha256 to spec_key, and compare --vmm against the manifest's vmm"

Fixed in bb21ab9, together with the thread above: spec_key now covers guest_home, skip_git_identity_check and etc_hosts_sha256, each with its default, and the record now carries guest_home and etc_hosts_sha256. A spec that sets one of these against an older record rebuilds. --vmm and the kernel are compared with the manifest. Test: the same section 4b, which also checks that the same values are still taken as already built and that the record no longer says skip_git_identity_check after it is switched off.

deploy/microvm/build-snapshot.sh:2163

"Use LC_ALL=C sort on both the caps_json and caps_csv lines."

Fixed in 4c5dc9c: both sorts run under LC_ALL=C, which matches Go's sort.Strings. Test: build-snapshot.test.sh, "the manifest's capabilities are in byte order under an en_US locale" (capabilities a and B; this fails without the fix on a host that has that locale).

deploy/sbx/template-onboarding/template-build.sh:318

"set -e doesn't fire when the pull fails here."

Fixed in 4b364b0: the pull is now if ! podman image exists "$PULL"; then podman pull "$PULL" >/dev/null || die "could not pull $PULL"; PULLED=1; fi, as suggested. Test: template-build.test.sh section 4c, "a failed pull fails the build at once, naming the image". It checks that neither the inspect nor the rootfs build runs after a failed pull.

Review summary: "Rebase needed"

"It needs a rebase on #757's latest or on main."

Not changed by a rebase: this branch takes main by merge, through #757, and is never rebased, following the project's contribution flow. d4445a2 merged #757's head at that point (5181204), and the follow-up review on d4445a2 found the branch merges cleanly with main. The new commits above are on top of that merge. If "rebase" meant something other than bringing in #757's latest, please say so.

New tip: a9eaf97 (4c6c732 plus the merge of #757's fcd85c8)

Limits (added)

With a template record configured, a worker now needs a hash-version-2 manifest carrying source_image_digest; a snapshot built before that needs a rebuild before its worker gets a record.

Assisted-By: Claude Code

Conflicts:
- deploy/sbx/RUNBOOK.md: main's guest RAM, budget and SBX_WORKER_BIN text, then this branch's
  template-record paragraph.
- deploy/sbx/install-host.sh: the header keeps main's SBX_WORKER_BIN and guest RAM lines with the
  template-record lines above them; validate_worker's comment names both W_GUEST_MB and
  W_RECORD/W_TEMPLATE; the worker env writes main's SH_GUEST_RAM_MB line, then
  SH_TEMPLATE_RECORD and SANDBOX_TEMPLATE when a record exists.
- remote-worker/internal/vmpool/snapshot_test.go: both sides' tests kept (the manifest hash
  version 2 tests and main's probe teardown test).

Beyond the markers:
- deploy/sbx/tests/install-host.test.sh: the template-record case builds its snapshot with the
  suite's snap helper, so its manifest carries guest_ram_mb, which main's install now requires.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Brings in upstream main through f60db30 (turn grants, API 1.7.0). No conflicts: this branch
changes no control-plane file.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review of #771 (manifest hash v2, template-record check, onboarding tools).

Overall this is in good shape — hash v2 is implemented consistently on the Go and shell sides, the new template-record check is wired through install-host.sh, and the new features are well tested (template_record_test.go, template-build/register test suites, install-host tests). DCO and CI pass. The rest are suggestions and nits.

Author: webchang (MEMBER — maintainer)
Areas reviewed: Shell, Go, Docs
Agent/IDE config (.claude/.vscode): none
Commits: 19 commits, all signed-off: yes
CI status: passing (shellcheck, deploy-scripts, lint, k8s-kind-e2e pass; deploy-scripts-bash32 pending at review time)

}
sort.Strings(m.Capabilities)
m.Hash = m.ComputeHash()
m.HashVersion = HashVersionAll

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion — Fill now unconditionally sets HashVersion = HashVersionAll, so every existing caller of Fill outside this diff silently switches to producing v2 manifests, which per deploy/microvm/P4-ON-P6.md a worker that predates version 2 refuses. The upgrade-ordering hazard is documented for build-snapshot.sh output but not for programmatic Fill callers. Suggested fix: confirm no other tool in the repo calls Fill to produce snapshots for already-deployed workers (and/or note the forced upgrade in the docs), since a missed caller makes this PR a breaking change for older workers.

# The record must name this worker: a bundle of another worker is refused here, before anything is
# written, rather than left to crash-loop. No record (a snapshot built without template-build.sh):
# no check, as before. Sets W_RECORD and W_TEMPLATE (empty without a record).
check_template_record() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion — check_template_record validates the record's schema/id/worker but never compares the record's own .snapshot field to $SNAPSHOT at install time. A record copied under the wrong filename installs fine and only surfaces later when the worker crash-loops at start (the Go side does catch it). Suggested fix: compare .snapshot to $SNAPSHOT here so the failure keeps the "refused before anything is written" property the function advertises. Also consider [[ -f "$rec" ]] instead of -e, so a directory named like the record fails with the schema refusal rather than a jq error.

| `SH_MAX_COMMITTED_MB` | none | **Required**, positive integer: the worker refuses to start without it. Size it against the slot count | Committed-memory (OOM) gate |
| `SH_VMM` | `firecracker` | `fake` and unknown values are refused |
| `SH_ALLOW_INSTANCE_TYPE_MISMATCH` | off | Opts a host out of the snapshot instance-type check, for deliberate cross-host use | Skip the hardware-match check |
| `SH_VERIFY_MEMFILE` | off | Exactly `1`: also re-hash the snapshot's memory file at start (a version-2 manifest records its digest). A full read of the guest's RAM image, so off by default; the kernel, rootfs, agent and vmstate are checked at every start |

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit — this row says "the kernel, rootfs, agent and vmstate are checked at every start" without a hash-version qualifier, but in snapshot.go (VerifyWith) the vmstate check only runs when m.HashVersion == HashVersionAll; a v1 manifest never gets its vmstate re-hashed even with SH_VERIFY_MEMFILE=1. The same unqualified sentence appears in deploy/microvm/P4-ON-P6.md. The PR body's Limits section discloses the v1 memfile gap but not this vmstate gap.

# way leaves the previous file, never half of one.
write_file() {
local path="$1" tmp
tmp="$(mktemp "$path.XXXXXX")"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit — if the cat >"$tmp" write fails mid-way (e.g. disk full), the mktemp temp file is left beside the target — no trap or failure path removes it, so stale $path.XXXXXX files accumulate. The original file is safe (the mv never runs under set -euo pipefail). Suggested fix: rm -f "$tmp" on failure.

# record (or none) rewrites the record.
gate_key() { jq -c '.gate_record.sha256 // null' "$1"; }

[[ -n "${SBX_SKIP_ROOT_CHECK:-}" || "$(id -u)" == 0 ]] || die 'must run as root (build-rootfs.sh and build-snapshot.sh do)'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit — SBX_SKIP_ROOT_CHECK disables the must-run-as-root check for anyone who sets it, though the comment frames it as "overridable for the tests only" and nothing enforces that. Impact is low (the builders themselves need root), but it is a safety check that silently disappears with an env var.

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
…inks; manifest capabilities in byte order

- build-rootfs.sh changes nothing through the image's symlinks. $OUT is the tree podman export
  extracted from an untrusted image, and this runs as root. Before the rm -f of
  usr/local/bin/remote-worker, the mkdir of dev, proc and sys, and the provenance write, each
  directory is checked with cd -P to resolve inside the tree (the deepest existing part before
  mkdir -p, and the full path after it), the way build-snapshot.sh's tree_write_target does. A
  symlinked etc/moca-rootfs-source is refused, not replaced. A refused tree is removed, like a
  tree missing a required tool. The rm -f only needs its directory checked: it removes a symlink
  itself, never its target.
- build-snapshot.sh sorts the manifest's capabilities (caps_json and caps_csv) under LC_ALL=C,
  which matches Go's sort.Strings: under an en_US locale sort put `a` before `B`, so the manifest
  the worker hashes could differ from the one the build wrote.

Tests (fail with the fix reverted): build-rootfs.test.sh, "the image's symlinks out of the tree are
never written through" (an absolute /etc/moca-rootfs-source symlink to a host file; /etc,
/usr/local/bin and /dev each a symlink out of the tree; a relative /etc symlink inside the tree,
which still builds; its fixture directory has a neutral name); build-snapshot.test.sh, "the
manifest's capabilities are in byte order under an en_US locale".

Host-side (deploy/microvm, run as root on the KVM host).

(cherry picked from commit 486472d)
(cherry picked from commit 4c6c732)
(cherry picked from commit 4c5dc9c)

Ports rossoctl#771 review fixes

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
…hash version 2

With a template record configured (SH_TEMPLATE_RECORD), a version-1 manifest skipped the image
comparison and only logged that it had: the record path is new, so it fails closed instead. A
manifest older than hash version 2 is refused ("rebuild the template: its manifest predates hash
version 2"), and so is a version-2 manifest with no source_image_digest, a state the tooling never
creates, for which the image comparison was otherwise skipped. main.go's "predates
source_image_digest" log branch is removed. The SH_TEMPLATE_RECORD row of the configuration
reference says so.

Upgrade note: a worker given a record over a snapshot built before hash version 2 now refuses to
start; rebuild that snapshot first.

Tests: TestTemplateRecordV1ManifestRefused (was ...SkipsOnlyTheImage) and
TestTemplateRecordManifestWithoutImageDigestRefused; both fail with the fix reverted.

Host-side (remote-worker).

(cherry picked from commit da3b325)

Ports rossoctl#771 review fixes

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
…r before writing anything

install-host.sh wired a snapshot's template record into the worker env (SH_TEMPLATE_RECORD and
SANDBOX_TEMPLATE) without reading it: a record that names another worker, or a file that is not a
moca-sbx-template/1 record, was installed anyway, and the worker then crash-looped on its own start
check. check_template_record now refuses both before anything is written or systemd is touched,
naming the record's worker and this bundle's. A snapshot without a record installs as before. (This
tree already wrote the two env lines; the upstream change also added them.)

Test (install-host.test.sh; fails with the fix reverted): another worker's bundle on a recorded
snapshot is refused, naming both workers, with no env file written and no systemctl call; a record
of another schema is refused, saying why.

Host-side (deploy/sbx/install-host.sh).

(cherry picked from commit e9ca087)

Ports rossoctl#771 review fixes

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
…put it can; a failed pull fails at once

- The "already built" short cut ignored build inputs outside the spec: it now also requires the
  manifest's vmm to equal --vmm and its kernel_sha256 to equal the sha256 of --kernel. spec_key
  now covers guest_home, skip_git_identity_check and etc_hosts_sha256, each with its default, and
  the record carries guest_home and etc_hosts_sha256, so a spec that sets one against an older
  record rebuilds. The guest agent is built from --agent's source inside build-snapshot.sh and
  can't be compared without a build: the header and the "already built" line say that --force is
  needed after an agent change.
- The pull is `if ! podman image exists ...; then podman pull ... || die "could not pull ..."`:
  under set -e, `exists || { pull && PULLED=1; }` did not stop on a failed pull, and the build
  went on to inspect and build from nothing.

Tests (template-build.test.sh, bash 5 and 3.2; each fails with its fix reverted): section 4b
changes each input in turn (spec fields, --vmm, --kernel) and checks it rebuilds, and that the
same values are still taken as already built; 4c, a failed pull fails the build at once, naming
the image, with no inspect and no rootfs build after it.

Host-side (deploy/sbx/template-onboarding/template-build.sh, run on the KVM host).

(cherry picked from commit bb21ab9)
(cherry picked from commit 4b364b0)

Ports rossoctl#771 review fixes

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Brings in upstream main through 949dc5f (mocactl --record, the worker stop's VM reap, template
tags, edits and owner transfer at API 1.8.0, SBX_WORKER_AT_BOOT).

Conflicts:
- deploy/sbx/RUNBOOK.md: the worker install step keeps this branch's template record paragraph,
  then main's SBX_WORKER_AT_BOOT paragraph.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Brings in upstream main through ab8d10e (setup.sh's Redis image guard, the image's old esbuild
dropped). No conflicts.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
…lates file, keeping the target's mode

write_file wrote a temporary file beside the path, gave it the path's
mode, then moved it over the path. When the env file or the templates
file is a symlink, GNU stat without -L reads the link's own mode, 0777.
The move then replaced the link with a world-writable regular file.

The path is now resolved through its links first, with a cap on the
depth. The temporary file is written beside the target, with the
target's mode (stat -L), and moved over the target, so the link stays a
link. A path that does not resolve to a regular file is refused.

Test: a symlinked env file (relative link, mode 600) and templates file
(absolute link, mode 640). Both links stay links, both targets keep
their modes and get the new content, and no temporary file is left.
Without the fix the test fails.

Refs rossoctl#740

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This PR lands manifest hash version 2 (every field and file digest hashed, cross-pinned between build-snapshot.sh and vmpool.Manifest.ComputeHash via golden tests on both sides), the --source-name/symlink hardening in build-rootfs.sh, and the new template onboarding pair (template-build.sh, template-register.sh) with the worker-side SH_TEMPLATE_RECORD check. The verification story is unusually thorough: shell tests recompute the v2 hash from the manifest's own fields, the Go side pins the same golden digest, and v1 manifests keep verifying. I found no blocking issues.

Author: webchang (MEMBER — maintainer)
Areas reviewed: Shell, Go, Docs, Tests, Security
Agent/IDE config (.claude/.vscode): none
Commits: 21 commits, all signed-off: yes
CI status: failing — the proto check fails on head (all other checks, including shellcheck, deploy-scripts, k8s-kind-e2e and the Go tests, pass). I could not pull the failing job's log from this environment; worth a look before merge.

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

# spec field that changes the snapshot or its checks is here, with its default, so a record from
# before a field was recorded reads as that default and a spec that sets it rebuilds.
spec_key() { jq -S '{id, image, guest_ram_mb, vcpus, egress, seed, probe, description, tools,
guest_home_gitconfig: (.guest_home_gitconfig // false), guest_home: (.guest_home // null),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion — spec_key includes description and tools, so a cosmetic wording tweak to a spec (or adding a tool to the advertised list, which does not change the snapshot) silently triggers a full multi-GiB snapshot rebuild plus a new probe run, and — since the snapshot name is keyed on the image digest — rewrites the same $OUT directory. If that is the intended "the record must match the spec exactly" semantics, fine; but consider splitting the rebuild key (fields that change the snapshot: image, sizes, seed, probe, guest_home*, skip_git_identity_check, etc_hosts_sha256) from the record-rewrite key (description, tools), the way the gate-record path already distinguishes a record-only rewrite from a rebuild. Test 4 currently pins the rebuild-on-description-change behaviour, so this is a design call, not a bug.

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
Brings rossoctl#771's template-register.sh fix: a symlinked env or templates
file is written through to its target, keeping the target's mode. No
conflicts.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
Brings rossoctl#771's template-register.sh fix: a symlinked env or templates
file is written through to its target, keeping the target's mode. No
conflicts.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit to webchang/moca that referenced this pull request Nov 13, 2026
Brings rossoctl#771's template-register.sh fix: a symlinked env or templates
file is written through to its target, keeping the target's mode. No
conflicts.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Rong — this is a solid piece of work. The v2 manifest hash is well designed: the 16-line preimage is pinned from both sides by cross-language golden tests, the line-forgery refusal in Go is mirrored in the shell, the LC_ALL=C capabilities sort fixes a latent collation drift, and the symlink hardening in build-rootfs.sh is genuinely adversarial. I verified the review claims directly on 1c371ea0 (details below).

One suggestion on the hash preimage's line-break guard; the rest of the review found no blocking issues.

Summary

Manifest hash v2 (Go ComputeHash/VerifyWith + build-snapshot.sh write_manifest), build-rootfs.sh --source-name keeping the registry host out of the guest, the worker's SH_TEMPLATE_RECORD start-time check, and the new template-build.sh/template-register.sh onboarding pipeline, with thorough test coverage (symlink escapes, locale collation, cross-language golden digest, spec validation, register add/update/retire/remove).

Author: webchang (MEMBER — maintainer)
Areas reviewed: Shell, Go, Docs (all areas the PR touches)
Agent/IDE config (.claude/.vscode): none
Commits: 22 commits, all signed-off: yes
CI status: proto failing at the "Build and test remote-worker" step on this head (run 43521422377); the rest — shellcheck, lint, check, microvm-gates, docs, CodeQL, Trivy, hadolint — passes, with e2e/kind jobs still pending. I could not pull the failing step's log text (the log download endpoint is unreachable from here), so that failure deserves a look before merge — it is the only red on the PR.

Locally on 1c371ea0: go build/go vet clean; go test ./remote-worker/... passes except TestRestoreFoldsCloudHypervisorsOwnLogIntoTimeoutError, which fails identically on main in my sandbox (the fake virtiofsd helper gets permission denied — an artifact of this environment's /tmp, not of this PR).

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

# These lines, in this order, are what vmpool.Manifest.ComputeHash hashes for version 2;
# a difference here makes every worker refuse a perfectly good snapshot at start. A value
# holding a line break could forge a line: the Go side refuses one, so refuse it here too.
for f in "$IMAGE" "$VMM" "$INSTANCE_TYPE" "$krel" "$caps_csv"; do

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion — The line-break guard's comment states the invariant "a value holding a line break could forge a line", but the loop only covers $IMAGE, $VMM, $INSTANCE_TYPE, $krel and $caps_csv. $GUEST_RAM_MB and $VCPUS also go into the v2 preimage (the guest_ram_mb:%s\nvcpus:%s lines) unguarded. $VCPUS is fine in practice — it's validated against vcpus_re (line 314) — but $GUEST_RAM_MB has no such check: unlike --vcpus, --guest-ram-mb is only assigned (line 223) and never validated, so a crafted value with an embedded newline would reach the printf preimage. The Go side's ComputeHash refuses it, so the realistic outcome is a worker refusing a "good" snapshot rather than a forgery — but that asymmetry is exactly what the guard exists to close, and the manifest JSON at line 2220 would also silently embed the broken value.

Suggested fix: add "$GUEST_RAM_MB" (and "$VCPUS" for symmetry, so the guard doesn't depend on a distant regex) to the loop at line 2182 — or, cleaner, give --guest-ram-mb an integer validation next to vcpus_re the way --vcpus has.

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review tracking note — the full review is in my previous comment on this PR (review 5899198449), posted at this head.

@webchang

Copy link
Copy Markdown
Member Author

@pdettori @cwiklik, #771 is ready for a re-review. The must-fix the approval was dismissed for (a symlinked env or templates file turned into a world-writable regular file) is fixed in 1c371ea, with a test; the details are in that thread.

Assisted-By: Claude Code

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up at 1c371ea. One new commit: 1c371ea (template-register.sh resolves a symlinked env/templates path, with a 40-level cap, then reads the target's mode with stat -L, writes the temp file beside the target and mvs it over the target, so the link stays a link. A path that doesn't resolve to a regular file is refused. Test 7 covers a relative and an absolute link with modes 600/640.)

This closes clawgenti's must-fix at template-register.sh:153. That must-fix is why we dismissed our earlier approval. I traced the new write_file: GNU stat -L and BSD stat -L -f %Lp both read the target's mode, a dangling link or a directory fails the -f check before mktemp, and mktemp beside the target keeps mv an atomic rename on one filesystem. Nothing else is open from our side. clawgenti's 22:32 spec_key suggestion (template-build.sh:275) is theirs and is not repeated here.

CI: proto was red in "Build and test remote-worker" at first, and it passed on re-run. This commit touches only two shell files, so it was a flake.

Author: webchang (MEMBER — maintainer)
Agent/IDE config (.claude/.vscode): none
Commits: 1 own commit (1c371ea); DCO pass
CI status: all 17 checks green (proto passed on re-run)

AI-assisted review, approved by a maintainer before posting.

@pdettori
pdettori merged commit 01e342a into rossoctl:main Nov 13, 2026
23 of 24 checks passed
webchang added a commit to webchang/moca that referenced this pull request Nov 14, 2026
Brings upstream main 01528b6 (rossoctl#769, rossoctl#782, rossoctl#771, rossoctl#773) through
pr/i18-host-agent. Main took API 1.9.0, and the host agents moved to
1.10.0, so this branch's activation section moves to 1.11.0.

Conflicts:
- docs/api/CHANGELOG.md: ## 1.11.0 activation, above ## 1.10.0 host
  agents and main's ## 1.9.0, which are unchanged.
- docs/api/openapi.yaml: main's 409 self_attested on the owner transfer,
  then this branch's activate and deactivate paths. info.version is
  1.11.0.
- docs/reference/change-policy.md: main's list, then "the template host
  agents, then activation leases". Both version numbers are 1.11.0.
- docs/reference/http-api.md: the host agents row (API 1.10.0), then the
  Activation row (API 1.11.0). "Activation came with API 1.11.0."
- packages/control-plane/src/sandbox-handlers.ts: ReadinessFacts carries
  both this branch's placement and nowS and main's trusted set. Its
  docs argument and both returns carry all three.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@pdettori pdettori added this to the v0.11.0 milestone Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Template build tooling: from a container image to a checked snapshot and a template record

4 participants