Skip to content

S07-20 - Hand-off Sockets

Purpose: The 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.

Requirements: SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another., SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter., SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.

Tests: C02-streams-and-tlsC02-streams-and-tls: Streams, TLS, and the Inspection CAThe test cases for the streams wb-proxyd takes over: the hand-off from wb-netd, the first-byte and TLS checks, upstream addresses, the HTTP request form, and the inspection CA's leaves, rotation, and keys., 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…

Brief: B754-handoff-contractB754-handoff-contract: What happens to one VM's hand-off socket, from its creation to its end?S04-12-descriptor-passing, S07-20-handoff-sockets and S07-21-vm-end settle the hand-off contract in one place.

wb-netd wb-hostd wb-proxyd 1. HandoffSocket n, an end 2. HandoffSocketAck n 3. HandoffSocket n, the other end 4. HandoffSocketHeld n 5. serving: the VM starts or resumes streams and name reports, on socket n HandoffSocketClosed n, rule ends this VM's wb-netd or, at a VM stop, before wb-netd stops: HandoffSocketEnd up to n, stop HandoffSocketEnded, last event record s
wb-hostd makes each hand-off socket, passes one end to wb-proxyd and, after its acknowledgment, the other to the VM's wb-netd. Each end acknowledges with the socket's number. wb-proxyd reports a socket it closes, and acknowledges the end of a VM's sockets at its stop.

A hand-off socket carries a VM’s streams and name reports from its wb-netd to wb-proxyd (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.). These values name it:

Every message about a socket names all three, except on wb-netd’s control channel, whose VM is its own. Waits and state are keyed by all three. A replacement in the same generation is a new socket, so nothing meant for the old one reaches it.

These are messages of proto/wraithbox/egress/v1/control.proto. The last column says which ones I728I728 (closed): Hand-off socket contract of S07-20: socket number, HandoffSocketHeld, states, close reports, and a VM's endBuilds the hand-off socket contract of S07-20-handoff-sockets and the end exchange of S07-21-vm-end (#754, PR #758) in one change, before #480. adds, with the socket number in each, and 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. has the last two.

Message From Means Added by
HandoffSocket wb-hostd here is an end, with its VM, generation and number the number
HandoffSocketAck wb-proxyd it holds the end it names the number
HandoffSocketHeld wb-netd it holds the end it names I728I728 (closed): Hand-off socket contract of S07-20: socket number, HandoffSocketHeld, states, close reports, and a VM's endBuilds the hand-off socket contract of S07-20-handoff-sockets and the end exchange of S07-21-vm-end (#754, PR #758) in one change, before #480.
HandoffSocketClosed wb-proxyd it closed the socket it names, with a rule and a check the number and two rules
HandoffSocketEnd wb-hostd close the VM’s sockets up to a number, and whether the VM stops I728I728 (closed): Hand-off socket contract of S07-20: socket number, HandoffSocketHeld, states, close reports, and a VM's endBuilds the hand-off socket contract of S07-20-handoff-sockets and the end exchange of S07-21-vm-end (#754, PR #758) in one change, before #480.
HandoffSocketEnded wb-proxyd it closed them, and at a stop its last event record I728I728 (closed): Hand-off socket contract of S07-20: socket number, HandoffSocketHeld, states, close reports, and a VM's endBuilds the hand-off socket contract of S07-20-handoff-sockets and the end exchange of S07-21-vm-end (#754, PR #758) in one change, before #480.

wb-hostd keeps one state per socket:

State Entered when wb-hostd holds
offered it sent HandoffSocket to wb-proxyd both ends
acknowledged HandoffSocketAck came, and it sent wb-netd its end wb-netd’s end
serving HandoffSocketHeld came nothing
failed a deadline passed, or a HandoffSocketClosed came before serving nothing
closed HandoffSocketClosed came while serving nothing
replaced it offered a newer socket for the VM nothing
ended its wb-netd exited or was ended, or wb-hostd sent a HandoffSocketEnd that covers it nothing

The last four are final. A VM has at most one socket that isn’t final. A VM starts or resumes only once its socket is serving. The build VM has no hand-off socket (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.).

