mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
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]>
60 lines
2.2 KiB
Plaintext
60 lines
2.2 KiB
Plaintext
# A VM's ssh port is one of the ports browsers refuse (here the sandbox's
|
|
# own, DEVVM_SSH_PORTS): chosen as it's made, kept at its starts. A
|
|
# running VM on a port an older devvm chose is warned of at each launch,
|
|
# and a start with none of the ports free fails, naming who has them.
|
|
|
|
# A new VM's port is on the list, and its clone sets it.
|
|
project web
|
|
exec devvm --network open --no-git-protect
|
|
vm_name WEB web
|
|
exec sh -c 'p=$(sed -n "s/.*\"ssh\": \([0-9]*\).*/\1/p" "$WEB_dir/vm.json") && case ",$DEVVM_SSH_PORTS," in *",$p,"*) ;; *) exit 1 ;; esac'
|
|
! stderr ports_ssh
|
|
|
|
# Running on a port off the list, as an older devvm started it: kept, and
|
|
# each launch warns of it.
|
|
listen_any OLD
|
|
json_set $WEB_dir/vm.json ports.host.ssh:=$OLD
|
|
stub_reset
|
|
exec devvm
|
|
stderr '^devvm: ports_ssh_old vms=devvm-web-[0-9a-f]{14}$'
|
|
stub_calls
|
|
! stdout 'limactl (edit|start)'
|
|
grep '"ssh": '$OLD'\b' $WEB_dir/vm.json
|
|
|
|
# Stopped, it moves back onto the list at its next start, with no
|
|
# warning. (Its Lima config still has the port it was made with, which
|
|
# the start may choose again, so it makes at most one edit; the frozen
|
|
# fixtures' starts check the edit.)
|
|
exec limactl stop $WEB
|
|
stub_reset
|
|
exec devvm
|
|
! stderr ports_ssh
|
|
stub_calls
|
|
! stdout '(?s)limactl edit .*limactl edit'
|
|
! grep '"ssh": '$OLD'\b' $WEB_dir/vm.json
|
|
exec sh -c 'p=$(sed -n "s/.*\"ssh\": \([0-9]*\).*/\1/p" "$WEB_dir/vm.json") && case ",$DEVVM_SSH_PORTS," in *",$p,"*) ;; *) exit 1 ;; esac'
|
|
exec limactl stop $WEB
|
|
|
|
# A list that names ports browsers refuse, kept for VMs' ssh, says so;
|
|
# one without them says nothing.
|
|
exec devvm ports -g 5173,6000-6666
|
|
stderr '^devvm: ports_ssh_listed count=4 ports=6000,6566,6665,6666$'
|
|
exec devvm ports -g 5173
|
|
! stderr ports_ssh_listed
|
|
exec devvm ports 6000
|
|
stderr '^devvm: ports_ssh_listed count=1 ports=6000$'
|
|
# And each launch says so, whatever set the list: here, --ports.
|
|
project x11
|
|
exec devvm --network open --no-git-protect --ports 5173,6000
|
|
stderr '^devvm: ports_ssh_listed count=1 ports=6000$'
|
|
vm_name X11 x11
|
|
exec limactl stop $X11
|
|
|
|
# None of the ports free: a new VM isn't made, saying they're taken on
|
|
# this machine.
|
|
listen_any HELD
|
|
env DEVVM_SSH_PORTS=$HELD
|
|
project api
|
|
! exec devvm --network open --no-git-protect
|
|
stderr '^devvm: ports_ssh_limit_others limit=1$'
|