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.
Design
Section titled “Design”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..
One protocol per host and port
Section titled “One protocol per host and port”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”).
First bytes
Section titled “First bytes”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.
- On a TLS port the stream must start with a TLS handshake record that holds a ClientHello. It is read by the ClientHello parser of 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., “Name binding”. The parser reassembles a ClientHello split across more than one record.
- On port 80 the stream must start with an HTTP/1.1 or HTTP/1.0 request line. An HTTP/2 connection preface is reset, because 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. (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., “Request form”) parses HTTP/2 only inside TLS.
- The byte cap. The check reads at most a byte count fixed in code
(SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.). A stream that doesn’t match by then, or
whose bytes are another protocol, is reset with the rule
stream-protocol-mismatch. - The deadline. A deadline fixed in code runs from the moment
wb-netdhands the stream over to the decision. A stream that isn’t decided by then is reset with the rulestream-first-bytes-timeout. That holds whether its client didn’t send or sent too slowly.
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.
Logging a reset
Section titled “Logging a reset”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.
- Resets and refusals are rate-limited per rule, like the other events the guest can trigger (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”).
wb policy explainshows the refusal with its rule, and the policy change that would allow it, if any (NFR06-explained-refusalsNFR06-explained-refusals: OperabilityEvery refusal names the rule that caused it and how to change it.).- The guest sees a TCP reset.
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.
Inside TLS on an inspected host
Section titled “Inside TLS on an inspected host”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.
- The handshake runs under the deadline that runs from the
hand-off, as on a plain port. A handshake that fails resets the
stream:
- a received
ech_requiredalert withtls-ech-refused(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., “Encrypted ClientHello”); - any other alert from the client, or the client’s close after the
server’s flight and before its first request byte, with
tls-client-rejected-leaf. The record holds the name, the port, and the alert’s description orclosed. It names FR08-no-proxy-configFR08-no-proxy-config: No per-tool proxy settingsAllowlisted network destinations work for every tool without per-tool proxy configuration., whose known gap is the usual cause: a client that doesn’t trust the VM’s CA (S09-08-guest-trustS09-08-guest-trust: Guest TrustHow wb-guestd makes the guest's clients trust the VM's CAs., “Fails closed”); - the deadline with
stream-first-bytes-timeout, and anything else, such as a malformed record, withstream-protocol-mismatch.
- a received
- After the handshake the bytes must start with an HTTP/1.1 or
HTTP/1.0 request line. The byte cap applies, and the same deadline
runs on. Only then does
wb-proxydhand the stream to the HTTP checks, which resolve and connect upstream at the first request that passes them. - Each request on the stream has a deadline fixed in code, from its
first byte to the end of its headers. For the first request it runs
from the hand-over to the HTTP checks. A request past it ends the
stream with the rule
http-header-timeout(SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.). The other bounds of an HTTP/1.1 stream are in “HTTP/1.1 connections”, below. - Protocol switches. An upstream
101 Switching Protocolsanswer resets the stream with the rulehttp-tunnel. The exception is a WebSocket upgrade that the host’s policy allowed, answered withUpgrade: websocket. It relays both ways unchanged. Each policy recompute checks it again (“HTTP/1.1 connections”).
HTTP/1.1 connections
Section titled “HTTP/1.1 connections”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.
Upstream failures
Section titled “Upstream failures”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”):
- a forge that a built-in kind or a project’s remote names;
- the SSH hosts of the built-in kinds, such as
ssh.github.com(S07-11-http-policyS07-11-http-policy: HTTP PolicyThe HTTP rules of inspected hosts, the built-in profiles, and the parts a user can turn off., “git hosting”).
The guest doesn’t need SSH:
- It has no SSH keys (SEC04-no-guest-secretsSEC04-no-guest-secrets: No secrets in the guestThis includes the model credential.).
- The guest’s clone gets each SSH remote rewritten to
https://host/path(S08-01-into-the-guestS08-01-into-the-guest: Into the GuestHow the project's code reaches the guest: the clone, its transport, its remotes, and the uncommitted changes carried in at session start., “Remote URLs”).
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.
Other protocols on allowed ports
Section titled “Other protocols on allowed ports”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.
Raw TCP entries
Section titled “Raw TCP entries”A raw TCP entry names one host and one port. The entry allows that host and port by itself.
- The host doesn’t need another rule. Its name resolves for the guest once an entry names it.
wb-proxydresolves the host itself. It connects to that port under 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., “Upstream address”.- It relays bytes both ways unchanged, with no first-byte check. A server-first protocol works there.
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”):
- One named host. The entry names one exact host and one port. A wildcard host, an IP literal (S07-03-dnsS07-03-dns: DNSHow wb-netd answers the guest's DNS queries: synthetic addresses, the name form, negative answers and the wildcard budget., “IP literals”) or a port range is refused at load. The hostname comes from the synthetic address, which is the only name binding a raw stream has.
- Only the user sets it. Only the global policy or a project’s
network policy on the host adds one (S09-policy-credentials-auditS09-policy-credentials-audit: Policy, Credentials, Certificates and AuditWhere policy comes from, how secrets are held, how TLS inspection is trusted, and what is recorded.).
Repository configuration, an approval,
wb allow, and learn mode never do (SEC09-host-policySEC09-host-policy: Policy is held on the hostThe guest cannot read or change policy., S07-17-approvals-and-learningS07-17-approvals-and-learning: Approvals and LearningHow an unknown destination reaches the user as an approval request, what an approval grants, and how learn mode collects names.). - A reason for each. An entry without a reason is refused at load.
wb policy explainlists every raw TCP entry with its host, port, file and reason. - Never on a guarded host. A guarded host can’t have a raw TCP entry on any port (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., “Guarded hosts”). The same checks as for a pass host apply: at load, at every recompute over the union, and when a binding is added later. So git hosting, the model API and the package registries are reached only over inspected TLS (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., SEC07-dep-gateSEC07-dep-gate: Dependency gatePackage downloads (npm, PyPI, Go modules, crates) are refused when the version is younger than a minimum age or has a known vulnerability at or above a severity threshold.).
- Audited. Each policy change that adds a raw TCP entry is a Device Config State Change (5019) event, with the host, the port, the file and the reason (SEC10-auditSEC10-audit: AuditEvery egress decision, approval, and returned change is recorded on the host in a persisted log the guest cannot alter.).
- Residual channel.
wb-proxydcan’t read the bytes of a raw stream. So each entry 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, as a pass host is.
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.
Decisions
Section titled “Decisions”Check the first bytes of every stream
Section titled “Check the first bytes of every stream”wb-proxyd resets a stream that is neither TLS nor HTTP, unless
policy names its host and port for raw TCP.
- Why: a guest can send SSH, or any other protocol, to port 443 of an allowed host.
- Decided: I47I47 (closed): S07-egress-gateway: non-HTTP streams, SSH remotes and ECHS07-egress-gateway describes TLS and HTTP. (B47-non-http-streamsB47-non-http-streams: What does the gateway do with a connection that isn't TLS or HTTP?Reset it and audit the rule, unless policy names that host and port for raw TCP.).
Status: Draft