Skip to content

S07-15 - Non-HTTP Streams

Purpose: How wb-proxyd checks the protocol of each stream, and what it does with SSH, other protocols and raw TCP.

A guest can send SSH, or any other protocol, to port 443 of an allowed host. So wb-proxyd checks the first bytes of each stream against the protocol policy expects on that host and port. It resets a stream that is neither TLS nor HTTP, unless policy names that host and port for raw TCP. SEC05-default-denySEC05-default-deny: Default-deny egress, enforced on the hostOnly allowlisted hostnames are reachable. and SEC06-repo-writesSEC06-repo-writes: Repository-scoped writesGit pushes and repository-mutating API calls are allowed only for the repositories of the projects that have a session in the VM. hold as written.

Client certificates, ECH and tunnels are on S07-16-tls-and-tunnelsS07-16-tls-and-tunnels: TLS and TunnelsWhat wb-proxyd does with client certificates, encrypted ClientHello and tunnels, and which refusals no mode or approval relaxes..

Each host and port that the effective policy allows (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.) expects one protocol:

Port Protocol
80, when policy names host:80 plain HTTP, inspected (S07-07-hosts-and-modesS07-07-hosts-and-modes: Hosts and ModesHow wb-proxyd binds a stream to its name, which upstream addresses it refuses, and the inspect, pass and audit modes., “Modes, per host”)
a port that a raw TCP entry names (“Raw TCP entries”) raw TCP
every other allowed port TLS, inspected or passed by the host’s mode

A policy file whose rules give one host and port two of these is refused at load. In the union it is a conflict that refuses the joining session (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., “Conflicts refuse the joining session”). Both errors name the host, the port, and both sources (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.).

TCP to a port that policy doesn’t name for the host is reset by wb-netd, with the rule port-not-allowed (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., “Connections”).

On a TLS or plain HTTP port, wb-proxyd reads the first bytes of the stream before it resolves or connects upstream. So no byte of a refused stream leaves the host.

In a server-first protocol, such as SMTP or MySQL, the client waits for the server’s greeting, which never comes. Without the deadline, the stream would hang instead of failing with a reason.

Each reset is a refusal 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.). It holds the VM, the host, the port, the rule, and the protocol the first bytes looked like: ssh, tls, http, http2 or unknown. It never holds the bytes themselves.

A stream that passes its checks is logged too, once, with the rule that let it on. That rule is inspect-allowed when the stream goes to the HTTP checks of S07-08-requests-and-credentialsS07-08-requests-and-credentials: Requests and CredentialsThe form of each request wb-proxyd sends upstream, and how it removes the guest's credentials and injects bound ones., pass-allowed when a pass relay sends its ClientHello upstream, and raw-tcp-allowed when a raw TCP relay connects. A pass and a raw TCP record also name the policy entry’s source and reason. Each relay logs its end, with the bytes it relayed each way.

A stream’s end is logged once, by what ended it. When a recompute (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., “Open streams”), an address conflict or the hand-off socket’s end resets a stream, wb-proxyd stops its checks and its dial and logs nothing more for it. A connection that opens after that is closed before any byte goes upstream.

wb-proxyd offers only the ALPN protocol http/1.1, until I499I499 (open): wb-proxyd: HTTP/2 on inspected TLS streams, with the same request form, caps and steps as HTTP/1.1Package M3.6 of docs/implementation-plan.md, part 3 of 4 (M3.6c). adds h2. wb-proxyd resets a ClientHello whose ALPN list is non-empty and leaves http/1.1 out with stream-protocol-mismatch, before the handshake completes. A client with no ALPN list gets HTTP/1.1.

On an inspected HTTP/1.1 stream wb-proxyd opens the upstream connection at the first request that passes the steps of S07-08-requests-and-credentialsS07-08-requests-and-credentials: Requests and CredentialsThe form of each request wb-proxyd sends upstream, and how it removes the guest's credentials and injects bound ones., “Order of the steps”, and keeps it for the stream’s later requests. A stream whose requests are all refused opens none. These bounds are fixed in code (SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.):

Bound Value On expiry
A request’s head, from its first byte 10 s reset, http-header-timeout
From a response’s end to the next request 2 min close, http-idle-timeout
The read of the kept connection before a later request goes upstream 1 ms the request goes upstream, or 502, upstream-request-failed (“Upstream failures”)
Each pause inside a request body 30 s reset, http-body-timeout
The first write upstream on plain HTTP, the first request head 5 s 502, upstream-request-failed
Each later write upstream 30 s 502, upstream-request-failed
From a request’s end to its response head 10 min 502, upstream-request-failed
Each pause inside a response body 5 min reset, upstream-request-failed

