Skip to content

nixos/test-driver: drop /dev/net/tun requirement for vm <-> container communication - #512268

Draft
jfly wants to merge 3 commits into
NixOS:staging-nixosfrom
jfly:vde_plug2tapless-poc
Draft

jfly wants to merge 3 commits into
NixOS:staging-nixosfrom
jfly:vde_plug2tapless-poc

Conversation

@jfly

@jfly jfly commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

This is a POC: just looking for high level feedback right now.

With these changes, I am able to run nix-build -A nixosTests.nixos-test-driver.containers without exposing /dev/net/tun in my nix sandbox.


vde_plug2tap allows communication between our QEMU VMs (connected via vde_switch) and our systemd-nspawn containers (connected via Linux bridge interfaces). Unfortunately, it requires /dev/net/tun to create a TAP interface to hook into the bridge interfaces. /dev/net/tun is not normally present in the nix build sandbox, and folks have raised security concerns about making it available. TODO: citation needed, all I have right now is this.

Here I've put together a proof of concept of an alternate implementation of vde_plug2tap that uses raw sockets instead of TAP interfaces. I haven't been able to find an existing project that does this, probably because it's unusual to be in a situation where you can create raw sockets (which requires root), but you cannot create TAP interfaces. From Universal TUN/TAP device driver:

There’s no harm in allowing the device [/dev/net/tun] to be
accessible by non-root users, since CAP_NET_ADMIN is required for
creating network devices or for connecting to network devices which
aren’t owned by the user in question.

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

@jfly
jfly requested review from kmein and tfc April 22, 2026 06:01
@jfly
jfly force-pushed the vde_plug2tapless-poc branch from c084670 to d6607ac Compare April 22, 2026 06:02
github-actions[bot]

This comment was marked as outdated.

@jfly
jfly force-pushed the vde_plug2tapless-poc branch from d6607ac to 4b78c1d Compare April 22, 2026 06:08
jfly added 3 commits April 21, 2026 23:11
I found when running locally that if `vde_switch` crashes, we just
permanently end up in a state where its stdout appears readable, but we
find no lines to read. I think this is a quirky interaction between
nonblocking mode and the underlying implementation of `readline`.
Whatever the root cause, I believe this is the correct fix: stdout is
line buffered, so if it's readable, we should find a line. If we don't
then the process must be dead.

Also log the output at debug level while we're waiting for `vde_switch`
to start. Previously we were blackholing it, which made debugging issues
quite challenging.
This just moves the thing that should create the `ctl` folder
(`vde_switch`) next to the assertion that it actually created it.
…er communication

This is a POC: just looking for high level feedback right now.

`vde_plug2tap` allows communication between our QEMU VMs (connected via `vde_switch`) and our systemd-nspawn containers (connected via Linux bridge interfaces). Unfortunately, it requires `/dev/net/tun` to create a TAP interface to hook into the bridge interfaces. `/dev/net/tun` is not normally present in the nix build sandbox, and folks have raised security concerns about making it available. TODO: citation needed, all I have right now is [this](NixOS/infra#987 (comment)).

Here I've put together a proof of concept of an alternate implementation of `vde_plug2tap` that uses raw sockets instead of TAP interfaces. I haven't been able to find an existing project that does this, probably because it's unusual to be in a situation where you can create raw sockets (which requires root), but you cannot create TAP interfaces. From [Universal TUN/TAP device driver]:

> There’s no harm in allowing the device [`/dev/net/tun`] to be
> accessible by non-root users, since CAP_NET_ADMIN is required for
> creating network devices or for connecting to network devices which
> aren’t owned by the user in question.

[Universal TUN/TAP device driver]: https://www.kernel.org/doc/html/latest/networking/tuntap.html
@jfly
jfly force-pushed the vde_plug2tapless-poc branch from 4b78c1d to 7e618a9 Compare April 22, 2026 06:11
@jfly
jfly changed the base branch from master to staging-nixos April 22, 2026 06:11
@nixpkgs-ci nixpkgs-ci Bot closed this Apr 22, 2026
@nixpkgs-ci nixpkgs-ci Bot reopened this Apr 22, 2026
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 6.topic: testing Tooling for automated testing of packages and modules 8.has: documentation This PR adds or changes documentation labels Apr 22, 2026
Comment on lines +139 to +140
# TODO: Only do this if necessary (it fails if we don't have pid 0 inside the sandbox).
# refs: <https://github.com/NixOS/nixpkgs/pull/511413#discussion_r3108252527>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is why most tests are failing with these changes. I just wanted to put up a POC that shows that nix-build -A nixosTests.nixos-test-driver.containers does work without /dev/net/tun exposed in the build sandbox.

@jfly
jfly requested a review from Ma27 April 22, 2026 14:47
@nixpkgs-ci nixpkgs-ci Bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Apr 27, 2026

@Ma27 Ma27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate the dedication, but I'm really hesistant to having such a low-level tool that is essentially up to us, the people maintaining & developing the test-driver to maintain.

My worries are about maintainership itself, but also the chance of having to debug subtle bugs in our own code that make network debugging even harder inside VM tests. This is not to say that I don't trust this code in particular, but from experience, this feels pretty risky and I'd kinda like to avoid that.

That being said, as you indicated in your TODO-comment, have you reached out to the VDE project? Would be helpful to know what they think and if they'd be willing to take care of this.

/dev/net/tun is not normally present in the nix build sandbox, and folks have raised security concerns about making it available

Just to get this right, this isn't directly about purity concerns to not have it, but since that might be a vector to escape the sandbox in general (I wouldn't consider the Nix sandbox a security boundary, my point is rather about any sandbox solution passing through this device).

cc @RaitoBezarius who also seemed interested in having a non-sandbox-paths solution for this.

@jfly

jfly commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Everything you say totally makes sense, @Ma27. This was a "is it possible?" question I couldn't let go of.

that might be a vector to escape the sandbox in general

I've been waiting to reach out to the vde folks until I can give them some sort of explanation about the risks associated with /dev/net/tun. @Ma27, are you able to write something up (or point me to someone who can)?

@Ma27

Ma27 commented Jun 26, 2026

Copy link
Copy Markdown
Member

@jfly so, I've been chatting with @RaitoBezarius recently about the question whether/not this is a good idea and he signalled it's likely fine and the easiest solution for the time being, so I proposed https://gerrit.lix.systems/c/lix/+/5711 to the Lix project. Let's see how that goes.

@thadguidry

Copy link
Copy Markdown

Hi @jfly , On Fulltime Nix Podcast, I listened to your explanations and problems of having an easier abstraction than Nspawn can provide especially around hardware like Storage, Networking, GPUs.

I would like to see this effort pivot to use Incus (the community fork of LXD). Which can manage VMs and Containers and a much easier configuration management.

Happy to work on this draft with you going forward to build a robust container/vm template system for building and testing NixOS and NixPkgs.

@jfly

jfly commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, @thadguidry!

I would like to see this effort pivot to use Incus (the community fork of LXD). Which can manage VMs and Containers and a much easier configuration management.

Happy to work on this draft with you going forward to build a robust container/vm template system for building and testing NixOS and NixPkgs.

I'm not familiar with Incus. I think this question is better suited for the @NixOS/test-driver team. You may also want to take a look at #589203, which looks like it's adopting a different VM runner (test.thing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: testing Tooling for automated testing of packages and modules 8.has: documentation This PR adds or changes documentation 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 1-10 This PR causes between 1 and 10 packages to rebuild on Darwin. 10.rebuild-darwin: 1 This PR causes 1 package to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants