3 Commits
Author SHA1 Message Date
w3cjandClaude Opus 5.5 8afdec7de4 fix(proxy): a NO_PROXY address with an IPv6 zone names nothing (#59)
parseNoProxy read an entry with netip.ParseAddr, which accepts a zone,
and PrefixFrom then dropped it, so fe80::1%eth0 sent fe80::1 direct.
Go's httpproxy, HostOK, dial and the policy all treat a zoned address
as naming nothing; the NO_PROXY reader now does too.

Tests: FuzzNoProxy's crash input (::%0 against [::]), and fe80::1%eth0
and [fe80::1%eth0]:443 in TestNoProxy's names-nothing cases.
FuzzHostSites' noProxySite lists the zoned address as a divergence
from the legacy reader.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-18 11:51:54 -07:00
w3cjandClaude Opus 5.5 a7cc12521e test(fuzz): fuzz targets with properties, fuzzed nightly
Twenty-three new fuzz targets, built-in Go fuzzing, each checking a
property rather than only that nothing panics: parsers of what a VM or
the network sends fail closed and keep to their caps, a secret goes only
where it's bound, and no planted secret survives a redaction.

- internal/proxy: FuzzCursorFrames (passes only what came; no message
  over frameMax or holding a JWT's start, decompressed and unescaped),
  FuzzInject (a binding's value only to a host it names, judged apart
  from the matcher in NormHost's form, for its path and methods, in its
  own header, which held the exact placeholder once; other headers
  untouched), FuzzParseBindings, FuzzLinkList, FuzzParseUpstream (errors
  hold no more of the URL than its scheme), FuzzNoProxy, FuzzParseNarinfo
  (only cache.nixos.org-1's signed narinfo is taken).
- internal/agentlogin: FuzzParseTokenRequest, FuzzRedact (secrets planted
  eight ways in JSON and TOML settings), FuzzCapture (the VM's reply holds
  none of the endpoint's tokens).
- internal/redact: FuzzSplit (a password written in parts through Split,
  as the run log writes it, never survives).
- internal/jsonc: FuzzStrip, differential against encoding/json.
- internal/upgrade: FuzzParsePublicKey, FuzzVerify, FuzzEntryName,
  FuzzUnpack.
- internal/vmssh: FuzzParseHostKeys, FuzzParsePorts.
- internal/vm: FuzzParseCloneState, FuzzParseInit, FuzzParseKept,
  FuzzParseLFSPointer.
- internal/desktop: FuzzHandshakeVM.

What they found, each fixed with a regression test:
- NO_PROXY: an entry with port 0 (git.test:0) was read as the host on
  every port, and git.test:080 or :+80 as port 80, which Go's clients
  match against nothing; an entry whose port no request has, or that
  isn't plain decimal, now matches nothing (TestNoProxy,
  testdata/fuzz/FuzzNoProxy). FuzzHostSites' NO_PROXY site allows this
  difference from its frozen copy, and the design note lists it.
- A JSON token request with more after its object was judged by its
  first object; it's refused now (TestCaptureRefuses).

The Fuzz workflow runs nightly rather than two minutes weekly: five
minutes a target, eight at a time, each target's corpus restored from
and saved to a cache of its own (a failing input added to it, so it
fails nightly until fixed), new inputs minimized in at most 1,000 runs,
and one issue, "Fuzzing found failing inputs", opened, commented on when
the failing targets change and closed on a clean night, by a separate
job with issues: write that runs no repo code, on main alone. Target
names must be unique across packages. bump.sh moves an action in a
folder of its repo (actions/cache/restore, /save) with its repo's
releases.

Docs: Contributing's Fuzzing (running a target, the nightly run, every
target's property), Maintaining's Fuzzing failures and its actions bump,
the proxy README, the NO_PROXY and token request facts in How it works'
network page and the design note.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 22:04:31 -07:00
w3cjandClaude Opus 5.5 6f680a6f8b feat(proxy): a shared, read-only Nix cache that only the host fills
VMs with network policy and the nix layer share their downloads from
cache.nixos.org: the proxy answers http://devvm.proxy/nix/ itself (a
reserved endpoint, never forwarded), and the guest setup puts it before
https://cache.nixos.org in Nix's substituters, trusted-public-keys left
as Nix's own (cache.nixos.org-1). Each VM keeps its own store and daemon;
only downloads are shared, and no VM can change what another gets.

The proxy (internal/proxy/nixcache.go, -nix-cache DIR and
-nix-cache-max BYTES):
- takes only GET and HEAD, no query, nothing escaped, of
  nix-cache-info, <32 nix32>.narinfo and nar/<52 nix32>.nar with no
  suffix or .xz, .zst or .bz2 (nixPath, FuzzNixPath); 400 otherwise;
- makes up nix-cache-info (priority 30, before cache.nixos.org's 40);
- fetches from https://cache.nixos.org alone, when the VM's policy
  allows cache.nixos.org:443, through the floor or the company proxy,
  with the system's roots and the user's CAs, following no redirect,
  sending nothing of the VM's request;
- keeps a narinfo when its StorePath is the path asked for, its URL is
  of the pattern and named by its own NarHash or FileHash, and a Sig by
  the pinned cache.nixos.org-1 Ed25519 key verifies over
  1;StorePath;NarHash;NarSize;References (parseNarinfo, against a real
  narinfo and NAR of cache.nixos.org's in testdata/nix/);
- fetches a NAR only after a narinfo it checked names it, never for a
  HEAD, once however many ask and at most four at once (fetchOnce), and
  keeps it when its SHA-256 and size are the narinfo's FileHash and
  FileSize; a cached copy of another size is dropped;
- answers 404 to anything that fails, keeping nothing, so Nix goes to
  cache.nixos.org itself; logs each request as a nix-cache event
  (hit, fetched, or why not), which devvm log shows as cache;
- writes files whole and renames them in, 600 in folders of 700.

The cap: the nix-cache.size retention setting, 10 GiB when off
(state.NixCacheDefault, proxy.NixCacheDefault), with state.ParseSize
(500M, 20G, 1T). Under a flock on .lock every proxy takes a file's room
before writing it (reserve, in whole blocks), deleting the least
recently used files (by mtime, which a hit sets) down to nine tenths of
the cap; a NAR being fetched is made its full size at once and counts,
so a fetch the in-flight files leave no room for is refused. devvm gc
trims to the cap, devvm gc --nix-cache empties it, and the daily
retention run trims it (proxy.TrimNixCache, NixCacheUsage). devvm space
has a Nix cache row (GC: what's over the cap, FREED BY gc --nix-cache,
RETAIN nix-cache.size), devvm images says what it takes of its cap.

netpolicy passes -nix-cache and -nix-cache-max only for images with the
nix layer (nixCacheArgs; a retention file it can't read warns and uses
the default). The guest setup writes /etc/nix/devvm-cache.conf through
!include in nix.conf only with the nix layer and policy on, removes it
otherwise, and restarts nix-daemon when it changes. VMs without network
policy get no shared cache: they fetch from cache.nixos.org directly,
and nothing new runs or listens on the host for them.

Review (security-audit skill, on nixcache.go, its callers and the
setup): a NAR could be kept under another NAR's name, as the URL isn't
signed (fixed: the URL must be named by the narinfo's own hashes, and a
hit of another size is dropped); files being fetched didn't count
against the cap and blocks weren't counted, so one VM's parallel
requests could pass it (fixed: reserve, full-size temp files, block
counts, fetchOnce); a HEAD downloaded a NAR (fixed). Ruled out: stored
VM input, paths out of the folder, another upstream, parser
differences, cross-VM visibility beyond timing, a VM's own nix.conf.
Open, documented: timing tells a VM whether some VM fetched a public
path, and a VM can fill the cache to its cap.

Messages: gc_nix_cache_over, gc_nix_cache, deleted_nix_cache,
images_nix_cache; retention_deleted gains nix_files. Paths:
Dirs.NixCache (structure limit for Dirs to 40). Flags: devvm gc
--nix-cache; the CLI reference regenerated.

Tests: TestNixPath, TestNix32, TestParseNarinfo, TestNixCacheServes,
TestNixCacheRefuses, TestNixCachePolicy, TestNixCacheFetches,
TestTrimNixCache, TestNixCacheCap, FuzzNixPath, TestParseSize,
TestRetention, TestNixCacheArgs, TestFormatEvent; nix_cache.txtar (the
proxy's endpoint and refusals, space, images, gc, gc --nix-cache,
retention); e2e nix: the VM's substituters and keys, hello through the
cache, fetched by the host (600/700), a VM's writes and other requests
refused and nothing kept, a second VM's hits fetching nothing, no cache
after devvm network off.

Docs: the design note (internals/design.md), internals/network.md's The
shared Nix cache, the VM's setup, logs and flags, internals/security.md,
internals/images.md, safety/network.md's Nix and Logs,
using/toolchains.md's Nix projects, using/images.md, using/space.md,
using/settings.md's Retention, internal/proxy/README.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-31 22:56:53 -07:00