Each wait from offered and from acknowledged has a deadline in code (egress.AckTimeout), and wb-hostd holds its copies until then (S04-12-descriptor-passingS04-12-descriptor-passing: Passing DescriptorsHow one host process passes an open socket to another: who holds it when, how the receiver shows it holds it, when the sender closes its copy, and what a lost or bad acknowledgment does.). When a socket fails, wb-hostd closes its copies and sends a socket end for 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.), so wb-proxyd doesn’t keep it open. At a start or restore it refuses the start with proxyd-setup-failed and the check: ack-timeout, held-timeout, or handoff-closed. For a running VM, “Who a failure is charged to” says what it does.

wb-hostd sorts each HandoffSocketAck, HandoffSocketHeld and HandoffSocketClosed by the socket it names:

A notice never fails or ends a socket other than the one it names. So an old socket’s notice can’t end its replacement’s wb-netd. A socket that failed by its deadline holds nothing back, as the next one has a new number. HandoffSocketEnded is never stale (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.).

wb-proxyd checks a HandoffSocket 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. (“From wb-hostd”) says. With the socket it accepts, in this order, it:

  1. closes the VM’s old socket and every stream that came on it;
  2. clears the VM’s state when the message is fresh (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., “Lifetime”);
  3. sends its version record on the new socket;
  4. sends HandoffSocketAck;
  5. starts the socket’s reader.

So no HandoffSocketClosed for the socket comes before its acknowledgment. If step 3 fails, it closes the socket and sends HandoffSocketClosed instead of the acknowledgment.

A close never waits on a write to a peer. A write in progress on a stream or a socket that closes ends with an error at once. So the acknowledgment deadline covers these steps alone, and a wb-netd that stops reading can’t make another VM’s socket miss it.

A HandoffSocketClosed or HandoffSocketEnded that wb-proxyd can’t send ends its control channel, as a write that fails does (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., “Control channels”). So no socket it closed goes unreported.

wb-netd checks its HandoffSocket as 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”) says. Once it holds the end and sent its version record on it, it sends HandoffSocketHeld with the generation and number. It sends nothing for an end it refuses or can’t send that record on. A newer end replaces the old one, whose streams it resets (handoff-socket-ended).

No fault on a socket ends wb-proxyd’s control channel. It ends for a fault in a message from wb-hostd: its form, its socket type, its VM slot, its generation or its number, 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. (“From wb-hostd”) lists them (I576I576 (closed): wb-proxyd: one VM's failed hand-off socket ends the control channel for every VMIn wb-proxyd's hand-off receiver (#492, PR #574), a failure on one VM's new hand-off socket ends the whole control channel, and with it every VM's sockets and streams.). wb-hostd is the trusted core, so such a fault is a bug in it. It also ends for wb-proxyd’s own faults on the channel: a notice wb-hostd refuses (“Notices for another socket”), or one it can’t send (“wb-proxyd’s end”).

Anything that goes wrong on a socket after wb-proxyd accepted it closes that socket only, with its streams. wb-proxyd reports it in one HandoffSocketClosed, and other VMs’ sockets go on.

wb-proxyd closes a VM’s socket, with every stream that came on it, for one of these rules:

Rule Check Cause Charged to
name-report-malformed message-form, name-form, synthetic-range 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., “Malformed reports” wb-netd
stream-reset-unsent buffer-full, deadline a StreamReset it can’t send, for want of room (ENOBUFS, EAGAIN) or by its deadline (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., “Resets”) wb-netd
handoff-socket-ended peer-closed, control-cut wb-netd closed or shut down its end, a StreamReset’s send failed with an error the other rows don’t name (such as EINVAL or EDESTADDRREQ), or wb-netd sent control data that was cut wb-netd
handoff-socket-ended receive-failed, version-record a receive failed with an error, or step 3 above failed wb-proxyd
handoff-socket-ended send-failed a StreamReset’s send failed with EBADF, ENOMEM, ENOTSOCK or EFAULT, faults of wb-proxyd or the host wb-proxyd

For each, it sends one HandoffSocketClosed with the rule and the check, for the VM, generation and number. wb-netd resets every stream of a socket that closed (handoff-socket-ended). A socket that is replaced or ended sends no HandoffSocketClosed.

A guest can cause each failure charged to wb-netd, through a wb-netd it compromised or one it slows down. For one on a running VM, wb-hostd ends the wb-netd the socket was given to, with handoff-netd-ended and the rule or check as the cause. The exit counts toward wb-netd’s restart limit (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., “Restarting a daemon”). A held-timeout is charged the same way, as wb-netd withheld its acknowledgment.

A failure charged to wb-proxyd is a fault of wb-proxyd or the host, which no wb-netd can cause. For one on a running VM, wb-hostd ends wb-proxyd with handoff-proxyd-ended and the check. An ack-timeout is charged the same way. The exit counts toward wb-proxyd’s restart limit, and never toward a wb-netd’s.

wb-proxyd raises its descriptor limit at its start to cover every descriptor the wb-netds of all VM slots can make it hold at once. Per slot that is its hand-off socket, three for each stream (DescriptorsPerStream), one for each message read but not yet decided under 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. (“Caps”), and the most descriptors one message holds (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”). A margin in code covers its own. If it can’t, it logs proxyd-descriptor-limit and exits, as wb-netd does for a failed start check (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.). So one VM at its caps can’t make the other’s records arrive at a full descriptor table.

Event Generation New socket, with a new number Fresh
a start that isn’t a restore new for the VM yes
a restore new for the VM, with 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., “Restore”) no
a wb-netd restart kept for the VM no
a wb-proxyd restart kept for every running VM no
a new active period kept none: ActivePeriodStart only no

A socket for a kept generation replaces the old one. After a wb-proxyd restart it holds no socket, and each VM’s first sets the generation and number it holds. 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. (“Lifetime”) says which HandoffSocket is fresh.

Each stream’s socket is bounded in time where it can stall:

A stream isn’t bounded in time while neither side sends, or while a raw or pass relay’s write blocks after upstream ended. Inspected streams have their own timeouts, but an inspected host’s WebSocket relay has no write bound upstream (I980I980 (open): wb-proxyd: bound a relay's write upstream once its stream socket's writes are shutIn that state, if the guest has filled the relay toward an upstream that doesn't read, the relay blocks in its write upstream, and wb-netd's close of the socket isn't seen.). Such a stream holds its place under 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. (“Caps”) and 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. (“Per-VM caps”).

A decision about a stream, a name report or a socket is an egress decision (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 is recorded on the host). The process that makes it sends it on the VM’s event channel with its rule, rate-limited per rule (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”). That includes wb-netd’s hand-off sender. A decision’s record is queued before the bytes it allows are forwarded.

Process Rules it records
wb-netd handoff-send-failed, handoff-unavailable, handoff-socket-refused, stream-refused, stream-reset, guest-write-timeout, guest-write-failed, proxyd-stream-read-failed, handoff-socket-ended, proxyd-message-refused
wb-proxyd handoff-socket-refused, name-report-refused, stream-handoff-refused, fdchan-fd-table-full, address-conflict, stream-write-timeout, stream-hangup-wait-failed, stream-end-unrecorded, and each rule of “Closing a socket”
wb-hostd proxyd-setup-failed, handoff-netd-ended, handoff-proxyd-ended, handoff-end-timeout, handoff-end-read-timeout, proxyd-records-lost

wb-hostd writes its own decisions to the audit log itself. Some rules go only to the daemon log of the process that logs them, because they decide nothing about a guest’s traffic. wb-hostd logs handoff-notice-stale and handoff-stop-end-skipped. wb-netd logs stream-hold-expired and stream-reset-unknown. wb-proxyd logs handoff-socket-end, vm-fresh-start, active-period-start, stream-peer-closed and wildcard-name-rewritten. proxyd-descriptor-limit is a start check of wb-proxyd. Its log line reaches wb-hostd on the log pipe, and the exit counts toward the restart limit.

Two processes record handoff-socket-ended and handoff-socket-refused, each with its own meaning. The record’s sender, which wb-hostd stamps from the channel, tells them apart, so a reader keys on the sender and the rule together. A wb-netd can only send records about its own VM. So a compromised one can suppress its own refusals, but not a decision of wb-proxyd or wb-hostd.

wb-hostd numbers each hand-off socket, and every message about one names it.

After wb-proxyd accepts a socket, a failure on it closes that socket only and is reported. wb-hostd ends the daemon the failure is charged to. No fault on a socket ends the control channel.

Status: Draft