S04-09 - Starting `wb-netd`
Purpose: 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.
Design
Section titled “Design”Start interface
Section titled “Start interface”wb-hostd starts one wb-netd per VM run, once it holds the VM’s
packet transport (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., “Packet transport”). It starts it
with no arguments and an empty environment. wb-netd inherits these
descriptors, and no other:
| Descriptor | What it is |
|---|---|
| 2 | the pipe of its log lines to wb-hostd (S04-03-self-sandboxingS04-03-self-sandboxing: Self-SandboxingHow each host daemon confines itself at startup, and the wb-launcher that starts confined programs on macOS., “Daemon logs”) |
| 3 | its control channel (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., “Control channels”) |
| 4 | the VM’s packet transport |
| 5 | its accounting channel (S04-08-records-and-boundsS04-08-records-and-bounds: Records, Versions and BoundsThe records daemons send wb-hostd, the build version rules between processes, the bounds on host work a guest can cause, and logs.) |
| 6 | its event channel |
Descriptors 0 and 1 are /dev/null. After its confinement it refuses
any open descriptor above 6. Then it checks that each of 2 to 6 is
open, and that 3 to 6 are connected AF_UNIX datagram sockets. It exits with
netd-descriptor-invalid when one is wrong, and with netd-arguments
when it got an argument. It exits 0 with netd-stopped only when
wb-hostd closes the control channel. Any other end, the packet
transport’s included, is logged with netd-failed, and it exits 1.
wb-hostd may inherit a descriptor without close-on-exec from launchd
or a shell. Before each spawn it marks every descriptor from 3 on
close-on-exec, logged with inherited-descriptor, so only the start
interface reaches wb-netd. A walk that fails refuses the start with
netd-start-failed.
The hand-off socket to wb-proxyd isn’t among them. It comes on the
control channel, after the start message (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., “New
hand-off sockets”). wb-proxyd doesn’t run yet (I512I512 (closed): wb-proxyd: the program, its confinement and start, hand-off sockets per VM, and restartsPackage M3.12 of docs/implementation-plan.md, part 3 of 4 (M3.12c).), so for now no
wb-netd gets one. Each stream hand-off then fails because there is no
socket, and no stream leaves the VM.
The held transport
Section titled “The held transport”wb-hostd holds its copy of the packet transport in a type without a
read or write path (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., “A new wb-netd”). Besides
closing it, the type can only start a child with the descriptor in one
slot of the child’s inherited files. After the start, a failed one
included, the slot is empty again. The descriptor never reaches
wb-hostd’s own code.
Start message and first policy
Section titled “Start message and first policy”wb-hostd and wb-netd exchange version records on the control
channel. wb-hostd then sends NetdStart and the first policy, the
static one of the VM’s start (S07-01-per-vm-policyS07-01-per-vm-policy: Enforced per VMWhy the VM is the unit the gateway enforces, how the policies of its projects combine, and what happens when they conflict or change.), and waits
for its acknowledgment. If a step before the acknowledgment fails,
wb-hostd stops wb-netd and refuses the VM start with
netd-start-failed.
NetdStart holds the link’s addressing: the guest’s and the gateway’s
MAC address, the subnet, the gateway and the leased address. Each VM
has its own link. Every VM gets 192.168.127.0/24, the gateway .1 and
the lease .2. The gateway’s MAC is the guest’s with its last byte
inverted, another unicast address of the same kind.
wb-netd refuses with the check addressing a MAC that isn’t a
unicast 6-byte address, and the same MAC twice. It also refuses a
prefix length outside 8 to 30, a subnet with host bits set, and a
gateway or leased address that isn’t a host address of the subnet or
is the other’s. wb-hostd checks the guest’s MAC and loads the policy
before the VM starts, so the transport isn’t held unread while it reads
the policy file.
Drain before the start
Section titled “Drain before the start”wb-netd reads the transport from the moment it has checked it. Until
its start message arrives, it drops every frame with the rule
link-not-started. A guest that floods frames before and during the
start then doesn’t fill the socket and stall its NIC.
Profile
Section titled “Profile”The wb-netd profile is (deny default) alone, without parameters
(S04-03-self-sandboxingS04-03-self-sandboxing: Self-SandboxingHow each host daemon confines itself at startup, and the wb-launcher that starts confined programs on macOS., SEC12-least-privilegeSEC12-least-privilege: Least privilege on the hostNo root or administrator rights at run time and no extra host user accounts.). The descriptors it
inherited work without a rule. It doesn’t open files, make sockets,
reach services or start programs. It loads the local time zone before
it confines itself, so that its log doesn’t read a file. In its tests,
a confined wb-netd serves a DHCP lease, a DNS answer and a stream
hand-off with this profile. A rule added to it is a change to this
page first.
No restart yet
Section titled “No restart yet”Until V1-M6-release-gateV1-M6-release-gate: Release gateThe Seatbelt profiles of wb-hostd and the sessions, confinement self-checks, warm start and suspend, the full conformance suite and benchmarks, packaging and upgrades. (I480I480 (open): wb-hostd daemon supervision: control channels, restarts with backoff, giving up, and process healthPackage M3.11 of docs/implementation-plan.md, part 3 of 3 (M3.11c).) wb-hostd restarts no daemon, and it starts
wb-netd itself, without wb-launcher. wb-hostd has no profile
before then, so wb-netd can still confine itself.
- Exit. When a VM’s
wb-netdexits during a run,wb-hostdstops the VM with the rulenetd-exited. The stop is recorded as a failure. - Ended. A channel reader that refuses what
wb-netdsent ends it withnetd-ended, and the VM stops the same way. - Stop. At the VM’s stop,
wb-hostdfirst sendswb-proxydthe VM’sHandoffSocketEnd(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.). It then closes the control channel and waits 10 s for the exit. It kills awb-netdthat doesn’t exit withnetd-stop-timeout. It reads what is left on the accounting and event channels. It ends the VM’s event stream only once that is done andwb-proxyd’s end exchange is done too (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., “Events in band”). Then it closes its copy of the transport. - Hang.
wb-hostddoesn’t check that a runningwb-netdis live. One that hangs leaves its VM without a network, which fails closed. Liveness checks come with the restarts (I480I480 (open): wb-hostd daemon supervision: control channels, restarts with backoff, giving up, and process healthPackage M3.11 of docs/implementation-plan.md, part 3 of 3 (M3.11c).).
An exit while the VM is already stopping, by request or forced, doesn’t
take over that stop’s rule. wb-netd refuses a second NetdStart, so
a new transport can’t reach a running one. Each generation, a restore’s
included, gets a new wb-netd (S04-02-vm-providerS04-02-vm-provider: VM Provider and StreamsHow wb-vmd hands guest connections and the NIC endpoint to other processes, the fixed device set of a VM, and where wb-proxyd takes a stream's identity from., I590I590 (closed): S04-02-vm-provider: a restore starts a fresh wb-netd for its generationFollow-up from #511, its decision 6, which the PR for #511 doesn't build.). The VM
manager has no restore path yet, so today each start is a new run.
Status: Draft