mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
main
36
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
2de3e31a6c |
fix(vm): devvm ports shows a status line as it restarts a running VM's forwarder, and every lock's wait is tested for its label
Lock waits: - Tests record the label of each lock's wait that had none, the lock held as by another devvm and the wait ended by a cancel, a deadline failing one that shows nothing rather than hanging: git_lock_waiting (TestGitLockWaits; .git protection's Serial is gitSerial, so a test can reach it), packages_waiting and rebuilds_waiting (TestImageLocksWait), ubuntu_pin_waiting (TestPinOriginWaits), custom_secrets_waiting (TestYoursLockWaits) and forwarder_waiting (TestForwardsLockWaits). - A test build's locks panic on a nil platform.Waiting (platform.CheckWaiting, which the root's run calls in every test build beside state.CheckLockOrder), so the CLI tests and e2e catch a nil wait the structure test can't see, such as a zero agentlogin.File's; a msg.Waiting given a nil status shows nothing and stays review only. msg.Waiting with no status gives a wait that shows nothing, never nil; platform.NoWait is the Waiting of a lock that never waits (the build port's record, which passed nil), and the status-lines rule holds it to statusSites as it does nil (TestCheckWaiting, TestWaiting, the rule's NoWait case). - forbidigo refuses syscall.Flock and unix.Flock outside internal/platform, internal/proxy/rotate.go, the stubs and tests (testdata/lint, both). - TestLockFileWaiting runs in a synctest bubble and checks the wait shows while held, not before (its counters under a mutex, which the race detector needs, as only the file's lock orders them). Status lines: - TestCommandStatusLines runs the setters too: devvm ports LIST and ports add, size --cpus, network open, allowlist, transparent off and on, learn and allow, git-protect off and on, ssh-agent off. It found devvm ports on a running VM starting its forwarder again (ssh and a command in the VM) with no status line; that step now shows ports_restarting. The folder named twice: - vm_folder_unreadable's why was the open's error, the folder's path in it; folderUnreadable gives the system's reason alone when the error is about the folder itself (TestUnreadableFolder checks the whole message). - platform.OpenNoLinks and StatFolder return a link on the path as an fs.PathError about the folder too (ErrLinkOnPath still matches), so that case names it once as well (TestStatFolderUnique). Docs: Contributing's CLI page (status lines) and structure page, the codebase-standards guards; CHANGELOG (devvm ports' status line). Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
cb7177b32c |
feat(ui): waits for another devvm's lock show a status line; a project folder devvm can't read says so
Lock waits: - platform.LockFile and LockFileShared take a platform.Waiting, called once they find the lock held, never when it's free, whose end they call once the wait ends; LockFileWaiting, LockFileSharedWaiting and their delays (ShareNote, OCINote, WaitNote, groupsNote, makingNote) go. - msg.Waiting makes one from a Reporter's Status and a label; msg.WithStatus and msg.StatusOf carry the run's Status in its context for the two packages that take no Reporter, internal/state and internal/trust, which cli's execute sets; forbidigo keeps StatusOf to them, and AGENTS.md says so. - Every lock that waits shows its own label: vm_state_waiting (a VM's state, its deletion), claims_waiting, layout_waiting, git_lock_waiting, ca_waiting, packages_waiting, rebuilds_waiting, ubuntu_pin_waiting, custom_secrets_waiting, forwarder_waiting, agent_store_waiting, and the waits that printed a line after a delay, which now show theirs as a status line: share_waiting, oci_waiting, image_build_waiting, group_waiting, making_waiting. - An agent's login file's lock (agentlogin's lockLogin, a folder's flock that a VM's proxy holds while it refreshes the login) tries first without waiting and shows agentlogin.File's Waiting (agent_login_waiting) while it waits; secrets fills it from its Reporter, for SaveLogins, Claude Code's logins folder and every File. - The structure test's status-lines rule counts a LockFile or LockFileShared whose waiting is nil as slow work; the build port's record, a file just made that never waits, is listed in statusSites. - Without a terminal, or with -v, a status line draws nothing, so the waits that printed an info line after a delay no longer print it there; the CHANGELOG and the troubleshooting page say so. from.txtar's check that a free conversion lock printed no wait goes, as TestLockOCI checks it. The layout's migration runs under a status line (layout_migrating), only when there are migrations to run. Backend calls outside a launch: TestCommandStatusLines runs devvm ls, ports, size, network, tools, git-protect, history export, stop and rm on a running and a stopped VM and fails on a backend call with no status line showing, with a control that each makes one. A project folder devvm can't open and read (vm_folder_unreadable) was taken for another folder's VM (vm_other_folder, which offers rm and adopt, and adopt went on); the finder now keeps why (target.unread), and every command on the folder's VM, from the folder or a subfolder of it, names the folder and why; devvm rm VM run elsewhere goes by the VM's name as before. platform.UniqueFolderID had no caller but its test: FolderStat.Unique, from the open folder, replaced it; it goes, and its test checks StatFolder's Unique instead. Tests: TestLockFileWaiting (rewritten: called only when held, its end once got or given up, shared too), TestVMLockWaits, TestCheckLayoutWaits, TestCheckLayout (migrations under layout_migrating, nothing shown otherwise), TestLockGroups, TestLockShare, TestMaking, TestLockOCI and the build lock's test (status lines, not info lines), TestLockLogin, TestInitCACancelled (ca_waiting), the status-lines rule's lock cases, TestCommandStatusLines, TestUnreadableFolder (a subfolder of it too), TestStatFolderUnique. Docs: Contributing's CLI page (Status lines) and structure page, the cli and codebase-standards skills (the guards), AGENTS.md's Go conventions, internals/images.md and design.md (the waits), using/troubleshooting.md, using/vms.md (a folder devvm can't read); CHANGELOG. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
f9c02c1c5c |
build(lint): a file a VM can write is changed through what opened it
forbidigo refuses os.Chmod, os.Chtimes, os.Chown, os.Lchown and os.Truncate in internal/proxy, internal/vmlog and internal/vmssh, outside tests: a change by path follows a link a VM swapped in after the open. The two sites today, the proxy's SSH agent relay socket and the link session's sockets, chmod a unix socket devvm has just made in its own folder, which only its path can set; each says so in a nolint. The safefile rule widens to internal/vmlog, which has no open of its own, and to the proxy's rotate.go and nixcache.go, whose three opens to write or lock say why in their nolints. testdata/lint breaks the rule once for each function and keeps the descriptor's own methods. Named as the guard in codebase-standards' Treat what a VM can write as hostile and rules.md, and in the checks on owners. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
aeea3135b2 |
feat(proxy): the proxy's broker and its child
A VM's proxy runs as two processes, as design.md's "The proxy's broker"
says: devvm _proxy, the broker, which keeps what only the host should
do, and devvm _proxy-child, which reads the VM's network and can be
confined by the follow-ups.
- wire.go: the protocol over one socketpair (close-on-exec from the
start: SOCK_CLOEXEC on Linux, ForkLock elsewhere), length-prefixed JSON
frames of at most 2 MiB, unknown fields refused, bytes as base64, one
descriptor on a frame's first bytes (SCM_RIGHTS, MSG_CTRUNC breaks the
rules), wire types for every secret (redact.Secret at once).
- broker.go: newBroker, the start (handshake: version 1 and each side's
executable's SHA-256, within 4 s), the answers (value through lookups,
kept 30 s or 5 min, a failure 5 s, dropped when the bindings change;
file by number; link connected by the broker and passed as a
descriptor; token exchanged by the broker), each by something in its
own config, with caps 1/8/4/256; live: the lifeline closes the socket
and kills the child 6 s later, SIGTERM stops it within a second, a
child that ends ends the broker, a rule broken stops the child.
- child.go: the start (startOf), the child's server (newChildServer),
the broker as hostSide over the socket (brokerClient), runChildOn;
ready only after it reads the host's addresses (kept: the last good
read), roots and time zone loaded first.
- process.go: Main(ctx, ...) and ChildMain; the child spawned with
/proc/self/exe on Linux, PR_SET_PDEATHSIG from a locked thread
(daemon.Cmd.DieWithThread), descriptors 3 and 4, and TZ, SSL_CERT_*
and GODEBUG with updatemaxprocs=0 alone; run/proxy-child.pid and
run/proxy.confined ("none" until the follow-ups); KeepLogs in the
broker. ChildMain refuses to start unless descriptors 3 and 4 are a
unix socket and an IP one (checkInherited): run by hand, without
them, those numbers can be the Go runtime's own, which closing
crashed it (signal_recv: inconsistent state).
- capture.go: a captured token request goes to the broker
(captureToken, exchanger), so a login's real tokens never enter the
child; an error reply passes up to 1 MiB, longer gets 502.
- watched.go: the child stats each changing file and asks the broker
for it once it changed, keeping the stamp of what the broker read.
- rotate.go: proxy.log rotated by both through its descriptor, under a
lock of a description of its own; OpenLog opens a log never through a
link, one link, yours, replacing what a child left in its place.
- nixcache.go: the trim and its count through a safefile.Root, nar/
only as a folder, links deleted as themselves; reads never through a
link; the lock tried for 5 s (ErrNixLocked, nix_cache_locked).
- daemon: Cmd.Err, Files, Env, DieWithThread; Handle.Kill, Exit;
WritePID.
- netpolicy: Proxy.Stop also stops a child that outlived its broker
(run/proxy-child.pid, _proxy-child -for); proxy.log opened with
OpenLog; a refused launch keeps a running VM only while both run.
devvm network log and lock read the event log through safefile.
- vm, vmssh, vmlog: links.log and ports.log opened with OpenLog, read
through safefile, trimmed only as a regular file with one link.
- backend: the build proxy's logs in a logs/ folder of their own.
- cli: _proxy-child; _proxy waits for its child on a signal
(StopsItsOwn); the child reads none of devvm's folders (no
makePrivate); ui.Files.
- Tests: FuzzBrokerFrames, the frames' rules, the handshake and the
pair's end in synctest bubbles, the caps, the broker naming its own
alone, the client over a real socketpair with a passed descriptor,
ChildMain, TestInheritedSocket and proxy.txtar's child run by hand,
the frozen 0.1.0 configs starting a broker and child,
two writers rotating once, planted links, FIFOs and hard links; the
testscript runner stops _proxy-child too; e2e: broker and child, their
arguments, descriptors and environment, stop, SIGKILL either, planted
files in the logs folder and the Nix cache, build proxies gone.
- Review fixes: the lifeline closes the socket and starts the kill's
timer before logging; every log lock (proxy.log's, the event log's
rotation) is tried without blocking for 200 ms (flockWithin, which the
Nix lock shares), then written without or the rotation skipped; a
copied log's rotation streams at most twice its limit from a line's
start (copyFrom, copyAtomic); a reply too long to send goes as
too_long; kept token headers capped at 1 KiB; the child gives up on a
request whose context ended, dropping its late reply and holding its
slot until then; a write deadline on the start frame; errors reach the
child as codes (not_found, refused, busy, too_long, failed), their
text in the broker's log; FuzzFrameStreams, and FuzzBrokerFrames
writes from a goroutine; nix_cache_locked links to How it works.
- Docs: processes, network, overview, design (with threat rows for the
logs' locks and a log made huge), troubleshooting, the proxy's
README, structure, testing; CHANGELOG.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
||
|
|
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]> |
||
|
|
90a64a44d1 |
fix(races): lock order checked, sandboxes' own ports, pins that meet a rename, daemons' groups stopped
- state: test builds and tests check the state locks' order (state.held, CheckLockOrder): a second VM's lock, a VM's lock under the claims lock, or a lock taken again panics before waiting. - platform: PinBeneath opens the path again when a rename takes the file away before move_mount (ENOENT), so the keeper no longer reports a false lost pin (TestPinsInNamespace's 'f lost / f pinned-again'); TestPinWhileRenamed. - daemon: Proc.Stop signals the process group (SignalGroup), so forwarders' and link sessions' ssh masters and relays end with them; ui.UI.StopsItsOwn makes _ports and _links wait for their ssh on an outside SIGTERM. - vm: gc --orphans and devvm space count forwarders' leftover control sockets (vmssh.ControlGlob). - CLI tests: each sandbox claims a block of ports below devvm's range and the ephemeral range (claimPortBlock, /tmp/devvm-test-ports); free_port, the fixtures' ports and DEVVM_SSH_PORTS come from it, and the sandbox's devvm chooses from its own range (DEVVM_PORT_RANGE override). Fixtures' forwarded ports and settings ports are rewritten too (FIXTURE_PORT_<port>). - netpolicy and vm tests: the fake proxy's stop waits for its reap, and fake daemons run until the test ends, not 30 s. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
a7cc12521e |
test(fuzz): fuzz targets with properties, fuzzed nightly
Twenty-three new fuzz targets, built-in Go fuzzing, each checking a property rather than only that nothing panics: parsers of what a VM or the network sends fail closed and keep to their caps, a secret goes only where it's bound, and no planted secret survives a redaction. - internal/proxy: FuzzCursorFrames (passes only what came; no message over frameMax or holding a JWT's start, decompressed and unescaped), FuzzInject (a binding's value only to a host it names, judged apart from the matcher in NormHost's form, for its path and methods, in its own header, which held the exact placeholder once; other headers untouched), FuzzParseBindings, FuzzLinkList, FuzzParseUpstream (errors hold no more of the URL than its scheme), FuzzNoProxy, FuzzParseNarinfo (only cache.nixos.org-1's signed narinfo is taken). - internal/agentlogin: FuzzParseTokenRequest, FuzzRedact (secrets planted eight ways in JSON and TOML settings), FuzzCapture (the VM's reply holds none of the endpoint's tokens). - internal/redact: FuzzSplit (a password written in parts through Split, as the run log writes it, never survives). - internal/jsonc: FuzzStrip, differential against encoding/json. - internal/upgrade: FuzzParsePublicKey, FuzzVerify, FuzzEntryName, FuzzUnpack. - internal/vmssh: FuzzParseHostKeys, FuzzParsePorts. - internal/vm: FuzzParseCloneState, FuzzParseInit, FuzzParseKept, FuzzParseLFSPointer. - internal/desktop: FuzzHandshakeVM. What they found, each fixed with a regression test: - NO_PROXY: an entry with port 0 (git.test:0) was read as the host on every port, and git.test:080 or :+80 as port 80, which Go's clients match against nothing; an entry whose port no request has, or that isn't plain decimal, now matches nothing (TestNoProxy, testdata/fuzz/FuzzNoProxy). FuzzHostSites' NO_PROXY site allows this difference from its frozen copy, and the design note lists it. - A JSON token request with more after its object was judged by its first object; it's refused now (TestCaptureRefuses). The Fuzz workflow runs nightly rather than two minutes weekly: five minutes a target, eight at a time, each target's corpus restored from and saved to a cache of its own (a failing input added to it, so it fails nightly until fixed), new inputs minimized in at most 1,000 runs, and one issue, "Fuzzing found failing inputs", opened, commented on when the failing targets change and closed on a clean night, by a separate job with issues: write that runs no repo code, on main alone. Target names must be unique across packages. bump.sh moves an action in a folder of its repo (actions/cache/restore, /save) with its repo's releases. Docs: Contributing's Fuzzing (running a target, the nightly run, every target's property), Maintaining's Fuzzing failures and its actions bump, the proxy README, the NO_PROXY and token request facts in How it works' network page and the design note. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
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]> |
||
|
|
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]>
|
||
|
|
1b8fd8a639 |
test(lifecycles): synctest bubbles for the relays, the forwarder, the links, the proxy and the daemon's stop
Timeouts, graces and closes are tested in testing/synctest bubbles on the
bubble's fake clock, to the moment, instead of sleeping and polling on the
real one, with stand-ins in memory behind seams that are fields. Each kind
keeps one real-process test. No behaviour change: each seam's production
value is what the code did before.
Seams:
- vmssh: sshRelay{grace, start} carries a relay (pipeSSH's body, as
pipeSSHFor was); start is execSSH in production.
- vmssh: Links.Listen (listenSocket unless set), for the links' sockets.
- proxy: egress.connect, the dialer for allowed far ends (a net.Dialer
with its 15 s timeout, set in newServer).
- daemon: Proc.Alive (Alive unless set).
- proxy: httpServer, the proxy's http.Server as run serves it, which the
tests' memServe shares.
New test-only package internal/memnet (standard library only): Pipe, whose
connections half-close, buffer 64 KiB and have deadlines, and Network,
listeners by address with Listen, Dial, DialContext and SetDeadline. The
structure test keeps it for tests and a leaf, depguard keeps it standard
library only, and its AfterFuncs are in goroutineSites.
Bubble tests:
- relay: TestRelayGrace (silent and talking, closed and half closed),
TestRelayGraceSlowClient, TestRelayGraceWriteError,
TestRelayCancelEndsBlockedWrite, TestGraceTimer (exact grace).
- forwarder: TestForwarder, TestForwarderAliveOnEnd, TestForwarderOnly,
TestForwarderGap (reports exactly Gap apart), TestForwarderGivesUpSilently,
TestForwarderClosesConnections (now also its stuck relay's ssh and slot).
- links: TestLinks, TestLinksSessionLost, TestLinksCap,
TestLinksEndStuckRelays (memSSH; relays end at the next sync on removal,
master replacement and target change), TestLinksList.
- proxy: TestTunnelHelloDeadline (EOF at exactly helloTimeout),
TestTunnelHelloStall (and a hello whole a moment before the deadline),
TestTunnelAddressSplitHello, TestConnectLimit, TestCloseConns,
TestCloseConnsWaitsBounded (close gives up at exactly closeWait),
TestSpliceEnds, TestSpliceEndsWhenItsClientCloses.
- secrets: TestSecretLookupFailuresNeverCached (hung lookups cut at
lookupTimeout, cancelled, failed and empty ones never cached; a request's
end doesn't cancel a lookup; the TTL to the moment).
- daemon: TestProcStopWaitsForTheEnd, TestProcStopKillsOnlyItsOwn,
TestProcStopKillsAfterWait (fakeProc), TestFollowLifeline.
- TestCursorReplyScans uses httptest.NewTestServer.
Kept on real processes and the real clock: TestPipeSSHGrace,
TestPipeSSHGraceSlowClient, TestPipeSSHGraceWriteError,
TestForwarderEndsStuckRelay, TestLinksBurst, TestSpliceKeepsAnEarlyAnswer,
TestProcStop.
Docs: Contributing's Tests has Time and lifecycles; structure.md, _index.md
and AGENTS.md name memnet.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
||
|
|
e4ea123927 |
feat(ports): VMs' ssh on ports browsers refuse
Lima listens on a VM's ssh port on this machine's loopback, and root in the VM can make what answers on port 22 speak HTTP, so a page opened as http://localhost:PORT reached a server the VM controls with the cookies of every app on localhost, even in a VM that forwards no ports. - Every VM's ssh port, and every build VM's, is one of the 17 ports every browser engine refuses (ports.SSHPorts): the Fetch standard's bad ports from 1024 up that Chromium's kRestrictedPorts blocks too, which leaves out 4190 and 6679 (headless Chrome 157 loads both). The one allocator chooses it (Allocator.SSH and Build, through freeSSH). A stopped VM keeps its port while it's on the list, free, not listed to forward and not held by another start or build; else it gets one no state records, or else a stopped VM's, which that VM gives up at its own next start. Another VM's listed ports are avoided only while that VM runs or starts. - The proxy and desktop ports never take one (free); one an older devvm chose moves at the VM's next start (Choose's keep path, proxyPort, the desktop's listener; Allocator.SSHOnly). - A forwarder never takes one unless its VM lists it (ports.Reserved), so a guest forwarding every port can't fill them; devvm ports and each launch warn when a VM's list names one, whatever set it (--ports, a devcontainer.json, config.toml's ports) (ports_ssh_listed, ports.SSHListed). - A start holds its port, kept or new, for a minute in the VM's own run/ports.ssh-hold (paths.VM.Forwarder; hold, held, projectHold), which other starts and builds avoid, so none takes it before Lima binds it; it goes with the VM's folder. - A build takes its clone's own port (was) only when no other is free. - Past 17: ports_ssh_limit names the VMs whose recorded ports are in use ("a or b" for a port two states record) with how many are taken otherwise, ports_ssh_limit_all when they have them all, and ports_ssh_limit_others when none of your VMs has one. - Older devvm's ports move at the VM's next start, in startSets' one limactl edit, and the start pins the new host keys (pinHostKeys); a running VM keeps its port until then, and each launch warns of running VMs still on an off-list port (ports_ssh_old, Allocator.OffList, confirmed with the backend's Running). - A test build's own list (DEVVM_SSH_PORTS, registry.Overrides.SSHPorts, the Allocator's and the Proxy's SSHList field), read only by readOverrides in a test build: each CLI test sandbox gets as many ports of its own from below the ephemeral range (sandboxPorts). Frozen 0.1.0 fixture: each launch now makes exactly one limactl edit, of .ssh.localPort alone, onto the sandbox's list, and vm.json changes only in .ports.host.ssh (and the start it records); the fixture's data is untouched. Messages: ports_ssh_limit, ports_ssh_limit_all, ports_ssh_limit_others, ports_ssh_listed, ports_ssh_old. Tests: TestSSHPorts (Fetch's list less Chromium's gaps, SSHListed, SSHOnly), TestSSH, TestSSHHolds, TestSSHListed, TestOffList, TestBuild, TestReserved, TestForwardsHeld's reserved counts, TestStartBuildSSHPort, TestPrepareRestartsTheProxy, TestDesktopListener, TestOverrides (DEVVM_SSH_PORTS), ssh_ports.txtar, fixture_v010.txtar, layout.txtar; e2e project: the ssh port, first and after a move, is one browsers refuse. Docs: internals/lima (the ssh bullet, the hold's limit), processes (listener table), design (threat check), ports, overview, contributing/structure and testing (DEVVM_SSH_PORTS), using/ports-size, troubleshooting (Too many VMs at once), safety/attack-vectors (allowed ports, port squatting), CHANGELOG Breaking (17 VMs; forwarding every port leaves the 17 out) and After you upgrade. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
cc94465400 |
test(leaktest): goroutine leak checks, and the leaks they found
A new internal/leaktest, standard library only, so the proxy's and the daemon's tests use it too (depguard's proxy rule allows it, and the structure test holds it to tests and to importing nothing of devvm's): - leaktest.Main(m), in TestMain: once the tests pass, every goroutine's stack (runtime.Stack), a settle of 5 s, then a failure naming those still running, but the standard library's own that outlive every test (allowed: signal.Notify's loop, an HTTP client's idle connections); then Go 1.27's goroutineleak profile, which fails on any goroutine blocked for good. - leaktest.Check(t), first in a test: its own goroutines, followed by parent through those still running, and by which ran before it, never by ID (each thread takes a batch of IDs). Main runs in proxy, vmssh, daemon, desktop, ui, vm, backend/lima, platform, cli and gitprotect (main_test.go, or the TestMain they had). Check runs in TestLinksEndStuckRelays (replacing its NumGoroutine count), TestForwarder, the desktop relay's serve helper, TestRunChild, TestPinWaits, and the proxy's new close tests. The structure test's goroutines rule (internal/structure/goroutines_test.go): goroutineSites lists every function outside tests that starts a goroutine, with a go statement, a wait group's Go, or time's or context's AfterFunc, function literals in package-level vars included, as "file: Func", with its waiter, or "detached: " and why nothing waits. A new one fails until listed, a listed one that starts none fails, and a package that starts one fails until its tests call leaktest.Main. Leaks it found, each fixed with a test: - The proxy's close left its connections running: http.Server's Close neither closes a connection a handler took (a CONNECT's tunnel, a WebSocket upgrade ReverseProxy takes) nor waits for a handler. conns (conns.go) holds every connection the listener accepted (track) and counts every handler (handle); serve calls closeConns once Serve returns, which closes them, closes any accepted after, and waits up to 5 s for the handlers. splice also ends when its client's connection can't be read (closed, reset), rather than half-closing the far end and waiting on it; a failed write to the server (one that answered early and closed) still lets its answer through. Tests: TestCloseConns (a tunnel and an upgrade), TestConnectAfterClose, TestSpliceEndsWhenItsClientCloses, TestSpliceKeepsAnEarlyAnswer; the tests' listen closes as the proxy does, and the fake upstream closes its target once its client's end comes. - platform's runChild left its signal-passing goroutine blocked on a channel signal.Stop never closes; it now closes it and waits (TestRunChild). - platform's WaitExit and WatchFolders blocked in poll(2) and read(2), which closing their fd from the stop doesn't wake on every kernel (Debian's didn't), and a retried call could land on a reused fd. They now wait in Go's poller (pollable), which the stop wakes (TestPinWaits, with a wait stopped before its process ends). Docs: Contributing's tests page (Goroutine leaks), the structure page (the goroutines rule, goroutineSites, the layers, the packages), the Go lint rules' depguard line, the proxy's shutdown in How it works' processes page and the proxy's README, and AGENTS.md. Coverage baselines: internal/leaktest's line on both systems, netpolicy's raise on macOS. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
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]> |
||
|
|
02ba74e614 |
build(lint): stricter linters, and the fixes they need
golangci-lint now also runs govet's nilness, unusedwrite, hostport and waitgroup analyzers, nilnesserr, durationcheck, canonicalheader, errchkjson, forcetypeassert, contextcheck and gochecksumtype. - errchkjson checks each JSON encoding's error where the value could fail and drops it where errchkjson proves it can't, and reports structs without exported fields; tests may drop theirs. - forcetypeassert holds the code; tests are exempt. - gochecksumtype: agentlogin's format is a sum type (//sumtype:decl), and a switch on one names every case, default or not. - canonicalheader: WWW-Authenticate, X-Request-ID, X-Api-Key. - contextcheck: ctx threaded through carry, peekClientHello and sniOf, and through inject and value, whose cached lookup takes WithTimeout(WithoutCancel(ctx)), so two forbidigo nolints go; openTransparent takes its dialer's ctx. nolints stay where contextcheck can't follow: ReverseProxy's Rewrite, WithoutCancel alone, cobra's cmd.Context, e2e's runner window. - No-behaviour fixes: scrubList for redact's list, the loopback forward's ports kept with its listeners, upgradetest's Key keeps its public key, a CA's leaves read through leafOf. Contributing's Go lint rules lists each one and the sum-type convention. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
5225d5b43e |
fix(links): a relay's grace waits out a slow client; CI-proof timing in two tests
TestPipeSSHGrace failed on GitHub's macos-latest runner ("talking, half
closed: the relay ended while the VM talked") twice, and
TestLinkCheckBurst once.
The relay's grace restarted only when a read from the VM completed, and
io.Copy reads nothing while its write to the client waits, so a client
that half-closed and read slowly, holding back the VM's answer, was cut
after the grace though the VM kept sending. The grace is now time the VM
sends nothing, never time a slow client takes: graceTimer runs only once
armed (the client's side closed, or the copy to the client ended with a
failed write or the VM's EOF), stops while a write to the client waits,
and starts again after each write. A client that stops reading thus
holds its relay and ssh itself, so the owner's context now also closes
the connection when it ends (context.AfterFunc), which ends a write
waiting on such a client: a forward's close, a link's removal or
LoopbackForward.Close can't hang on it.
The CI failures themselves were the test's margins: a 200 ms grace
against a stand-in that spawns sleep between writes. The talking case
now has a 2 s grace, 40 times the stand-in's 50 ms, and reads for a
second past it; pidOf waits up to 10 s for the stand-in to start.
TestLinkCheckBurst wasn't the relay changes': its 256 checks ran on the
real clock, and a burst slower than linkRunFor (1 s) looked the target
up twice. vm.Links has a clock seam, Now (time.Now unset), which
linkCheck's targetRuns uses, and the burst runs through linkCheck on a
clock that stands still. With a targetRuns made for each call, it fails
(256 Inspects).
- vmssh: graceTimer (arm, write, restart, stop) replaces reset;
graceWriter replaces graceReader; pipeSSHFor closes the connection
when its context ends
- vm: Links.Now, used by linkCheck; env.go names Links' Env field
- tests: TestPipeSSHGraceSlowClient and TestPipeSSHCancelEndsBlockedWrite
(each failed on the old code); TestGraceTimer replaces
TestGraceTimerStopped (unarmed, armed, written to, stopped, armed
while a write waits many graces); TestPipeSSHGrace's per-case grace;
pidOf's wait; TestLinkCheckBurst through linkCheck on a still clock
- stress, with four cores of background load: TestLinkCheckBurst and the
relay tests under -race -count=50 -cpu 1,2 and GOMAXPROCS=1, then the
relay and link tests of vmssh and vm under -race -count=20 -cpu 1,2:
all pass
- coverage: internal/vmssh's baseline raised
- docs: internals/ports (how it reaches the VM), the design note (each
connection, the lead for relays held after their client closed)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
||
|
|
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 (
|
||
|
|
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 (
|
||
|
|
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]>
|
||
|
|
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]> |
||
|
|
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]>
|
||
|
|
eaa1706966 |
docs: a unix socket's path has fewer than 104 characters
macOS's sun_path holds 104 bytes, its terminating NUL included, and Lima refuses a socket path whose length is UNIX_PATH_MAX or more, so a path has 103 characters at most. The internals pages (design, overview, ports), AGENTS.md and the comments on paths.SocketMax, the forwarder's control socket and the links' sockets said "at most 104"; they now say fewer than 104, as the Lima backend page and NameMax already did. The figures computed from the limit (a home folder of up to 37 characters, ControlMax) already allowed for the NUL and stay as they are. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
e0c4ed97e4 |
fix(vm): bound what devvm reads from a VM
The history export keeps at most 2 GiB: past it, devvm stops the VM's command, removes the partial file and keeps no export. devvm history export fails with history_too_large; devvm rm, devvm rm VM and a remake warn with it and go on. opencode's import of devvm's logins (devvm agent login) is read up to 1 MiB, then stopped and refused (opencode_import_too_much). Each VM command adds at most 4 MiB to the run log (Env.vmLog), then a "devvm: truncated" line. agentsave's bounded writer is the one owner, in bounded.go: it takes in vm's capped, and with a cancel it fails every write past its max, so a command that keeps writing ends. Its buffer is a field: embedded, it gave the writer bytes.Buffer's ReadFrom, which io.Copy (os/exec's copy of a command's output) used in place of Write, so no cap held, agent save's 128 MiB included. vmssh's capped had the same flaw, fixed the same way. Env.HistoryMax, and DEVVM_HISTORY_MAX in a test build, stand in for the export's cap in tests. The stub guest's opencode-floods and history-floods switches write without end. Tests: TestBounded (io.Copy too), TestVMLog, TestExportTooLarge, TestRemakeHistoryTooLarge, TestImportLoginsTooMuch, TestShellFloods, vmssh's capped through io.Copy; history_import.txtar (an export that never ends: export fails, rm deletes and warns, the run log truncated) and agent_login.txtar (opencode's import floods). Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
9b0bdf9685 |
refactor: deadcode lists only what tests use
msg.Fake's writers use cmp.Or in place of orDiscard, which only Fake called, and LoopbackForward.Ports, which only its test called, is the test's own listening helper. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
8d44175601 |
refactor: the Go module is github.com/devvmhq/devvm
Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
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]> |
||
|
|
2df3c6840c |
feat(agents): devvm agent login, an agent's login in the VM for every VM
devvm agent login codex|opencode logs the agent in from inside this
folder's VM, so this machine never needs Codex or opencode, and devvm's
agent store keeps the login for every VM with the agent. It sits under
devvm agent beside import and save: it fills the store, as they do, and
a bare devvm login would read as a verb on the VM itself.
- Browser login (the default): the agent's own login runs in the VM on
this terminal (codex -c cli_auth_credentials_store="file" login;
opencode auth login --provider openai --method "ChatGPT Pro/Plus
(browser)"), and devvm forwards this machine's localhost:1455, and
1457 (Codex's fallback) when free, on 127.0.0.1 and ::1, to the same
ports on the VM's loopback, only while the login runs: closed when it
ends, fails or is interrupted (AddCleanup), and an interrupt also ends
the agent's login in the VM (its pid kept in ~/.cache/devvm-login.pid),
so its server doesn't linger for the VM's port forwarder. Port 1455
taken on this machine: refused, naming --device-code.
- --device-code: codex login --device-auth, or opencode's headless
ChatGPT login; nothing forwarded.
- --api-key [--provider anthropic|openai|openrouter] [--stdin]: the key
is asked for on this machine (msg.Question answered by --stdin) and
saved in the store, never in the VM: Codex's auth.json becomes
{auth_mode: apikey, OPENAI_API_KEY}, opencode's gets the provider's
{type: api, key} beside the others; the running VM gets its copy with
a placeholder and its proxy the binding at once.
- The proxy's capture (agentlogin's capturers) saves ChatGPT logins;
devvm then confirms what the store saved, with the account's email,
and fails when the login saved nothing new.
- opencode 1.19.5 has no Anthropic OAuth in its core (no Anthropic
plugin among its built-ins), so there's no pasted-code capturer:
Anthropic is an API key. opencode's OpenAI login listens on 1455 only;
Codex 0.166 on 1455, falling back to 1457.
- vmssh: SSH.ForwardLoopback (LoopbackForward: listeners in devvm's own
process, each connection its own ssh -W to the VM's 127.0.0.1, no
master; ErrPortTaken).
- agentlogin: KeyProviders, File.SetKey, File.ChatGPT.
- secrets: Store.SaveKey, LoginSum, ChatGPT (loginsDir shared with
Capture).
- vm: AgentLogin (agentlogin.go), LoginAgents.
- cli: agentlogin.go (--device-code, --api-key, --provider, --stdin,
--here/--parent); usage errors before anything runs.
- assets/guest/sync.sh: cli_auth_credentials_store = "file" first in
the VM's ~/.codex/config.toml on every launch.
- Messages: agent_login_* and agent_key_*; codex_no_key,
codex_no_chatgpt, codex_refresh_failed and opencode_refresh_failed
point at devvm agent login.
- Tests: agent_login.txtar (usage errors, no VM, no agent, device code
argv, browser forward and its end, the agent failing, a login saved
while it runs, port taken, interrupt, API keys, the VM's copy failing,
no terminal, an empty key), unit tests for the forward, SetKey,
ChatGPT, SaveKey, the confirmation and the argv; coverage baselines
raised.
- e2e (network): the real Codex's login in the VM against the run's
fake token endpoint, its callback opened through the forward, the
store's tokens and key, placeholders in the VM, the forward gone; an
interrupted login takes its forward away.
- Docs: Logging in with devvm agent login (using/coding-agents.md),
the Commands page, the questions table, Contributing's e2e, the cli
skill's tree, AGENTS.md; the CLI reference.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
||
|
|
ac5aaeef0c |
refactor(vmssh): one checked ssh for a VM, vmssh.Checked
vmssh.Checked(ctx, dirs, review, backend, vm, ReadKeys|PinKeys) is the one way to a running VM's ssh: the review lets the backend's ssh through, its SSH target passes FromTarget, and the VM's host keys for its current start are read (KnownHostsFor) or pinned (PinHostKeys). It returns a Reach (SSH, the backend's other ssh options, the record's start). A failure before the host keys is an *UnusableError, the host keys' own wrap ErrNoHostKeys. It replaces vm's ownSSH body (ReadKeys), Forwards.start (PinKeys; Forwards gets a Review, from NewForwards) and sshconfig.Write (PinKeys, skipping UnusableError and ErrNoHostKeys; the start now comes from the record, not a second Running). Tests: TestChecked (refused, stopped, off loopback, read before a pin, pin, read, another start). Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
7bdaf8e99e |
refactor: one Reporter for every package's messages and prompts
msg.Reporter is what every package below cli prints and asks through: Info, Say, Note, Warn, Status, Ask, Confirm, Answer, the terminal checks and CanPick, the run log (LogNote, LogWriter, LoggedCmd, WithSteps), Stdout, Stderr, AddCleanup and Interrupted, under the UI's signatures. *ui.UI implements it (a compile-time check in ui), and msg.Fake is the tests': quiet as its zero value, its On funcs and fields record and answer. The six UI interfaces (tools, netpolicy, lima, registry, sshagent, vm) are gone, and the copied output and prompt func fields of tools.Env, tools.Making, gitprotect.Protector, secrets.Store, netpolicy.Proxy, from.Lookup, backend.Review, lima.Lima, sshagent.Agent, vm.Env, vm.SizeChoice, vm.AgentsChoice, vm.LayersChoice, vm.NetworkChoice, vmssh.Forwards, build.Env and sshconfig.Config: each embeds the Reporter. Lima's and the shared tools' Warn, which says where the run log is too, is a method of their own over it; vm's interactive check is a function over it. The pickers (build.Env.Pick, vm.Env's PickFeatures and PickParts, the choices' Pick) and vm.Env.CanAsk stay fields: they carry types of their own or cli's answer. The test UIs of tools, netpolicy, lima, registry, build and vm become msg.Fake. Coverage baselines raised: internal/backend/lima, internal/msg, internal/tools. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
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]> |
||
|
|
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]> |
||
|
|
bb7bc55d36 |
refactor(vmssh): remove Forwards.Running, which had no caller
Tests ask the forwarder's process (proc) directly; mise run deadcode now lists only the test helpers AGENTS.md allows. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
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]> |
||
|
|
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]> |
||
|
|
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]> |
||
|
|
6128f400e4 |
refactor(backend): Backend is four role interfaces, and Running replaces StartID, Confined and Lifeline
backend.Backend is Name, Caps and four roles, each required: - Host: Problems, NameMax, Location, DiskDirs, Floors - Images: BuildImage, Images, ImageSize, DeleteImage, BuildTools, ToolFormat, KeyFiles - Machines: CreateVM, Start, Running, ProxyURL, Stop, Delete, Rename, List, Inspect, Exec, Shell, SSH, ForwardTarget - Housekeeping: Usage, Strays, DevvmCache, DeleteCache The optional interfaces Lima implemented (KeyFiles, Storage, Locator, UsageReporter, StrayFinder, CacheCleaner) are gone into the roles, and their callers call the methods directly; Forgetter stays the one optional role, found with backend.As. Running(ctx, vm) returns a backend.Run (ID, Confined, Lifeline) in place of StartID, Confined and Lifeline. Space.Check, Space.Warning and LocationOf take a Host. lima.Lima keeps its fields, Name, Caps and its shared helpers (14 methods), and embeds host, images, machines and housekeeping, each over the Lima it's part of (withRoles); backendtest.Fake is split the same way. The guard has every role's methods, its own for the ones it guards. Structure test: max-methods counts an interface's declared methods too; Lima and the fake leave largeTypes. Tests: TestRunning, TestGuardRoles, TestAs (Forgetter), TestFakeRunningAndNone, two TestRulesFail cases. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
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]> |