Repository navigation
test(minimald): prove RustSlirp tap creation rootless and as root - #1370
norrietaylor wants to merge 2 commits into
Conversation
Spec 012 (#1354) is priced around there being two own-IP tap mechanisms with two rollback owners: hakoniwa's RustSlirp in-namespace for DM2, and open_tap + move_tap_into_netns under CAP_NET_ADMIN for DM1/3/4. If the in-VM path can use RustSlirp too, the two collapse into one mechanism differing only in relay transport, which is what docs/specs/03-spec-networking/networking-with-diagrams.md already describes. The blocking unknown is whether RustSlirp's setns(CLONE_NEWUSER) plus in-netns tap creation still works when the hakoniwa parent is root. sandbox2 calls .uidmap(1000), so only the unprivileged case has ever run. Root should be a superset, but the combination is untested. Add a harness with both halves, built the way sandbox2::new_container builds an own-IP PTask container: - rustslirp_tap_comes_up_unprivileged: the DM2 baseline, which has no automated coverage today. - rustslirp_tap_comes_up_as_root: the same assertions with the parent re-execed under sudo. A preflight distinguishes a missing host prerequisite from a real negative: without /dev/net/tun neither mechanism can work, and reporting that as "RustSlirp handed out no tap fd" would wrongly read as a failed spike. The probe also captures the sandboxed child's exit status, so a dead sandbox and an unmade tap are told apart. Both are #[ignore]d and additionally early-return unless MINIMALD_NETNS_TEST is set, so a default cargo test run never unshares anything. The ci-linux-native minimald-root-integration job discovers them by the _root_integration suffix and already supplies sudo, unprivileged userns, and the gate variable. No VM and no workflow edit are needed.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueComment |
libtest exits 0 when its filter matches nothing, so asserting only on the sudo child's exit status could not tell a passing root proof from an inner run that selected no tests at all. The spike's entire conclusion turns on this one result, so a green that means nothing is worse than a red. Assert the inner run reported a test passing, and keep its stdout/stderr in the failure message either way.
CI result: Q1 passes
Why this green is trustworthyA green from a gated
What it means for spec 012 (#1354)The blocking question is settled in favour of unification: the in-VM own-IP path can use the same rootless mechanism as the native one, so the two mechanisms differ only in relay transport — which is what Consequences for the spec as written:
Scope noteTwo caveats on how far this generalises, neither blocking. The runner is x86_64 on a GitHub-hosted kernel, not the libkrun guest kernel; and this proves tap creation, not end-to-end connectivity through the vsock relay. Both are Q2's job — boot a guest, mint an own-IP session, assert egress + ingress + PTask↔PTask — which needs the transport-generalization patch and a harness in |
Summary
Spike harness, not a behaviour change. Draft on purpose: it exists to get an answer
out of CI, not to merge as-is.
Assessing spec 012 (#1354) surfaced a cheaper design than the spec prices for. Spec
012's complexity —
plan()returning data,abandon(),NetPlan/TapSpec,PhaseOneAttachGuard, theunsafe from_raw_fd— exists because there are twoown-IP attach mechanisms with two rollback owners:
minimaldunprivileged): hakoniwa'sRustSlirpmakes thetap inside the sandbox's userns+netns, rootless, and hands the fd back via
Child.rustslirp_tapfd.minimaldroot):open_tap+move_tap_into_netnsmake thetap in the guest's root netns under
CAP_NET_ADMINandip link set … netnsit in.If the in-VM path can use
RustSlirptoo, the two collapse into one mechanismdiffering only in relay transport (unix socket vs vsock) — which is what
docs/specs/03-spec-networking/networking-with-diagrams.mdalready says thedifference should be. Diagram 7 labels both host panels
PTasks (each: userns + netns + tap); diagram 6 maps R1 → B1 "Linux user namespaces (unprivileged netns +tap)". The current in-VM mechanism is the deviation, so unification converges on the
documented design rather than departing from it.
Settled by reading hakoniwa at the pinned rev (
souk4711/hakoniwa@0810ffa3,src/unshare/newnet/rustslirp.rs) and needing no test:RustSlirpdoes not replacegvproxy. Despite the name there is no slirp, no TCP/IP stack and no NAT — it forks,
setnses into the target's userns then netns, brings uplo, builds a TUN/TAP viatun_rs, adds a default route and returns the fd overSCM_RIGHTS. A one-for-onerootless substitute for
open_tap+move_tap_into_netns, nothing more. gvproxyremains switch + NAT + port-forward API either way.
The blocking question
Does
RustSlirp'ssetns(CLONE_NEWUSER)+ in-netns tap creation still succeed whenthe hakoniwa parent is root?
sandbox2/src/lib.rscalls.uidmap(1000), so onlythe unprivileged case has ever run. Root should be a superset —
CAP_SYS_ADMINforthe setns,
CAP_NET_ADMINin the joined netns — but the combination is untested.What this adds
One harness,
crates/minimald/tests/rustslirp_root_integration.rs, building thecontainer exactly as
sandbox2::new_containerdoes for an own-IP PTask:rustslirp_tap_comes_up_unprivileged— the DM2 baseline, which has no automatedcoverage today.
rustslirp_tap_comes_up_as_root— the blocking question, re-execing the test binaryunder
sudo -E env …so the hakoniwa parent is root. Separate test functions ratherthan an env-var A/B, since CI cannot flip a new variable without a workflow edit.
A
preflight()separates a missing host prerequisite from a real negative. Without/dev/net/tunneither mechanism can work, and reporting that as "RustSlirp handedout no tap fd" would read as a failed spike and wrongly trip its kill criteria — I hit
exactly that locally. The probe also captures the sandboxed child's exit status, so a
dead sandbox and an unmade tap are distinguishable.
Both are
#[ignore]d and additionally early-return unlessMINIMALD_NETNS_TESTisset, matching
netns_root_integration.rsandnsenter_integration.rs, so a defaultcargo testnever unshares anything.Why no workflow change
.github/workflows/is frozen; none of this needs it. The_root_integrationsuffixis auto-discovered by
ci-linux-native'sminimald-root-integrationjob, whichalready supplies sudo, unprivileged userns
(
kernel.apparmor_restrict_unprivileged_userns=0), a netns-capability probe andMINIMALD_NETNS_TEST=1. No KVM and no VM needed — this is the fastest availablesignal on the blocking question.
Refs: #1354
Testing
Everything below is local; the proofs themselves cannot run on my workbench, which is
why this PR exists.
cargo test -p minimald --test rustslirp_root_integration --no-run --locked— buildsclean, no warnings.
test result: ok. 2 passed; 0 failed— both self-skip green, so adefault
cargo testcannot be reddened by this.cargo clippy -p minimald --tests --locked -- -D warnings— clean.cargo fmt -p minimald -- --check— clean.every_integration_test_binary_ends_in_integrationnaming guard — passes.Not run locally, and cannot be: this host has no
/dev/net/tun, no/dev/kvmandruns as uid 1000. A gated run here correctly reports the prerequisite rather than a
result:
The
minimald-root-integrationjob is the execution venue. What its result means:attach path, one rollback owner, and deletion of
attach_own_ip,open_tap,move_tap_into_netns,tap_netns_commands, theip/nsentersubprocess dependencyand its
trusted_programhardening (~200 lines plus tests).plan()andabandon()still survive —
RustSlirpsets the address inside hakoniwa's spawn(
create_tun_device→.ipv4(…)), so the pre-spawn lease and its rollbackobligation remain.
sandbox2→ stop. Unificationwould mean patching a git-pinned third-party fork, which changes the cost calculus
entirely; spec 012 proceeds as written. The harness is worth keeping either way — it
documents the root/rootless behaviour permanently and the baseline is coverage that
does not exist today.
The follow-on transport-generalization patch and its VM-lane harness are deliberately
not in this PR; they are gated on this answer.
Checklist
BREAKING CHANGE:footer present if this is a breaking change — n/a🤖 Generated with Claude Code