mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
Every file devvm keeps for a project VM is in one folder, vms/<hash>/, where <hash> is the 14-hex hash of the project folder's path that the VM's name ends with: its state, its own rules (policy), its backend's files (backend/: record.json, key, known_hosts, proxy, ports and the port forwarder's ports.*), what its runs leave (run/: proxy.*, sandbox.sb, started, lifeline.pid, secrets.*, links.*) and its logs (logs/: network.jsonl, proxy.log, links.log). Build VMs keep the same layout in run/builds/<name>/. The top-level run/ holds only what isn't one VM's or must be short: the hashed control sockets, links' link-<hash>.sock/.ctl, the QEMU wrapper and the ports lock. A folder's VM is found by its path's hash (state.ReadHash), with the name and backend its state records, so devvm --backend docker then devvm in the same folder opens the one VM, and a backend's name limit applies to new VMs only. The state records the VM's name and its ssh alias, chosen once at creation (sshconfig.ChooseAlias) and never recomputed. Links' targets match recorded names, aliases and folders (project.Targets). One teardown (vmFolders.teardown) replaces Lifecycle.forget, undoCreate's own list, Leftovers.Forget's, Proxy.Forget and space's leftoverFiles: it stops the proxy and link session, then the pieces outside the folder (clone remote or .git locks, other VMs' links and the group, host keys, the backend's leftovers), removes the folder, and writes the ssh config. Each backend's Delete and Forget remove the VM's backend/ folder (vmssh.Forwards.Forget). A new VM made where an earlier one's folder was left clears it first. devvm space counts an orphan's whole folder as leftover state and the other VMs' logs as network logs. Path builders move into paths: Dirs.VMDir, Dirs.VM and paths.VM's files (secrets' BindingsFile/PolicyFile, netpolicy's run, EventLog, ProxyLog, LinkList, VMPolicyFile, Lima's profileFile, startedFile, forwards.file, vmssh.Forwards.file, links' LinksLog/linksPID, Docker's vmFile and lifeline), ToolLockConfig, ToolLockChecked and ToolsCheckLog; the user's cache folder for Lima's and smolvm's caches is Dirs.UserCache, from HOME, not os.UserCacheDir. Dirs.VMState, LimaVMs, SmolvmVM and DockerVM go. vmname.HashOf and IsHash, project.Hash. The proxy takes the links' sockets' folder (-link-sockets, devvm's run folder) apart from the links' list, which is in the VM's run folder. Tests: a VM made and removed (rm, gc --orphans) leaves nothing under vms/, and with network policy has no file named for it outside its folder (TestTeardownLeavesNothing); a new VM over an old folder starts clean; lookup finds a VM made on another backend with a long folder name and makes no second one (TestLookupOtherBackend, and in docker.txtar); the alias stays put when a second VM shares the folder name (TestChooseAlias, ssh.txtar); every socket fits under a 35-character home with the longest VM name (TestSocketsFit); space counts an orphan's whole folder (TestLeftoverFolders); paths.VM's files; state by hash and name; the proxy refuses a socket in the list's own folder. Co-Authored-By: Claude Opus 5.5 <[email protected]>
84 lines
3.5 KiB
Plaintext
84 lines
3.5 KiB
Plaintext
# devvm's ssh config: every running project VM by name (devvm-<folder>,
|
|
# and its full name), checked against its own host keys, read from the VM;
|
|
# Lima's own settings that turn host key checks off, share a connection or
|
|
# run commands left out. The user's ~/.ssh is never touched.
|
|
project web
|
|
exec devvm --no-network-policy --no-git-protect
|
|
catg $DATA/ssh_config
|
|
stdout '\A# Written by devvm on every launch; edits are overwritten\.\n\nHost devvm-web devvm-web-[0-9a-f]{14}\n'
|
|
stdout '^ HostKeyAlias devvm-web-[0-9a-f]{14}$'
|
|
stdout '^ UserKnownHostsFile "/\S*/data/devvm/known_hosts"$'
|
|
stdout '^ StrictHostKeyChecking yes$'
|
|
stdout '^ NoHostAuthenticationForLocalhost no$'
|
|
stdout '^ ForwardAgent no$'
|
|
stdout '^ ControlMaster no$'
|
|
stdout '^ ControlPath none$'
|
|
stdout '^ ForwardX11 no$'
|
|
stdout '^ ForwardX11Trusted no$'
|
|
stdout '^ Tunnel no$'
|
|
stdout '^ PermitRemoteOpen none$'
|
|
stdout '^ AddKeysToAgent no$'
|
|
stdout '^ ProxyJump none$'
|
|
stdout '^ ProxyCommand none$'
|
|
stdout '^ UpdateHostKeys no$'
|
|
stdout '^ HashKnownHosts no$'
|
|
stdout '^ Hostname 127\.0\.0\.1$'
|
|
stdout '^ Port 60022$'
|
|
stdout '^ User stub$'
|
|
stdout '^ IdentityFile "/\S*/lima/_config/user"$'
|
|
stdout '^ IdentitiesOnly yes$'
|
|
! stdout 'StrictHostKeyChecking no|/dev/null|NoHostAuthenticationForLocalhost yes'
|
|
! stdout 'ControlMaster auto|ssh\.sock|ControlPersist|LocalCommand'
|
|
catg $DATA/known_hosts
|
|
stdout '\Adevvm-web-[0-9a-f]{14} ssh-ed25519 AAAAstubkeydevvmweb[0-9a-f]{14}\n\z'
|
|
exec sh -c 'ls -l "$DATA/ssh_config" "$DATA/known_hosts"'
|
|
! stdout '^-.{3}[^-]'
|
|
! exists $HOME/.ssh
|
|
|
|
# A stopped VM drops out; its keys stay. A project folder named like an
|
|
# image (img-foo) is a project VM; images and build VMs aren't listed.
|
|
exec sh -c 'sed "s/^\(devvm-web-[0-9a-f]*\) Running$/\1 Stopped/" "$STUB_DIR/instances" > "$STUB_DIR/i" && mv "$STUB_DIR/i" "$STUB_DIR/instances"'
|
|
exec sh -c 'echo "devvm-img-0123456789ab Running" >> "$STUB_DIR/instances" && echo "devvm-tools-build Running" >> "$STUB_DIR/instances"'
|
|
project img-foo
|
|
exec devvm --no-network-policy --no-git-protect
|
|
catg $DATA/ssh_config
|
|
stdout '^Host devvm-img-foo devvm-img-foo-[0-9a-f]{14}$'
|
|
! stdout 'devvm-web|devvm-img-0123456789ab|devvm-tools-build'
|
|
catg $DATA/known_hosts
|
|
stdout '^devvm-web-'
|
|
stdout '^devvm-img-foo-'
|
|
|
|
# A second folder named web: its VM by its full name only, as the first
|
|
# VM keeps devvm-web, chosen when it was made.
|
|
vm_name WEB web
|
|
exec sh -c 'sed "s/^\(devvm-web-[0-9a-f]*\) Stopped$/\1 Running/" "$STUB_DIR/instances" > "$STUB_DIR/i" && mv "$STUB_DIR/i" "$STUB_DIR/instances"'
|
|
mkdir $WORK/other/web
|
|
cd $WORK/other/web
|
|
exec devvm --no-network-policy --no-git-protect
|
|
catg $DATA/ssh_config
|
|
stdout -count=1 '^Host devvm-web-[0-9a-f]{14}$'
|
|
stdout '^Host devvm-web '$WEB'$'
|
|
! stdout '^Host '$WEB'$'
|
|
|
|
# A VM made again under a name whose host keys devvm has: they're read
|
|
# again once it starts, not trusted.
|
|
vm_name IMG img-foo
|
|
exec sh -c 'limactl delete -f "$IMG" && rm -r "$IMG_dir" && sed "s/^\($IMG\) .*/\1 ssh-ed25519 AAAAold/" "$DATA/known_hosts" > "$WORK/kh" && cp "$WORK/kh" "$DATA/known_hosts"'
|
|
cd $WORK/img-foo
|
|
exec devvm --no-network-policy --no-git-protect
|
|
catg $DATA/known_hosts
|
|
! stdout AAAAold
|
|
stdout '^devvm-img-foo-[0-9a-f]{14} ssh-ed25519 AAAAstubkeydevvmimgfoo[0-9a-f]{14}$'
|
|
|
|
# A VM that doesn't show its host keys gets no entry: ssh couldn't check it.
|
|
exec sh -c ': > "$STUB_DIR/hostkeys-fail"'
|
|
project nokeys
|
|
exec devvm --no-network-policy --no-git-protect
|
|
catg $DATA/ssh_config
|
|
! stdout devvm-nokeys
|
|
stdout '^Host devvm-img-foo '
|
|
catg $DATA/known_hosts
|
|
! stdout devvm-nokeys
|
|
rm $STUB_DIR/hostkeys-fail
|
|
! exists $HOME/.ssh
|