Skip to content

S06-16 - The Base Layer

Purpose: What the base layer holds, how the image build installs Apple’s Command Line Tools from a package the host fetched, and the toolchain user that named images and project layers install as.

Requirements: FR06-native-toolsFR06-native-tools: Native guest toolsAgent tool calls run tools native to the guest operating system (on macOS guests: Homebrew packages, Xcode command line tools, optionally full Xcode). (the guest’s own tools), SEC04-no-guest-secretsSEC04-no-guest-secrets: No secrets in the guestThis includes the model credential., SEC05-default-denySEC05-default-deny: Default-deny egress, enforced on the hostOnly allowlisted hostnames are reachable., SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another., SEC15-no-guest-disk-mountSEC15-no-guest-disk-mount: The host never mounts a guest-written diskA disk image is guest-written once a guest has run with it attached, and every copy or clone of a guest-written image is guest-written too.

Tests: C09-guest-and-sessionsC09-guest-and-sessions: Guest and SessionsThe test cases for what a project user can reach inside the guest, wb-guestd's update and the guest clock, the shared toolchain prefix, the guest admin password, and the session lifecycle., C12-install-and-downloadsC12-install-and-downloads: Install and DownloadsThe test cases for installing and upgrading Wraith Box: wb-download, wb-release-check, the checks wb-hostd makes on what it fetches, wb setup, and the migrations of state.db and configuration.

Brief: B150-named-imagesB150-named-images: Which VM runs a recipe, and how does a recipe build get through the proxy?A new recipe VM, `wb-vmd-recipe`, with a network of its own and the build CA installed at runtime and removed before sealing.

The base layer is minimal (I150I150 (closed): S06-vm-lifecycle: minimal base image and named derived images built from recipesS06-vm-lifecycle "Images" puts Homebrew, the Xcode command line tools and wb-guestd in the base image.):

