Skip to content

S04-07 - Supervision

Purpose: Who starts and restarts each host process, what happens when wb-hostd stops or the bundle is upgraded, and daemon outages.

The service manager keeps wb-hostd running, and wb-hostd keeps the other host processes running. A failure stops egress and never opens it. The work a guest can make the host do is bounded (SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter., 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., SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped., NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.).

VMs stop with wb-hostd, for V1V1-initial: Initial versionThe first version: what it delivers, what it leaves out, and the milestones that get there. (see “Decisions”). wb-launcher, wb-vmd, wb-netd and wb-proxyd each inherit a control channel to wb-hostd: a socket, never a path. End of file or an error on that channel means wb-hostd is gone. Each of them then acts on its own:

The per-run programs don’t hold a control channel, and can’t learn that wb-hostd has gone. wb-launcher ends them. On hosts without wb-launcher, the service manager ends them with wb-hostd. That is to be confirmed when those hosts are built (S12-platformsS12-platforms: PlatformsWhich host and guest operating systems Wraith Box targets, how platform-specific code is isolated, what each platform uses, and how wb works inside WSL., I176I176 (open): End per-run programs with wb-hostd on hosts without wb-launcher (Linux, Windows)Follow-up from the code re-review of #171 (#48, finding G).).

On macOS, launchd also kills the processes left in wb-hostd’s process group when wb-hostd exits (man launchd.plist, AbandonProcessGroup). That is a second layer. The control channel is the rule on every host.

A new wb-hostd takes over nothing. It:

  1. starts a new wb-launcher and new daemons;
  2. marks the sessions it has as starting, running, paused or ending as lost (S06-11-reconnect-and-recoveryS06-11-reconnect-and-recovery: Reconnect, Loss and RecoveryWhat happens when the host-guest link drops, when a session is lost, and how a lost session's work is recovered or discarded., “Lost”);
  3. starts a VM again only when a session or warm start asks for one (S06-06-devices-and-warm-startS06-06-devices-and-warm-start: Devices, Warm Start and TimeA VM's devices and resources, saving and restoring its state, and how the guest clock follows the host., “Warm start”).

A start that fails because the old VM is still stopping is a temporary failure. wb-hostd retries it a bounded number of times, as for a restore.

An upgrade takes the same path as a crash:

  1. the installer replaces the bundle (S17-05-upgrades-and-migrationsS17-05-upgrades-and-migrations: Upgrades and MigrationsHow an upgrade replaces the bundle, and how wb-hostd moves stored data to a new version., “Upgrades”);
  2. the running wb-hostd exits;
  3. the service manager starts the new one;
  4. the running VMs stop, with their sessions lost.

wb-hostd notices a replaced bundle itself and restarts. It reads the installed bundle’s build version (S17-install-and-upgradeS17-install-and-upgrade: Install, Downloads and UpgradesBuild, install, upgrade and remove a Wraith Box bundle, move its stored data to a new version, and download what an image build needs from the internet.):

  • on macOS from the WBBuildVersion key of the app bundle’s Info.plist;
  • elsewhere from the file wraithbox-version next to the programs.

It reads it when a host peer reports a build version other than its own (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., “Version skew”), and before it starts a daemon. Then:

  • The installed version isn’t its own. It logs the rule bundle-replaced with both versions and exits. The service manager starts the new wb-hostd. A daemon refused this way doesn’t count as an exit toward the restart limit.
  • The installed version is its own, and the peer’s isn’t. The peer is refused. A daemon refused this way counts as a failed start.
  • It can’t read the installed version. It logs that with the rule bundle-version-unreadable, treats the installed version as its own, and doesn’t exit. wb status shows it. So a damaged bundle can’t make wb-hostd exit in a loop.

wb-hostd restarts wb-proxyd, and each VM’s wb-netd except the build VM’s (“A new wb-netd”, below), after an exit it didn’t ask for.

  • Backoff. It waits 0.5 seconds before the first restart, and doubles the wait after each one, up to 30 seconds.
  • Giving up. After the fifth exit in 10 minutes it stops restarting that process. It logs that it gave up, with the last exit reason. So a crash a guest can cause doesn’t become a stream of fresh processes.
  • After giving up. A wb-netd it gave up on leaves its VM without network until the VM stops, and the VM’s next start gets a new one. A wb-proxyd it gave up on is tried once more at the next session start in any VM.
  • Refusals. Once it gives up, every session start that needs the process is refused with the rule daemon-given-up. The refusal names the process, the VM, its last exit reason, and what starts it again: stopping the VM for wb-netd, the next session start for wb-proxyd (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.).
  • No path around. The guest sees resets and refusals while a daemon is down, never a path around it. Nothing else on the host forwards guest traffic.

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).) none is restarted (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., “No restart yet”).

A new wb-netd gets the same start as the first one:

  • its VM’s packet transport descriptor;
  • the VM’s MAC address and leased address;
  • the effective policy;
  • the VM’s synthetic name mapping and its counts (“What a restart keeps”, below);
  • a new hand-off socket to wb-proxyd, except for the build VM, whose wb-netd has none.

The guest keeps its lease, and its cached DNS answers still work.

wb-hostd never restarts the build VM’s wb-netd. When it exits, the image build fails with its exit reason (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.).

wb-hostd keeps its copy of each VM’s packet transport descriptor only to hand it to a new wb-netd. It holds the copy in a type that has no read or write path. It closes it when the VM stops, and when a restore hands over a new descriptor for a new VM generation.

A restart doesn’t reset what bounds the guest.

wb-hostd keeps each VM’s synthetic name mapping too: every live entry, with its name, its address, and the time wb-hostd received its last record.

Without them, an address the guest still has cached for one name could go to another. A raw or pass-mode stream meant for the first would then reach the second.

A new wb-proxyd has no streams. It fetches binding secrets again when proxying needs them (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-hostd hands it each running VM’s placeholder set on its control channel, before it creates that VM’s new hand-off socket. So the placeholder scan has every placeholder before the first stream arrives (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 each restore of a suspended VM, wb-hostd hands back the VM’s set the same way, before it creates the VM’s hand-off socket.

A wb-netd restart gives its VM a new hand-off socket, for the same generation. A wb-proxyd restart gives one to every running VM. S07-20-handoff-socketsS07-20-handoff-sockets: Hand-off SocketsThe life of one VM's hand-off socket: its identity, the acknowledgments of both ends, how it closes, who a failure is charged to, what each restart does to it, and which of its decisions reach the audit log. (“Generations and restarts”) has the order and the socket numbers.

Every wb-netd gets its end on its control channel after its start message (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 a message with exactly one descriptor and the VM, generation and socket number. It refuses the message, with handoff-socket-refused, when the socket type is wrong, the VM or generation isn’t its own, or the number isn’t above the one it holds. It then closes the descriptor and logs the refusal, and the control channel goes on. A message with another descriptor count than one is of the wrong form: every descriptor in it is closed, and the control channel ends.

On each new socket, wb-netd first replays the VM’s live mapping, so that wb-proxyd has it again (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., “Replay”).

wb-hostd shows a native notification once per outage of a VM’s wb-netd or wb-proxyd. It asks for nothing (SEC14-no-fake-approvalsSEC14-no-fake-approvals: Approvals cannot be spoofed by the guestApproval prompts are never rendered in the agent's terminal stream.). It says:

Only the 1Password backend, after V1V1-initial: Initial versionThe first version: what it delivers, what it leaves out, and the milestones that get there. (S15-02-secret-storeS15-02-secret-store: The Secret StoreWhere credentials are held: the secret store, its backends, and the guarantees a backend must give.), can prompt for those accesses. The Keychain doesn’t show a dialog in any build (S15-03-access-rulesS15-03-access-rules: Access RulesHow each host process gets only the credentials it needs, for only as long as it needs them, and which process may access which item., access rule 4).

One wb-proxyd serves both VMs. These take the network of the other VM down too:

Neither a VM’s normal stop nor its stop for the audit log ends it (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., 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.). That is a residual risk to availability, not to egress (T14-shared-proxydT14-shared-proxyd: One proxy process serves both VMsOne wb-proxyd serves the work VM and the isolated VM (S04-architecture, "Processes").).

Status: Draft