S07-18 - Build Network
Purpose: The build VM’s network: what its wb-netd serves, the
one connection to the guest’s port 22, and its refusal for session
VMs.
Design
Section titled “Design”What the build VM’s wb-netd serves
Section titled “What the build VM’s wb-netd serves”The image build’s one SSH session needs a network
(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”). The build VM’s wb-netd
gives it the least that session needs:
- DHCP and ARP, as for any VM (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., “Addressing”);
- ICMP echo to the gateway, answered by its stack;
- one TCP connection from its stack to the guest’s port 22, on
wb-hostd’s request (“The connection”); - no egress.
For no egress, its stack runs in build mode with no stream or DNS
handler. A TCP connection the guest opens is reset. UDP after DHCP
is dropped, DNS included. Each is logged with the rule
build-egress-refused, rate-limited as 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” says. It doesn’t hold a hand-off socket to wb-proxyd:
wb-hostd gives it none, and wb-proxyd refuses one for the build VM
with handoff-socket-refused (S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach.).
Build mode
Section titled “Build mode”wb-netd learns whether its VM is the build VM from its start
message, which also names its VM and generation.
- The mode
buildmarks the build VM. A missing or unknown mode makes it a session VM’swb-netd. - The VM of a build start is
build, which is no VM slot. A build start that names another VM, or a start ofbuildin another mode, is refused at decode with the checkvm-slot, which ends the control channel. - The mode is fixed for the life of the process. A second start that
names a mode is logged with
build-mode-refused, then ends the control channel as any second start does (S04-09-netd-startS04-09-netd-start: Starting `wb-netd`How wb-hostd starts and stops each VM's wb-netd, what the program inherits, its profile, and what it does before its start message.). - In build mode,
wb-netdtakes no hand-off socket, policy change, or active period start, andwb-hostdsends none: no policy follows a build start. One that names the VMbuildis refused at decode with the checkvm-slot, which ends the control channel. One that names a VM slot passes the decoder and is refused withbuild-mode-refusedand the message’s kind as the check, and the channel goes on. - A start in build mode needs the build connection, and a session
VM’s start needs its hand-off sockets and policy. A start whose
parts are missing ends the control channel with
control-message-refused, and the process exits.
The build VM’s wb-netd opens the accounting channel, as every
wb-netd does (S04-09-netd-startS04-09-netd-start: Starting `wb-netd`How wb-hostd starts and stops each VM's wb-netd, what the program inherits, its profile, and what it does before its start message., “Start interface”), but no event
channel yet: a record of the audit contract names a VM slot, work or
isolated, and the build VM has none. Its events are logged with
their rule to its standard error only, so they don’t reach the audit
log. They belong in the audit log (SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter.). This is an open gap
until I866I866 (open): wb-netd: send the build VM's events to the audit logThe build VM's wb-netd (#659) opens no event channel. gives the audit contract a way to name the build VM.
The connection
Section titled “The connection”The request comes on wb-netd’s control channel and names a VM and a
generation. wb-netd refuses it, and logs build-connect-refused
with the check that failed, when:
- its mode isn’t
build; - the VM or the generation isn’t its own;
- a connect is already running;
- it has already handed a socket to
wb-hostd.
Otherwise it:
- opens a TCP connection from the gateway address to the guest’s leased address, port 22;
- tries again after a reset or no answer, as long as the connect
deadline allows, because
sshdanswers only some time after the guest starts (X17-image-buildX17-image-build: Unattended image buildCan a macOS guest installed from an Apple restore image get past Setup Assistant, with wb-guestd running as a root LaunchDaemon, without SSH, scripted clicks, or MDM?); - once the connection is established, logs
build-connectwith the VM, the generation and the leased address; - relays it over a Unix domain
SOCK_STREAMsocketpair, as for a stream (S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach.); - sends the other end to
wb-hostdon its control channel, in a message with exactly one descriptor.
Only an established connection counts. Each wb-netd process hands
at most one socket to wb-hostd. When the deadline passes first, it
logs build-connect-timeout, tells wb-hostd, and the build fails.
| Limit | Value | Rule |
|---|---|---|
| Wait between tries | 1 s | none |
| One try, SYN to established | 5 s | none, logged at debug level |
| Connect deadline, from the request | 3 minutes | build-connect-timeout |
After a timeout, wb-hostd may send another request, which starts a
new deadline: the build VM’s wb-netd has handed no socket yet.
Messages
Section titled “Messages”The contract is proto/wraithbox/egress/v1/control.proto, and
egressmsg decodes and checks each message before its reader acts
on it.
| Message | Direction | Fields | Descriptor |
|---|---|---|---|
NetdStart.mode |
wb-hostd to wb-netd |
MODE_BUILD, or none |
the payload, as before |
BuildConnect |
wb-hostd to wb-netd |
VM, generation | none |
BuildSocket |
wb-netd to wb-hostd |
VM, generation | the socketpair’s end |
BuildConnectFailed |
wb-netd to wb-hostd |
VM, generation, rule | none |
The rule of a BuildConnectFailed is build-connect-timeout or
build-connect-refused. wb-hostd sends one BuildConnect at a time
and waits for its answer before it sends another, so an answer is
always to the request it waits on. build-connect-refused then means
a confused request, and the build fails. A BuildConnectFailed
doesn’t say which request it answers, and wb-hostd never needs it
to. When a session VM’s wb-netd sends a
BuildSocket or a BuildConnectFailed, wb-hostd refuses it with
control-message-refused and the check build-not-asked, and ends
that wb-netd.
| Rule | Decision | Checks |
|---|---|---|
build-egress-refused |
reset or drop | none |
build-mode-refused |
refuse | the message’s kind, or start-mode |
build-connect-refused |
refuse | mode, vm, generation, running, handed |
build-connect |
hand the socket | none |
build-connect-timeout |
none | none |
wb-hostd receives the socket as S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach., “Message
form”, says for wb-proxyd, and hands it to wb-build-ssh
(S04-05-helper-programsS04-05-helper-programs: Helper ProgramsThe programs that run once for an image build or a store operation: wb-guestadmin, wb-release-check, wb-download and wb-build-ssh.). wb-netd doesn’t open an upstream
connection on this path.
wb-hostd never restarts the build VM’s wb-netd. When it exits, the
image build fails with its exit reason (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.). So one
build gets at most one socket.
What the refusal guards against
Section titled “What the refusal guards against”The session VM refusal guards against a confused request. A
compromised wb-hostd writes the start message, so it could start a
session VM’s wb-netd in build mode. It still has no password for
wbadmin, which only wb-guestadmin holds (S15-04-guest-adminS15-04-guest-admin: The Guest Admin UserHow the host keeps the password of the guest admin user wbadmin, from the image build to each VM's first contact.), and
the image build turns Remote Login off before it seals the image
(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.).
Decisions
Section titled “Decisions”One connection into the build guest
Section titled “One connection into the build guest”The build VM’s wb-netd opens one connection to the guest’s port 22,
and a session VM’s refuses to.
- Why: the provisioning boot installs
wb-guestdover SSH, before any host-guest socket answers. The build network gives that session a path with no egress, and keeps every session VM without a path into its guest. - Decided: I139I139 (closed): S06-vm-lifecycle: SSH for the image build's provisioning boot without a NAT networkX17-image-build (#28) answered "no": a host without root can't get wb-guestd into a new macOS guest by writing to its disk. and I165I165 (closed): S04-architecture, S15-least-privilege: wb-build-ssh on Go's SSH library over wb-netd's build-only connection1..
Status: Draft