mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 16:27:33 -10:00
ssh for editors is emulated on smolvm, and reviewed: devvm ssh, devvm code, --clone and the ssh config's entries work as on Lima. - sshd: sshd.sh installs openssh-server in base after its scripts (from the snapshot they pin; before them, the live archive's systemd libraries broke Docker's install) and deletes its host keys; prepare.sh sets the user's password to * (sshd without PAM refuses a locked account's keys). Both are in base's key. - Start: Confinement.SSH (set by vm.start when Require lets ssh through) forwards guest port 22 from a host loopback port (Confinement.SSHPort, else the recorded one while free, else a new one; never one of the VM's own forwards: smolvm_ssh_port_forwarded), then services.sh makes new ed25519 host keys at every start, writes the VM's only authorized key and devvm's own sshd config (VM's user only, publickey only, local forwarding only, no remote forwarding, tunnels or X11; SetEnv of /etc/environment and the proxy's variables, by name), and starts sshd. The record's ssh_up is cleared before each start and set once sshd runs; SSH answers only then. - An image without sshd (probed before services.sh) starts without ssh, warned (smolvm_no_sshd). - Keys: one per VM, smolvm/vms/<vm>.key (mode 600, OpenSSH format made in Go, its public half read back from it), deleted with the VM. SSH returns 127.0.0.1, the port, the user, IdentityFile, IdentitiesOnly yes, PreferredAuthentications publickey. - Ports: smolvm forwards at most 64 per machine, so a VM's own are at most 63; port 22 in --ports is refused (smolvm_port_ssh). - Shared ssh entries (Lima too): ForwardX11 no, ForwardX11Trusted no, Tunnel no, PermitRemoteOpen none, AddKeysToAgent no, ProxyJump none, ProxyCommand none, UpdateHostKeys no, HashKnownHosts no; no IgnoreUnknown (its first value would replace a user's Host * one), so devvm needs OpenSSH 8.7 or newer. sshconfig.Write skips a backend whose ssh isn't usable (backend.Allowed); vm.reach checks the backend's SSH. - netpolicy: freePort avoids every VM's forwarded ports, and a stopped VM's ssh_port is picked again when it's one of its own. - Lima: layers/base.sh writes /etc/ssh/sshd_config.d/00-devvm.conf (local forwarding only, no remote forwarding, tunnels or X11), which changes base's image key on Lima and smolvm. - Messages: smolvm_port_ssh, smolvm_no_ssh, smolvm_no_sshd, smolvm_ssh_port_forwarded. - Tests: unit (keys and their parsing, Start with and without ssh, port reuse and collisions, ssh_up, no sshd, Allowed, entries under a user's Host * with an IgnoreUnknown through the real ssh -G, netpolicy forwards); testscript smolvm.txtar (forward, services args, entry, pinned keys, devvm ssh, no sshd, port 22) and ssh.txtar (entry options); e2e smolvm: entry and loopback-only forward, listening ports, net backend pinned (virtio-net with a forward, TSI without), pinned host keys of each VM's own and new ones per start, a changed key refused, environment, agent off with ssh -A as the control, password/keyboard-interactive/other key/root/other user refused, remote forwarding refused, sshd -T, a hostile sshd that gets no display and no key through a Host * asking (command-line controls, and ssh -R shown not covered), devvm ssh and code, another VM's key refused, a squatted port, no sshd, stop and rm, --clone seed/fetch/push/rm, and under network policy ssh on ssh_port with the proxy's variables, no way out through local or remote forwards (with controls), DNS no-leak with the forward and the nettop DNS control on a machine without one; e2e Lima: its sshd's forwarding refused, the entry's options under a hostile Host *. - Docs: smolvm.md (ssh for editors), backends.md, security.md (ssh into VMs, remote forwards you ask for), ssh.md, install.md (OpenSSH 8.7), design.md (the design note: the guarantee, what keeps a session from carrying the VM out, DNS detection by net backend, not covered: remote forwards you ask for), limits.md, testing.md, contributing.md; AGENTS.md gotchas. Co-Authored-By: Claude Opus 5.5 <[email protected]>
85 lines
3.7 KiB
Plaintext
85 lines
3.7 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 '^ 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'
|
|
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
|