Skip to content

S07-01 - Enforced per VM

Purpose: Why the VM is the unit the gateway enforces, how the policies of its projects combine, and what happens when they conflict or change.

A VM has one guest MAC address and one leased IPv4 address (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”). Every project user in it sends from them. In this spec a session is any session wb-hostd starts for a project, a debug shell (wb shell) included.

The recipe VM’s policy is the build policy alone (S06-17-named-imagesS06-17-named-images: Named Images and RecipesThe build of a named image from a recipe on a clone of the sealed base.). A session VM’s effective policy is the union of:

wb-hostd recomputes it whenever a session starts or ends. A project’s allow rules and bindings leave the effective policy when its last session in the VM ends. Its denies, limits and modes leave under the rules of “Session end”.

Projects can set a limit, such as the wildcard budget, the minimum age or the vulnerability threshold. The VM gets the strictest value among them.

When one project sets a host to enforce and another to audit, the VM gets enforce. The join notice and the audit event name the host and both projects.

A host in pass mode for one project and inspected for another is a conflict (“Conflicts refuse the joining session”).

At each recompute wb-hostd checks the union. It refuses the session start that would create one of these conflicts, with an error that names both projects and the host (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.):

wb-hostd never settles a conflict by weakening a mode or by picking one binding. A check that fails or can’t run refuses the start too (fail closed).

A policy file can change while sessions of its project run.

A change narrows when the new union allows a subset of what the old union allowed. No request, host, method, path, credential injection or mode that the old union refused becomes allowed.

These narrow, unless the change moves a host and port to audit:

  • removing an allow rule, a binding or an approval;
  • tightening a limit or a mode;
  • removing a raw TCP entry.

These widen:

Every other change widens, including one that narrows in part.

A change that narrows applies at once, without the union checks. A subset of a union inside the boundary is inside it too, and doesn’t add reach.

  • If it leaves a host in pass mode for one project and inspected for another, the VM inspects it. The 5019 event names the host and both projects.
  • A raw TCP stream can’t be inspected. So if it leaves a host and port named in a raw TCP entry for one project and expecting another protocol for another, the VM drops the raw TCP entry and closes its relays. The 5019 event names the host, the port, and both projects.

Open streams are then checked again (“Open streams”).

A change that widens goes through the same checks as a joining session. If one fails or can’t run:

  • the change is refused, and logged with the project and rule that caused it;
  • the VM keeps its last effective policy that passed;
  • wb policy explain shows the change as pending.

The user can still apply a removal as a change of its own. When a refused change narrows in part, the refusal and wb policy explain name the narrowing part. They say “apply the removal on its own to revoke it now” (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.).

Such a removal applies at once, as other removals do, so revoking a rule never waits for the prover.

  1. The host and port’s enforce mode is kept as a held source (“Session end”) while the checks run. It holds no rule from the removed endpoint.
  2. The held source is dropped when the checks pass. It stays when they fail or can’t run.
  3. The 5019 event and wb policy explain show it. It stays until a recompute without it passes, or the active period ends.

When a project’s last session in the VM ends, its allow rules and bindings leave the union at once. So do the approvals whose session set has fully ended.

That part only narrows, unless it moves a host and port to audit (see the list below).

The rest of what the project set can widen the union when it leaves. The recompute widens when any of these leave with it:

  • a deny_rules entry;
  • a limit the project held at the strictest value;
  • a part it turned off;
  • enforce that any of its endpoints or approvals gave a host and port that another source puts in audit, which then resolves to audit;
  • inspection it set on a host another project puts in pass mode, which the VM inspected (“Policy changes while sessions run”);
  • another protocol it set on a host and port that another project names in a raw TCP entry, which the VM dropped (“Policy changes while sessions run”).

A recompute that widens goes through the extension check and the boundary check of a joining session. The join risk check doesn’t run, because no project joins.

If a check fails or can’t run, the VM keeps a held source: the departing project’s deny_rules, limits, modes and parts that are off.

  • An enforce mode is held alone. The host and port stays in enforce, and the allow rules and approvals that gave it leave.
  • A Device Config State Change (5019) event names the project that left and the rule that failed.
  • wb policy explain shows the held source and the widening as pending.

The held source stays until a recompute without it passes, or the active period ends.

A project can join while a held source exists, a held enforce mode from a removal while sessions run (“Policy changes while sessions run”) included.

  1. wb-hostd runs the extension check, the boundary check and the risk check on the union without the held source.
  2. It drops the held source only if all three pass.
  3. Otherwise the held source stays through the join, and the risk check runs on the union with it.

The join approval is cached on the union without the held source (S09-09-approvalsS09-09-approvals: ApprovalsWhat an approval adds, the checks that each request goes through, and approvals for a joining project., “Join approval”).

After each recompute, wb-proxyd checks every open stream of the VM against the new effective policy. An open stream is a WebSocket, an HTTP/2 connection, a pass relay, a raw TCP relay (S07-15-non-http-streamsS07-15-non-http-streams: Non-HTTP StreamsHow wb-proxyd checks the protocol of each stream, and what it does with SSH, other protocols and raw TCP.), a server-sent event stream, or a held download.

A stream whose allow rule, mode or binding is gone is closed. It is logged with the rule policy-recomputed. So a project’s bindings can’t be reached while none of its sessions run.

At session start, wb prints the other projects with a session in the VM. It prints the credential bindings and write grants of theirs that the new session can reach, and those of the new project that they can reach.

wb status lists the same reach for each VM. Each recompute is a Device Config State Change (5019) event that names the projects that joined or left (SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter.).

These stay per project: the project’s policy file and settings on the host, its guest user and clone (S06-vm-lifecycleS06-vm-lifecycle: VM Lifecycle, Images and the Guest AgentHow guest images are built, how VMs are kept warm, how projects and sessions map onto guests, and what wb-guestd does.), and its landing repository, with the ref restriction per session (S08-workspace-and-gitS08-workspace-and-git: Workspace and Git Round TripHow code gets into the guest and how the agent's work gets back out, without sharing the host filesystem.).

Pushes of returned work go over the host-guest socket, not through this gateway.

Per-project, per-session and per-program rules can only narrow the effective policy. They use a label the guest reports for each flow (S13-guest-confinementS13-guest-confinement: Guest ConfinementControls inside the guest that narrow what a project user's processes can do, and tell the host which program opened each connection.).

Until X14-flow-attributionX14-flow-attribution: Guest flow attributionA Network Extension transparent proxy in a macOS guest (S13-guest-confinement): can it be approved during the image build without MDM? delivers labels, nothing narrows the effective policy.

Any process in a VM can use the grants of every project with a session in it: their credential bindings, their write grants under the git hosting profile, their dependency-gate overrides, and their approvals.

The projects also share the VM’s limits (T11-shared-vm-grantsT11-shared-vm-grants: Projects in one VM share network grantsThe host sees one guest address per VM, and can't tell which project user, session or program opened a connection.). A project whose grants must stay apart is set to placement = isolated. wb-hostd then gives it the isolated VM to itself (S06-04-vms-and-placementS06-04-vms-and-placement: VMs and PlacementThe work VM and the isolated VM, Xcode in them, and which VM a project's sessions run in.).

The wildcard budget is counted per active period. That is from the first session start in the VM to the end of the last session running in it.

The gateway enforces policy per VM, not per project, session or program.

wb-hostd refuses the session start or the change. It doesn’t weaken a mode or pick one binding, and a check that can’t run refuses too.

  • Why: fail closed.

Status: Draft