S04-08 - Records, Versions and Bounds
Purpose: The records daemons send wb-hostd, the build version rules between
processes, the bounds on host work a guest can cause, and logs.
Design
Section titled “Design”Accounting and event channels
Section titled “Accounting and event channels”wb-netd and wb-proxyd send wb-hostd two kinds of record, on
inherited sockets of type SOCK_SEQPACKET or SOCK_DGRAM. macOS uses
SOCK_DGRAM (C11-host-daemonsC11-host-daemons: Host Daemons, Audit, and DisksThe test cases for the host daemons' own checks: wb-vmd's device set and slots, the image build bundle, supervision, the accounting and event channels, the daemon log pipes, the audit writer, free space, and the data…, “Descriptor channels”), a socket per kind.
- One record goes in one message. A record arrives whole or not at all.
- Each record is at most 4 KiB, in a fixed format (
AccountingRecord). wb-hostdparses them withegressmsg.DecodeAccountingRecord, which has a fuzz target (C11-host-daemonsC11-host-daemons: Host Daemons, Audit, and DisksThe test cases for the host daemons' own checks: wb-vmd's device set and slots, the image build bundle, supervision, the accounting and event channels, the daemon log pipes, the audit writer, free space, and the data…) and refuses another daemon’s kind.
wb-hostd treats these as a crash of the process that sent them: a
malformed record, an oversized record, and one received with
MSG_TRUNC (accounting-record-malformed). It ends that process, and
counts the exit toward the restart limit. wb-hostd sends nothing on these sockets after its version record. A record or refused message from it after that ends wb-netd’s accounting channel, logged with control-message-refused, and later writes fail.
Accounting records
Section titled “Accounting records”Accounting records carry the counts and the name mapping of S04-07-supervisionS04-07-supervision: SupervisionWho starts and restarts each host process, what happens when wb-hostd stops or the bundle is upgraded, and daemon outages. (“What a restart keeps”, “The kept name mapping”):
- each wildcard budget debit (
WildcardDebit); - each new or renewed
MappingEntry, with its name and address; - each release (
MappingRelease).
From wb-proxyd they carry each ProxydWildcardName, which wb-hostd keeps in memory per VM
and active period and gives back in ProxydStart (S07-06-name-mappingS07-06-name-mapping: Name MappingHow wb-proxyd keeps its own checked copy of the names wb-netd gave synthetic addresses: name reports, releases, replay, lifetime, the second count of the wildcard budget, and the copy wb-hostd keeps.). They also carry the Go
clock’s accepted calibration point, each new verified tree head, and a go-sumdb-inconsistent finding.
wb-hostd checks each of those, stamps it with its receipt time, keeps it in state.db, and passes it back at start (S07-13-publish-timeS07-13-publish-time: Publish TimeWhere the dependency gate gets each version's publish time, and how it builds a clock for Go modules from the checksum database., “Persisted state”).
They aren’t audit events. Nothing rate-limits, suppresses or drops them, with one exception: the read after wb-netd exits is
bounded, and records past the bound are refused unread (S07-06-name-mappingS07-06-name-mapping: Name MappingHow wb-proxyd keeps its own checked copy of the names wb-netd gave synthetic addresses: name reports, releases, replay, lifetime, the second count of the wildcard budget, and the copy wb-hostd keeps., “Kept by wb-hostd”).
wb-netdwrites one before any drop or suppression decision about the event that goes with it, and before it sends the DNS answer.- A write that fails, or that blocks for more than 100 ms, counts as failed. The lookup is then refused (S07-03-dnsS07-03-dns: DNSHow wb-netd answers the guest's DNS queries: synthetic addresses, the name form, negative answers and the wildcard budget.).
wb-hostdreads what is left in the socket afterwb-netdexits, before it starts a new one, until the socket is empty or the read reaches the bound above.
Mapping entries are checked
Section titled “Mapping entries are checked”wb-netd derives the names from guest queries. So wb-hostd checks
each entry before it keeps it:
- The name is in canonical form (S07-03-dnsS07-03-dns: DNSHow wb-netd answers the guest's DNS queries: synthetic addresses, the name form, negative answers and the wildcard budget., “Name form”): lowercase, no trailing dot, and at most 253 bytes in all. Each label is 1 to 63 bytes of letters, digits and hyphens, with no dot byte inside it.
- The address is inside 198.18.0.0/15.
- The count is at most 131,072 live entries per VM.
An entry that fails a check here or in S07-06-name-mappingS07-06-name-mapping: Name MappingHow wb-proxyd keeps its own checked copy of the names wb-netd gave synthetic addresses: name reports, releases, replay, lifetime, the second count of the wildcard budget, and the copy wb-hostd keeps. (“Kept by
wb-hostd”) is logged with mapping-entry-invalid, rate-limited. It
ends the wb-netd that sent it, as a malformed record does. So
wb-netd never runs on with a mapping that differs from wb-hostd’s.
wb-hostd stamps each entry with its own receipt time. It never uses a
time from wb-netd.
Placeholder records
Section titled “Placeholder records”Placeholder records carry a VM, a binding, and one placeholder that
wb-proxyd generated (S09-05-credentialsS09-05-credentials: CredentialsHow credentials are stored and bound to requests, and how the model credential reaches the model API without entering the guest., “Model credential”).
At a session start that needs a binding with a placeholder:
wb-hostdaskswb-proxydfor the VM’s placeholder on its control channel.wb-proxydfetches the binding, and generates a placeholder if the VM has none for it.wb-proxydreplies with a placeholder record on the same control channel, not on the one-way accounting socket. The record has the size limit and fixed format of the records above.- The session start waits for that reply before
wb-guestdstartsclaude(S06-08-projects-and-sessionsS06-08-projects-and-sessions: Projects and Sessions Inside a VMHow projects map onto guest users and sessions onto worktrees, and how Claude Code runs in the guest., “Claude Code in the guest”). It waits as it does for a locked secret store (S15-least-privilegeS15-least-privilege: Least Privilege on the HostThe security design for SEC12-least-privilege: which rights Wraith Box takes on the host, where credentials are held, and how each host process gets only the credentials it needs, for only as long as it needs them.).
wb-proxyd also sends a record on the control channel for each
placeholder it draws after a failed check.
wb-hostd checks the form of each record before it keeps the
placeholder or puts it in a guest’s environment:
- letters, digits and
-only; - 32 to 256 characters;
- at most 8 kept per binding per VM, with the oldest dropped past that.
A record that fails the check is a malformed record. wb-hostd ends
wb-proxyd, and counts the exit toward the restart limit. It refuses
the waiting session start with the rule placeholder-record-invalid.
Event records
Section titled “Event records”Event records carry what goes to the audit log (S09-11-auditS09-11-audit: AuditWhat the audit log records, the budgets that bound it, and what happens when the log can't be written.). Each
has a sequence number: 1 for the first on its channel, and one more
than the last after that. A gap or a repeat ends the sender with
event-record-invalid. A restarted wb-netd or wb-proxyd gets a new
channel, and its sequence starts again at 1 (S07-21-vm-endS07-21-vm-end: A VM's End in wb-proxydHow wb-hostd ends a VM's hand-off sockets in the one wb-proxyd, and how the VM's last event records reach its stop record without one VM's stop or backlog taking the other VM's network down.).
An event write can block for more than 100 ms, or fail without
blocking (ENOBUFS or EAGAIN on a SOCK_DGRAM socket). Then, with
the rule event-channel-blocked, wb-netd refuses new lookups and
connections, and wb-proxyd new streams and requests. It keeps the record and retries it until a write succeeds, so no event
is lost. So a slow or hung wb-hostd makes the VM’s network refuse,
not run without records. A full queue stalls guest input (S09-13-event-sendersS09-13-event-senders: Event SendersHow wb-hostd tells the senders of event records about the audit budgets, what it holds back, and when it stops a VM for its records., “The hold”).
Version skew
Section titled “Version skew”Every host program comes from one bundle with one build version. Every
build task sets it in the Go and the Swift code alike, the dev build
and CI included (S10-02-packaging-and-signingS10-02-packaging-and-signing: Packaging and SigningHow Wraith Box is packaged and signed on each host, and the one version every build stamps.). wb is
linked from that bundle as well.
- The version includes the VCS revision, and marks a modified working tree.
- Only a bare toolchain build (
go build,go run,swift build) is unstamped. It has no version, and two unstamped builds refuse each other. Versions match only when they are equal as bytes.
Between host processes
Section titled “Between host processes”The first message on every host connection, gRPC or not, is the sender’s version record (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves.). A peer of another build version is refused, and the connection closed. Both versions are logged, and the installed bundle is checked (S04-07-supervisionS04-07-supervision: SupervisionWho starts and restarts each host process, what happens when wb-hostd stops or the bundle is upgraded, and daemon outages., “Upgrades”). So there are no compatibility rules between host processes.
- When
wb-hostdrefuseswb,wbprints awraith box:line that names both versions, and exits with 255. - When
wb-hostdexits because the bundle was replaced, the line says that Wraith Box is restarting after an upgrade, and to run the command again.
.proto packages
Section titled “.proto packages”Each package name ends in its major version (wraithbox.<area>.v1). A
change that an older peer can’t read is a new major package next to
the old one, never an edit of the old one (I52I52 (closed): S04-architecture, S09-policy-credentials-audit, S10-tech-stack: first .proto contracts and settings schemaS04-architecture says all IPC is protobuf over gRPC and S10-tech-stack adds proto/ "with the first RPC".).
With wb-guestd
Section titled “With wb-guestd”After the host opens a connection, the first message from wb-guestd
gives its build version, and the major version of each package it
serves.
In V1V1-initial: Initial versionThe first version: what it delivers, what it leaves out, and the milestones that get there., wb-hostd accepts only its own build version:
- The running bundle started each running VM, because VMs stop with
wb-hostd. wb-guestdupdates itself at start from that bundle’s guest tools disk (S06-12-guest-agentS06-12-guest-agent: Guest AgentWhat wb-guestd, the service in the guest, does for the host, and how it updates itself., “wb-guestd”).
The package list is refused unless it holds at most 16 names of at
most 64 bytes, each wraithbox.<lowercase letters>.v<number>, and
equals the host’s own list. The host uses it only to refuse.
A wb-guestd that reports another version is refused before any
session request. wb-hostd logs both versions. A session start in
that VM is refused with a message that names both versions
(NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.). It says to stop and start the VM, and to
rebuild the image with wb image build if that doesn’t help.
The guest’s version is a label
Section titled “The guest’s version is a label”wb-guestd runs as root in the guest, which T00-indexT00-indexboundary 6 is the host terminal stream. takes as the
adversary. The version string is checked against a fixed form first:
- printable ASCII, at most 64 bytes;
MAJOR.MINOR.PATCH, with an optional-prerelease part and+build part of letters, digits, dots and hyphens.
Any other string is refused with the rule guest-version-form.
Wherever the string is shown, in a log record or in wb’s message, it
is escaped and cut to 64 bytes.
The host uses the reported version only to refuse. It never uses it to allow something, or to pick how a message is parsed. Each message gets the same checks whatever the version (SEC11-root-gains-nothingSEC11-root-gains-nothing: Guest root is not a privilegeFull control of the guest grants no control over enforcement, secrets, or policy.).
Host work the guest can cause
Section titled “Host work the guest can cause”SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped. caps each VM, and also the host work each VM can cause. Every host handler that takes input from a guest has:
- a per-VM rate limit;
- a size limit on each input;
- a bound on the work it runs at once.
A request over a limit is refused or dropped, never queued without bound, and logged with the limit’s rule. For the refusal classes that S07-02-packet-pathS07-02-packet-path: Packet PathHow wb-netd carries the guest's frames: the packet transport, the stack, the link filter, its caps, addressing, the MTU and connections., “Events and rate limits”, aggregates, a run of refusals is logged as one record with its count. A new handler gets its limits before it merges.
Clock lookup limits
Section titled “Clock lookup limits”The dependency gate’s clock lookups to sum.golang.org, in wb-proxyd:
- In flight: 4 requests per VM, lookups and their tile fetches. 8
requests per
wb-proxyd, with one kept for the timer’s calibration and its tiles. - Rate and queue: 6,000 uncached lookups a minute per VM, and a queue of 2,000 per VM. Requests are served first in, first out.
- Time: one retry, and 10 s per upstream request. A deadline per request of 42 s, plus 125 ms per uncached lookup and per lookup queued ahead, counted at admission, and at most 5 minutes.
- Size: 2,000 versions per
@v/list. 100,000 cached records and 16 MiB of cached tiles per VM. 1 MiB of calibration tiles. - Calibration runs on its own timer only.
- Refusals: over a cap, a request is refused with
go-clock-lookup-rate,go-clock-deadlineorgo-list-too-long. - Stored state:
wb-hostdchecks the stored heads, points and findings. It keeps at most 192 heads of 1 KiB.
Leftover-process limits
Section titled “Leftover-process limits”Leftover-process results, in wb-hostd:
- one per kill loop, kept until acknowledged, in a session report or a cleanup record;
- at most one record per project user in the VM, apart from the 64 session entries;
- accepted only on an exact kill ID that
wb-hostdsent, before the kill’s 7-minute deadline. When none has arrived by then, that counts as processes left.
Input from the internet
Section titled “Input from the internet”An image build, which the user starts, takes input from the internet
through wb-download (S17-03-downloadsS17-03-downloads: DownloadsHow wb-download fetches what an image build needs from the internet.) and Apple’s installation service:
| Internet input | Process | Limits |
|---|---|---|
Apple’s catalog, a HEAD, the manifest and its signature |
wb-download |
4 MiB for the catalog, 1 MiB and 64 KiB for the manifest and signature, 2 minutes per request, 30 s to connect, 60 s without a byte |
| The restore image and the Claude Code binary | wb-download |
the size from the catalog’s entry, at most 40 GiB, and 1 GiB; a file size limit wb-download sets on itself; 12 hours and 30 minutes; free space checked before the run |
| The result records | wb-hostd |
a fixed form per field, at most 16 requests per run |
| Audit records of downloads | wb-hostd |
one per request or refusal, at most 16 per run, never dropped |
| Apple’s signing server’s replies to the TSS requests (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.) | Apple’s installation service, outside Wraith Box | none set by Wraith Box, and not audited |
Logs and health
Section titled “Logs and health”wb-hostd writes its own log, and the lines the other daemons send it,
to <logs>, in one file per process, apart from the audit log.
- It writes at most 100 lines per second per process.
- It cuts a line at 4 KiB, with a truncation marker.
- It writes one record with the count of lines it dropped over the rate.
- Each file is rotated at 10 MiB, and the last 5 are kept.
A daemon log isn’t the record of a decision. The audit log is (S09-11-auditS09-11-audit: AuditWhat the audit log records, the budgets that bound it, and what happens when the log can't be written.).
For each host process, wb-hostd keeps:
- its state: running, waiting to restart, given up, or stopped;
- its version, and when it started;
- its restarts in the last 10 minutes;
- its last exit reason: the exit code or signal.
wb status shows them. For each VM without network, it shows which
process is down and why (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.).
When wb can’t reach wb-hostd, wb status says so. It says to run
wb setup, which installs and starts the service (S05-03-management-commandsS05-03-management-commands: Management CommandsThe commands of wb other than the agent commands.).
Status: Draft