mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
limactl shell asks ssh to send COLORTERM (SendEnv), but its session rides Lima's shared ssh connection (ControlMaster), opened without it, and the master filters a session's environment by its own SendEnv, so the variable never reached the VM (lima-vm/lima#2208, #1481). Closing that connection would end every session and the VM's SSH agent relay, so devvm now sets COLORTERM in the command it runs in the VM instead: - backend.ShellOpts and ExecOpts get ColorTerm. Lima's Exec runs `cd D && export COLORTERM=<quoted> && exec argv`, and its Shell, with a ColorTerm, runs `sh -c 'export COLORTERM=<quoted> && exec "$SHELL" --login'`, as limactl shell does without a command; without one, the argv is as it was. colorTerm (lima) quotes the value with shell.Quote and links Lima #2208, so it can go once Lima sends it. - vm's colorTerm is the one allow-list: only truecolor and 24bit pass, anything else or none is "". target.shell (devvm's shell) and AgentLogin.loginOpts (an agent's login on a terminal) fill it from Env.Getenv; no other command in the VM gets it. - devvm's ssh config entries add `SendEnv COLORTERM`, so plain ssh by name (ControlMaster no) sends it: the e2e showed the base's sshd has AcceptEnv COLORTERM. It adds to a Host *'s SendEnv. Tests, each failing without the fix: TestExecAndShellColorTerm (lima), TestColorTerm (vm: the shell's and the login's value for allowed, near-miss and injection-shaped values), testdata/script/colorterm.txtar (the stub limactl's argv for the shell and an agent's login), ssh.txtar and sshconfig's pinned lines, and e2e: a fresh VM's first shell, a login shell on a terminal in the folder (24bit, and none for another value) and ssh devvm-web. The structure test's dynamicScripts lists both new built scripts. Docs: Managing VMs, ssh access by name, How it works' Lima (A shell's colors) and security (the ssh entries), and CHANGELOG Fixed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
96 lines
3.6 KiB
Plaintext
96 lines
3.6 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 --network open --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 '^ SendEnv COLORTERM$'
|
|
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 stub vm $WEB Stopped
|
|
exec stub vm devvm-img-0123456789ab Running
|
|
exec stub vm devvm-tools-build Running
|
|
project img-foo
|
|
exec devvm --network open --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 stub vm $WEB Running
|
|
mkdir $WORK/other/web
|
|
cd $WORK/other/web
|
|
exec devvm --network open --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-fails"'
|
|
project nokeys
|
|
exec devvm --network open --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-fails
|
|
! exists $HOME/.ssh
|