Each recompute checks the request whose response is in flight, a WebSocket relay or a server-sent event stream included, and resets the stream when the new policy no longer allows it (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., “Open streams”). Between requests there is nothing to check, because the next request passes the steps under the policy in effect when it arrives. Once a later request passed the steps, the check runs on it once more under the policy in effect, so a recompute that landed while the steps ran still resets the stream.

The policy step gives this check, and without one every request gets http-step-missing and none goes upstream. A nil check fails as http-open-check-missing, and the stream is reset with policy-recomputed. The step that holds a request’s binding, the injection step, must also fail the check when that binding is gone or changed. This page only states that contract.

A body has no total cap: it streams through with constant memory. A response head, with the interim answers before it, is capped at 1 MiB, and one over the cap gets a 502 with upstream-request-failed.

A refusal answers with a short text/plain body that names the rule and the host, never the guest’s bytes, and Connection: close. The stream ends after it, and the refusal is logged with its rule.

An upstream connection that fails to open gets a 502 that names its rule (S07-07-hosts-and-modesS07-07-hosts-and-modes: Hosts and ModesHow wb-proxyd binds a stream to its name, which upstream addresses it refuses, and the inspect, pass and audit modes.). The answer never holds the error’s text, which can hold names from the server’s certificate. When the upstream fails before its response began, the guest gets a 502 with the rule upstream-request-failed. A response body that breaks off resets the stream, so the guest can’t take it for whole.

A kept connection that the server closed before any byte of the response is the exception: wb-proxyd closes the stream to the guest with no answer, as a server’s idle close would, and logs it with upstream-idle-close. The client retries on a new stream.

wb-proxyd reads the kept connection while the stream waits for the next request. The server’s close then closes the stream at once, unless the next request’s first byte has arrived. From that byte the server’s close no longer ends the stream at once: the request’s handling does, and a refusal keeps its answer and its record.

Before a later request goes upstream, pipelined or not, wb-proxyd reads the connection once more for at most 1 ms. A read that times out may not have reached the socket, so wb-proxyd then counts the socket’s unread bytes (S12-01-platform-interfacesS12-01-platform-interfaces: Platform InterfacesHow platform-specific code is isolated behind interfaces, and what each host OS uses for each., “Socket receive queue”), and reads again a bounded number of times while there are some. Bytes a read sees, or a count that stays above zero or fails, get the request a 502 with upstream-request-failed. A close with no data counts zero, and the request ends as upstream-idle-close. Bytes reaching the socket after the count, or a TLS record’s rest, are read as the response’s start.

The response goes to the guest with HTTP/1.1, the reason phrase of its status code, the server’s fields without the hop-by-hop ones, through the response step, and with the framing wb-proxyd sends the body with. Interim 1xx answers other than 101 are dropped, at most 16 of them. An upstream Connection: close, a body that runs to the connection’s end, or a body the guest can’t read the end of, such as an unframed body to an HTTP/1.0 client, closes the guest’s stream after the response.

SSH to a git forge is refused.

SSH reaches a host only through a raw TCP entry. Every other allowed port expects TLS or HTTP, and SSH fails the first-byte check there.

These are guarded hosts, which can’t have a raw TCP entry (“Raw TCP entries”):

The guest doesn’t need SSH:

So every push to a forge that a built-in kind or a project’s remote names goes over HTTPS through the git hosting profile. SEC06-repo-writesSEC06-repo-writes: Repository-scoped writesGit pushes and repository-mutating API calls are allowed only for the repositories of the projects that have a session in the VM. holds for it.

A forge that nothing names, reached through a raw TCP entry the user added, is a T01-allowed-channelsT01-allowed-channels: Data through allowed channelsData sent through allowed operations to allowed destinations, for example a push to an allowed repository that is public, or prompt content sent to the model provider. channel like any raw TCP entry.

A database protocol, SMTP, or any other protocol sent to a TLS or HTTP port is reset as above.

A protocol that starts in plain text and switches to TLS is reset too. Examples are PostgreSQL’s SSLRequest and SMTP’s STARTTLS.

A user who needs such a host adds a raw TCP entry.

A raw TCP entry names one host and one port. The entry allows that host and port by itself.

An entry is in the same class as a pass host, with the same restrictions (S07-07-hosts-and-modesS07-07-hosts-and-modes: Hosts and ModesHow wb-proxyd binds a stream to its name, which upstream addresses it refuses, and the inspect, pass and audit modes., “pass”):

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. lists the raw TCP cases of a conflict, of a change while sessions run, and of a session end. 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., “Open streams” closes a raw relay whose entry is gone.

wb-proxyd resets a stream that is neither TLS nor HTTP, unless policy names its host and port for raw TCP.

Status: Draft