diff --git a/.github/justfile b/.github/justfile index 0d2dde81ca3..6d395fdd0d3 100644 --- a/.github/justfile +++ b/.github/justfile @@ -17,6 +17,17 @@ runner-vm-ci: trap 'sudo apparmor_parser --remove "$profile"' EXIT just gh runner-vm +# Install the persistent host profile that lets Nix store unshare map user namespaces. +runner-userns: + #!/usr/bin/env bash + set -euo pipefail + if [[ "${GITHUB_ACTIONS:-}" == true ]]; then + echo "runner-userns is persistent host policy; a hosted runner uses runner-vm-ci" >&2 + exit 1 + fi + sudo install -m 0644 nix/runner/nix-builder-unshare /etc/apparmor.d/nix-builder-unshare + sudo apparmor_parser --replace /etc/apparmor.d/nix-builder-unshare + # Build and test the persistent NixOS runner VM on x86_64 Linux. runner-vm: bash sh/local.sh nix build --no-link .#checks.x86_64-linux.github-runner-vm .#checks.x86_64-linux.github-runner-vm-image .#checks.x86_64-linux.github-runner-vm-config --print-build-logs diff --git a/nix/runner/README.md b/nix/runner/README.md index 1a20ce2dfce..0ab20e780a3 100644 --- a/nix/runner/README.md +++ b/nix/runner/README.md @@ -144,6 +144,13 @@ refuses local and self-hosted runners, and unloads the profile on exit, including build failure. `just gh runner-vm` does not change host policy; its build host must already support rootless user namespaces. +Ubuntu denies that map when `kernel.apparmor_restrict_unprivileged_userns` is +set, unless the binary has a profile. `just gh runner-userns` installs +`nix/runner/nix-builder-unshare` into `/etc/apparmor.d/` and loads it. The +profile allows user namespaces only for `/nix/store/*util-linux*/bin/unshare`, +so a nixpkgs bump still matches, and `/usr/bin/unshare` stays denied. AppArmor +stays enabled. Run it again only after the host profile is removed. + `just gh runner-vm` builds a guest image and runs NixOS integration tests for startup without carrier, public egress for multiple guests, private-network and sibling-guest isolation including spoofed established replies, compatible host NAT diff --git a/nix/runner/nix-builder-unshare b/nix/runner/nix-builder-unshare new file mode 100644 index 00000000000..776e2b781c2 --- /dev/null +++ b/nix/runner/nix-builder-unshare @@ -0,0 +1,12 @@ +# Nix image builds run the store copy of util-linux unshare +# (`unshare --map-root-user fakeroot systemd-repart`). Ubuntu denies the +# uid map unless that binary has a userns profile. /usr/bin/unshare stays denied. +abi , +include + +profile nix-builder-unshare /nix/store/*util-linux*/bin/unshare flags=(unconfined) { + userns, + + # Site-specific additions and overrides. See local/README for details. + include if exists +} diff --git a/quest/m0/ci/README.md b/quest/m0/ci/README.md index 4be581e5f17..6e6954ddb27 100644 --- a/quest/m0/ci/README.md +++ b/quest/m0/ci/README.md @@ -186,4 +186,3 @@ The historical samples locate candidates; they are not controlled benchmarks. - [A release merge opens no stale release PR](/quest/m0/ci/release-pr-after-release.md) - `just rs release` publishes before it proposes, so a merged release isn't re-proposed - [Build two queue entries at once if it helps](/quest/m0/ci/queue-concurrency.md) - a measured trial of `maximumEntriesToBuild: 2` against the serial lane's burst latency - [macOS CI runs kio's tests](/quest/m0/ci/macos-kio.md) - `just rs macos-test` includes kio -- [The desktop host's Nix builders may map user namespaces](/quest/m0/ci/nix-builder-userns.md) - agents' local `just ci` builds the runner image instead of failing `check flake` diff --git a/quest/m0/ci/nix-builder-userns.md b/quest/m0/ci/nix-builder-userns.md deleted file mode 100644 index adb268aca9e..00000000000 --- a/quest/m0/ci/nix-builder-userns.md +++ /dev/null @@ -1,39 +0,0 @@ -# [XS] The desktop host's Nix builders may map user namespaces - -## Goal - -On the desktop host, where agents run their local gates, `just ci` builds the -flake's runner image instead of failing `check flake`, and `just check` runs -it instead of skipping. - -## Plan - -Decided 2026-11-05 (maintainer, follow-up seen in -[moq-dev/moq#7918](https://github.com/moq-dev/moq/pull/7918), -[moq-dev/moq#7684](https://github.com/moq-dev/moq/pull/7684), -[moq-dev/moq#7858](https://github.com/moq-dev/moq/pull/7858), and -[moq-dev/moq#7883](https://github.com/moq-dev/moq/pull/7883)): ✅ m0. - -Each of those gates failed `check flake` while building `github-runner`, with -`unshare: write failed /proc/self/uid_map: Operation not permitted`. `just ci` -sets `CI_STRICT`, so the check fails there; without it, -`nix/runner/userns-probe.nix` and `sh/dispatch.sh` detect the refusal and skip, -which is why [moq-dev/moq#7763](https://github.com/moq-dev/moq/pull/7763) -retired the earlier quest. This quest fixes the host instead, so nothing fails -or skips. - -As of 2026-11-05 the probe fails on the desktop host (Ubuntu 26.04, where -`kernel.apparmor_restrict_unprivileged_userns = 1` and even a plain -`unshare --map-root-user true` is refused) and passes on `nixos`. Lift -AppArmor's restriction for Nix builds there, persistently and as narrowly as -works, apply it when no gate is running, and check that the probe succeeds and -`just ci` passes `check flake`. - -Decided 2026-11-05 (maintainer, /quest-plan): flip the sysctl host-wide rather than a narrow AppArmor -profile for the Nix builders. Not chosen: a narrow profile; declining and -deleting the quest. Applied the same day: -`/etc/sysctl.d/99-userns.conf` sets -`kernel.apparmor_restrict_unprivileged_userns = 0` (it loads after Ubuntu's -`/usr/lib/sysctl.d/10-apparmor.conf`), `unshare --map-root-user true` -succeeds, and `nix/runner/userns-probe.nix` builds. What remains: run -`just ci` on the desktop and confirm `check flake` passes.