Skip to content

feat(guest-image): derive the guest rootfs from the pinned agent OCI image - #1252

Merged
trunk-io[bot] merged 3 commits into
compass-managed/rig-3786-agent-image-pinfrom
compass-managed/rig-3787-derive-rootfs
Sep 17, 2026
Merged

trunk-io[bot] merged 3 commits into
compass-managed/rig-3786-agent-image-pinfrom
compass-managed/rig-3787-derive-rootfs

Conversation

@rigel-mintaka

@rigel-mintaka rigel-mintaka commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

This PR is part of a stack containing 3 PRs:

  1. main
  2. feat(guest-image): pin the agent OCI image the guest rootfs derives from (RIG-3786) #1215
  3. "feat(guest-image): derive the guest rootfs from the pinned agent OCI image" (this PR)
  4. feat(guest-image): publish the guest triple as a non-runnable OCI artifact #1268

The guest userland was a second nix evaluation of the agent image's
expressions under a different nixpkgs pin, so the microVM guest and the
published container could drift silently.

The rootfs now unpacks the published image itself: per-layer
fixed-output fetches keyed by the locked descriptor digests, applied in
manifest order with each layer's whiteouts resolved against the lower
layers before its own content lands. A boot layer is overlaid on top
and wins every conflict: guestd as /sbin/init, modprobe, /lib/modules
from the root-pinned kernel, and a writable /etc/resolv.conf.

Two build-time gates keep it honest. The eval re-checks the lock's
shape, and the userland contract is verified on the assembled tree by
resolving every path component inside it -- the way the kernel will
after switch_root -- so a missing /bin/sh breaks the build instead of
shipping a guest that cannot arm egress.

Refs RIG-3787

Co-authored-by: Matt Wilkinson matt@rigel.build

…image

The guest userland was a second nix evaluation of the agent image's
expressions under a different nixpkgs pin, so the microVM guest and the
published container could drift silently.

The rootfs now unpacks the published image itself: per-layer
fixed-output fetches keyed by the locked descriptor digests, applied in
manifest order with each layer's whiteouts resolved against the lower
layers before its own content lands. A boot layer is overlaid on top
and wins every conflict: guestd as /sbin/init, modprobe, /lib/modules
from the root-pinned kernel, and a writable /etc/resolv.conf.

Two build-time gates keep it honest. The eval re-checks the lock's
shape, and the userland contract is verified on the assembled tree by
resolving every path component inside it -- the way the kernel will
after switch_root -- so a missing /bin/sh breaks the build instead of
shipping a guest that cannot arm egress.

Refs RIG-3787

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@linear-code

linear-code Bot commented Sep 16, 2026

Copy link
Copy Markdown

RIG-3787

@github-actions

github-actions Bot commented Sep 16, 2026

Copy link
Copy Markdown

Compass engineering docs preview: https://compass-managed-rig-3787-der.compass-eng-docs.pages.dev

Deployed from compass-managed/rig-3787-derive-rootfs at abc8a29.

…unpacking

Review findings on the OCI-derived rootfs, each with a reproduced counterexample:

- The lock's manifest digest constrained nothing: only the layer descriptors
  decided what was unpacked, so a lock pairing that digest with another image's
  valid layers built clean. The manifest is now fetched fixed-output against the
  digest (a manifest digest is the sha256 of its body) and its own ordered layer
  list must equal the lock's.
- A lower layer's absolute symlink used as a parent path let tar write, and the
  whiteout `rm -rf` delete, outside the staged root. Such parents are dropped
  before extraction and a `..` member now breaks the build.
- The userland contract passed on a non-executable or a directory; it now
  requires an executable regular file.
- setuid/setgid files are asserted absent rather than assumed.

The packed image is byte-identical: the published layers trip none of these.

Refs RIG-3787
…arkers

Correctness-lens findings on the OCI-derived rootfs, each reproduced first:

- Extraction used --no-same-permissions, so every member took the builder's
  umask instead of its published mode: /bin packed 0755 where the image ships
  0555. Extract with -p and re-open staging write access on directories only,
  then restore the directories' published modes before packing. Directory
  members are selected by tar's type flag, since these layers list directories
  with no trailing slash.
- The whiteout scan matched the marker prefix anywhere in a path, so an
  ordinary directory whose name contained it became a delete order.
  Reproduced deleting a lower-layer file outright. The match is now anchored
  to a marker-prefixed final component.
- An opaque marker naming a missing directory was swallowed by a redirect to
  /dev/null plus a true fallback; it now breaks the build, since it means the
  layer stack is not what this build thinks it is.
- The image root's mode was a chmod side effect (0555 inherited from the boot
  layer's store path until a later pass happened to widen it); it is now set
  outright.
- The store-path loop word-split an unquoted command substitution under
  nullglob, so a path containing a glob metacharacter was silently dropped,
  yielding an incomplete rootfs. It now reads line-wise.
- The contract resolver counted path components, not symlink hops, so a deep
  symlink-free path could be reported as a loop.
- The lock guard called builtins.match on a non-string tag, replacing the
  curated error with a raw nix type error.

Not fixed, measured: mkfs.erofs drops the sticky bit on /tmp whatever the
staged mode, so /tmp packs 0777 rather than 1777. The rootfs boots read-only,
so the lower layer's mode is not what makes /tmp writable.

Refs RIG-3787
@rigel-mintaka
rigel-mintaka marked this pull request as ready for review September 16, 2026 22:35
@mattwilkinsonn
mattwilkinsonn added this pull request to stack #1261 September 17, 2026 02:01
@trunk-io

trunk-io Bot commented Sep 17, 2026

Copy link
Copy Markdown

😎 Stack merged successfully - details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants