mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
main
19
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
a8f0517579 |
feat(lima): devvm downloads Ubuntu's cloud image itself
Lima's download of the cloud image neither retries nor times out: one cut in its 900 MB fails base's build, and a stall hangs it. devvm now downloads the pinned image itself through fetch.Resumable (ubuntu.Download), into images/ubuntu/<sha256>.img (Dirs.UbuntuImage), resuming across cuts, stalls and runs, and gives Lima that file. Lima 2.3 checks a local file against the digest before it copies it. - Before downloading, it takes the image from Lima's own download cache when that holds it with the pin's SHA-256: copied into a new file of devvm's own, mode 600, hashed as it's written, capped, stopped by the context, and kept only once it checks out. Lima's cache is never changed, and a base whose dated release Ubuntu may have removed still builds again. - One devvm downloads at a time (images/locks/ubuntu-image), another waiting under ubuntu_image_waiting and looking again under the lock (TestUbuntuImageAfterWait, which fails without that second look). - The download goes through the company proxy and trusts the user's CAs (Lima.Roots, from trust.Pool, which internal/cli passes through the registry), as do the Finder's lookups (TestNewTrustsRoots, and the registry's TestOverrides). An untrusted certificate is ubuntu_untrusted, naming the CAs' folder, one from a trusted CA that's for another host, out of date or not valid yet ubuntu_bad_certificate (check the clock and what answers for the host), and any other that fails to verify (a SHA-1 signature, a CA's name constraints, a key for clients alone) ubuntu_certificate_invalid, naming Go's reason, for the lookups (the listing, the checksums, their signature: TestLookupCertificates) and the download alike (TestLocalImageFailsFor), and a release Ubuntu removed (404, 410) ubuntu_release_gone, which names devvm rebuild base; none is retried. ubuntu_download_failed no longer starts with devvm. - fetch.Untrusted, fetch.BadCertificate (an x509.HostnameError, or a CertificateInvalidError that's Expired) and fetch.Unverified (any failure to verify, with its reason, so every error the other two name), beside fetch.Gone, are the one place that tells a certificate's failures apart: Transient asks Unverified, the lookups and the download ask all three, host mise asks Untrusted, and a forbidigo rule keeps x509's and tls's verification errors in internal/fetch (TestCertificateClasses, TestTransient, testdata/lint, the owners doc's row). - An https address, or a test build's file:// DEVVM_UBUNTU_URL, read from disk the same way; anything else is refused. The CLI tests' sandbox has a stand-in of this host's image in the store. - Base's record keeps the image's address, and the key is as it was: it hashes the pin (release, file, digest), not the location. - devvm gc --caches frees devvm's copies that no record names and that aren't pinned now, unchanged for an hour, a stopped .part and a killed import's .import included, and those of a kept image once its .img is there. A pin it can't read fails it. - Of Lima's cache, it frees only an entry that devvm's own state shows a build of devvm's left: a base record names its address, devvm has its own copy of the image, and the installed Lima's own templates (share/lima/templates beside limactl, Lima.Templates) don't name it. An entry no record names may be the user's own Lima's, so it stays, and none is freed when the templates can't be read, with a line in the run log naming the folder and why. A test build's DEVVM_LIMA_TEMPLATES stands in for the templates folder. - ubuntu.ParseImage reads a record's image as Image.String writes it, and ubuntu.IsSHA256 is the one check of a cloud image's SHA-256, in place of Lima's own regex. - devvm space shows the copies as a cloud images row, freed by gc --caches, kept as state, as a release Ubuntu removed can't be downloaded again. 0.1.0's frozen state runs the new commands (fixture_v010_cloud_image): devvm looks in Lima's cache under the SHA-256 of the address 0.1.0's base record keeps and never changes the entry, base builds from devvm's own copy, and gc --caches keeps that copy, frees Lima's entry the record names and devvm's own stale copies, and keeps an older entry no record names. Docs: images.md (the download, its failures, the import, gc's rules), space.md, backends/lima.md, settings.md (the lookups and the download trust your CAs), troubleshooting.md, overview.md, testing.md, tests.md, structure.md's internal/fetch row; the CHANGELOG's two Fixed lines, which later commits make highlights, What to do 5 and 6, and the release page's Ubuntu's cloud image in devvm's folder. New messages: downloading_ubuntu, importing_ubuntu, ubuntu_image_waiting, ubuntu_download_failed, ubuntu_release_gone, ubuntu_bad_certificate, ubuntu_certificate_invalid, ubuntu_image_checksum, ubuntu_untrusted. Lima.LocalImage is the seam, Lima.ImageClient the client. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
aeea3135b2 |
feat(proxy): the proxy's broker and its child
A VM's proxy runs as two processes, as design.md's "The proxy's broker"
says: devvm _proxy, the broker, which keeps what only the host should
do, and devvm _proxy-child, which reads the VM's network and can be
confined by the follow-ups.
- wire.go: the protocol over one socketpair (close-on-exec from the
start: SOCK_CLOEXEC on Linux, ForkLock elsewhere), length-prefixed JSON
frames of at most 2 MiB, unknown fields refused, bytes as base64, one
descriptor on a frame's first bytes (SCM_RIGHTS, MSG_CTRUNC breaks the
rules), wire types for every secret (redact.Secret at once).
- broker.go: newBroker, the start (handshake: version 1 and each side's
executable's SHA-256, within 4 s), the answers (value through lookups,
kept 30 s or 5 min, a failure 5 s, dropped when the bindings change;
file by number; link connected by the broker and passed as a
descriptor; token exchanged by the broker), each by something in its
own config, with caps 1/8/4/256; live: the lifeline closes the socket
and kills the child 6 s later, SIGTERM stops it within a second, a
child that ends ends the broker, a rule broken stops the child.
- child.go: the start (startOf), the child's server (newChildServer),
the broker as hostSide over the socket (brokerClient), runChildOn;
ready only after it reads the host's addresses (kept: the last good
read), roots and time zone loaded first.
- process.go: Main(ctx, ...) and ChildMain; the child spawned with
/proc/self/exe on Linux, PR_SET_PDEATHSIG from a locked thread
(daemon.Cmd.DieWithThread), descriptors 3 and 4, and TZ, SSL_CERT_*
and GODEBUG with updatemaxprocs=0 alone; run/proxy-child.pid and
run/proxy.confined ("none" until the follow-ups); KeepLogs in the
broker. ChildMain refuses to start unless descriptors 3 and 4 are a
unix socket and an IP one (checkInherited): run by hand, without
them, those numbers can be the Go runtime's own, which closing
crashed it (signal_recv: inconsistent state).
- capture.go: a captured token request goes to the broker
(captureToken, exchanger), so a login's real tokens never enter the
child; an error reply passes up to 1 MiB, longer gets 502.
- watched.go: the child stats each changing file and asks the broker
for it once it changed, keeping the stamp of what the broker read.
- rotate.go: proxy.log rotated by both through its descriptor, under a
lock of a description of its own; OpenLog opens a log never through a
link, one link, yours, replacing what a child left in its place.
- nixcache.go: the trim and its count through a safefile.Root, nar/
only as a folder, links deleted as themselves; reads never through a
link; the lock tried for 5 s (ErrNixLocked, nix_cache_locked).
- daemon: Cmd.Err, Files, Env, DieWithThread; Handle.Kill, Exit;
WritePID.
- netpolicy: Proxy.Stop also stops a child that outlived its broker
(run/proxy-child.pid, _proxy-child -for); proxy.log opened with
OpenLog; a refused launch keeps a running VM only while both run.
devvm network log and lock read the event log through safefile.
- vm, vmssh, vmlog: links.log and ports.log opened with OpenLog, read
through safefile, trimmed only as a regular file with one link.
- backend: the build proxy's logs in a logs/ folder of their own.
- cli: _proxy-child; _proxy waits for its child on a signal
(StopsItsOwn); the child reads none of devvm's folders (no
makePrivate); ui.Files.
- Tests: FuzzBrokerFrames, the frames' rules, the handshake and the
pair's end in synctest bubbles, the caps, the broker naming its own
alone, the client over a real socketpair with a passed descriptor,
ChildMain, TestInheritedSocket and proxy.txtar's child run by hand,
the frozen 0.1.0 configs starting a broker and child,
two writers rotating once, planted links, FIFOs and hard links; the
testscript runner stops _proxy-child too; e2e: broker and child, their
arguments, descriptors and environment, stop, SIGKILL either, planted
files in the logs folder and the Nix cache, build proxies gone.
- Review fixes: the lifeline closes the socket and starts the kill's
timer before logging; every log lock (proxy.log's, the event log's
rotation) is tried without blocking for 200 ms (flockWithin, which the
Nix lock shares), then written without or the rotation skipped; a
copied log's rotation streams at most twice its limit from a line's
start (copyFrom, copyAtomic); a reply too long to send goes as
too_long; kept token headers capped at 1 KiB; the child gives up on a
request whose context ended, dropping its late reply and holding its
slot until then; a write deadline on the start frame; errors reach the
child as codes (not_found, refused, busy, too_long, failed), their
text in the broker's log; FuzzFrameStreams, and FuzzBrokerFrames
writes from a goroutine; nix_cache_locked links to How it works.
- Docs: processes, network, overview, design (with threat rows for the
logs' locks and a log made huge), troubleshooting, the proxy's
README, structure, testing; CHANGELOG.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
||
|
|
e4ea123927 |
feat(ports): VMs' ssh on ports browsers refuse
Lima listens on a VM's ssh port on this machine's loopback, and root in the VM can make what answers on port 22 speak HTTP, so a page opened as http://localhost:PORT reached a server the VM controls with the cookies of every app on localhost, even in a VM that forwards no ports. - Every VM's ssh port, and every build VM's, is one of the 17 ports every browser engine refuses (ports.SSHPorts): the Fetch standard's bad ports from 1024 up that Chromium's kRestrictedPorts blocks too, which leaves out 4190 and 6679 (headless Chrome 157 loads both). The one allocator chooses it (Allocator.SSH and Build, through freeSSH). A stopped VM keeps its port while it's on the list, free, not listed to forward and not held by another start or build; else it gets one no state records, or else a stopped VM's, which that VM gives up at its own next start. Another VM's listed ports are avoided only while that VM runs or starts. - The proxy and desktop ports never take one (free); one an older devvm chose moves at the VM's next start (Choose's keep path, proxyPort, the desktop's listener; Allocator.SSHOnly). - A forwarder never takes one unless its VM lists it (ports.Reserved), so a guest forwarding every port can't fill them; devvm ports and each launch warn when a VM's list names one, whatever set it (--ports, a devcontainer.json, config.toml's ports) (ports_ssh_listed, ports.SSHListed). - A start holds its port, kept or new, for a minute in the VM's own run/ports.ssh-hold (paths.VM.Forwarder; hold, held, projectHold), which other starts and builds avoid, so none takes it before Lima binds it; it goes with the VM's folder. - A build takes its clone's own port (was) only when no other is free. - Past 17: ports_ssh_limit names the VMs whose recorded ports are in use ("a or b" for a port two states record) with how many are taken otherwise, ports_ssh_limit_all when they have them all, and ports_ssh_limit_others when none of your VMs has one. - Older devvm's ports move at the VM's next start, in startSets' one limactl edit, and the start pins the new host keys (pinHostKeys); a running VM keeps its port until then, and each launch warns of running VMs still on an off-list port (ports_ssh_old, Allocator.OffList, confirmed with the backend's Running). - A test build's own list (DEVVM_SSH_PORTS, registry.Overrides.SSHPorts, the Allocator's and the Proxy's SSHList field), read only by readOverrides in a test build: each CLI test sandbox gets as many ports of its own from below the ephemeral range (sandboxPorts). Frozen 0.1.0 fixture: each launch now makes exactly one limactl edit, of .ssh.localPort alone, onto the sandbox's list, and vm.json changes only in .ports.host.ssh (and the start it records); the fixture's data is untouched. Messages: ports_ssh_limit, ports_ssh_limit_all, ports_ssh_limit_others, ports_ssh_listed, ports_ssh_old. Tests: TestSSHPorts (Fetch's list less Chromium's gaps, SSHListed, SSHOnly), TestSSH, TestSSHHolds, TestSSHListed, TestOffList, TestBuild, TestReserved, TestForwardsHeld's reserved counts, TestStartBuildSSHPort, TestPrepareRestartsTheProxy, TestDesktopListener, TestOverrides (DEVVM_SSH_PORTS), ssh_ports.txtar, fixture_v010.txtar, layout.txtar; e2e project: the ssh port, first and after a move, is one browsers refuse. Docs: internals/lima (the ssh bullet, the hold's limit), processes (listener table), design (threat check), ports, overview, contributing/structure and testing (DEVVM_SSH_PORTS), using/ports-size, troubleshooting (Too many VMs at once), safety/attack-vectors (allowed ports, port squatting), CHANGELOG Breaking (17 VMs; forwarding every port leaves the 17 out) and After you upgrade. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
54cce97049 |
fix(ports): a stopped VM no longer keeps its listed ports from other VMs
Only a running VM holds a host port. Each VM's forwarder records the ports it forwards, and those it tried and couldn't take (run/ports.forwarded: its pid, then each list on a line; an empty one when it starts, and devvm removes it under ports.lock before each start). A forwarder reserves another VM's ports only while that VM has a claim: its forwarder runs, or devvm holds its ports.lock to start one again (the restart window). It never takes the ports such a VM forwards now, nor those it lists unless this VM lists them too. A stopped or crashed VM holds nothing. A reserved port the VM listens on waits and is forwarded once free, so a VM gets its port back within about 20 s of the other VM stopping. The host decides when a port is given up: every forwarder closes a forward whose port is now reserved every 10 s on its own clock (Forwarder.Recheck), so a VM that holds its session open and stops reporting can't keep another VM's listed port, and closing a forward closes the connections it accepted, so a browser's keep-alive connection never reaches the old VM afterwards. Two VMs starting at once are settled by the host's bind. The ports devvm chooses (ssh, proxy, desktop) still avoid every VM's listed ports, running or not. - ports: Used(d) for the allocator; Reserved, Holders and Live for the forwarders - vmssh: Forwarder.Recheck, Note and release; a forward tracks and closes its connections; Forwards.Reserved, Held, Taken, live, recorded and record; a start keeps a port another VM holds in -only and warns ports_held for any holder, listed or every-port; Main takes paths.Dirs - devvm ports warns ports_held and, for a running VM's listed port its forwarder recorded as a program's, ports_taken, reading the forwarder's record and binding nothing; --json adds held_by - backend.CountPorts; the stub's ssh master reports again when guest-ports changes - tests: TestReserved, TestForwarderWaits, TestForwarderGivesUpSilently, TestForwarderClosesConnections, TestForwardsHeld (restart window, every-port holder, no record, Taken from the record alone, another process's or no record), TestForwardsRecordFails, TestForwardsStart (old record removed), ports_stopped.txtar (CJ's case end to end, and an every-port VM leaving a running VM's listed port alone), layout.txtar - docs: ports-size's Two VMs and one port (the browser origin) and its JSON, internals' Ports other VMs forward, design.md's ports note and the listed ports' threat check; CHANGELOG Fixed Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
8f6b30a887 |
feat(secret): your own secrets, bound to the hosts you choose
devvm secret set NAME --host HOST[,HOST…] --env VARIABLE [--header H] [--prefix P] [--stdin] saves a secret of your own: the value from a hidden prompt or stdin (never argv) into the Keychain or devvm's secrets folder, and its definition into custom-secrets.json. A VM that uses it (devvm secret use NAME) gets only a per-VM placeholder in VARIABLE, and its proxy puts the real value in that header only for those exact hosts, over TLS on 443; the hosts join that VM's allowlist. Names, hosts, headers, variables and prefixes are checked; wildcards, addresses, internal names and other ports are refused. One placeholder builder serves every secret and login, and the proxy caches values by kind, agent and name. After an independent review, a secret goes in only in four exact shapes (alone; Bearer, Token or a saved --scheme in Authorization; the Basic password; the Basic username only with --basic-user), values are printable ASCII under 3,800 bytes, the proxy checks each binding against its definition, definitions carry IDs and VMs record their hosts, and custom values are stored apart from the known secrets. 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]>
|
||
|
|
9f619bd2ca |
fix(lima): choose every build VM's ssh port under the claims lock, and clear stale build-port records
Linux build VMs' ssh ports were Lima's own pick, outside the claims lock, so another VM's forwarder could take one before Lima bound it. Lima's start now gets every build VM's port from ports.Allocator.Build on macOS and Linux alike, and sets it with its one edit. - start.go: the l.OS == "darwin" condition goes. - build.go, tools.go: cloneEdits goes; a build VM's start always edits its new ssh port, so the configure step is always counted. - ports.Allocator.Build holds a file lock on run/build-ports/<name> (platform.LockFile) until release, so the kernel lets go of it when devvm ends, killed or not. free, under the claims lock, first deletes (clearStale) the records no process holds that are over 15 minutes old (staleAfter: longer than Lima's 10 minutes of waiting for ssh, which a killed devvm's limactl start may still spend binding it). Tests: TestBuild (a stale record kept while young, then cleared; a held one kept however old), TestStartBuildSSHPort on darwin and linux, TestStartConfined's Linux builds, TestBuildImageLayer, TestBuildTools; TestCloneEdits goes. build.txtar checks the build's port edit and that its record is gone; tools.txtar's steps are one count on both systems; layout.txtar lists run/build-ports on Linux. The limactl stub needed no change: it applies .ssh.localPort on every host, and the contract's scenario already starts builds with a port. Docs: internals/design (reserved ports; the build VM's ssh port lead is now confirmed, fixed), internals/overview, using/space. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
da5bae47f9 |
fix: tighten VM names, validate aliases, make written folders private and choose build VMs' ssh ports under the claims lock
- vmname.IsVM takes a name's folder part only as project.Slug makes it ([a-z0-9-], a letter or digit at each end), so a hand-edited name never carries spaces, slashes, newlines or ssh patterns. TestSlug checks that every name project.New makes is one. - vmname.Short and vmname.IsAlias: a VM's alias is devvm-<folder> of its own name or the name itself. sshconfig.Host, ChooseAlias and project.Named ignore any other alias, so one edited into vm.json never reaches the ssh config's Host line or names a VM. - state's writeFileMode makes a missing folder with PrivateDir (exactly 700, whatever the umask, a link refused); a folder already there keeps its mode. - ports.Allocator.Build chooses a build VM's ssh port on macOS under the claims lock (state.Claims, which VM.Claim now shares), records it in run/build-ports/<name> until limactl start returns, and ports.Used reads those records, so no VM or forwarder takes the port before Lima binds it. Lima's own freePort and platform.PortFree, its only user, go; Lima gets a Ports field (the allocator). paths.Dirs.BuildPorts is new, and Dirs' method limit goes to 54. Tests: TestIsVM, TestIsAlias, TestSlug, TestChooseAlias, TestWrite, TestTargets, TestWriteFileMakesPrivateDir, TestBuild, TestStartBuildSSHPort; layout.txtar lists run/build-ports on macOS. Docs: internals (backends, overview, design), contributing, using/space. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
8d00c42e14 |
fix(netpolicy): a VM's CAs are readied under a lock and deleted once its policy is off, and the proxy refuses minting GitHub credentials in absolute form too
- trust.InitCA takes the caller's ctx and holds the CA folder's lock (paths.CA.Lock, vms/<hash>/run/ca/lock), so two launches of one VM at once never leave a key and a certificate of different runs (TestInitCATogether failed first, TestInitCACancelled, TestInitCAMismatched). - netpolicy.Proxy.Unconfined: a VM's first start without network policy stops its proxy and then deletes its CA folder, keys and all, under that lock; a proxy that won't stop keeps them (TestUnconfined, network.txtar). - The proxy's forwarder refuses GitHub calls that make a lasting credential for every HTTPS request, so absolute-form https:// requests get the 403 that intercepted tunnels got (TestForwarderRefusesMinting failed first); the minting paths also match /repositories/ID and /organizations/ID. Each forwarder's idle upstream connections close when its request or tunnel ends. - e2e: the build proxy check expects the run log's devvm:<key>@ and no proxy key in the log. - Docs: design.md's CA threat check, network.md, overview.md's locks, space.md, safety/network.md. Baselines raised (darwin). Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
0941219a76 |
feat(build): base's packages recorded per key, replayed from a host cache
base's apt packages are no longer pinned by a snapshot. A key's first build of base records them: assets/layers/apt.sh (a recipe step, as root, before base.sh and after the last feature) points the image's sources at an apt mirror+file: list of config.toml's ubuntu-mirror and then Ubuntu's own archive, so apt checks everything against the archive key whichever server answers, and keeps what it downloads. At the end it gives back each package with apt's entry for it. devvm checks what comes back (regular files only, each named by its own SHA-256, each entry matching a file's size and SHA-256, nothing left over, at most 20,000 entries and 16 GiB), keeps the files in ~/.local/share/devvm/packages/<sha256>.deb and the key's set in packages/sets/<key>.json, before the image's record. Every later build of that key replays the set from the cache, checked on the host first, with apt given only those files: no network for base's packages, and a key's packages never change. A --from base keeps its image's own sources, unpinned. base keeps no package lists, so each layer's recipe starts with apt.sh lists, which fetches them when there are none. - backend.ImageSpec.Packages (Send before the steps, Take after) and backend.PackagesDir; Lima runs both over limactl shell as root. - Fail fast: apt.sh turns apt's retries off and exits 75 when no source answers, which Lima reports as build_sources_unreachable. - packages_missing refuses a replay whose cached file is gone or changed; packages_refused what a build gives back that isn't packages. - config.toml's ubuntu-mirror (settings.UbuntuMirror), checked as an http(s) address without a user, query or spaces (ubuntu_mirror_invalid). - devvm gc deletes the sets of keys neither current nor built, then, under the cache's lock, the files no set names at that moment, and builds' leftover folders over a day old (gc_packages, deleted_packages); devvm space lists the cache. - The snapshot is gone from base.sh, guest/sync.sh and desktop.sh, and scripts/bump.sh's apt step with it. - Tests: recording then replaying, a missing or changed cached file, every refusal of what comes back, gc's view of the cache and its race with a new set, the set record, the mirror setting, Lima's exchange and exit 75, apt.sh's mirrored and record functions, apt.sh in the keys; the limactl stub keeps what's sent and gives back $STUB_DIR/packages-out.tar. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
e93f29333a |
feat(ubuntu): pin the newest signed cloud image at base's first build
devvm's files keep only Ubuntu's release (26.04) and its cloud image key. The first build of base on a machine pins the newest dated release whose SHA256SUMS carry a valid signature from that key and list an image for the host (state.UbuntuPin, images/ubuntu.json), and every later build uses the pin without looking anything up. devvm rebuild base pins the newest again. The pin is in base's recipe, so base's key hashes it. The signature is checked in Go (internal/ubuntu/pgp.go: OpenPGP v4 RSA signatures with SHA-256/384/512, the standard library's crypto), so no gpgv is needed and a host without one is no longer unchecked. - backend.Images gains PinOrigin (backend.Pin: PinFirst, PinNewest, PinOlder); internal/build pins before it keys a build, and says what it pinned (origin_pinned). - Lima: Origin and createFromUbuntu read the pin; PinOrigin finds the newest with ubuntu.Finder (Newest, Release) under images/locks/ubuntu; a --from conversion pins only when nothing is. - Messages: ubuntu_unreachable and no_ubuntu_release; ubuntu_unsigned and ubuntu_checksum_unpinned are gone. - e2e pins its own release (DEVVM_UBUNTU_RELEASE, a test override; scripts/bump.sh e2e-ubuntu moves it); bump.sh's apt moves the package snapshot alone. The gpgv stub is gone. - Tests: the verifier against Ubuntu's real signature and a test key (damaged keys and signatures, packet and subpacket lengths, armor), Newest/Release, PinOrigin, the pin record, and the key covering the pin. 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]> |
||
|
|
1640feb608 |
feat(netpolicy): one CA per VM, with a successor the VM trusts ahead of time
Each VM with network policy has CAs of its own in its run folder, vms/<hash>/run/ca/ (paths.VM.CA, paths.CA: ca.pem/ca.key, next.pem/ next.key; folder 700, keys 600, kept out of Time Machine on macOS), so a leaked key reaches one VM and no proxy can sign for another VM. The shared ~/.local/share/devvm/ca (Dirs.CA) is gone. trust.InitCA(paths.CA) readies the current CA and the next one at each launch: the current one stays while it has over a week left, then the next one (started) takes its place, else a new one; the next one starts a week and an hour before the current one ends and is made again when it doesn't follow it. Each CA lasts 30 days and an hour, and its common name holds its serial, so a VM's two CAs never share a subject. The proxy's config gains ca_next, ca_next_key and ca_next_sha256 (part of Sum); the proxy signs with the next CA from an hour after its start (ca.signer), so the switch needs no launch or new proxy, and a VM not opened again stays verifiable for at least 30 days less an hour after its last launch. /ca.pem serves both certificates. loadCA reads the CA files with readPrivate (no links, a key only the user may read, 64 KiB cap) instead of tls.LoadX509KeyPair. The VM's setup sends both certificates (devvm-proxy.crt, devvm-proxy-next.crt) and no key. Tests: TestInitCA, TestInitCASwitch, TestInitCAReplaced (trust); TestNextCASigns, TestLoadCA, config check rows (proxy); TestPrepare and TestPrepareRestartsTheProxy for the VM's CA files and both sums (netpolicy); TestVMFiles; network, sync and layout txtar; e2e network: a second network-policy VM with different CAs, each VM trusting only its own and holding no key, each proxy serving and presenting only its own VM's CAs, devvm rm deleting one VM's CAs. Docs: internals/network.md (The VM's CA), design.md (A CA per VM, its threat check), safety/network.md, overview.md's per-VM files, space.md, security.md, attack-vectors.md, limits.md, coding-agents.md, contributing, internal/proxy/README.md. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
c40f9bbf74 |
fix(sshconfig): change known_hosts under its own lock
Pinning or forgetting a VM's host keys takes known_hosts.lock (an OS file lock, paths.Dirs.KnownHostsLock), reads the file again inside it and writes it whole with state.WriteFile, so two devvms at once lose neither's pin. ForgetHostKeys takes its caller's ctx. TestHostKeyConcurrent holds two pins' reads until both have read; it fails on the unlocked code. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
bdc95ef6ee |
refactor(ports): port forwarding out of the backends, one owner in vmssh
The port forwarder is devvm's on every backend. vmssh (moved out of internal/backend) holds it, the link sessions, and its one owner, vmssh.Forwards: the lock, stop and start of a VM's forwarder, which ports it forwards read from vm.json (ports.Forwarding) each time, the listed ports a host program has left out (ports_taken), the host key devvm pins, and the backend's new ForwardTarget (user, key, host loopback port) and Lifeline. One hidden command, devvm _ports (cli/forwarder.go, vmssh.Main), replaces _lima-ports. The backend no longer forwards: SetPorts, Want.Ports, Confinement.Free, Confinement.HostKey and Confinement.Forwarded go; Lima keeps its own forwards off and gives ForwardTarget (Lima's ssh port on 127.0.0.1, Lima's user, _config/user). Lima's Stop and Delete no longer touch the forwarder, and Lima's Forget goes with the backend/ folder: the forwarder's files are in the VM's run/ (ports.pid, .status, .lock, .known_hosts) and logs/ (ports.log), its control socket run/port-<hash>.ctl. vm starts the forwarder after each start and on devvm ports of a running VM; devvm stop, rm, gc --orphans and an interrupted start stop it. vm/ports.go's hand rollback goes: the state changes first, and a forwarder that can't start only warns. A structure-test layer keeps backends from importing vmssh. Tests: TestForwardsStart, TestForwardsRun, TestForwarderMain, TestSplitPorts (vmssh); TestForwardTarget (lima); TestForwarding (ports); TestStartPorts, TestSetPortsRunning (vm); testscripts up, ports, layout, gc_orphans updated. Docs: internals/ports.md, backends.md, lima.md, design.md (Ports on Lima), overview.md, using/space.md, contributing. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
8e914b17c9 |
refactor(proxy): one typed, versioned config for every proxy, read as a private file
devvm _proxy runs with one argument, -config FILE: proxy.Config as JSON (version 1), which a VM's proxy (vms/<hash>/run/proxy.json, written by netpolicy.Proxy) and a build's (build-proxy/proxy.json, written by backend.ProxyStarter) both use. It holds what the flags and the run folder's sidecars held: the address, the VM, the password (proxy.auth), the built-in policies and the user's files (proxy.policy), the logs, the lifeline, the CA, the secrets, the user's CAs (proxy.cas), the company proxy (proxy.upstream, now proxy.Upstream), upstream_unresolved, the Nix cache and its cap, the links, and the SHA-256 of devvm's binary and CA (proxy.bin, proxy.ca), which the proxy doesn't read. devvm writes it whole, mode 600, before each start, and starts a running VM's proxy again when the config it would start it with has another Sum. ReadConfig reads it as the links' list is read (readPrivate): O_NOFOLLOW and O_NONBLOCK, fstat, a regular file owned by the proxy's user that nobody else may read or write, at most 1 MiB, of ConfigVersion, no unknown field, a password, a loopback listen address. The VM's proxy is found by _proxy -config with its own config's path. paths.VM names ProxyConfig, ProxyPID and ProxyStatus. Policy files are read only as regular files of at most 1 MiB (proxy.ReadRegular, PolicyMax), in the proxy, devvm network and doctor, so a FIFO or a link to /dev/zero can't hang them (ErrNotRegular, ErrTooLong; ErrNotPrivate for the config and the links' list); the proxy keeps a file's last rules and logs why once. hostOK refuses a name with an empty label (evil.test.., evil..test, .evil.test), so no form of a name gets past a deny the policy's own trim would miss. A build proxy that can't be spawned leaves no config behind. Tests: config round trip and Sum; ReadConfig refusing a link, a FIFO, a folder, group-readable and group-writable files, a long file, other versions, unknown fields, two configs, no password, non-loopback addresses, a CA without its key, a negative cap; ReadRegular and the policy readers on a FIFO, /dev/zero and a big file without hanging; the running proxy keeping its last rules; hostOK and requests with empty labels (failing on the code before); Prepare's config, restarts on a binary change, a missing config and one others may read; concurrent config writes; the build proxy's config and its removal; proxy.txtar, network.txtar, nix_cache.txtar and layout.txtar; e2e checks of the config's mode, password and the proxy's arguments. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
51007fe851 |
refactor(backend): declarative Start, one Lima edit of what differs
Start takes what a VM's state asks of it, backend.Want (its size, agent folders, agent forwarding and ports), beside its Confinement, and a stopped VM's start changes only what differs, in one limactl edit with the confinement's own edits. CreateVM makes the VM as its spec's Want says (VMSpec embeds Want). SetSize, SetAgentDirs and SetAgentForwarding go, and with them vm_not_stopped: devvm size, ssh-agent and the agent mounts save to the state, and the next start applies them. A pure backend.Validate keeps the early refusal (disk_shrink) before anything changes. Lima's ports record (vms/<hash>/backend/ports) goes: which ports a VM forwards is vm.json's ports.forward alone, passed in Start's Want and in SetPorts, which now changes only a running VM's forwarder. Tests: backend TestValidate, TestFakeStartValidates; lima TestWantEdits, TestStartWantInOneEdit, TestSetPortsNoEdit, TestCreateVM and the forwarder tests on Want's ports, the real-Lima scenario's combined edit; vm tests read Start's Want; size, ports, up, up_size, layout and gc_orphans scripts. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
6c276af933 |
fix(state): every path in devvm's folders from paths, a VM's folder deleted under its lock, and the state layout review's fixes
paths names the files that were built elsewhere: Dirs.ShareLock (tools.lock), RetentionLock, GroupsLock, ToolImage, QEMUWrapper, DefaultLima and ToolsBuildPrefix, and paths.VM's comment says what backend/ holds. The structure test's owners rule fails a filepath.Join onto a Data or Config field outside internal/paths, and an os.MkdirTemp or os.CreateTemp there with a literal name (pathCases). Fixes: - state.RemoveFolder deletes a VM's folder holding the VM's lock, so a change another devvm is making lands first and none after it; teardown and clear use it (TestRemoveFolder). - Retention at a command's start skipped tool images when tools/.lock existed, a file nothing makes: it asks tools.Env.ShareBusy, which tries the share's lock (TestLockShare). - An image's build VM's folder (its sandbox profile and start record) is deleted once the image is built (TestBuildImageBase; layout.txtar). - doctor says what in vms/ it can't read (vms_unreadable) instead of dropping the error (TestVMFolderProblems). - devvm rm VM checks again after asking: a folder that came back, a VM made again, or an agent VM stopped meanwhile keeps the VM (TestRmVMChecksAgain). Docs: overview's run/ and locks, rm VM's second check, space's run/ row and doctor's findings, images' retention and the share's lock, Contributing's owners table. Co-Authored-By: Claude Opus 5.5 <[email protected]> |
||
|
|
628dc11c94 |
feat(state): a layout version for devvm's folders, made_by in its records, the golden listing and doctor's leftovers in vms/
The data and config folders each hold a version file (state.Layout, 1). state.CheckLayout runs before every command but help, completion, version and devvm's hidden commands, under version.lock: the same version goes on, a missing file gets this devvm's, an older one runs the migrations in order (migrations(), empty now), and a newer one in either folder refuses with layout_newer; a file that isn't a version fails with layout_unchecked. made_by, devvm's version, is in vm.json's core fields (set when the VM is made, kept by later changes), image records and tool image records. It's passed from cli's devvmVersion through vm.NewEnv, tools.New and build.Env.Version. testdata/script/layout.txtar makes two network-policy VMs with a forwarded port, a link and a secret, and compares every path under the data and config folders with checked-in listings (macOS and Linux). devvm doctor warns about entries in vms/ that aren't VM folders (vms_stray) and VM folders without vm.json (vm_folder_stateless), changing nothing. Tests: TestMigrations, TestCheckLayout, TestCheckLayoutMigrationFails, TestVMFolderProblems, TestSkipsLayout; made_by checks in TestVMRoundTrip, TestImage, TestToolImage, TestUp, the build and tools tests and scripts; doctor's unit test and script. Docs: internals/overview (the layout version, made_by), using/space, using/settings, using/troubleshooting, internals/images, Contributing (changing the state layout). Co-Authored-By: Claude Opus 5.5 <[email protected]> |