S17-06 - Command Line Tools
Purpose: The steps by which wb-download and wb-hostd fetch and
check Apple’s Command Line Tools for the base layer
(S06-16-base-layerS06-16-base-layer: The Base LayerWhat 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: SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter. (every egress decision recorded), SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped. (what the host spends is capped), NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it. (each refusal names its rule and the fix)
Design
Section titled “Design”Each step runs under the rules of S17-03-downloadsS17-03-downloads: DownloadsHow wb-download fetches what an image build needs from the internet., from the entry
wb-download-clt. The guest gets the packages over the host-guest
socket and has no network for them (S06-16-base-layerS06-16-base-layer: The Base LayerWhat 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., “No guest
network in the base build”).
A build runs the entry twice: a catalog run that picks the product, then a package run that fetches its packages.
The catalog run
Section titled “The catalog run”wb-hostdsends the macOS version of the restore image the build installed.wb-downloadfetches Apple’s software update catalog for that major version fromswscan.apple.com. The catalog path of each major version is compiled in. A version with no path fails withdownload-clt-catalog-unknown.- The catalog is a gzip-compressed XML property list.
wb-downloadreads at most 2 MiB compressed and 16 MiB decompressed. - The candidates are the products that list a package named
CLTools_Executables.pkg, newestPostDatefirst, at most 8. - For each candidate in turn, it fetches the English distribution
file from
swdist.apple.com, at most 1 MiB, and takes the first that fits the guest:- its
os-versionrange holds the guest’s macOS version; - its
hostArchitecturesholdsarm64; - it has one choice, whose package references each name a package the catalog lists for the product.
- its
- It reports the product ID, the version from the distribution file’s
SU_VERS, and for each package in the choice’s order its name, URL, size and digest.
A catalog or distribution file that can’t be parsed, or lacks those
keys, fails with download-catalog-invalid. A catalog without a
candidate that fits fails with download-no-clt. The catalog and the distribution file
parsers each have a fuzz target.
The floor
Section titled “The floor”Before the package run, wb-hostd checks the version the catalog run
reported, from the distribution file’s SU_VERS:
- It refuses a version below the minimum compiled into Wraith Box with
clt-below-minimum. - It refuses a version older than the one
state.dbrecords for the last base a build sealed withclt-rollback, unless the user passedwb image build --allow-older-macos, as for the restore image (S17-04-restore-and-releaseS17-04-restore-and-release: Restore Image and ReleaseThe steps by which wb-download and wb-hostd fetch and check a macOS restore image and a Claude Code release., “The floor”).
The flag accepts older tools as well as an older restore image. The text of each refusal it overrides says both.
The distribution file isn’t signed. After the install, step 5 of
S06-16-base-layerS06-16-base-layer: The Base LayerWhat 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., “The Command Line Tools”, checks that the signed
package’s receipt starts with that version. The package then matches
what the floor checked. state.db records the receipt’s version, as
wb-guestd reports it, cut to 64 bytes.
The package run
Section titled “The package run”wb-hostd creates one output for each package in
<data>/downloads/clt/, with O_CREAT | O_EXCL | O_NOFOLLOW and mode
600, and sends the reported list back as the request. wb-download
refuses a list that isn’t the one it reported, or a count of outputs
that doesn’t fit it, with download-request-invalid.
For each package, it sends a GET to its URL on swcdn.apple.com.
It requires a 200 with a Content-Length equal to the size, writes
the body, and stops reading at the size. A shorter body fails with
download-short. A package run doesn’t resume: a failed run deletes the outputs,
and the next build fetches them again.
The check
Section titled “The check”After wb-launcher reports the exit, wb-hostd checks each package
from its own descriptor:
- the size, with
fstat; - the XAR header: the magic
xar!, a header size of at least 28, and the compressed table of contents’ length, within the file; - the SHA-1 of those table of contents bytes, which must equal the catalog’s digest;
- the SHA-256 of the whole file, which
wb-hostdkeeps for the stream to the guest (S06-16-base-layerS06-16-base-layer: The Base LayerWhat 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., “The Command Line Tools”).
A mismatch deletes every package and fails the build with
clt-package-hash-mismatch. The header parser has a fuzz target.
The catalog’s Digest is the SHA-1 of the table of contents, not of
the whole file (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”).
The trust base
Section titled “The trust base”The catalog isn’t signed, and comes over TLS checked against the
system trust store. wb-guestd checks Apple’s signature over the
table of contents against a compiled-in Apple root before it installs
anything (S06-16-base-layerS06-16-base-layer: The Base LayerWhat 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., “Apple’s signature”).
One property is still to be verified (I868I868 (open): Probe whether installer refuses a CLT package with changed files under a kept signatureS17-06-command-line-tools, "The trust base" (from #150): wb-guestd checks Apple's signature over a Command Line Tools package's table of contents with pkgutil --check-signature, then installs it with installer.): a package
whose files were changed, with its table of contents and signature
kept, fails installer. The table of contents holds the checksum of
every file in the package. If installer checks them, a compromised
wb-download or catalog can pick an older Apple package, which the
floor bounds, but can’t change one. If it doesn’t, wb-guestd checks
each file against the table of contents before the install.
Bounds
Section titled “Bounds”A catalog run makes at most 9 requests, and a package run one for each
package. Each stays within the 16 requests of S17-03-downloadsS17-03-downloads: DownloadsHow wb-download fetches what an image build needs from the internet., “The
result record”. A product with more than 15 packages fails with
download-no-clt.
Decisions
Section titled “Decisions”The newest product, with a floor
Section titled “The newest product, with a floor”wb-hostd takes the newest product Apple’s catalog offers for the
guest’s macOS, and doesn’t pin one.
- Why: Apple ties each release of the tools to a range of macOS versions, and the restore image follows the host’s macOS. A pin would lag each new restore image. The floor and the rollback check bound a catalog that offers an old product.
- Rejected: an exact product pinned in code and bumped by Renovate. Renovate has no data source for Apple’s catalog, and product IDs change with each release.
- Decided: 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. (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.).
Status: Draft