Skip to content

feat(microvm-worker): a verify cache, so a start re-hashes only changed snapshot files - #773

Merged
pdettori merged 34 commits into
rossoctl:mainfrom
webchang:pr/i23-verify-cache
Nov 13, 2026
Merged

pdettori merged 34 commits into
rossoctl:mainfrom
webchang:pr/i23-verify-cache

Conversation

@webchang

@webchang webchang commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Closes #746. Stacked on #771 (the build and register tooling, #740): this branch contains #771's commits, and its own change is the last 4 commits (review range 20e62625..2d24ed75). Once #771 merges, only those remain.

What it does: a worker start re-hashes only the snapshot files that changed since they were last verified, instead of hashing the whole snapshot on every cold start. Four signed-off commits:

  1. The verify cache in vmpool, plus microvm-worker -verify-snapshot, with SH_VERIFY_CACHE, SH_VERIFY_CACHE_PATH and SH_VERIFY_CACHE_DIR.
  2. build-snapshot.sh seeds the cache after publishing (--worker-bin, best-effort).
  3. The template path: template-build.sh passes its own worker binary and SH_VERIFY_CACHE_DIR, and install-host.sh writes SH_VERIFY_CACHE_DIR.
  4. The cache's file identity leaves out ctime (cache schema 2). Each VM restore's jail hardlink, chown and unlink move the shared inode's ctime, so with ctime in the identity every start after the first restore missed the cache.

Measured:

  • Conditions: one KVM host; a network block volume at 750 MiB/s and 3,000 IOPS; 8 templates with 4 GiB guests; the page cache dropped; 8 cold starts posted at once, 4 starting at a time.
  • Before commit 4: all 8 active after 204.0 s, with 8.99 GiB read per start (every file re-hashed).
  • With it: all 8 active after 100.7 s, with 4.00 GiB read per start, which is the memory file the pin still reads. Every start logged "4 of 4 snapshot files unchanged, 0 hashed in full".
  • A warm round, with one restore per worker since the seed, also logged "4 of 4 unchanged, 0 hashed in full".
  • P4-ON-P6.md already carries the earlier figures from before the cache, with their conditions.

Limits:

  • The memory file is still read in full at every start, by the pin.
  • A same-size rewrite whose mtime is set back is trusted. Only the snapshot's owner can write those files, and it could rewrite the cache as well.
  • A device number that changes across a reboot costs one full re-hash.
  • install-host.sh's SBX_WORKER_BIN default is main's (from fix(sbx): Redis memory limit and image pin, relay rolls, worker units #758), so this PR writes only SH_VERIFY_CACHE_DIR.

Tests on the tip:

  • go test ./... in remote-worker passes, and so does go vet on vmpool and microvm-worker. The new link/chown/unlink test fails on the old identity, with "0 of 4 unchanged".
  • build-snapshot.test.sh, template-build.test.sh and install-host.test.sh pass on bash 5.
  • On bash 3.2, template-build.test.sh passes, and install-host.test.sh stops at the janitor case, as on the parent branch (noted on feat(control-plane,sbx): a template host agent builds queued templates; builds register by policy #772).
  • shellcheck adds no new findings, and prettier passes.

17 files, +1,421 / -36, 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]>
… snapshot files

A worker start hashed the kernel, rootfs, agent and vmstate in full to
check them against the manifest, though the build had hashed exactly
these files and nothing had touched them since.

vmpool: VerifyOptions.Cache names a JSON cache (schema 1) mapping each
file's canonical absolute path to {dev, ino, size, mtime_ns, ctime_ns,
sha256}. A file whose identity is unchanged and whose recorded digest
equals the manifest's is not hashed; otherwise it is hashed in full and
recorded only if it matched, its identity did not change across the
hash, and its ctime is outside a 2 s racy window (coarse timestamps).
A mismatch is never recorded. A missing, unparsable, wrong-schema,
non-regular, not-0600 or foreign-owned cache reads as empty (logged);
a failed write is logged; neither fails the start. Writes are temp
file + fsync + rename in the cache's directory. VerifyOptions.Settle
waits out the racy window instead (for a build-time seed); Logf
reports what the cache did.

microvm-worker: SH_VERIFY_CACHE (0 off, 1 or unset on, anything else
fatal), SH_VERIFY_CACHE_PATH (the file) and SH_VERIFY_CACHE_DIR (its
directory, default /var/lib/moca-microvm-worker/verify-cache; the file
is <image>-<hash of the canonical snapshot dir>.json). New one-shot
mode `microvm-worker -verify-snapshot DIR`: the full verify, memfile
included, recording into the same cache the worker for DIR reads.

Docs: configuration.md rows for the three settings.

Refs rossoctl#746

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