It doesn’t hold third-party code. Homebrew comes from the built-in homebrew recipe (S06-17-named-imagesS06-17-named-images: Named Images and RecipesThe build of a named image from a recipe on a clone of the sealed base.), and full Xcode from a named image’s Xcode step (S06-14-xcode-imageS06-14-xcode-image: The Xcode ImageHow an image gets full Xcode and the simulator runtimes from the host, as a read-only disk the host builds, and who runs Xcode's first launch.).

The base build has no guest egress at all. Its wb-netd is the build VM’s, which serves only DHCP, ARP and the one connection to the guest’s port 22 (S07-18-build-networkS07-18-build-network: Build NetworkThe build VM's network: what its wb-netd serves, the one connection to the guest's port 22, and its refusal for session VMs.). Everything the base needs from the internet, the host fetches with wb-download.

The host fetches the package files of one Command Line Tools product from Apple’s software update catalog (S17-06-command-line-toolsS17-06-command-line-tools: Command Line ToolsThe steps by which wb-download and wb-hostd fetch and check Apple's Command Line Tools for the base layer (S06-16-base-layer).). They reach the guest over the host-guest socket, never over a network.

Step 4 of the second stage (S06-02-image-buildS06-02-image-build: Image BuildHow wb image build makes a guest image: the build VM, its two provisioning stages, terminfo, sealing, and storage., “Provisioning stages”) installs them through the named operation install-command-line-tools:

  1. wb-hostd sends the product’s version, then streams each package file in the product’s order from the descriptor it checked (S17-06-command-line-toolsS17-06-command-line-tools: Command Line ToolsThe steps by which wb-download and wb-hostd fetch and check Apple's Command Line Tools for the base layer (S06-16-base-layer)., “The check”). It reads with pread, hashes what it sends, and after the last byte sends the SHA-256 it computed in that check.
  2. wb-guestd writes each one to a temporary file that only root can read or write. It keeps a file only when the SHA-256 of what it received equals the one wb-hostd sent, and wb-hostd reports that its own hash of the sent bytes matched too.
  3. It checks every file’s signature with pkgutil --check-signature (“Apple’s signature” below), before it installs any of them.
  4. It installs each file with installer -pkg <file> -target /, in the product’s order.
  5. It checks that xcode-select -p prints /Library/Developer/CommandLineTools, and that the installed receipt of com.apple.pkg.CLTools_Executables has a version that starts with the product’s version and a dot.
  6. It deletes the temporary files, on every path.

A file changed between the check and the send fails the build with clt-bytes-changed, as S14-01-installS14-01-install: InstallHow the image build downloads Claude Code on the host, checks it, and installs it in the guest image, and which version a guest runs., “The checked bytes”, does for Claude Code.

Each tool runs by its absolute path, with a fixed environment and a deadline in code. A failure fails the build with its rule: clt-hash-mismatch, clt-signature-invalid, clt-install-failed or clt-not-selected. The host cuts the failure text to 1024 bytes and escapes it, as for terminfo (S06-02-image-buildS06-02-image-build: Image BuildHow wb image build makes a guest image: the build VM, its two provisioning stages, terminfo, sealing, and storage., “Terminfo”).

The catalog isn’t signed, so a compromised wb-download can report any package. Apple’s signature is what the build trusts. wb-guestd accepts a package only when pkgutil --check-signature reports:

  • the status signed Apple Software;
  • a chain of exactly three certificates: Software Update, then Apple Software Update Certification Authority, then Apple Root CA;
  • a root whose SHA-256 fingerprint equals the one compiled into wb-guestd.

B150-named-imagesB150-named-images: Which VM runs a recipe, and how does a recipe build get through the proxy?A new recipe VM, `wb-vmd-recipe`, with a network of its own and the build CA installed at runtime and removed before sealing., “Evidence”, has the package this chain was read from. The parser of pkgutil’s output has a fuzz target. Anything else it reads is refused.

An older product that Apple signed passes this check. The floor and the rollback check of S17-06-command-line-toolsS17-06-command-line-tools: Command Line ToolsThe steps by which wb-download and wb-hostd fetch and check Apple's Command Line Tools for the base layer (S06-16-base-layer)., “The floor”, run on the version the catalog reported, before the download. Step 5 ties that version to the signed package’s receipt, and state.db records the receipt’s version.

The named operation create-toolchain-user creates the toolchain user that writes the tool prefix (I144I144 (closed): S06-vm-lifecycle: which user installs the base layer before sealingFrom the security review of PR #141 (X17-image-build, #28), finding 3., S06-01-image-layersS06-01-image-layers: Image Layers and the Toolchain PrefixThe layers of a guest image, and the toolchain prefix that project layers install into., “Toolchain prefix”). It runs once in each base build, and takes no input.

  • The user is _wbtool, with UID 440, and its own group _wbtool, with GID 440 and no other members.
  • It isn’t in admin, wheel or any other group.
  • Its shell is /usr/bin/false, its password *, and it is hidden (IsHidden).
  • Its home belongs to it, with mode 700.
  • The prefix, /opt/homebrew, belongs to it and its group, with mode 755, and is empty.

The operation refuses with toolchain-user-exists, and doesn’t create anything, when the user, the group, either ID or the prefix already exists.

UID 440 is below 500, so macOS treats the user as a system account and doesn’t list a login for it. _wbtool is the name and UID that X20-shared-homebrewX20-shared-homebrew: Homebrew with more than one project userCan each project user in one guest get its declared Brewfile without a Homebrew prefix that another project user can write to (SEC08-proj-isolation)? measured. The operation’s refusal covers a later macOS that takes either.

The sealing scan (S06-02-image-buildS06-02-image-build: Image BuildHow wb image build makes a guest image: the build VM, its two provisioning stages, terminfo, sealing, and storage., “Sealing”) accepts _wbtool only with every property above. It refuses an image where:

So the base, and every image built on it, has one user that may write the prefix. That is what SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another. rests on for the toolchain: project users only read it (S06-01-image-layersS06-01-image-layers: Image Layers and the Toolchain PrefixThe layers of a guest image, and the toolchain prefix that project layers install into., “Toolchain prefix”).

Status: Draft