Files
devvm/testdata/script/clone_hostkeys.txtar
w3cjandClaude Opus 5.5 c1cf96e4b6 fix(vm): every start pins the VM's host keys, whatever its ports
A start whose VM forwarded nothing, because other programs held every
listed port or the VM was devvm ports none, never pinned its ssh host
keys: only the port forwarder (Forwards.start, which returned before
vmssh.Checked) and the ssh config pinned them, and a start that went no
further than bringUp (devvm clone fetch, rm's fetch, the clone check)
wrote no ssh config. devvm's own ssh (ownSSH, vmssh.ReadKeys) then found
no record, and devvm clone fetch failed with clone_fetch_failed.

bringUp now pins them last, once the start or the running VM has gone
through the self-check (starter.pinHostKeys, vmssh.PinHostKeys), for a
VM whose backend's ssh the review allows. A record of the current start
is kept without reading the VM; ErrNoHostKeys is skipped, as the ssh
config skips it, and other errors fail the command. A running VM without
a record of its start, as this bug left one, gets it at its next
command.

Tests: TestFetchPinsHostKeys (forwarding none, every port taken,
running without a record), and TestUp, TestUpNetworkPolicy and
TestUpTools' calls with the pin after the self-check; testscript clone_hostkeys, its ports the
script's own listeners. fixture_v010_clone passes with 3000 and 5173
held. CHANGELOG Fixed entry; design.md's host key and security.md's ssh
into VMs say when the keys are read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-14 23:15:36 -07:00

41 lines
1.6 KiB
Plaintext

# Every start pins the VM's host keys, whatever it forwards: a --clone
# VM whose listed ports a program on this machine has, every one, and
# one that forwards none, are fetched from once a fetch starts them.
# Neither has a forwarder to pin them. The ports are the script's own
# listeners, so what this machine has listening doesn't matter.
env GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@t GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@t
listen_any TAKEN
listen_any TAKEN2
mkdir $WORK/web
cd $WORK/web
exec git init -q -b main
exec git commit -q --allow-empty -m one
exec devvm --clone --network open --ports $TAKEN,$TAKEN2
vm_name WEB web
exec sh -c 'git -C "$STUB_DIR/vmfs$(pwd -P)" checkout -q -b agent/x && git -C "$STUB_DIR/vmfs$(pwd -P)" commit -q --allow-empty -m from-vm'
# Stopped, then started by the fetch: both ports are the programs', so
# nothing is forwarded, and the fetch reaches the VM with its keys.
exec devvm stop
exec devvm clone fetch
stderr '^devvm: ports_taken count=2 ports='
stdout '^agent/x: \.$'
exists $WEB_dir/run/known_hosts
! exec sh -c 'ps -axww -o command= | grep -- "[_]ports -vm $WEB "'
# Forwarding none: the same.
exec devvm ports none
exec devvm stop
exec sh -c 'git -C "$STUB_DIR/vmfs$(pwd -P)" commit -q --allow-empty -m from-vm-2'
exec devvm clone fetch
! stderr ports_taken
stdout '^agent/x: \.$'
exec git log --format=%s -1 devvm/agent/x
stdout '^from-vm-2$'
# Running without a record of its start, as one started this way by an
# earlier devvm: the fetch pins them.
rm $WEB_dir/run/known_hosts
exec devvm clone fetch
exists $WEB_dir/run/known_hosts