mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
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]>
94 lines
3.9 KiB
Plaintext
94 lines
3.9 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
|
|
# once for each start into its own record; 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
|
|
vm_name WEB web
|
|
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/vms/[0-9a-f]{14}/run/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 $WEB_dir/run/known_hosts
|
|
stdout '\A# devvm: host keys of start [0-9]+ \S+\ndevvm-web-[0-9a-f]{14} ssh-ed25519 \S+\n\z'
|
|
exec grep -c ' ssh-ed25519 ' $WEB_dir/run/known_hosts
|
|
stdout '^1$'
|
|
exec sh -c 'ls -l "$DATA/ssh_config" "$WEB_dir/run/known_hosts"'
|
|
! stdout '^-.{3}[^-]'
|
|
! exists $DATA/known_hosts
|
|
! 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.
|
|
cp $WEB_dir/run/known_hosts $WORK/web-keys
|
|
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'
|
|
cmp $WEB_dir/run/known_hosts $WORK/web-keys
|
|
vm_name IMG img-foo
|
|
catg $IMG_dir/run/known_hosts
|
|
stdout '^devvm-img-foo-[0-9a-f]{14} ssh-ed25519 '
|
|
! cmp $IMG_dir/run/known_hosts $WEB_dir/run/known_hosts
|
|
|
|
# A second folder named web: its VM by its full name only, as the first
|
|
# VM keeps devvm-web, chosen when it was made.
|
|
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'$'
|
|
|
|
# The record is read once for each start: a launch of the running VM
|
|
# keeps it, and keys recorded for another start are read again once it
|
|
# starts, not trusted.
|
|
exec sh -c 'sed "s/^\($IMG\) ssh-ed25519 .*/\1 ssh-ed25519 AAAAold/" "$IMG_dir/run/known_hosts" > "$WORK/kh" && cp "$WORK/kh" "$IMG_dir/run/known_hosts"'
|
|
cd $WORK/img-foo
|
|
exec devvm
|
|
catg $IMG_dir/run/known_hosts
|
|
stdout AAAAold
|
|
exec devvm restart
|
|
catg $IMG_dir/run/known_hosts
|
|
! stdout AAAAold
|
|
stdout '^devvm-img-foo-[0-9a-f]{14} ssh-ed25519 '
|
|
|
|
# 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
|
|
vm_name NOKEYS nokeys
|
|
catg $DATA/ssh_config
|
|
! stdout devvm-nokeys
|
|
stdout '^Host devvm-img-foo '
|
|
! exists $NOKEYS_dir/run/known_hosts
|
|
rm $STUB_DIR/hostkeys-fail
|
|
! exists $HOME/.ssh
|