Nix builds and credential isolation

The mechanism and threat model for nix build inside an agent container, from the security model.

Background

nixos-containers' start script bind-mounts the host's nix-daemon socket directory (/nix/var/nix/daemon-socket) into every container, hyperhive's agents included; hyperhive adds no bind for it. The host daemon may have sandbox-fallback = false (strict NixOS defaults), which causes nix build inside nspawn containers to fail — containers lack kernel user namespaces, so nix can't set up its build sandbox. the agent modules set sandbox-fallback = true so that builds fall back to unsandboxed execution rather than failing outright.

Per-agent nix builds mode

services.hyperhive.agent.nixBuilds picks where an agent's nix builds run. It has two values, and defaults to host:

The mode reaches the container as privateUsers does: the swarm builder reads the option from the evaluated config into the agent's closure record (nix_builds), hive-c0re reads the record when it writes the container's flags and sends the mode to hive-priv, and the flags apply at the container's next start.

none cuts the daemon only. It leaves the agent's egress alone.

Under host an agent shares the daemon with the hive's own closure pull. The daemon holds the swarm cache as a substituter, with the pull token in a netrc only root reads, so an agent can ask it to substitute a swarm closure as well as a path from the public caches the host configures. The agent never sees the token, and a closure is world-readable once it's on the host and holds no secret. See hive-c0re-privilege.md.

Threat model

Unsandboxed nix builds run as nixbld users (non-root; nrBuildUsers is at least 32, so UIDs 30001 and up). Without sandbox isolation, a build derivation's builder script has read access to any file in the container that the nixbld user can read.

The blast radius also has a network dimension. swarm-ci-runner runs its unsandboxed builds of untrusted PR code in its own private netns behind the bridge: a build reaches the forge by name and can't reach host-loopback services — including the core dashboard at 127.0.0.1:<dashboard_port>, which has no application-layer auth of its own (see docs/4-implementation/scheduler/ci.md). The 0600 token policy bounds file reads; network isolation bounds network reach.

What's NOT exposed:

Policy: all credential files written to agent state directories MUST be mode 0600 or stricter. Don't create world-readable secret files in agent state dirs.

Long-term fix

The proper fix is to enable user namespaces inside nspawn containers (--private-users=inherit in EXTRA_NSPAWN_FLAGS) so nix can set up its real sandbox and sandbox-fallback becomes a true last resort. This requires verifying bind-mount compatibility with user namespace UID mapping first.