17 Commits
Author SHA1 Message Date
w3cjandClaude Opus 5.5 9c74dac11e fix(logs): a VM's logs are held to their caps while it runs
internal/vmlog owns every log a VM can drive but the proxy's own:
Limit (moved from vmssh's logLimit, with Allow for the link session's
warnings), Capped and Trim for ports.log and links.log while they run,
and KeepVM, which the VM's proxy (proxy.IO.KeepLogs, Config.VMLogs from
backend.Run.Logs) and a Lima build run on the serial consoles' and the
hostagent's logs: redacted as they grow (redact.FileFrom), so a reboot
in place can't leave the proxy password there, and rotated past 10 MiB,
counting what a log holds past the hole its writer left
(platform.DataStart).

The proxy's http.Server logs through its own limited log, and its
copied log counts what reached it as stderr; the build proxy's log is
held as a VM's proxy's is. git-pins.jsonl has a cap. Run logs take at
most 256 MiB together, never the newest or a live run's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 22:04:32 -07:00
w3cjandClaude Opus 5.5 19f9900b86 fix(sshagent): a VM reaches its SSH agent only through its proxy's relay
OpenSSH's ssh-agent answers every request a forwarded connection sends,
so a VM that forwarded your agent or devvm's own (shared by every VM
that uses it) could remove all its keys (ssh-add -D), lock it with a
password of its own (ssh-add -x) or add keys without bound, denying the
agent to you and to the other VMs. Checked with a throwaway sshd and
ssh-agent: all three succeed over ssh -A.

Each VM's proxy now relays the agent its start chose on a socket of the
VM's own (paths.Dirs.AgentRelay, run/agent-<hash>.sock, mode 600), and
the VM's backend, devvm's own connections and the ssh entries for
editors name that socket. The relay passes on only
SSH_AGENTC_REQUEST_IDENTITIES, SSH_AGENTC_SIGN_REQUEST and the
[email protected] extension (so destination-constrained keys keep
their constraints), answers everything else with SSH_AGENT_FAILURE,
reads messages whole up to OpenSSH's 256 KiB, carries at most 16
connections and closes one idle for 2 minutes. A filtering relay rather
than an agent per VM: it covers your own agent too, needs no copy of a
key or a passphrase per VM, and fronts hardware and app-held keys.

- proxy: Config.Agent/AgentSocket (checked together, absolute), the
  relay in agent.go, listened before the proxy says it's ready; its
  accept loop backs off after an error that leaves the listener open
  (EMFILE), 5 ms doubling to 1 s, logging the first.
- daemon: AcceptRetry, vmssh's acceptRetry moved to the stdlib-only
  package the proxy already imports, so the relay, the port forwarder,
  the link session and a login's forward share one owner.
- netpolicy: Prepare takes a start's agent; a running VM's proxy keeps
  its start's agent from proxy.json (relayedAgent); Stop deletes the
  relay's socket.
- structure: paths.Dirs may have 62 methods (AgentRelay); the relay's
  goroutines in goroutineSites.
- sshagent: Made.Relayed, which RecordStart sets on every start of this
  devvm's whose choice forwards an agent, one without SSH_AUTH_SOCK
  included, and ReachOf(st,
  start): a relayed start gets the relay (or none while it's down), a
  start devvm didn't record (one outside devvm) gets none, or its
  proxy's relay, and only an older devvm's recorded start keeps the raw
  agent until its next start (runningConfinement, finder.inspect,
  sshconfig).
- vm: LeftoverSockets also finds a killed proxy's relay socket for
  devvm gc --orphans and devvm space.
- Tests: relay filter, wiring through Main, bounds and idle close, real
  ssh-agent/ssh-add/ssh-keygen through the relay, Prepare's relay,
  RecordStart/Relayed, sshconfig entries, vm agent tests, ssh_agent.txtar,
  an outside start in ssh_agent.txtar, and e2e checks that the VM can't
  remove, lock or add to your agent, nor the VM or an editor's
  connection remove devvm's agent's keys.
- Docs: processes (the SSH agents, listeners), ssh, attack-vectors,
  security, design, lima, overview, space, structure, proxy README,
  AGENTS.md, CHANGELOG Fixed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 22:04:31 -07:00
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
w3cjandClaude Opus 5.5 b6954e1e11 refactor(vmname): a VM's name is a vmname.VM, parsed where it's read
vmname.VM is the name of every machine devvm runs on a backend: a
project VM, an image's machine (devvm-img-<key>), a build VM and a
remake's aside. Fields, parameters, results and map keys that held a VM's
name as a string now hold a VM, from the backend interface down to the
CLI's --json structs, whose output is byte for byte the same.

Boundary parsers, the only places a string becomes a VM:
- vmname.Parse: a project VM's name (state's vm.json name, export file
  names, devvm _links's argument, the forwarder's -vm, project.Nth)
- vmname.ParseListed: one path element, for what a backend lists
- VM.UnmarshalText: JSON (Lima's list, proxy config and events, links'
  targets in state, link lists); empty stays no VM
- vmname.Image(key), VM.Aside(), and typed constants for Lima's build VMs
- msg.M.VM: the VM a message's function took, read back

vmname's functions on names became methods (Hash, Slug, Short, Aside,
AsideHash, ImageKey, IsProject); Lima's image prefix moved to vmname;
vmname.Join joins VM lists. Messages' vm and vm_name fields are typed
by the generator. Seven messages whose field took something else became
what= (backend_lacks, backend_unreviewed, backend_unreviewed_used,
starting, deleting, configuring, running_script) and rm_vm_failed's
name=: the text is unchanged, the names-mode scripts follow.
Review.RequireFor names an image or the tools being built.

Typed sites per package (added lines with vmname.VM, non-test): msg 347
(generated), vm 124, lima 48, backendtest 32, vmssh 31, netpolicy 22,
backend 16, gitprotect 14, proxy 11, cli 11, project 10, state 8,
ports 6, paths 3, sshagent 2, sshconfig 2, tools 2.

The structure test's owners rule now fails on a field, parameter or
result named for a VM (vm, vms, otherVM, vmName) typed string, []string
or map[string]…, and on converting anything but a literal to vmname.VM
outside the files it lists; internal/stubtest is free. depguard holds
internal/vmname to the standard library, and the proxy may import it.

ParseListed and UnmarshalText refuse a name starting with -, which would read as a flag in limactl's argv, and vmname.Image refuses a key that's empty, holds a / or NUL, or makes a project VM's name, so Lima's ImageSize and DeleteImage no longer check it themselves. The check also fails on a *string VM name and an alias of vmname.VM, and says what it doesn't see.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 19:36:28 -07:00
w3cjandClaude Opus 5.5 608ab43714 fix(ports): an IPv6 listen error fails the port as an IPv4 one would, and ::1 refused alone forwards on IPv4
The forwarder's open listened on 127.0.0.1, then ::1, and gave the port
up only for EADDRINUSE on ::1. Any other IPv6 error (EMFILE, ENOBUFS...)
was ignored, so the port was forwarded and recorded on IPv4 alone until
its VM's listener went and came back: a client that connects only over
IPv6 (http://[::1]:PORT, tools without fallback) didn't reach it, and
another program on this machine could take ::1 on the port.

Now any other ::1 error closes the IPv4 listener and is returned, so try
handles it as an IPv4 listen error (f76b2fa2): EADDRINUSE recorded in
use, anything else logged, not recorded, and tried again at the next
report. A host without IPv6 on its loopback (EADDRNOTAVAIL, EAFNOSUPPORT,
EPROTONOSUPPORT) still gets IPv4 alone, and so does one that refuses ::1
alone with 127.0.0.1 bound (EACCES, EPERM), logged, so a security module
denying IPv6 sockets doesn't stop forwarding. A partly open forward is
never recorded: a port is forwarded on both addresses, on IPv4 alone on
such a host, or not at all.

- vmssh: noIPv6; open's cases for ::1 (no IPv6, EACCES and EPERM logged,
  any other error returned)
- tests: TestForwarderIPv6Failures (EMFILE on ::1: not forwarded, its
  IPv4 listener closed, unrecorded, forwarded on both at the next report;
  EADDRNOTAVAIL, EAFNOSUPPORT and EPROTONOSUPPORT: IPv4 alone; EACCES and
  EPERM: IPv4 alone and logged; EADDRINUSE: in use, not tried again)
- coverage: internal/vmssh's baseline raised
- docs: internals/ports (when it can't forward), the design note
  (listening, a lead for a forward on IPv4 alone), CHANGELOG Unreleased
  Fixed

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-13 16:15:45 -07:00
w3cjandClaude Opus 5.5 c63f9a3340 fix(links): relays end with their link, their master or 30 s after their client closes
A relay's ssh (-W) ends only when the VM's sshd ends its channel, so a
VM that ignored EOF could keep a relay, its ssh process and one of its
owner's 256 slots:

- A link's removal closed only its listener, so its open connections
  went on until the target's master or the session ended. The same held
  for connections through a target master replaced when the target
  started again, and for a link whose address and port named another
  target at the next sync.
- While a forward or a link lasted, a relay whose client had closed its
  side stayed for as long as the VM liked.

Each relay now gets its own context, which a link's removal, its
master's replacement or end, and its target's change cancel, as a
forward's close already did (f76b2fa2); that pattern has one owner,
relayConns, which the forward, each link and each target master use.
pipeSSH, which carries every relay of the forwarder's, the link
sessions' and a login's callback, also cancels it once the client has
closed and the VM has sent nothing for 30 s, the first byte included, or
30 s after the client can take nothing more. A client that half-closes
and waits still gets an answer the VM keeps sending; one that waits
longer than that for a first byte (nc -N in front of a slow query) is
cut. devvm link unpublish keeps the link, so its open connections stay.
No cap for each target: what a target can still hold is connections the
client's programs keep open.

- vmssh: relay.go, the relays' owner: relayConns (add, done, cutAll),
  pipeSSH moved from forward.go, pipeSSHFor, relayGrace, graceTimer
  (newGraceTimer, reset, stop), graceReader. forward.conns is a
  relayConns; linkEnd holds a *relayConns, with close, and targetMaster
  one, with end; sync cuts a link's set when it goes or its target
  changes; take reads the link and its set together; carry tracks each
  connection in its link's set and its master's (track, untrack);
  targetMaster returns the master
- structure: relay.go listed in execSites (each connection's ssh -W);
  forward.go's reason is its master alone
- tests: TestLinksEndStuckRelays (an ssh stand-in that never exits: a
  removed link's, a replaced master's and a changed target's relays end,
  their ssh gone and slots freed, no goroutine left, under -race);
  TestLinksCarryCut (a cut link's and a cut master's connection: no
  check or relay, no event, not tracked); TestPipeSSHGrace (closed,
  half-closed, talking and closed while talking clients);
  TestPipeSSHGraceWriteError (failed writes end the relay within the
  grace); TestGraceTimerStopped
- e2e: link's lkRmEnds, on a port of its own: a connection held by the
  client to a server that never closes it, whose relay ssh ends after
  devvm link rm
- docs: using/links (removing a link), internals/ports (how it reaches
  the VM, when links change), the design note (each connection for
  forwards and links, a lead for relays held after their client closed,
  not covered, two threat-check rows), CHANGELOG Unreleased Fixed

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-13 16:15:34 -07:00
w3cjandClaude Opus 5.5 f76b2fa2a4 fix(ports): devvm ports says why a listed port isn't forwarded; a relay ends with its forward
The forwarder recorded every listed port it couldn't take on one line,
and devvm ports warned ports_taken ("in use on this machine") for all of
them, even a port past its limit of 256 forwards or one the host refused,
such as EACCES below 1024 on Linux. It now records why: in use
(EADDRINUSE), past its limit, or refused (EACCES, EPERM), each on a line
of its own in run/ports.forwarded (pid, forwarded, in use, limit,
refused). Any other listen error (EMFILE, ENOBUFS, EADDRNOTAVAIL...) says
nothing of the port: it's logged, not recorded, and tried again at the
next report, the log's limit capping the repeats. A port past the limit
is tried again at the next report once the forwarder is below it. An
older devvm's three-line record, whose third line held every failure,
is read as giving no reason, so it warns of none rather than call a
refused port in use; its forwarded ports still count.

A forward's close closed its accepted connections, but each relay's ssh
(-W) waited for the VM's sshd to end the channel, so a VM that ignored
EOF kept that ssh process and one of the forwarder's 256 relay slots
until the forwarder ended. Each relay now gets its own context, cancelled
by the forward's close under mu, so CommandContext kills its ssh; a relay
that ends by itself releases its context.

- vmssh: failure (in use, limit, refused) and failedPorts; failureOf's
  ok for errors that are the port's; Forwarder.try; apply clears limit
  failures below the limit; Note takes failedPorts;
  Forwards.Unforwarded replaces Taken; record writes five lines
  (recordLines); MaxForwards exported for ports_limit; forward.conns
  holds each relay's cancel
- messages ports_limit (count, limit, ports, vm) and ports_refused
  (count, ports, vm), linked to troubleshooting's listed-port section;
  devvm ports warns each by why
- --json unchanged: it never listed failed ports
- tests: TestForwarderFailures (EACCES, EPERM and EADDRINUSE through
  Listen, EMFILE tried again unrecorded, the limit and its retry once
  below it), TestForwarderEndsStuckRelay (an ssh stand-in on PATH that
  never exits: the relay ends, the process is gone, the slot is free),
  TestForwardsHeld's record round trip, older and foreign records, and
  ports.txtar's three warnings from a record and none from an older one
- docs: internals/ports (record lines, relays, when it can't forward and
  what's retried), the design note (how many, each connection, the
  below-1024 lead, the stuck relay as confirmed and fixed, channels a VM
  never closes as listed), ports-size, troubleshooting, CHANGELOG Fixed

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-13 07:38:42 -07:00
w3cjandClaude Opus 5.5 54cce97049 fix(ports): a stopped VM no longer keeps its listed ports from other VMs
Only a running VM holds a host port. Each VM's forwarder records the
ports it forwards, and those it tried and couldn't take
(run/ports.forwarded: its pid, then each list on a line; an empty one
when it starts, and devvm removes it under ports.lock before each
start). A forwarder reserves another VM's ports only while that VM has a
claim: its forwarder runs, or devvm holds its ports.lock to start one
again (the restart window). It never takes the ports such a VM forwards
now, nor those it lists unless this VM lists them too. A stopped or
crashed VM holds nothing. A reserved port the VM listens on waits and is
forwarded once free, so a VM gets its port back within about 20 s of the
other VM stopping. The host decides when a port is given up: every
forwarder closes a forward whose port is now reserved every 10 s on its
own clock (Forwarder.Recheck), so a VM that holds its session open and
stops reporting can't keep another VM's listed port, and closing a
forward closes the connections it accepted, so a browser's keep-alive
connection never reaches the old VM afterwards. Two VMs starting at once
are settled by the host's bind. The ports devvm chooses (ssh, proxy,
desktop) still avoid every VM's listed ports, running or not.

- ports: Used(d) for the allocator; Reserved, Holders and Live for the
  forwarders
- vmssh: Forwarder.Recheck, Note and release; a forward tracks and
  closes its connections; Forwards.Reserved, Held, Taken, live,
  recorded and record; a start keeps a port another VM holds in -only
  and warns ports_held for any holder, listed or every-port; Main takes
  paths.Dirs
- devvm ports warns ports_held and, for a running VM's listed port its
  forwarder recorded as a program's, ports_taken, reading the
  forwarder's record and binding nothing; --json adds held_by
- backend.CountPorts; the stub's ssh master reports again when
  guest-ports changes
- tests: TestReserved, TestForwarderWaits, TestForwarderGivesUpSilently,
  TestForwarderClosesConnections, TestForwardsHeld (restart window,
  every-port holder, no record, Taken from the record alone, another
  process's or no record), TestForwardsRecordFails, TestForwardsStart
  (old record removed), ports_stopped.txtar (CJ's case end to end, and
  an every-port VM leaving a running VM's listed port alone),
  layout.txtar
- docs: ports-size's Two VMs and one port (the browser origin) and its
  JSON, internals' Ports other VMs forward, design.md's ports note and
  the listed ports' threat check; CHANGELOG Fixed

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-13 00:20:43 -07:00
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
w3cjandClaude Opus 5.5 8d44175601 refactor: the Go module is github.com/devvmhq/devvm
Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 06:16:29 -07:00
w3cjandClaude Opus 5.5 36f910839e fix(desktop): browsers reach the web through a local proxy that adds the VM's password
Chrome, Chromium and Firefox ignore the password in HTTP(S)_PROXY, so in
devvm desktop they asked for the proxy's username and password on every
site. The guest setup now writes devvm-local-proxy, which socat (now in
the desktop layer) serves on 127.0.77.1:3128, the VM's loopback alone.
For each connection it reads the request's head, drops the client's
Proxy-Authorization and Proxy-Connection, adds the VM's password and
sends it to devvm's proxy, then socat carries the rest both ways. It
takes only CONNECT HOST:PORT and absolute http(s):// requests, the
latter with Connection: close, so each connection's one request carries
the password. devvm-desktop starts it and points the Xfce session's
http_proxy, https_proxy, HTTP_PROXY and HTTPS_PROXY at it; on Xfce,
Chrome and Chromium read those, and Firefox reads them first with its
default system proxy setting. A blocked host still gets the proxy's 403.

- proxy.LocalProxyAddr, LocalProxyPort, IsLocalProxyAddr: the one owner
  of the address, sent to the guest as DEVVM_LOCAL_PROXY (vm.localProxy).
- vmssh: the port forwarder never forwards a server on 127.0.77.1.
- Tests: netpolicy's TestLocalProxy runs sync.sh's script (bash 3.2 on
  macOS) against a fake proxy: the password replaced, Connection: close,
  a tunnel, the 403 passed on, origin-form and junk refused with 400
  before any connection; TestListeners, TestIsLocalProxyAddr,
  TestLocalProxy (vm), sync.txtar. e2e desktop (tests/e2e.sh, still the
  bash section): the session's variables, the listener on 127.0.77.1
  alone, curl without a password to github.com, example.com's 403 over
  CONNECT and plain HTTP, 400 for origin form, nothing on this
  machine's 3128.
- Docs: using/desktop.md (Browsers), internals/desktop.md (The local
  proxy), design.md's desktop note, ports.md, network.md's setup.

Security review (security-audit skill, guidance mode, local IPC and
proxy request handling):
- Fixed by design: devvm forwards every VM port by default, so a local
  proxy on 127.0.0.1 would have put a password-less route to the VM's
  proxy, and its secrets, on the host's localhost for every local user.
  The forwarder now skips the local proxy's address on every port.
- The password goes only to the VM's proxy, whose address is fixed in
  the script, never to an address a request names, in the one header
  the local proxy adds; devvm's proxy strips Proxy-Authorization before
  forwarding. It's never in a process's arguments (bash builtins only).
- Web pages: requests from a page to the loopback are origin form,
  refused with 400 before any connection; a page can't send CONNECT or
  an absolute-form line, and DNS rebinding changes only Host.
- No new power in the VM: the same password is in /etc/environment;
  the script is mode 700, the VM user's.
- Residual: a program in the VM can hold up to 256 connections slowly
  (30 s a line, 100 headers), only against the VM's own browsing; an
  ssh -L the user types to 127.0.77.1:3128 would expose it, as any
  forward they choose.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-06 00:03:45 -07:00
w3cjandClaude Opus 5.5 2e84e0d3c6 fix(vmssh): the forwarder gives up a held forward whose port is now reserved
apply closed a forward only once the VM stopped listening, so a port
another VM's start had since chosen (its ssh, proxy or desktop port, or a
listed port) stayed forwarded to this VM. Each report now closes a held
forward on a reserved port; while the reserved ports can't be read, the
forwards it has stay. Test: TestForwarderReservedLater (failed before).
Docs: internals/design.md's How many.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 15:46:39 -07:00
w3cjandClaude Opus 5.5 e148ca33ca fix(clone): the --clone push and fetch's ssh always connects to the VM itself
devvm's ssh for a --clone VM's seed push and rm's fetch read devvm's ssh
config, so a url.*.insteadOf, pushInsteadOf or remote URL in the repo's
config could send them to another host; only the pinned host key
(HostKeyAlias, BatchMode) stood in the way.

Their GIT_SSH_COMMAND (gitSSHCommand) is now a shell function that
ignores the host, port and options git passes, and runs ssh with
vmssh.SSH's new CommandArgs: no ssh config (-F none), the VM's loopback
port, user and key from vmssh.FromTarget, and the host keys pinned for
its current start (vmssh.KnownHostsFor) under HostKeyAlias, with
BatchMode and nothing forwarded. In the VM it runs only git-receive-pack
or git-upload-pack, whichever git's last argument asks for, on the
clone's own path; anything else fails without ssh. Links' linkSSH is now
Env's ownSSH, which both use.

Tests: TestUpCloneInsteadOf (failed on the previous code),
TestGitSSHCommand, TestForwarderSSH's command args, clone.txtar's push
past an insteadOf, and e2e's clone section (an insteadOf on the first
push, and a git worktree's clone with only its branch and upstream).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 12:56:37 -07:00
w3cjandClaude Opus 5.5 57378f98c3 refactor(vmssh): the port forwarder reaches a VM over its backend's SSH, checked by vmssh.FromTarget
backend.Machines drops ForwardTarget and backend.ForwardTarget goes:
vmssh.Forwards builds the forwarder's target from the backend's SSH and
vmssh.FromTarget, the one check of a target that links and the ssh
config use, so 127.0.0.1 as an ssh target is checked in vmssh alone.
Lima's own copy of the check and its fixed _config/user key path go;
Lima's SSH gives the same user, port and key (its ssh config's first
IdentityFile, Lima's _config/user). The forwarder's spec embeds
vmssh.SSH, KnownHosts included.

The fake loses Forward and its method; the conformance suite's stopped
and reach checks keep SSH's. The registry's guard embeds the roles, so
it needed no change.

Tests: TestForwardsStart sets the fake's SSH target and gains the
targets FromTarget refuses (another address, a name, 0.0.0.0, no user,
no key, a relative key, no port), each warned as ports_forward_failed
with no forwarder; TestForwardTarget (lima) goes, and TestSSH checks it
runs only limactl list. The up tests' fake has a loopback target, so
their calls include the ssh config's entry and its host keys; staged
finds the setup's Exec by its command.

Docs: internals/backends.md, internals/design.md and contributing say
the forwarder takes the backend's SSH, checked by vmssh.FromTarget.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 01:51:31 -07:00
w3cjandClaude Opus 5.5 50b0db2f7e refactor(vmssh): one host-key record per VM per start, which every ssh of devvm's checks
vmssh owns a VM's host keys: PinHostKeys reads them from the running VM through its backend (at most 64 KiB within 30 s) once for each start, into one record in the VM's folder, vms/<hash>/run/known_hosts (paths.VM.KnownHosts), whose first line names the start it was read for (backend.Run.ID). A record of another start is read again, keys read while the VM started again aren't recorded, and ErrNoHostKeys says none can be pinned. KnownHostsFor returns the record for the current start without reading, for links' sessions; ForgetHostKeys removes it before each start. ParseHostKeys is the one parser, for every key type: a line is kept only when its key decodes, names its own type and has more after it, and certificates, markers, patterns and anything else are dropped.

The ssh config's entries, the port forwarder (-known-hosts), links' sessions and a --clone VM's git all check the VM against that record. sshconfig's own parser, recordHostKeys, changeKnownHosts, HostKey and ForgetHostKeys go, with the shared known_hosts and its lock (Dirs.KnownHosts, Dirs.KnownHostsLock): a record per VM, each written whole, loses no other VM's keys. The forwarder's ports.known_hosts copy and Forwards.HostKey go, and teardown leaves the record to the VM's folder. paths.Dirs's method limit drops to 47.

Tests: TestParseHostKeys, TestPinHostKeys, TestPinHostKeysNone, TestPinHostKeysTogether (vmssh); TestForwardsStart and TestForwardsRun use the record; TestWrite reads keys again after a start, TestWriteUnreadableRecord (sshconfig); TestLinkConn refuses a target without a record and never reads one; up_test's call lists. The limactl stub shows a wire-format ed25519 key per VM. testscripts ssh (a launch keeps the record, a restart reads it again), up, existing, host_code, clone and layout updated; e2e's project and link checks read the VM's record. Docs: internals/security.md, design.md, overview.md, ports.md, lima.md, backends.md, git-protection.md, using/ssh.md and space.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 01:21:02 -07:00
w3cjandClaude Opus 5.5 6379e52c54 refactor(vmssh): a backend's ssh target carries its key, and vmssh.FromTarget checks it for links and the ssh config
backend.SSHTarget has Key, the one private key file that logs in (Lima:
its ssh config's first IdentityFile), and Options no longer carry
IdentityFile. vmssh.FromTarget is the one check of a target: a user and
an absolute key that can't break an ssh config line, on a port of the
host's loopback (vmssh.Loopback, 127.0.0.1) and nowhere else.

Links' linkSSH uses it in place of its own IdentityFile parsing and
checks. The ssh config uses it too, which adds the loopback check it
lacked: a VM whose backend names another address, a name, no user or no
key gets no entry, so an editor's ssh (and a forwarded agent) never
goes elsewhere. Entries write Hostname, User and IdentityFile from the
checked target.

Tests: TestFromTarget (vmssh); TestWriteNoAddress gains other
addresses, a name, 0.0.0.0, no user and no key (failed before on the
addresses); TestSSH (lima) checks Key is the first IdentityFile alone;
the conformance reach check needs a user and a key.

Docs: using/ssh.md says entries reach the VM on 127.0.0.1 alone;
internals/design.md says links take a VM's ssh only there, and names
internal/vmssh's path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 00:28:17 -07:00
w3cjandClaude Opus 5.5 bdc95ef6ee refactor(ports): port forwarding out of the backends, one owner in vmssh
The port forwarder is devvm's on every backend. vmssh (moved out of
internal/backend) holds it, the link sessions, and its one owner,
vmssh.Forwards: the lock, stop and start of a VM's forwarder, which
ports it forwards read from vm.json (ports.Forwarding) each time, the
listed ports a host program has left out (ports_taken), the host key
devvm pins, and the backend's new ForwardTarget (user, key, host
loopback port) and Lifeline. One hidden command, devvm _ports
(cli/forwarder.go, vmssh.Main), replaces _lima-ports.

The backend no longer forwards: SetPorts, Want.Ports, Confinement.Free,
Confinement.HostKey and Confinement.Forwarded go; Lima keeps its own
forwards off and gives ForwardTarget (Lima's ssh port on 127.0.0.1,
Lima's user, _config/user). Lima's Stop and Delete no longer touch the
forwarder, and Lima's Forget goes with the backend/ folder: the
forwarder's files are in the VM's run/ (ports.pid, .status, .lock,
.known_hosts) and logs/ (ports.log), its control socket run/port-<hash>.ctl.
vm starts the forwarder after each start and on devvm ports of a running
VM; devvm stop, rm, gc --orphans and an interrupted start stop it.
vm/ports.go's hand rollback goes: the state changes first, and a
forwarder that can't start only warns. A structure-test layer keeps
backends from importing vmssh.

Tests: TestForwardsStart, TestForwardsRun, TestForwarderMain,
TestSplitPorts (vmssh); TestForwardTarget (lima); TestForwarding
(ports); TestStartPorts, TestSetPortsRunning (vm); testscripts up,
ports, layout, gc_orphans updated. Docs: internals/ports.md,
backends.md, lima.md, design.md (Ports on Lima), overview.md,
using/space.md, contributing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 18:19:39 -07:00