Files
w3cjandClaude Opus 5.5 647ad4bf2a feat(network): transparent mode for tools that ignore the proxy settings
On every confined tier, a tool that ignores the proxy settings (workerd
under wrangler dev, a static Go binary, a container made through Docker's
API) reaches the VM's proxy by the names it looks up. In the VM, dnsmasq
answers every name with the stand-in address 198.18.0.1 and has no
upstream; nftables sends that address's ports 80, 443 and those the allow
rules name to socat listeners on it, which make each an authenticated
CONNECT transparent.devvm.proxy:PORT to the VM's proxy. The proxy reads the
host from the connection's first bytes (TLS SNI, or each HTTP request's
Host) and judges it as CONNECT host:PORT, with the same order of checks,
log, secrets and floor. A blocked HTTPS host gets the 403 over a
certificate from the VM's CA. Nothing new runs on the host, and the
backends don't change.

Proxy (internal/proxy):
- transparent.go: TransparentHost, ProxyDomain, SentinelAddr,
  IsSentinelAddr, ViaDNS, transparent (serve, take, tls, handler,
  refusePage, ports), sniHost, replay, reservedRefusal, withVia, viaOf.
- routeFor and route: the one order of checks for CONNECT and the
  transparent path; carry, the one tunnel with its SNI check; block split
  into the record and blockPage; links.refuse split (isLinkDomain);
  caEndedRefusal's test moved to routeFor; handshake and serveOne shared
  by intercept and the 403 page.
- devvm.proxy reserved whole, CONNECT devvm.proxy:P included; the stand-in
  address refused with its own reason.
- Hosts and SNI in ASCII alone, never folded (the Kelvin sign), in
  splitHostPort, sniMatches and sniHost.
- A ClientHello record past 16 KiB + 256 is never read; once it starts,
  a ClientHello must arrive whole within 10 s, on every tunnel; a stream
  whose first byte is 0x16 is TLS from then on, so a record header that
  doesn't come whole, or isn't TLS's version, is refused, never passed on
  unchecked; and only a ClientHello that parsed (sniOf) counts, so one
  split across records is refused, an address's tunnel's included, which
  may have no name (a gap older than this change).
- routeFor carries the method and path rules: a host they narrow is
  refused where it can't be decrypted and intercepted where it can, on
  the transparent path too.
- On the transparent HTTP path, devvm.proxy answers /blocked alone.
- policy.transparentPorts and /transparent/ports: 80, 443, then the ports
  allow rules name for hosts by name, at most 32, never 22 or 53.
- Event.Via ("dns"), shown in devvm network log, /blocked and the prompt's
  note as "without proxy settings".

Guest (assets/): base.sh installs dnsmasq(-base), socat and nftables;
guest/transparent.sh is devvm-transparent: setup and teardown from
sync.sh (the proxy URL on stdin), the supervisor service (systemd or
OpenRC), the ruleset (render: two filter chains at -150 keep every
interface but lo and Docker's bridges, and every protocol but TCP, UDP
and ICMP, off the stand-in address; both NAT chains at -110 map every port of
the stand-in address, so Docker's published ports never take one; DNS to
public servers and 127.0.0.1:53 go to dnsmasq, which listens on the
stand-in address alone; private, link-local, CGNAT and loopback servers
are left alone, but the VM's own name servers, which Lima's DHCP adds
beside 127.0.0.1 and Docker gives containers, go to dnsmasq too), slots,
the port list's check, and status for devvm-why. Names without a dot and
names under the search domains (this machine's network's, through Lima)
don't resolve.

Setting: config.toml's transparent-proxy, and devvm network transparent
[on|off], the VM's own value in net.transparent (Settings.Transparent,
SetTransparent; netpolicy.TransparentOf, TransparentAddr); the setup gets
DEVVM_TRANSPARENT_ADDR while the VM runs confined and its mode is on.
devvm network --json has transparent; devvm network lock lists apart the
hosts only tools without proxy settings reached (Learned.NoProxy, via in
--json). vmssh.dialAddr refuses the stand-in address.

Tests: the transparent path's unit tests and FuzzTransparent; the
setting, TransparentOf, FormatEvent's via and learned hosts; the ruleset,
slots and port list under bash 3.2; network_transparent.txtar and
sync.txtar; e2e: transparentRuns, the network section's checks, a docker
step, the from section's Debian 12 and Alpine on the allowlist tier, and
the guarantee checks run with transparent mode stopped and running.

Docs: safety/network.md (tools that ignore the proxy, what isn't
covered, the setting, logs, lock), internals/network.md (tools that skip
the proxy), internals/design.md (the design note and threat check),
using/settings.md, using/troubleshooting.md, using/limits.md,
using/images.md, safety/attack-vectors.md, internals/lima.md,
contributing/tests.md and testing.md, the proxy's README, the CLI
reference and the Commands page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-09 07:18:53 -07:00

20 lines
740 B
Go

package settings
import "github.com/devvmhq/devvm/internal/paths"
// KeyTransparentProxy is config.toml's switch for transparent mode: on a
// confined VM, the names of hosts that tools without proxy settings look up
// lead to the VM's proxy, which judges each connection by the name in it.
const KeyTransparentProxy = "transparent-proxy"
// TransparentProxy reports config.toml's transparent-proxy, and whether it
// sets it: on, unless it's false. A VM's own setting comes first
// (netpolicy.TransparentOf).
func TransparentProxy(d paths.Dirs) (on, set bool, err error) {
cf, err := decodeConfig(d.ConfigFile())
if err != nil {
return false, false, err
}
return cf.TransparentProxy.v != "false", cf.TransparentProxy.set, nil
}