16 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 3da38436a7 feat(proxy): the broker opens the child's connections; its sandbox refuses it every one of its own
A sandbox fixed at the child's start can't tell this machine's
loopback, its own addresses and the LAN apart from the internet as a
rule changes, so the child's sandbox now refuses it every connection
of its own, and the broker looks up each name and opens each
connection for it, once its own read of the VM's policy and of the
host's addresses allows the address, as the floor does. A child that a
VM takes over reaches this machine's loopback, its own addresses and
the private and link-local ranges only where a rule names the address,
as the VM does; a company proxy, which the child still speaks to with
its password, reaches whatever it reaches.

- wire.go: lookup (a host name, absolute, with its trailing dot), dial
  (an address and a port, or the https or http company proxy of the
  broker's config, never both), the connection as the reply's one
  descriptor, and cancel, for a lookup or a dial the child gave up on,
  which frees its slot.
- dial.go: the broker's own egress (newBrokerNet: the VM's built-in
  policies, its policy files, looked at on every dial, and the host's
  addresses), lookupable, broker.lookup, dial and dialProxy, within 20
  s and 15 s; the child's side (brokerClient.lookup, dial, dialProxy)
  wired into its egress by throughHost; the resolver's errors as codes
  the child makes into net.DNSError again.
- broker.go: the caps (256 lookups, 1024 connections at once); its
  line for each failed lookup and connection, which the VM drives, at
  most 20 a minute and then one that says it stops (logFailed,
  perMinute in limits.go, which egress.abandoned now shares).
- child.go and confine.go: every lookup and connection through the
  broker; the child lowers its open files, soft and hard, before it's
  confined (limitFiles).
- seatbelt: the child's profile allows no network out, TCP, UDP or a
  unix socket, nor mDNSResponder.
- landlock: the seccomp filter refuses every socket but a netlink
  route socket, connect, socketpair, listen and MSG_FASTOPEN on
  sendto, sendmsg and sendmmsg; Landlock no longer opens the resolver's
  files below /etc.
- Tests: the broker's dial and its rules (TestBrokerDial,
  TestBrokerDialFollowsRules, TestBrokerDialProxy), lookups and their
  errors, cancel, the client over a real socketpair,
  TestBrokerFailedLogCapped, TestPerMinute, the filter's programs, the
  child's own connections refused under Seatbelt and under Landlock and
  seccomp.
- Docs: the design note's broker (what crosses to the broker: the
  names and addresses, never a connection's bytes), its threat check,
  network's The child's sandbox and proxy.log, processes, attack
  vectors, troubleshooting, testing, tests, the proxy's README;
  CHANGELOG, with the company proxy's reach.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 22:04:32 -07:00
w3cjandClaude Opus 5.5 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]>
2026-11-15 22:04:32 -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 4d409589bb refactor(redact): every secret's value is a redact.Secret, revealed only where it's used
redact.Secret holds a value that lets whoever has it act as the user or
a VM, behind a pointer, so fmt's raw printing of an unexported field
shows only an address. String, GoString and Format print <redacted> for
every verb; MarshalJSON, UnmarshalJSON and MarshalText return
redact.ErrEncode, so a secret is never silently written as a stand-in
(which would lose a login); there's no LogValue. NewSecret ("" is the
zero Secret), Reveal, Empty and TrimSpace are the rest. internal/redact
joins the proxy's standard-library-only depguard group.

Reveal is refused by forbidigo outside tests; each of the 23 call sites
carries a //nolint:forbidigo saying why, and testdata/lint/forbidigo.go
keeps a call the rule must report. The structure test (checkSecrets)
refuses a struct that embeds redact.Secret outside internal/redact and
an interface that declares Reveal() string.

Typed now: proxy.Config.Password (configFile is the wire type, in
Config's order, held to it by TestConfigFile), the server's password,
proxy.Lookup and the cached values, upstream.auth, upstreamPassword,
Upstream.WithPassword's password; backend.NewProxyPassword, ProxyURL,
Confinement.ProxyPassword, BuildProxy.Password; netpolicy.Key and
NetMade.ProxyKey (netMade wire type); settings.CompanyProxy.Password;
secrets.Store.Value, saved, ProxyPassword, Token, Save, save, Get,
SaveKey, Yours.Save, Claude.Env, saveToken, oauthToken; agentlogin
File.Get, SetKey, ClaudeToken, every format's get, setKey and chatGPT,
refresh's refresh token, capture's access, refresh and id tokens, and
the JWT helpers (a login's map stays the wire, through token and
setToken; piKey is piBound); vm.Net.SecretSave, AgentLoginOptions.Key;
ui.UI.Secret. Strings by design: platform.KeychainGet/Set and the
desktop's VNC password.

Tests: TestSecret (unexported and nested fields too), TestConfigFile,
TestV010ProxyConfigs (0.1.0's proxy.json round-trips byte for byte),
TestFixtureStoreGet saves the Linux secret file back byte for byte,
checkV010Logins (login files read, copied and bound without a change),
secretCases, and e2e netNoLeaks, twice in the network section: every
VM's proxy password and the section's values, also as Basic
credentials, in no run log or proxy log, and the passwords in no
ha.stderr.log or serial log. Docs: Contributing's Secrets in the code,
the owners table, the secrets How it works page, design.md's Where
secret values live.

Fixed, found by netNoLeaks: Lima's boot script 07-etc-environment.sh
runs under set -x, so the console logs (serial*.log) kept the VM's
proxy password; redactLog now stars passwords in them as it does in
ha.stderr.log (CHANGELOG, overview, processes and attack-vectors pages).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 19:36:31 -07:00
w3cjandClaude Opus 5.5 4e925492ca fix(proxy): every host is read in one form, proxy.NormHost, guarded by the structure test
Every check that judges or compares a host now reads it through
proxy.NormHost (internal/proxy/host.go), which also holds HostOK,
splitHostPort, hostASCII and asciiEqualFold: a host of printable ASCII is
lowercased in ASCII alone and loses its one trailing dot; any other host
stays as it is, so HostOK refuses it and no Unicode fold makes another
name match. A host with two trailing dots or more, or a dot after a
closing bracket, keeps them, so NormHost is idempotent and reading a host
twice can't turn evil.test.. into evil.test. A proxy.Host is what the
matchers take (rule.matchHost, noProxyRule.matches, local, sniMatches).

Brackets are strict (hostAddr): HostOK, Host.Addr and splitHostPort take
an address bare or an IPv6 address in one pair of brackets, never a stray
bracket ([[::1]], 1.2.3.4]) or brackets around a name or an IPv4 address
([evil.com]:443, [1.2.3.4]:443), which get 400.

Migrated: splitHostPort, sniMatches, sniHost, parseHostRule, the
policy's rulesFor, quiet, byName and coversOn, secrets.forHost,
parseNoProxy, route and local in internal/proxy; netpolicy.RiskOf,
Tickable and sameRule (devvm network rm and the duplicate check, so a
Kelvin sign never names the rule with a k); secrets.CheckHost;
from.publicHost (a name HostOK refuses isn't public);
agentlogin.claudeHost; vm.urlHostPort and privateHost. vm.urlHost
(cloneseed.go) keeps its own reading: it's a remote's ssh host, which ssh
lowercases and keeps the trailing dot of, to find a VM's alias.

Differential fuzz targets keep a frozen copy of each reader as it was and
allow only the decided differences: FuzzHostSites (proxy), FuzzRiskSites,
FuzzCheckHostSite, FuzzPublicHostSite, FuzzClaudeHostSite and
FuzzPromisorHostSite. A rule line is the same rule or no rule exactly as
before, so a broken deny stays a broken deny. TestFixtureHosts reads the
frozen v0.1.0 state's secrets.policy, secrets.json and links.json hosts
and finds them unchanged.

The structure test's new hosts check refuses, outside host.go and tests:
Trim, TrimLeft or TrimRight with a cutset holding ".", TrimSuffix or
CutSuffix with "."; ToLower, ToUpper, EqualFold and the TrimFunc family on
an argument named for a host; and a conversion to proxy.Host of anything
but a literal. Exceptions are by file and function, each with why
(request.go:trimDots, cloneseed.go:urlHost, cloneworktree.go:safeIndexPath,
cloneconfig.go:transportHelper, lima/start.go:machines.fillPassword). It
doesn't see slicing, strings.Map or variables not named for a host. The
owners doc, the proxy README, structure.md, design.md (One form of a
host), network.md and safety/network.md say so.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-15 19:36:28 -07:00
w3cjandClaude Opus 5.5 09c5be1887 fix(proxy): a block for a name that doesn't resolve says why
A name the host's DNS couldn't resolve was blocked with "can't resolve it"
whatever the cause, and a request whose client went away mid-lookup was
logged as a block too, so a cancelled lookup looked like a DNS failure.

- egress.lookup: the resolver, a field tests set (net.DefaultResolver's
  LookupNetIP otherwise); resolve and floorUpstream go through lookupName,
  which asks once more after a temporary failure (not a not-found), within
  floorUpstream's 3 s.
- unresolvedReason: reasonNotFound ("this machine's DNS has no address for
  it"), reasonDNSTimeout, else reasonUnresolvable; the error itself stays
  in proxy.log, as before.
- floorCheck: a lookup that ended with the request's context gives
  reasonClientLeft; events.record drops a block with it, so /blocked and
  the counts never see it, and egress.abandoned names it in proxy.log,
  at most abandonedLogMax (20) a minute, as a name can carry data out.
  The Nix cache's floor gives the context's error for it.
- Tests: TestUnresolvedReason, TestCanceledLookupNotBlocked,
  TestCanceledLookupsLogCapped, TestFloorUpstreamLookupBudget;
  TestUpstreamNoProxyDirect no longer needs the real resolver.
- network.md's log files and a CHANGELOG Fixed entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-12 20:42:43 -07:00
w3cjandClaude Opus 5.5 760e602d18 fix(agents): host-side login refreshes trust the user's CAs
An agent's OAuth refresh (Claude Code, Codex, opencode) runs in the VM's
proxy on the host and goes through the company proxy, but trusted only the
system's roots, so a company proxy that inspects TLS made it fail. Each
secret lookup's context now carries the proxy's own roots, the system's
and upstream_cas (proxy.WithRoots, RootsOf), which the refresh's client
trusts through the new fetch.Client.Trust.

Tests: fetch TestTrust, agentlogin TestRefreshTrustsTheProxysRoots and
proxy TestLookupRoots, each against a TLS server signed by a test CA; the
e2e network section's Claude refresh check now expects success.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-05 21:17:04 -07:00
w3cjandClaude Opus 5.5 9568e6c47f fix(proxy): agents' OAuth refreshes go through the VM's proxy's company proxy
A VM's proxy refreshed Codex's and opencode's OAuth logins with net/http's
environment proxy alone, so with config.toml's [proxy] the refresh went
directly, and failed behind a company proxy. The proxy now makes its
upstream's route for its own requests as it starts (proxy.Upstream's
WithPassword, with the proxy secret it looked up, then Route) and gives it
to each lookup in the lookup's context; agentlogin's refresh sets it as its
transport's proxy. A proxy without an upstream routes the refresh directly,
as it does the VM's requests.

- proxy.WithRoute, proxy.RouteOf; upstreams.host; secrets.route.
- Tests: TestRefreshGoesThroughTheProxysRoute (fails without the fix),
  TestLookupRoute.
- Docs: How it works' Through a company proxy, network policy's Behind a
  company proxy, the proxy's README.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 02:03:11 -07:00
w3cjandClaude Opus 5.5 ed70aeae3b feat(netpolicy): config.toml's company proxy reaches devvm's own downloads and builds' checks, and VMs without policy warn
config.toml's [proxy] covers the places it missed:

- devvm's own requests on this machine (the download of its mise, Ubuntu's
  cloud image listing, --from's registries) go through it when the
  environment sets no proxy. settings.CompanyProxy.Route is their
  transport's proxy: at the first request it looks up the proxy secret,
  puts it in each URL that names a user, and routes each request as a VM's
  proxy does (proxy.Upstream.WithPassword, proxy.Upstream.Route, reusing
  the proxy's NO_PROXY matching). A missing password fails the request
  with fetch.ErrProxy, which isn't retried; HostMise shows its message.
- The mise devvm runs on this machine gets HTTPS_PROXY, HTTP_PROXY and
  NO_PROXY in its environment (settings.CompanyProxy.Env), with the
  password in the URL, as mise takes it nowhere else; never in its
  arguments or a file. With the environment's proxy it adds nothing.
- devvm build, rebuild, the remakes' builds and tool builds check the
  company proxy and its saved password before anything starts
  (build.Builds' checkProxy, tools.Share.Build), through the one check a
  new VM and a VM's proxy use: settings.CompanyProxy.Upstream, which
  netpolicy.Proxy.Upstream now calls. secrets.Store.ProxyPassword owns
  the proxy_password_missing mapping.
- A VM without network policy never gets config.toml's proxy, as the
  guest would need the password, which never leaves this machine; each
  start of one while config.toml is the only proxy warns
  (proxy_needs_policy), naming devvm network on or the shell's
  HTTPS_PROXY, with a doc link.

Wiring: tools.Env.Proxy (its Password set by cli and vm from devvm's
secrets), from.NewLookup/NewRegistry/NewPublicRegistry take the proxy,
lima.New and registry.New take a *settings.CompanyProxy for Ubuntu's
listing. internal/fetch stays standard library only.

- Tests: TestUpstreamWithPassword, TestUpstreamRoute,
  TestUpstreamRouteAuthorizes, TestCompanyProxy,
  TestCompanyProxyPasswordMissing, TestProxyPassword,
  TestHostMiseThroughCompanyProxy, TestMiseCmdCompanyProxy,
  TestBuildChecksCompanyProxy (tools and build), TestRegistryThroughProxy,
  TestUbuntuThroughCompanyProxy, TestTransient's ErrProxy, and
  company_proxy.txtar's build, rebuild and no-policy cases.
- Docs: network policy's Behind a company proxy and Without network
  policy, config.toml's [proxy], How it works' Through a company proxy.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 01:42:37 -07:00
w3cjandClaude Opus 5.5 2304f26bf0 feat(netpolicy): config.toml sets the company proxy, and a start warns when its proxy loses one
config.toml's [proxy] table (https, http, no-proxy) is the company proxy that
VMs' proxies and builds go through when devvm's environment sets neither
HTTPS_PROXY nor HTTP_PROXY; the environment's settings win whole, never mixed
with config.toml's. Each value is checked as config.toml is read
(backend.CheckProxyURL, backend.CheckNoProxy), and a URL holding a password is
refused (proxy_password_in_config): config.toml is copied between machines
and kept with dotfiles.

The password is the host-only secret proxy (devvm secret set proxy, in the
Keychain or devvm's secrets folder). A URL that names a user gets
upstream.secret in the proxy's config, and the proxy looks the value up
through IO.Secret as it starts (upstreamPassword), so no file of devvm's holds
it. No VM is ever bound to it: devvm secret use refuses (secret_host_only) and
secrets.Names drops it. A new VM and a VM's proxy refuse to start while it
isn't saved (proxy_password_missing, netpolicy.Proxy.Upstream).

A start whose VM's proxy last ran with an upstream and now has none warns
(upstream_proxy_gone), naming config.toml, with a doc link.

- settings.HostProxy: the environment's, else config.toml's; used by
  netpolicy, Lima's build proxy (buildUpstream) and devvm doctor's CA hint.
- proxy.Upstream.Secret, proxy.UpstreamSecret; secrets.Secret.HostOnly;
  secrets.Token keeps spaces inside the proxy password.
- Messages: proxy_password_in_config, proxy_password_missing,
  upstream_proxy_gone, secret_host_only, proxy_password_howto,
  password_prompt (answered by --stdin).
- Tests: TestHostProxy, TestUpstreamSecret, TestPrepareUpstreamConfig,
  TestBuildUpstreamConfig, config.toml refusals, the warning in
  TestPrepareUpstream, company_proxy.txtar, secret.txtar and ca.txtar cases.
- Docs: troubleshooting's Behind a company proxy, network policy's Behind a
  company proxy and secrets, config.toml's reference, How it works.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-04 01:10:36 -07:00
w3cjandClaude Opus 5.5 bcafcda739 refactor(proxy): one server struct holds what a proxy runs with and keeps, and a tunnel passes the far end's bytes at once
internal/proxy keeps no package state. newServer makes a server from the
config, as Main starts (it replaces Config.apply, loadPolicies and every
global they set), and each part keeps what it changes under its own lock:
events (the event log and recent blocks), egress (the policy, the host's
addresses in hostAddrs, the company proxies in upstreams), secrets (the
bindings file and the values cache, file lock taken before the values'),
ca (devvm's CA and its leaves), links (the list and the sockets' folder)
and nixCache (the cache's folder, checked narinfos, fetches and slots).
The proxy's own log is a *log.Logger each part is given; Main's lifeline
tick is a const, and run takes it for tests. What's left package-level is
error sentinels and three fixed tables (notPublic, nat64, githubMinting),
now in the structure test's allowedVars; the structure test no longer
leaves internal/proxy out, and its rule case for the proxy fails a var.

Tests make their own server with newServer (testServer, listen, logs,
fakeSecret on a secrets, testCA) and all run in parallel.
TestServersApart checks two servers in one process share no password,
blocks, events, values or CA leaves.

A tunnel to a host the policy allows passes the far end's bytes to the
VM from the start (splice's before), so a server that speaks first gets
its greeting through; the VM's bytes still pass only after the SNI check,
which reads one byte first and the ClientHello only when it starts 0x16.
TestTunnelServerSpeaksFirst failed on the code before.

Docs: the proxy README (the server, files, testing), network.md's
tunnel paragraph, AGENTS.md's test-seams line, Contributing's
package-vars row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-03 20:10:28 -07:00
w3cjandClaude Opus 5.5 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]>
2026-11-03 17:51:45 -07:00
w3cjandClaude Opus 5.5 529e8132c3 fix(netpolicy): Lima's and a Linux engine's build proxies pass names the host can't resolve on to the company proxy
A build's proxy has policy ** alone, so it refused every name this machine
can't resolve, and where only the company proxy resolves outside names,
builds behind it reached nothing by name. devvm _proxy gets
-upstream-unresolved, which sends such names upstream unjudged even when
only ** allows them; a denied name stays refused. Lima's build proxies and
a Linux Docker engine's start with it: without a company proxy those
builds reach internal addresses directly anyway. Docker Desktop's build
proxy starts without it, as its builds are kept off this machine's own
services, which a company proxy on its loopback could reach.

Tests: TestUpstreamUnresolved covers the flag; Lima's build test checks
the build proxy gets it; TestBuildOnDesktop's exact arguments keep it off.
Docs: safety/network.md, using/troubleshooting.md, internals/design.md,
internal/proxy/README.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-31 10:50:45 -07:00
w3cjandClaude Opus 5.5 080d57dd28 fix(netpolicy): builds reach a company proxy through a proxy of their own; ** refuses names the host can't resolve
From an independent review of the company-proxy change.

1. Builds never get the company proxy's credentials. Each build behind
   a company proxy goes through a devvm _proxy of its own on the host
   (backend.ProxyStarter / BuildProxy, shared by Lima and Docker; Docker
   Desktop's build proxy moved into it): policy **, a new random password,
   the company proxy in its -upstream file, -lifeline on the build VM's
   hostagent or the container's docker container wait. Builds get only
   http://devvm:<one-time>@<host>:<port> (each variable the host sets) and
   the host's NO_PROXY.
   - Lima: image builds, the tools build and --from's conversion VM reach
     it at 192.168.5.2; on macOS the build's Seatbelt profile allows that
     one loopback port (NetInternet + ProxyPort), so a loopback company
     proxy works for macOS builds too. guestProxyURL is gone. limactl runs
     without the host's proxy variables (Lima logged them, password and
     all, into devvm's run log; found by the new e2e check); only a
     NetDirect start gets them back for propagateProxyEnv.
   - assets/oci/build.sh: the /etc/os-release probe runs under env -i;
     chroot_run passes only the build proxy's variables (bootify.sh's
     downloads behind a company proxy).
   - Docker: buildNet takes Desktop's path (own network, relay, build
     proxy) on any engine behind a company proxy; hostProxyEnv is gone.
     A Linux engine's build behind one needs devvm's Linux build.
   - Settings the proxy can't go through are refused before anything is
     made (upstream_proxy_scheme, reworded for builds too).
2. noClientProxy on the tools' unpack container and the relay.
3. floorUpstream: a name the host can't resolve goes upstream only when
   an allow rule names it (itself or *.domain: policy.byName); with only
   ** it's refused (errUnresolved, logged as the reason).
4. CONNECT replies are read through a 64 KiB io.LimitReader
   (maxConnectReply); bytes after the answer stay the tunnel's.

Tests: backend (TestProxyStarter, TestProxyStarterFails,
TestListeningPort, TestBuildProxyStop), lima (TestBuildImageHostProxy on
linux and darwin with the Seatbelt port, TestBuildImageHostProxyRefused,
TestConfineProxyEnv), docker (TestBuildHostProxy for a Linux engine with
and without a company proxy, unpack's empty proxy pairs), proxy
(TestUpstreamUnresolved, TestUpstreamConnectReplyLimit). CLI: docker.txtar
(a Linux engine's build behind a company proxy; every container create
and run, kept by the stub in containers-made, sets the empty -e pairs),
from.txtar (builds' proxy folders gone). e2e: images (a build sees only
its own proxy), from (a --from alpine:3.21 base with every feature and a
layer behind a company proxy with a password: the registry, Alpine's
mirror and the layer reach it through the builds' proxies; the password
is in no converted disk, image, log, build file or process's arguments);
corp_start/corp_stop shared with network.

Docs: internals/design (A company proxy: the ** case, builds, checks;
build confinement), safety/network, internals/network, images, lima,
docker, using/troubleshooting, internal/proxy/README.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-31 09:53:45 -07:00
w3cjandClaude Opus 5.5 2f559eaaa5 feat(netpolicy): network policy behind a company proxy; host proxy credentials kept out of images
Behind a company proxy, network policy's proxy connected to servers itself
and reached nothing. It now reaches allowed hosts through the host's
HTTPS_PROXY / HTTP_PROXY, still deciding each request by the name the VM
asked for.

Step 1, credentials (traced in the code and the backends' published docs;
not yet proven on a real build, which the new e2e checks do):
- Lima: build VMs (images, the tools build, --from's conversion VM) started
  with propagateProxyEnv on, its default. Lima's 07-etc-environment.sh
  writes the propagated settings into the guest's /etc/environment between
  #LIMA-START/#LIMA-END on each boot, and a stopped build VM's disk keeps
  it, so an image built with HTTPS_PROXY=http://user:pass@... kept the
  password. Fixed: propagateProxyEnv is on only for NetDirect; build scripts
  get the variables exported on their input (a loopback proxy as
  host.lima.internal), and /etc/sudoers.d/devvm-build-proxy keeps them for
  sudo until the scripts end.
- Docker: the CLI puts ~/.docker/config.json's proxies into every container
  it creates, and a commit keeps them (Docker's docs). Fixed: every
  container devvm makes sets each proxy variable empty (noClientProxy); a
  Linux engine's build gets the host's settings from an env file
  (hostProxyEnv); Desktop's build proxy goes through the company proxy.
- smolvm: passes the host's proxy only with --use-host-proxy, which devvm
  doesn't use: nothing to fix.

The upstream:
- backend.HostProxy (new): ReadHostProxy (capitals, then lowercase), None,
  Upstream (the proxy's -upstream file; only http:// proxies:
  upstream_proxy_scheme, upstream_proxy_invalid), Env.
- internal/proxy/upstream.go (new): -upstream FILE; ParseUpstream,
  ErrUpstreamScheme; NO_PROXY as Go reads it; localhost, *.localhost and
  loopback/unspecified addresses always direct; CONNECT by name with
  Proxy-Authorization: Basic for tunnels and for the TLS connections that
  put secrets in (checked against the system roots and -upstream-cas);
  plain HTTP in absolute form, canonical host, credentials only in the
  header to the upstream; floorUpstream: addresses judged as before, a name
  refused when the host's resolver answers with any internal or denied
  address, unjudged when it can't resolve; Event.Upstream (host:port), and
  devvm log's "through host:port".
- hostOK refuses shorthand addresses (127.1, 2130706433, 0x7f000001),
  which a company proxy may read as inet_aton does (found in review).
- netpolicy: Proxy.Getenv, run/<vm>.proxy.upstream (mode 600), stale()
  (a changed upstream starts the proxy again), writeUpstream for both files.

Also, from a review of the company-CA change: a proxy that needed starting
again and didn't end within 2 s of SIGTERM was kept, with its old roots,
silently. Stop now sends SIGKILL after 2 s and reports whether it ended;
Prepare fails with proxy_stop_failed instead of keeping it (Proxy.Signal
seam).

Messages: proxy_stop_failed, upstream_proxy_scheme, upstream_proxy_invalid,
with doc links.

Tests: proxy (TestParseUpstream, TestNoProxy, TestUpstreamTunnel,
TestUpstreamNoProxyDirect, TestUpstreamPlainHTTP, TestUpstreamIntercept,
shorthand hosts in TestOddHostsRefused), backend (TestHostProxy), lima
(TestBuildImageHostProxy, TestGuestProxyURL, propagateProxyEnv
expectations), docker (TestBuildHostProxy, create's empty proxy variables),
netpolicy (TestPrepareUpstream, TestPrepareStopsTheOldProxy, FormatEvent's
upstream). e2e: images (a layer built with a fake proxy password: its
script and sudo see it; the image's disk, Lima's files and devvm's logs
don't), network (a devvm _proxy as the company proxy: allowed hosts through
it by name, blocked ones never reach it, its password nowhere, and back to
direct).

Docs: safety/network (Behind a company proxy, Without network policy),
using/troubleshooting (Behind a company proxy), internals/network (Through
a company proxy, restarts, -upstream), internals/design (A company proxy:
what an upstream changes, credentials, builds, checks), internals/images,
internal/proxy/README.md.

Review (security-audit skill, independent pass over the proxy change):
the shorthand-address bypass, fixed; a VM-controlled name can force the
unjudged branch, documented; refusals name the company proxy's address
(no credentials), accepted as on the direct path; a loopback company proxy
isn't reachable from macOS builds, documented.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-31 00:20:33 -07:00