Without a seed, the first worker start after a build still re-hashes
the whole snapshot. seed_verify_cache runs after publish_snapshot,
while the files are still in the page cache: the worker's own
`microvm-worker -verify-snapshot OUT` (--worker-bin, default
/usr/local/bin/microvm-worker) verifies OUT and records the matches in
the cache file the worker for OUT reads, so seed and worker share one
implementation of the cache. env -i clears the environment, passing
only SH_VERIFY_CACHE, SH_VERIFY_CACHE_PATH and SH_VERIFY_CACHE_DIR, so
an older binary without the mode stops on its missing SH_SNAPSHOT_DIR
instead of starting as a worker. Best-effort: a missing binary skips
the seed and a failing one is logged; neither fails or undoes a build.

Tests: the publish scenarios check the seed's argv, that it sees the
published OUT with a cleared environment, and that a failing or
missing binary leaves a successful build successful.

Docs: P4-ON-P6.md's verify-cache paragraph, with the cold-start
timings measured before the cache and their conditions.

Refs rossoctl#746

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

On an SBX0 host, build-snapshot.sh's default --worker-bin,
/usr/local/bin/microvm-worker, is the binary of Moca's own microVM
tier, possibly another version. template-build.sh now passes
`--worker-bin "$SBX_WORKER_BIN"`, default
/usr/local/libexec/sbx/microvm-worker (SBX0's own); a missing binary
only skips the seed, never falls back to another.

The cache's default directory is outside SBX0's tree, so
template-build.sh exports SH_VERIFY_CACHE_DIR=$SBX_SRV/verify-cache for
the seed and install-host.sh writes the same line into each worker's
env: seed and worker compute one file name, inside SBX0's tree.

Tests: template-build.test.sh checks --worker-bin and the seed's
SH_VERIFY_CACHE_DIR; install-host.test.sh checks the worker env line.

Refs rossoctl#746

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Every VM restore hardlinks the snapshot's files into its jail and chowns
the links (launcher_firecracker.go), and the teardown removes them. Each
of link, chown and unlink moves the shared inode's ctime, so with ctime
in the identity every start after the first restore re-hashed every
file: the cache saved only a worker's first start after a build.

The identity is now (dev, ino, size, mtime_ns), and the racy window is
taken from mtime. Schema 2: a schema 1 file reads as empty, so the first
start after an upgrade is one full check. The stated cost: a same-size
rewrite whose mtime is set back is trusted. Only the snapshot's owner
can write those files, and it can rewrite the cache file as well.

Tests: a restore's link, chown and unlink keep every entry (it fails
with ctime in the identity: "0 of 4 unchanged"); the stated limit is
pinned; a rewrite that moves mtime is still re-hashed.

Refs rossoctl#746

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

This PR is stacked on #772, and the review covers only the increment (842a1d9...48332ee): the vmpool verify cache, microvm-worker -verify-snapshot, the seed step in build-snapshot.sh, and the SBX0 wiring. I found no correctness or security defects. The identity check (dev, ino, size, mtime_ns, with ctime left out), the rule that a cache entry is used only when its digest equals the manifest's, the 0600 same-uid check on the cache file, the atomic temp-file-plus-rename write, and the matching cache path between the seed and the worker (both canonicalise the snapshot directory) all hold up when read against the launcher's hardlink/chown/unlink path. There are two small items: the build-time Settle wait has no upper bound when a file's mtime is in the future, and the -verify-snapshot help text leaves out SH_VERIFY_CACHE_DIR.

Author: webchang (MEMBER — maintainer)
Areas reviewed: Go (vmpool verify cache, microvm-worker CLI mode and cache path), shell (build-snapshot.sh seed, template-build.sh, install-host.sh), shell tests, Go tests, docs (configuration.md, P4-ON-P6.md), commit conventions/DCO, CI
Agent/IDE config (.claude/.vscode): none
Commits: 19 commits (5 in the increment over #772), all signed-off: yes
CI status: passing (all 17 checks green, including DCO, shellcheck, deploy-scripts and deploy-scripts-bash32)

0 must-fix, 1 suggestion, 1 nit.

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

return want, true, nil
}
if c.settle {
if wait := verifyCacheRacyWindow - time.Since(time.Unix(0, before.MtimeNs)); wait > 0 {

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 Settle wait has no upper bound. wait := verifyCacheRacyWindow - time.Since(time.Unix(0, before.MtimeNs)) becomes 2s + skew when a file's mtime is in the future, for example after an NTP step backwards between lock_down's install and the seed, or with a snapshot dir copied in from a host whose clock is ahead. time.Sleep then blocks build-snapshot.sh's best-effort seed for that whole skew, which could be hours. The non-settle path is safe here: it only declines to record. Suggested fix: clamp it, e.g. if wait > verifyCacheRacyWindow { wait = verifyCacheRacyWindow }, or skip the wait when before.MtimeNs is after time.Now(). That leaves the entry unrecorded, as the worker path already does.

func runCLI(args []string, get func(string) string, stderr io.Writer) int {
fs := flag.NewFlagSet("microvm-worker", flag.ContinueOnError)
fs.SetOutput(stderr)
dir := fs.String("verify-snapshot", "", "verify the snapshot in `DIR` against its manifest.json, "+

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: The flag help names SH_VERIFY_CACHE, SH_VERIFY_CACHE_PATH but not SH_VERIFY_CACHE_DIR. verifyCachePath reads SH_VERIFY_CACHE_DIR, and it is the variable SBX0's template-build.sh actually passes to the seed. Suggest (SH_VERIFY_CACHE, SH_VERIFY_CACHE_PATH, SH_VERIFY_CACHE_DIR).

@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.

Summary

The range adds a per-snapshot verify cache to vmpool.VerifyWith: a file is hashed in full once, and later starts trust that hash while (dev, ino, size, mtime_ns) are unchanged and the cached digest still equals the manifest's. It also adds microvm-worker -verify-snapshot (build-snapshot.sh runs it after publishing, best-effort), wires the SBX0 paths through template-build.sh and install-host.sh, and drops ctime from the identity (schema 2). The Go code is careful: Lstat/SameFile/0600/uid checks on the cache file, temp+fsync+rename writes, a racy-window guard, stat before and after each hash, and mismatches never recorded. The main concern is the trust argument behind dropping ctime. The restore hardlinks expose the same snapshot inodes inside the jail, so a writer who cannot reach the cache file can still change a snapshot file without the cache noticing.

Author: webchang (MEMBER — maintainer)
Areas reviewed: Go, Shell, Docs
Agent/IDE config (.claude/.vscode): none
Commits: all signed-off: yes
CI status: all 17 checks pass

Inline: 0 must-fix, 1 suggestion, 1 nit. The head a090405 is a merge-only cascade of #757 up the stack (empty remerge-diff, no new non-merge commits); the review covers this PR's own range 20e62625..2d24ed75, as the body asks.

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

// removes them; link, chown and unlink each move the shared inode's ctime, so a ctime
// check would miss on every start after the first restore. The cost: a writer who
// changes a file without changing its size and then sets its mtime back (utimes,
// touch -d) is trusted. Snapshot files are written only by the snapshot's owner (root

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: Your reason for dropping ctime is that only the snapshot's owner can write these files, and that owner "can rewrite this cache file just as well". Restore breaks that equivalence. On the Firecracker path, every Restore hardlinks all five golden files (vmstate, memfile, kernel, rootfs, agent) into the jail and chowns the shared inode to the jail UID/GID (launcher_firecracker.go, the os.Link/os.Chown loop). That UID is os.Getuid() today, which is root. So the jailed VMM process can open the same inodes that the worker verifies, and it holds the rights to write them and to put their mtime back (utimensat). The cache file lives outside its chroot, at /var/lib/moca-microvm-worker or /srv/sbx/verify-cache, so it cannot rewrite that. Snapshot.go calls the start-time verify the trust boundary that 'deliberately runs OUTSIDE the VMM', and vmstate has only a CRC. Before this PR, a VMM that escaped and changed a same-size snapshot file was caught at the next worker start. With ctime gone from the identity, that change now persists across restarts unseen. ctime was exactly the field that caught it, since user space cannot set ctime. Please either state this limit in the comment, P4-ON-P6.md and configuration.md, and point hardened hosts at SH_VERIFY_CACHE=0, or narrow the trust. Two ways to narrow it: keep ctime for the files a launcher never links (on the CH arm only vmstate and memfile are linked), or re-hash a file whose ctime moved and accept the new ctime only after the hash matches. The second costs a full read only after restores, not on every start.

return want, true, nil
}
if c.settle {
if wait := verifyCacheRacyWindow - time.Since(time.Unix(0, before.MtimeNs)); wait > 0 {

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: The settle wait is not bounded. If a file's mtime is in the future (a preserved timestamp copied from a host with a skewed clock, or a clock stepped back after the build), verifyCacheRacyWindow - time.Since(mtime) can be hours long. microvm-worker -verify-snapshot would then sleep that long, and build-snapshot.sh would hang at its best-effort seed step. Clamp the wait to the racy window: if wait > verifyCacheRacyWindow { wait = verifyCacheRacyWindow }. A file still too recent after the clamp is just left unrecorded by the existing check below.

@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

Re-review of the push since my last review (48332ee..a090405, review 5883321302). This PR's own commits are unchanged: git range-diff shows every earlier commit as equal. The push only merges the parent branches again ("Merge pr/i17-build-tooling into pr/i23-verify-cache", and the merges below it), and so brings in #757's five new fixes (381d7c4 too-large command closes its connection, b1beba6 lease keeps its VM on that refusal, ace1c43 build-snapshot.sh no writes through a symlink, ab347c1 install-host.sh removes the old jail path, 5181204 http-api doc). Those belong to #757 and are reviewed there. I checked the two conflicted merges on the way down (3ee0acf upstream/main into i10, d4445a2 i10 into i17) against their recorded resolutions. errors.go, guestconn.go, build-snapshot.sh, microvm-worker main.go and snapshot_test.go keep both sides, as the commit messages say, and main.go's single LoadManifest now feeds both ManifestFeatures and VerifyWith. No new findings. The earlier 1 suggestion, 1 nit still apply: none of the files they cite changed in this push.

Author: webchang (MEMBER — maintainer)
Areas reviewed: range-diff of this PR's own commits, the incoming #757 commits (scope only), the conflict resolutions in the two upstream merges, commits/DCO, CI, agent-config gate
Agent/IDE config (.claude/.vscode): none
Commits: 27 commits, all signed-off: yes
CI status: passing (all 17 checks green)

0 new must-fix, 0 new suggestions, 0 new nits.

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

…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]>
Conflicts, both sides kept:
- template-build.test.sh's build-snapshot mock: this branch's
  SH_VERIFY_CACHE_DIR capture, and rossoctl#771's vmm and kernel arguments.
- configuration.md's microvm-worker table: this branch's verify-cache
  rows, and rossoctl#771's SH_TEMPLATE_RECORD notes (install-host sets it; v2
  and source_image_digest required).

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

Copy link
Copy Markdown
Member Author

Merged #771's reviewed fixes (and #757's, which #771 carries) into this branch; the conflicts were in a test mock and the configuration table, and both sides are kept. This PR's own change is unchanged. New head: d5f15d6.

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 d5f15d6: this head only merges #771's reviewed fixes (a9eaf97) into the branch. git show --remerge-diff d5f15d65 shows two conflicts, both resolved by keeping both sides: the template-build.test.sh mock (it keeps the SH_VERIFY_CACHE_DIR capture and #771's vmm/ksha locals) and the configuration.md worker table (it keeps the verify-cache rows and takes #771's SH_TEMPLATE_RECORD wording). This PR's own files (verifycache.go, verify_cache.go, the seed wiring) are byte-identical to a090405, so our APPROVE at a090405 still stands.

Still open from a090405, not blocking: the ctime/hardlink identity suggestion (verifycache.go:25), the unbounded settle wait (verifycache.go:157, which clawgenti also raised), and clawgenti's flag-help nit (verify_cache.go:82, SH_VERIFY_CACHE_DIR not named).

Author: webchang (MEMBER, maintainer) · Agent/IDE config: none · DCO: no new non-merge commits in the own range · CI: green except k8s-kind-e2e and deploy-scripts-bash32, which were still pending at draft time.

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 pr/i17-build-tooling. No conflicts: the verify cache's worker env
line sits beside main's SH_GUEST_RAM_MB and the template-record lines in install-host.sh, and the
vmpool and microvm-worker changes merge with main's as they are.

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]>
Brings in upstream main through f60db30 (turn grants, API 1.7.0) by pr/i17-build-tooling. No
conflicts: main's change is to the control plane, which this branch does not touch.

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 949dc5f (mocactl --record, the worker stop's VM reap, template
tags, edits and owner transfer at API 1.8.0, SBX_WORKER_AT_BOOT) by pr/i17-build-tooling. No
conflicts.

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]>
Brings in upstream main through ab8d10e (setup.sh's Redis image guard, the image's old esbuild
dropped) by pr/i17-build-tooling. 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]>
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]>

@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 037d2bb. This is a merge of #771's 1c371ea only: it merges cleanly, and the net diff against edb72ea is exactly that commit (same patch-id). 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.) No own code changed. No new findings.

Author: webchang (MEMBER — maintainer)
Agent/IDE config (.claude/.vscode): none
Commits: merge only, no new own commits; DCO pass
CI status: all 16 checks green

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

@pdettori
pdettori merged commit 01528b6 into rossoctl:main Nov 13, 2026
17 checks passed
webchang added a commit to webchang/moca that referenced this pull request Nov 14, 2026
Brings rossoctl#773's verify cache, now merged.

Conflict:
- deploy/sbx/tests/install-host.test.sh: the two-worker check keeps this
  branch's template-record and SANDBOX_TEMPLATE checks, plus main's
  SH_VERIFY_CACHE_DIR check, with this branch's pass line.

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 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.

A worker start re-hashes only snapshot files that changed since a full check on this host

4 participants