mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
Each running project VM can be reached as devvm-<folder> (or by its full name when two folders share a name) through ~/.config/devvm/ssh_config, which up rewrites after the VM's setup. Every entry checks the VM's own host keys, kept in ~/.config/devvm/known_hosts and read from the VM through its backend, and sets StrictHostKeyChecking yes, ForwardAgent no (unless the VM forwards), and its own connection. Only Lima's login options are copied. Host keys are dropped before each start, and when an interrupted new VM is deleted, so they're read again. Ported: write_ssh_config (sshconfig.Write), record_host_keys, forget_host_keys (ForgetHostKeys, in vm start and the interrupt cleanup), ensure_ssh_include (EnsureInclude: asks with [Y/n] on a terminal, else says to add the line; no caller yet: --clone and devvm ssh/code), ssh_alias (Alias), is_project_vm (project.IsVM), check_ssh_agent (vm checkAgent, run when a new VM forwards the agent). Backend.SSH's SSHTarget gains Options (Lima: identityfile, identitiesonly, preferredauthentications, batchmode, compression, gssapiauthentication, ciphers). Registry.All, state.WriteFile. Messages: ssh_include_needed, ssh_include_yourself, add_it_now, ssh_include_added, no_ssh_agent, ssh_agent_empty, load_key, key_loaded, key_loaded_keychain, load_key_with. Doc links: ssh_remote_hint, ssh_include_yourself. Converted bats cases: cli.bats "ssh config: only running VMs, each with its own host key checked; Lima's unchecked settings left out" (ssh.txtar, lima TestSSH, sshconfig TestWrite; the rm half waits for rm), delete.bats "ls and the ssh config include a project VM named like an image" (ssh config half: ssh.txtar, TestWrite), project.bats "ssh_alias: short name unless two folders share it" (TestAlias, ssh.txtar). New: TestWriteUnchecked, TestParseHostKeys, TestEnsureInclude, TestCheckAgent, TestIsVM. Stub limactl: Lima-like ssh.config at start, host keys from shell, sshLocalPort/sshConfigFile in list. e2e: project checks the hostname, the entry, pinned host keys, ssh devvm-web through an ~/.ssh/config of the run's own (Include plus Host * ForwardAgent yes), no agent forwarded (a throwaway agent), a changed host key refused; network checks ssh devvm-net. Nothing touches the real ~/.ssh. Docs: ssh.md (from the ssh page), linked from the index, commands, security, images and contributing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
76 lines
3.4 KiB
Plaintext
76 lines
3.4 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.
|
|
env DEVVM_MESSAGES=names
|
|
env CFG=$XDG_CONFIG_HOME/devvm
|
|
mkdir $WORK/web
|
|
cd $WORK/web
|
|
exec devvm --no-network-policy --no-git-protect base
|
|
exec sh -c 'cat "$CFG/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*/config/devvm/known_hosts"$'
|
|
stdout '^ StrictHostKeyChecking yes$'
|
|
stdout '^ NoHostAuthenticationForLocalhost no$'
|
|
stdout '^ ForwardAgent no$'
|
|
stdout '^ ControlMaster no$'
|
|
stdout '^ ControlPath none$'
|
|
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'
|
|
exec sh -c 'cat "$CFG/known_hosts"'
|
|
stdout '\Adevvm-web-[0-9a-f]{14} ssh-ed25519 AAAAstubkeydevvmweb[0-9a-f]{14}\n\z'
|
|
exec sh -c 'ls -l "$CFG/ssh_config" "$CFG/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"'
|
|
mkdir $WORK/img-foo
|
|
cd $WORK/img-foo
|
|
exec devvm --no-network-policy --no-git-protect base
|
|
exec sh -c 'cat "$CFG/ssh_config"'
|
|
stdout '^Host devvm-img-foo devvm-img-foo-[0-9a-f]{14}$'
|
|
! stdout 'devvm-web|devvm-img-0123456789ab|devvm-tools-build'
|
|
exec sh -c 'cat "$CFG/known_hosts"'
|
|
stdout '^devvm-web-'
|
|
stdout '^devvm-img-foo-'
|
|
|
|
# Two folders named web: each VM by its full name only.
|
|
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 base
|
|
exec sh -c 'cat "$CFG/ssh_config"'
|
|
stdout -count=2 '^Host devvm-web-[0-9a-f]{14}$'
|
|
! stdout '^Host devvm-web '
|
|
|
|
# A VM made again under a name whose host keys devvm has: they're read
|
|
# again once it starts, not trusted.
|
|
exec sh -c 'n=$(ls "$XDG_DATA_HOME/devvm/vms" | grep "^devvm-img-foo-") && limactl delete -f "$n" && rm "$XDG_DATA_HOME/devvm/vms/$n" && sed "s/^\($n\) .*/\1 ssh-ed25519 AAAAold/" "$CFG/known_hosts" > "$WORK/kh" && cp "$WORK/kh" "$CFG/known_hosts"'
|
|
cd $WORK/img-foo
|
|
exec devvm --no-network-policy --no-git-protect base
|
|
exec sh -c 'cat "$CFG/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"'
|
|
mkdir $WORK/nokeys
|
|
cd $WORK/nokeys
|
|
exec devvm --no-network-policy --no-git-protect base
|
|
exec sh -c 'cat "$CFG/ssh_config"'
|
|
! stdout devvm-nokeys
|
|
stdout '^Host devvm-img-foo '
|
|
exec sh -c 'cat "$CFG/known_hosts"'
|
|
! stdout devvm-nokeys
|
|
rm $STUB_DIR/hostkeys-fail
|
|
! exists $HOME/.ssh
|