Files
w3cjandClaude Opus 5.5 f37c70a5cd fix(bounds): bound what a VM can make the host hold
Five bounds, each with a test that failed first. Long downloads,
WebSockets, slow streams and SSE are never cut: every bound is on what a
connection holds, never on how long it lasts.

- _qemu connect (Linux): each guest connection to the proxy was a host
  process with no cap. Connect now takes one of connectMax (256) slots,
  lock files in the VM's run/proxy.slots (paths.VM.Proxy(".slots")),
  each process about 7.7 MB, so about 2 GB per hostile VM. A connection
  past them gets an HTTP 503 (connectsFullReply) and closes before it
  dials; QEMU's stderr says qemu_connects_full at most once a minute,
  decided under full.lock so refusals at once say it once. A VM started
  before keeps the two-argument form, unbounded until its next start.
  No idle timeout or byte bound: the proxy bounds what each carries.
  TestConnectSlots.
- The VM proxy (limits.go):
  - maxConns (2048, twice maxConnects so a CONNECT still gets its 503
    first) counts a connection from its first request with the VM's
    password (conns.admit, via httpServer's ConnContext); a request past
    it gets 503 and the connection closes. Connections without the
    password wait in a pool of maxWaiting (128) where a new one closes
    the oldest, so holding connections can't take a VM's room (a host-speed flood still slows it
    through the accept queue: listed in design.md).
  - maxRequests (2048) requests upstream at once, plain HTTP's and
    intercepted tunnels' (requests.take), 503 past it: per-tunnel
    HTTP/2 streams alone allowed ~100,000 upstream connections.
  - each limit logs once a minute at most (everyMinute).
  - httpServer adds IdleTimeout (10 min); a 407 closes its connection;
    handleHTTP's WithoutCancel is replaced by whileHeard, which ends a
    plain HTTP request once its client has stopped sending and goneWait
    (1 min) passes with nothing written, so half-closing clients still
    get answers that keep coming; quiet WebSockets aren't cut.
  - heardWriter.Unwrap: plain ws:// upgrades got 502 (pre-existing) and
    get 101.
  - No ResponseHeaderTimeout: non-streaming LLM requests wait minutes
    for headers, and a waiting client is counted.
  Tests: TestProxyLimitsSet, TestProxyConnectionBounds,
  TestProxyConnectionLimit, TestProxyWaitingConnections,
  TestUpstreamRequestLimit, TestUpstreamRequestLimitIntercepted,
  TestPlainWebSocket,
  TestPlainHTTPEndsWithClient.
- serveOne (intercepted tunnels, transparent HTTP, the 403 page) takes
  maxHeaderBytes (64 KiB) always, not 1 MiB, and HTTP/2
  MaxConcurrentStreams streamsMax (100, not 250). TestServeOneHeaderLimit,
  TestServeOneStreamsLimit.
- Accept loops (forwarder, link session, login forward) retried nothing
  or at a fixed 100 ms: vmssh.acceptRetry backs off from 5 ms to 1 s and
  logs the first error of a run, ending only when the listener closes or
  ctx ends. TestAcceptRetry, TestForwarderAcceptRetries,
  TestLinksAcceptRetries.
- The login callback (LoopbackForward) carries at most
  loopbackConnsMax (16) connections, an ssh each.
  TestForwardLoopbackLimit.

Docs: processes, network, ports, lima, design (threat rows),
attack-vectors, the proxy README, CHANGELOG Fixed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 22:04:31 -07:00

57 lines
2.1 KiB
Go

package paths
import (
"path/filepath"
"strings"
"testing"
)
// Every file of a VM's is in its folder, each in its own place, none of
// them where another is.
func TestVMFiles(t *testing.T) {
v := Dirs{Data: "/d"}.VM("devvm-p-0123456789abcd")
want := map[string]string{
v.State(): "vm.json",
v.Lock(): "lock",
v.Policy(): "policy",
v.Run(): "run",
v.Logs(): "logs",
v.Proxy(".pid"): "run/proxy.pid",
v.ProxyConfig(): "run/proxy.json",
v.Proxy(".status"): "run/proxy.status",
v.GitPins(".jsonl"): "run/git-pins.jsonl",
v.GitPins(".json"): "run/git-pins.json",
v.Profile(): "run/sandbox.sb",
v.Proxy(".slots"): "run/proxy.slots",
v.BuildProxy(): "run/build-proxy",
v.Started(): "run/started",
v.Secrets(): "run/secrets.json",
v.SecretsPolicy(): "run/secrets.policy",
v.LinksPID(): "run/links.pid",
v.LinkList(): "run/links.json",
v.EventLog(): "logs/network.jsonl",
v.ProxyLog(): "logs/proxy.log",
v.LinksLog(): "logs/links.log",
v.ForwarderLog(): "logs/ports.log",
v.KnownHosts(): "run/known_hosts",
v.Forwarder(".lock"): "run/ports.lock",
v.CA().Dir: "run/ca",
v.CA().Cert(): "run/ca/ca.pem",
v.CA().Key(): "run/ca/ca.key",
v.CA().NextCert(): "run/ca/next.pem",
v.CA().NextKey(): "run/ca/next.key",
filepath.Join(v.Dir, "other"): "other",
}
if len(want) != 30 {
t.Fatalf("%d paths, want 30: two are the same", len(want))
}
for got, rel := range want {
if got != filepath.Join("/d/vms/0123456789abcd", rel) {
t.Errorf("got %s, want %s in the VM's folder", got, rel)
}
if strings.HasSuffix(got, ".sock") || strings.HasSuffix(got, ".ctl") {
t.Errorf("%s: a socket in a VM's folder", got)
}
}
}