mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
main
10
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
947decb301 |
fix(vm): VMs get the host terminal's COLORTERM (fixes #54)
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]> |
||
|
|
ceda0bf925 |
feat(cli): --network TIER, devvm network TIER and the tier question
The command line names the four network tiers. --network TIER (open,
internet, allowlist or none) chooses a new VM's tier, checked before
anything runs (arg_not_choice). devvm network open|internet|allowlist|none
gives the folder's VM a tier through Net.SetTier, and devvm network -g
takes the tiers and ask. config.toml's and settings.json's network is ask
or a tier (settings.NetworkChoices, checked against netpolicy.TierNames
by a test, since settings can't import netpolicy).
The question on creation is Proxy.Choose(vm): net_about says what each
tier reaches, net_ask asks for one (Answer, AnsweredBy("--network")),
Enter or a refusal gives allowlist, and an answer that isn't a tier is
warned of (net_tier_unknown) and asked again. devvm setup's picker
offers ask and the four tiers (network_default_open, _internet,
_allowlist, _none). On an existing VM, --network is ignored with the
devvm network TIER command that changes it.
devvm network --json: policy is the tier or unenforced, and each policy
file whose denies alone apply (internet and none) has denies_only: true,
as the text output's "(denies only)", so a script can tell a file's
denies from all of its rules without knowing the tier rules.
Messages reworded: net_tier_backend (--network open), net_open_policy
(devvm network allowlist), net_about, net_ask, network_default*,
net_default_failed, network_failed, setting_already's and
widen_parent_vm*'s descriptions. safety/network's "Choosing a tier"
replaces its on/off section; docs, the cli skill, testscripts and e2e
use the new forms, and e2e's internet and none checks go through devvm
network.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
||
|
|
39c2ff4f4e |
test: one Go multi-call stub for every host command
The 18 shell stubs in testdata/stubs (about 600 lines, limactl 337 of them) are one Go binary, internal/stubtest/stub, which acts as the command it's run as (argv[0]): limactl, docker, security, ssh, ssh-add, ssh-agent, ssh-keygen, qemu-img, qemu-system-aarch64, qemu-system-x86_64, chflags, tmutil, sw_vers, uname, open, code and mise, and stub, scripts' commands on the stubs' state. stub-log is gone: each stub logs its call itself, in one write to $STUB_LOG, its arguments on no other process's command line. - internal/stubtest builds the binary once, into $TMPDIR/devvm-stubs-<hash> (its sources and Go's version) with a link per command, which every test process and later run reuses until the sources change; a day-old folder of another build is removed. stubtest.Bin, stubtest.Command (DEVVM_HOST_MISE's path), and Stubs' VM, Size, VMs, Keychain and SetKeychain on the state. - internal/stubtest/stubstate: the stubs' state, $STUB_DIR/state.json, typed JSON under a file lock (Lima's instances with their status, size and config, the Keychain, the SSH agent and its keys, Time Machine's exclusions, the tools build VM's folder). The instances file wasn't locked; TestCreatesAtOnce and TestUpdatesAtOnce make 20 and 50 changes at once. - guest.go is the VM behind limactl shell and ssh alike: a --clone VM's git on vmfs, a remake's home, a base build's packages, the setup's tar, the direct connection, host keys, a forwarder's ports, link forwards. - A link session's master listens with a backlog of one and never accepts, as the Perl one did, so a killed session's socket reads as stale once probed (link_life). TestScript's cleanup stops the sandbox's masters by their -M -S arguments. - Structure: the stubtest layers cover internal/stubtest/..., the binary and its state import nothing else of devvm's; execSites lists internal/stubtest/build.go and internal/stubtest/stub/process.go. Renamed switch: hostkeys-fail is hostkeys-fails. Moved into the state: instances, size-<vm>, config-<vm>, keychain/<account>, agent-up, agent-held, tm-excluded and tools-out; scripts use stub vm, vms, size, keychain, keychain-set, agent and agent-stop instead (build, existing, from, gc, gc_orphans, images, ls, net_interrupted, rebuild, rm_vm, secret, size, space, ssh, ssh_agent, up). Tests: stub_test.go (every stub in-process, TestShellWords), stubstate_test.go, TestBuild, TestCreatesAtOnce, TestState; the lima, platform, vm, tools and build tests use the state helpers and stubtest.Command. Coverage: internal/stubtest/stub and stubstate added, stubtest, build and tools raised (and lima, netpolicy on Linux). Docs: contributing (Stubs: the binary, logging, the state and the stub command, switches, the guest, adding a stub or a switch; Go test helpers; the layers), testing.md; AGENTS.md's stubtest and testdata rows. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
50b0db2f7e |
refactor(vmssh): one host-key record per VM per start, which every ssh of devvm's checks
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]> |
||
|
|
d8a7d4de7f |
refactor(state): a folder per VM, keyed by its project folder's hash
Every file devvm keeps for a project VM is in one folder, vms/<hash>/, where <hash> is the 14-hex hash of the project folder's path that the VM's name ends with: its state, its own rules (policy), its backend's files (backend/: record.json, key, known_hosts, proxy, ports and the port forwarder's ports.*), what its runs leave (run/: proxy.*, sandbox.sb, started, lifeline.pid, secrets.*, links.*) and its logs (logs/: network.jsonl, proxy.log, links.log). Build VMs keep the same layout in run/builds/<name>/. The top-level run/ holds only what isn't one VM's or must be short: the hashed control sockets, links' link-<hash>.sock/.ctl, the QEMU wrapper and the ports lock. A folder's VM is found by its path's hash (state.ReadHash), with the name and backend its state records, so devvm --backend docker then devvm in the same folder opens the one VM, and a backend's name limit applies to new VMs only. The state records the VM's name and its ssh alias, chosen once at creation (sshconfig.ChooseAlias) and never recomputed. Links' targets match recorded names, aliases and folders (project.Targets). One teardown (vmFolders.teardown) replaces Lifecycle.forget, undoCreate's own list, Leftovers.Forget's, Proxy.Forget and space's leftoverFiles: it stops the proxy and link session, then the pieces outside the folder (clone remote or .git locks, other VMs' links and the group, host keys, the backend's leftovers), removes the folder, and writes the ssh config. Each backend's Delete and Forget remove the VM's backend/ folder (vmssh.Forwards.Forget). A new VM made where an earlier one's folder was left clears it first. devvm space counts an orphan's whole folder as leftover state and the other VMs' logs as network logs. Path builders move into paths: Dirs.VMDir, Dirs.VM and paths.VM's files (secrets' BindingsFile/PolicyFile, netpolicy's run, EventLog, ProxyLog, LinkList, VMPolicyFile, Lima's profileFile, startedFile, forwards.file, vmssh.Forwards.file, links' LinksLog/linksPID, Docker's vmFile and lifeline), ToolLockConfig, ToolLockChecked and ToolsCheckLog; the user's cache folder for Lima's and smolvm's caches is Dirs.UserCache, from HOME, not os.UserCacheDir. Dirs.VMState, LimaVMs, SmolvmVM and DockerVM go. vmname.HashOf and IsHash, project.Hash. The proxy takes the links' sockets' folder (-link-sockets, devvm's run folder) apart from the links' list, which is in the VM's run folder. Tests: a VM made and removed (rm, gc --orphans) leaves nothing under vms/, and with network policy has no file named for it outside its folder (TestTeardownLeavesNothing); a new VM over an old folder starts clean; lookup finds a VM made on another backend with a long folder name and makes no second one (TestLookupOtherBackend, and in docker.txtar); the alias stays put when a second VM shares the folder name (TestChooseAlias, ssh.txtar); every socket fits under a 35-character home with the longest VM name (TestSocketsFit); space counts an orphan's whole folder (TestLeftoverFolders); paths.VM's files; state by hash and name; the proxy refuses a socket in the list's own folder. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
dd3f0deb3f |
feat(state): config.toml and settings.json hold the defaults, and devvm's own files move to the data folder
~/.config/devvm/config.toml is the defaults you write by hand: backend,
network, ports, features, agents, [size] cpus/memory/disk and
[retention]'s six keys. devvm reads it and never writes it, strictly: an
unknown key (toml.MetaData.Undecoded, its line found by key) or a value
its check refuses (ParseCPUs, ParseGiB, ParsePorts, ask/on/off, a
backend's name, image.FeatureName, image.Agents, ParseDuration,
ParseSize, counts) fails naming the file and the line.
~/.local/share/devvm/settings.json holds what devvm setup, size -g,
ports -g, network -g and retention save (unknown fields ignored).
internal/settings owns both: Defaults (Value and List, each with its
Source: flag, config.toml, settings.json or built-in), Read, Save, which
refuses a key config.toml sets (set_in_config, with a doc link), and
the parsers and retention settings that moved from vm and state. A flag
wins over config.toml, config.toml over settings.json, settings.json
over the built-in default. Settings methods lose their files; setup
uses vm.NetworkChoice instead of its own copy; creation.plan reads one
snapshot (firstRun) after the first-run questions; the registry gets
the default backend through DefaultBackend; state's featureName copy
goes with base-features.
devvm size -g, ports -g, network -g and retention show each value's
source after a #, and in --json (source, sources); devvm doctor names
the file that sets its backend (doctor_backend_from) and adds
backend_source. devvm setup skips what config.toml answers
(setup_in_config) and refuses a flag that would change it.
ssh_config (and so the ~/.ssh/config Include line), known_hosts,
agent-keys.json and secrets/ move to the data folder. agent-keys.json is
{"keys": [{file, fingerprint, confirm, lifetime}]}, parsed once
(AddedKey); Keys formats KeyList.
Tests: settings' table tests (every key, unknown keys, bad values, an
empty file, precedence, Save's refusal and merge, settings.json's
fields), agent-keys.json, the registry's default backend, setup with
config.toml, SizeChoice with config.toml; CLI scripts for size -g,
ports -g, network -g, retention, setup and doctor's sources, each
refusal, a hand-edited config.toml with a typo, and ssh -G resolving
devvm-web through the Include line. Docs: settings.md's config.toml
section with a full example, linked from each command's page.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
||
|
|
a134e0d8a6 |
feat(cli): choose a new VM's toolchains, agents and layers in a picker or with --tools, --agents and --layers
devvm takes no IMAGE word any more than any other: in a terminal a new VM's toolchains, coding agents and layers are checked in one picker, under three headings, before the network-policy question; --tools, --agents and --layers (each an exact list, or none) skip it, and a part left out takes its default: the detected toolchains, devvm setup's agents, no layers (a devcontainer.json's features still count). Without a terminal, or with --no-input, the VM gets the defaults and new_vm_gets says so in one line. devvm setup --agents (and its first-run question) chooses new VMs' agents. devvm tools in a terminal opens the same picker for the VM, its layers fixed, and turns the changes into tools add and rm. An image is base and layers only: tools are the VM's tool_names state key. build, rebuild and images rm refuse a shared tool (tool_not_layer), and devvm build builds no tool images. devvm ls gains a TOOLS column and --json tools. gc's --tools is --tool-images, so --tools has one meaning. Gone: image.Reserved, checkWord's image half (devvm WORD is no_command or no_command_like, did-you-mean over commands, msg.Closest), the lacks path in internal/vm/existing.go, and the messages vm_lacks_tools, vm_lacks_layer, layer_is_command, layer_name_command, no_image_for, no_command_or_image*, tools_not_images, tools_not_images_rm, detected, vm_is_now (vm_tools_now), secret_with_image (secret_with_claude). New: ui.Pick takes headed sections with fixed rows, ui.CanPick, vm.PickPart/PickRow/AgentsChoice/CheckPart (internal/vm/parts.go), state.KeyToolNames, state.ReadAgents/WriteAgents, paths.Dirs.Agents, project.DetectFiles. Image keys are unchanged in form: images never held tools; docker.sh's and nix.sh's comments changed, so those layers rebuild. Docs: the home page's quick start steps, diagram (sandbox.svg), cards and FAQ; README; getting started; using (images' What a new VM gets, coding agents' Running an agent, settings' agents); internals; contributing; the cli skill; AGENTS.md. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
ddbc377f8f |
test: testscript commands for the scripts' setup, and a coverage baseline per package
script_test.go's sandbox sets DEVVM_MESSAGES=names and DATA, VMS, RUN and CFG by default, and adds stub_reset, catg (the one file a glob matches), vm_name VAR NAME (the folder's VM) and project NAME [git]; script_cmds.txtar checks each. Every script is rewritten onto them, its assertions kept; TestCommandLines leaves the scripts' own commands out. mise run test runs scripts/test.sh: the tests as before, with the CLI tests' devvm built with -cover for every package (CLI_GOCOVERDIR), merged with the Go tests' counters by go tool covdata, then scripts/coverage.sh holds each package to testdata/coverage/<os>.txt. mise run coverage raises the baselines; coverage.txtar checks the comparison. The macOS baseline is recorded from this tree. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
83726f6a56 |
feat(smolvm): ssh for editors
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]> |
||
|
|
4bdb3ea843 |
feat(ssh): ssh config and pinned host keys
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]> |