Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wireguard: add 'namespace' option to set interface netns #60983

Closed
wants to merge 2 commits into from

Conversation

yorickvP
Copy link
Contributor

@yorickvP yorickvP commented May 5, 2019

Motivation for this change

The usecase in the first section of https://www.wireguard.com/netns/ (making a network namespace to allow proper sandboxing) is rather easy to support in nixpkgs, and hard outside of it. This PR adds an option to do it.

(cc: @Lucus16 , @grahamc, @Mic92, @xeji, @fpletz )

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nix-review --run "nix-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Assured whether relevant documentation is up to date // can update the wiki after merge
  • Fits CONTRIBUTING.md.

Copy link
Contributor

@Lucus16 Lucus16 left a comment

Choose a reason for hiding this comment

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

LGTM

@nixos-discourse
Copy link

This pull request has been mentioned on Nix community. There might be relevant details there:

https://discourse.nixos.org/t/understanding-wireguard-network-namespaces-and-running-services-in-them/2829/2

@Mic92
Copy link
Member

Mic92 commented May 14, 2019

cc @zx2c4


${optionalString (values.allowedIPsAsRoutes != false) (concatStringsSep "\n" (concatMap (peer:
(map (allowedIP:
"ip route replace ${allowedIP} dev ${name} table ${values.table}"
"${ipns} route replace ${allowedIP} dev ${name} table ${values.table}"
Copy link
Contributor

Choose a reason for hiding this comment

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

The wireguard netns guide does

ip -n container route add default dev wg0

Is this a relevant difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if allowedIP is 0.0.0.0/0, then no. Otherwise, ours will only add relevant routes, while the wireguard example always routes all traffic. People wanting to route all traffic generally have allowedIPs set to ["0.0.0.0/0", "::0/0"].

@zx2c4
Copy link
Contributor

zx2c4 commented May 18, 2019

A quick look at this indicates that you've changed all the commands to run in a target named-namespace instead of the current namespace. Usually the appeal of namespace stuff with WireGuard is to create the device in one namespace and then move it into another, so that the listening socket lives in one while the interface lives in the other. I think that's what you have going on here? But perhaps you want to generalize it so that the creation happens in a designated namespace too? socketnamespace, interfacenamespace, and then you ensure the creation happens in the right place and is moved to another place?

@dtzWill
Copy link
Member

dtzWill commented Jun 4, 2019

Ping! Unfortunately looks like some conflicts have developed, can you take a look when you get a chance?

This is a great feature to support IMO, for example I think it's one of the cleanest and most reliable ways to ensure all traffic (for whatever you run in this namespace) goes through wireguard.

Honestly I'm a little surprised similar isn't done for tor, to avoid leaks without having to use a VM. Maybe that's not as practical or in fact is already common, but if so that's news to me! :).

Anyway, thanks and hopefully we can get this into a suitable state soon ^_^.

@Mic92
Copy link
Member

Mic92 commented Jun 4, 2019

Apparently there is orjail, which does the same thing for tor: https://github.com/orjail/orjail

@fpletz
Copy link
Member

fpletz commented Nov 14, 2019

Closing in favour of #71510.

@fpletz fpletz closed this Nov 14, 2019
@yorickvP yorickvP deleted the wg-netns branch January 12, 2020 17:08
@yorickvP yorickvP restored the wg-netns branch January 12, 2020 17:08
@yorickvP yorickvP deleted the wg-netns branch January 12, 2020 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants