Skip to content

feat(deploy/sbx): the general gate, gate-image.py: an OCI image and its contract to a gate record - #960

Merged
webchang merged 2 commits into
rossoctl:mainfrom
webchang:pr/general-gate
Nov 20, 2026
Merged

webchang merged 2 commits into
rossoctl:mainfrom
webchang:pr/general-gate

Conversation

@webchang

Copy link
Copy Markdown
Member

The onboarding guide's §4b.5 ("Path B: your own gate record") described a gate tool that "is the image builder's, and it is not part of Moca yet". This adds it, so a user can self-gate an image for benchmark-self or general-self with Moca alone.

  • deploy/sbx/template-onboarding/gate-image.py: one file, Python 3's standard library plus podman or docker, beside verify-provenance.py. From a moca-gate-input/1 contract it pulls the image by digest (linux/amd64), runs the image's own test command once, unmodified, in an emulation of the microVM guest (read-only root, --network none, root, tmpfs /workspace /tmp /var, env -i with init's PATH), and writes a moca-gate-record/1 record: the control plane's default SH_GATE_RECORD_SCHEMA, with the fields X1, X1.image, X1.offline and X12 read. On a pass it can also write the template spec (the schema of examples/default.json).
  • A record never holds a private registry host, a credential, the test command (only its sha256) or its output (only counts and the runner's summary lines; pytest's FAILED items are excluded). Its bytes are defined as json.dumps(record, indent=2, sort_keys=True) plus a newline, since the control plane hashes them.
  • Tests: tests/gate_image_test.py (stdlib unittest), run by tests/gate-image.test.sh under make test-deploy, including the CLI end to end against a fake podman on PATH (no engine, image or network in CI).
  • Docs: GUIDE §4b.5 (the contract's schema, the command, how a deployment set to another builder's schema takes these records), the folder README, GATING-RULES.md (G and §2.3).

Checks run: pre-commit (prettier, shellcheck, gitleaks), scripts/check-doc-links.py, scripts/check-docs-publish.sh, all four template-onboarding suites.

Assisted-By: Claude Code

…ts contract to a gate record

The onboarding guide's §4b.5 said the gate tool was the image builder's and not
part of Moca yet. This adds it beside verify-provenance.py: one file, Python 3's
standard library plus podman or docker. From a moca-gate-input/1 contract it
pulls the image by digest (linux/amd64), runs its own test command once,
unmodified, in an emulation of the microVM guest (read-only root, no network,
root, tmpfs /workspace /tmp /var, env -i with init's PATH), and writes a
moca-gate-record/1 record: the control plane's default SH_GATE_RECORD_SCHEMA,
with the fields X1, X1.image, X1.offline and X12 read. On a pass it can also
write a moca-sbx-template-spec/1 for benchmark-self or general-self.

A record never holds a private registry host, a credential, the test command
(only its sha256) or its output (only counts and the runner's summary lines,
with pytest's FAILED items excluded). Its bytes are defined as
json.dumps(record, indent=2, sort_keys=True) plus a newline.

Tests: tests/gate_image_test.py (48, run by tests/gate-image.test.sh under
make test-deploy), including the CLI end to end against a fake podman. GUIDE
§4b.5, the folder README and GATING-RULES.md now name the tool, and §4b.5.3
says how a deployment set to another builder's schema takes these records.

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 20, 2026
@pdettori pdettori added this to the v0.11.1 milestone Nov 20, 2026
@pdettori pdettori added the enhancement New feature or request label Nov 20, 2026

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

Review — feat(deploy/sbx): the general gate, gate-image.py: an OCI image and its contract to a gate record

This is the half of Path B that was a promise in the guide, and it holds up: the contract is validated strictly, the run is driven through argv (no shell), and the record carries exactly the paths template-policy.ts reads.

  • Contract. moca-gate-input/1, a pinned digest, a workdir that is absolute, not / and not /workspace, with no .. segment, a non-empty test_cmd, a floor of whole non-negative numbers, absent_sha256 as 64-hex, a probe only when public: true, tool names restricted to a shell-safe charset (they are interpolated into a probe command), and unknown fields refused.
  • The pull and the identity. --platform linux/amd64 always, a digest equality check after the pull, and --registry only for a repository naming no host — the record keeps a public host and drops any other, which is what the per-repository allowlist needs.
  • The guest emulation. env -i with init's exact PATH (build-snapshot.sh:893), HOME=/tmp/home (the spec's guest_home), root, a read-only root, --network none, and the test command run once, unmodified, through bash -c.
  • The verdict fails closed where it must. Counts are read from the last summary line only (an inner pytest summary cannot be mixed in), unittest skips/expected failures are not passes, a run with no summary is None (never 0), a timeout is a stated reason rather than a traceback, and the absence scan takes its shas from a file inside the guest, never a command line.
  • The record matches the policy. gate.passed, image.digest, gate.floor_checked_offline (always present, so a network_needed record is refused on benchmark profiles under any schema) and observed.testbed.agent_can_commit / observed.guest.git_identity are exactly what template-policy.ts and template-build.sh read; source_record_digest is the image digest, as X10 defines it, and the deterministic bytes are the tool's own json.dumps(..., sort_keys=True) + "\n".
  • Nothing private is recorded: no private registry host, no credential, the test command only as a sha256, the output only as counts and the runner's summary lines (pytest's FAILED … items excluded, which the tests pin), no sha from absent_sha256.
  • Process hygiene: the image is removed only when the gate pulled it, the emulation container is removed in a finally, and the CLI exits 2 for a contract it cannot gate, 1 for a failed gate, 0 on a pass.

The two inline comments are emulation fidelity — the workspace's size and /var's content — and the spec's unquoted seed. None of them changes a pass into a fail on the tests this PR runs itself; they matter for a user's image.

One non-blocking doc note: the guide's checklist says the /etc/hosts check passes when the file "resolves localhost", but the check is the exact sha256 of the guide's two-line file (§4b.3). A Debian-style image whose /etc/hosts also has the fe00::/ff02:: lines resolves localhost and is refused with a message that says it does not; naming the file the gate wants (or quoting the wanted content in the message) would save that confusion.

Checks 16/16 green, including make test-deploy's new gate-image.test.sh (unit tests plus one CLI run against a fake podman that asserts the argv). Author: webchang (MEMBER — maintainer). One commit, signed off.


# The guest, emulated in one container: a read-only root, no network, root, tmpfs /workspace /tmp /var.
EMULATION_FLAGS = ("--read-only", "--network", "none", "--user", "0",
"--tmpfs", f"{WORKSPACE}:rw,exec,size=16g", "--tmpfs", "/tmp:rw,exec,mode=1777",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Two emulation-fidelity gaps here, both against what the guest actually does.

  • size=16g for /workspace over-promises. The guest's workspace is a disk image sized by SH_WORKSPACE_IMAGE_MB — 2048 MiB by default and at most 2048 (deploy/sbx/setup.sh: "The largest SBX_WORKSPACE_IMAGE_MB a worker can use"). A test that writes 2–3 GiB into the workspace passes here and then fails at template-build.sh's probe in a real guest, which is a late, confusing refusal for a record that passed. On top of that, this tmpfs is charged to --memory 4096m, so the gate's workspace is RAM while the guest's is disk: size=2048m would match the guest's cap and make the memory accounting predictable.
  • --tmpfs /var hides the image's own /var. The guest keeps it: build-snapshot.sh's init mounts an overlay with the image's /var underneath and a tmpfs on top, and its comment names this exact mistake — "A plain tmpfs here hid it all (for example a prebuilt TeX format under /var/lib/texmf)". A test that reads something the image put under /var fails here and passes in Moca. Leaving /var as the image's (read-only) would keep the content and only be stricter about writes; seeding the tmpfs from an exported copy would match the guest exactly.

"guest_ram_mb": GUEST_RAM_MB, "vcpus": VCPUS, "guest_home": GUEST_HOME,
# egress only for a contract whose tests need the network (general-self, the host's allowlist)
"skip_git_identity_check": True, "guest_home_gitconfig": False, "egress": bool(c.get("network_needed")),
"seed": f"cp -a {c['workdir']}/. {WORKSPACE}/",

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. workdir is validated only as an absolute path without .., so /opt/my repo is accepted; the gate's own seed_cmd quotes it (shlex.quote), but this spec field does not, and the seed the build later runs is then a broken command over two arguments. Either shlex.quote(c['workdir']) here (the examples' paths have no spaces, so it changes nothing for them) or a charset rule on workdir in contract_problems would keep the spec valid for every contract the gate accepts.

…nd keeps the image's /var

Review of rossoctl#960:
- /workspace is a tmpfs of 2048 MiB, the golden snapshot's workspace drive
  (setup.sh SNAPSHOT_WORKSPACE_MB), not 16 GiB: a work tree that does not fit
  the guest fails the gate too.
- /var is the image's own /var made writable, as the guest's init makes it
  (build-snapshot.sh: an overlay, or a copy into a tmpfs). The tmpfs is seeded
  from the created container (cp :/var | tar -x in the guest, owners kept),
  and the record's observed.var counts the entries on both sides; a /var that
  does not arrive whole fails the gate. A plain tmpfs hid what the image put
  there (a prebuilt TeX format under /var/lib/texmf).
- The written spec's seed quotes the work tree (shlex.quote).
- GUIDE §4b.5.1: the /etc/hosts check is the exact sha256 of §4b.3's file,
  and the emulation names the workspace size and /var.

Tests: the workspace flag against setup.sh's SNAPSHOT_WORKSPACE_MB, the /var
check (not copied, not whole), the CLI's /var copy end to end against the
fake podman, and the quoted seed.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
@webchang
webchang merged commit a159c4c into rossoctl:main Nov 20, 2026
16 checks passed
webchang added a commit to webchang/moca that referenced this pull request Nov 22, 2026
57 commits past Moca v0.11.0 (rossoctl#953-rossoctl#976), among them rossoctl#959 (the member
routes write audit lines), rossoctl#960 (gate-image.py, Moca's general gate),
rossoctl#976 (the vault credential store, inert with egress credentials off)
and the lease-mode vmpool changes. No conflict; the fork-only set is
unchanged.

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 22, 2026
Moca's own general gate (gate-image.py, rossoctl#960) writes the control
plane's default moca-gate-record/1, so SBX_GATE_RECORD_SCHEMA is
needed only for records of another schema, such as image-factory/gate/1
records an earlier gate wrote: the install page's row and example, the
setup.sh header comment and the governance note say so. The note names
the 49cce28 sync (API 1.35.0). Comments and docs only.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
webchang added a commit that referenced this pull request Nov 23, 2026
…ar, and /workspace's size

X8 described a microVM gate's guest as "/tmp and /var tmpfs". Since
691c1a0 the guest's init keeps the image's own /var, made writable (an
overlay, or a copy into a tmpfs), and only /tmp is a plain tmpfs; the
guest's /workspace is the golden snapshot's 2048 MiB drive. The general
gate (gate-image.py, #960) and image-factory's microVM gates emulate both.
Wording only; the table's other rows are prettier's realignment.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: Rong Chang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants