Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upwireguard: add module #17933
Conversation
This comment has been minimized.
This comment has been minimized.
mention-bot
commented
Aug 23, 2016
|
@ericsagnes, thanks for your PR! By analyzing the annotation information on this pull request, we identified @edolstra, @bjornfor and @offlinehacker to be potential reviewers |
zx2c4
reviewed
Aug 23, 2016
View changes
| default = null; | ||
| example = "rVXs/Ni9tu3oDBLS4hOyAUAa1qTWVA3loR8eL20os3I="; | ||
| type = with types; nullOr str; | ||
| description = "Preshared key key used by the interface."; |
This comment has been minimized.
This comment has been minimized.
zx2c4
Aug 23, 2016
Contributor
You might want to update the description to say, "Optional preshared key used by the interface; most users will not need this."
zx2c4
reviewed
Aug 23, 2016
View changes
| listenPort = mkOption { | ||
| default = null; | ||
| type = with types; nullOr int; | ||
| example = 12345; |
This comment has been minimized.
This comment has been minimized.
zx2c4
Aug 23, 2016
Contributor
The example should be 51820. See https://git.zx2c4.com/WireGuard/tree/src/socket.c#n344
zx2c4
reviewed
Aug 23, 2016
View changes
| allowedIPs = mkOption { | ||
| example = [ "10.192.122.3/32" "10.192.124.1/24" ]; | ||
| type = with types; listOf str; | ||
| description = "IPs allowed by the peer."; |
This comment has been minimized.
This comment has been minimized.
zx2c4
reviewed
Aug 23, 2016
View changes
|
|
||
| endpoint = mkOption { | ||
| default = null; | ||
| example = "test.wireguard.io:18981"; |
This comment has been minimized.
This comment has been minimized.
zx2c4
reviewed
Aug 23, 2016
View changes
| default = null; | ||
| type = with types; nullOr int; | ||
| example = 12345; | ||
| description = "Keepalive seconds."; |
This comment has been minimized.
This comment has been minimized.
zx2c4
Aug 23, 2016
•
Contributor
This is an appalling description. Did you even read the man page of wg(8)? Here's something better:
This is optional and is by default off, because most users will not need it. It represents, in seconds, between 1 and 65535 inclusive, how often to send an authenticated empty packet to the peer, for the purpose of keeping a stateful firewall or NAT mapping valid persistently. For example, if the interface very rarely sends traffic, but it might at anytime receive traffic from a peer, and it is behind NAT, the interface might benefit from having a persistent keepalive interval of 25 seconds; however, most users will not need this.
You must not, under any circumstances, call this a "keepalive". Only "persistent keepalive".
This comment has been minimized.
This comment has been minimized.
ericsagnes
Aug 23, 2016
Author
Contributor
Sorry for that, I focused on having a somehow working module and kept the descriptions/example aesthetics at a bare minimum.
I was planning to copy paste the man page option description later when the module would be working.
Anyhow, my bad, will fix that ASAP.
Thanks for the review!
This comment has been minimized.
This comment has been minimized.
zx2c4
Aug 23, 2016
Contributor
I was planning to copy paste the man page option description later when the module would be working.
Great! In that case, for the above replies, roll with the extended man page description over what I commented here.
zx2c4
reviewed
Aug 23, 2016
View changes
| persistentKeepalive = mkOption { | ||
| default = null; | ||
| type = with types; nullOr int; | ||
| example = 12345; |
This comment has been minimized.
This comment has been minimized.
zx2c4
Aug 23, 2016
Contributor
This example is utter trash. I realize this is WIP, but it really shows a serious misunderstanding of what this nob does. A better example would be 25.
zx2c4
reviewed
Aug 23, 2016
View changes
| serviceConfig.ExecStart = "${pkgs.wireguard}/bin/wg setconf ${name} ${generateConf name values}"; | ||
| postStart = '' | ||
| ip address add ${values.ip} dev ${name} | ||
| ip link set up dev ${name} |
This comment has been minimized.
This comment has been minimized.
zx2c4
Aug 23, 2016
Contributor
All of these commands should be in ExecStart, no?
You're also forgetting ExecStop, which should call ip link del.
This comment has been minimized.
This comment has been minimized.
ericsagnes
Aug 23, 2016
Author
Contributor
The systemd unit is the part I am the less happy with, and also the part I didn't had much time to work on.
I was thinking to split the unit with preStart and postStart and add options to allow users to override the phases if they have more complicated needs like namespace setups.
Do you have any opinion on this point?
This comment has been minimized.
This comment has been minimized.
zx2c4
Aug 23, 2016
Contributor
I have no idea how NixOS generally implements its networking. If it's using systemd-networkd, then this should generate a .link unit or a .network unit or .netdev unit or something, and then have the wg setconf... in a service unit that depends on the former. If it's not using systemd-networkd, then you should try to integrate with whatever else NixOS is using. If NixOS is in fact just a series of ad-hoc modules like this, then the sky is the limit, and do whatever you feel is best. I'm no systemd expert, and while I'm vaguely aware of overriding parts of unit files in /etc, I don't know how extensible this would be for defining a series of phases. So, either trust your instinct here, or explain the problem to a systemd expert and ask them what they think.
zx2c4
reviewed
Aug 23, 2016
View changes
| ip = mkOption { | ||
| example = "192.168.2.1"; | ||
| type = types.str; | ||
| description = "The ip address added to the interface."; |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ericsagnes
Aug 23, 2016
Author
Contributor
Will fix that.
Do you think that this option should allow multiple IPs?
I saw that in https://git.zx2c4.com/WireGuard/tree/src/tests/netns.sh#n75 you set 2 IPs to the interface.
This comment has been minimized.
This comment has been minimized.
zx2c4
Aug 23, 2016
•
Contributor
Do you think that this option should allow multiple IPs?
Yes, probably. Some people like to have a v4 and a v6 address, for example, or many v4 or many v6 addresses; networking people are nuts and like to do all sorts of strange things. This part, which amounts to calling ip addr add, is the same as with setting up any network interface. What does the NixOS configuration do for ordinary Ethernet cards? If it allows adding multiple IPs to eth0, then this here should allow adding multiple IPs to wg0. In other words, this option is the most ordinary and standard one of the module.
zx2c4
reviewed
Aug 23, 2016
View changes
| options = { | ||
|
|
||
| ip = mkOption { | ||
| example = "192.168.2.1"; |
This comment has been minimized.
This comment has been minimized.
zx2c4
Aug 23, 2016
Contributor
Probably this should be: "192.168.2.1/24" or something involves a CIDR.
This comment has been minimized.
This comment has been minimized.
|
Hi -- WireGuard author here. This is nowhere near ready to be merged. I've made several comments inline with the source to review. There's also one big thing missing here: If the IP of the interface is 192.168.2.1/24, and the allowed IPs are 192.168.2.0/24 or a list of anything that falls within 192.168.2.0/24, then you don't need to do anything. However, if the allowed IPs contain something laying outside of 192.168.2.0/24, such as 10.0.0.0/16, then you need to add those routes to the routing table: |
This comment has been minimized.
This comment has been minimized.
|
@zx2c4 Thanks for all the inputs, that is very appreciated! It is indeed a rough sketch made in very short time to have some base to talk and work on. |
This comment has been minimized.
This comment has been minimized.
|
Added a commit to clean things up a little, not perfect but still an improvement.
Nix expression language is not really a general purpose language and doing a such thing programmatically could end in a little complicated an bloated code. |
This comment has been minimized.
This comment has been minimized.
This is completely unacceptable. Remove this option immediately. It's not okay, complicates things, and makes no sense. If you can't do any real computation in the language, just add all the allowed-ips as routes. This is equally as valid and the linux routing table will sort things out for you. I don't know this language, but something like this should do: foreach peer in values.peers: |
ericsagnes
force-pushed the
ericsagnes:wireguard-module
branch
2 times, most recently
Aug 23, 2016
This comment has been minimized.
This comment has been minimized.
|
One last quick commit to remove unacceptable and insanity :) I have no much more time to work on this this week, so if you are in a hurry please make a PR to this branch, sorry. |
This comment has been minimized.
This comment has been minimized.
|
Changes look good. Will wait til next week to see what's next. Thanks for your hard work on this! |
This comment has been minimized.
This comment has been minimized.
|
Regarding the unit
|
This comment has been minimized.
This comment has been minimized.
|
Yes. In this case you do want
|
ericsagnes
force-pushed the
ericsagnes:wireguard-module
branch
2 times, most recently
Aug 23, 2016
This comment has been minimized.
This comment has been minimized.
|
Wow, an upstream author reviewing a NixOS module… that's a first. Thanks a lot for your feedback @zx2c4! |
zx2c4
reviewed
Aug 24, 2016
View changes
| generateUnit = name: values: | ||
| nameValuePair "wireguard-${name}" | ||
| { | ||
| description = "Wireguard unit for interface ${name}"; |
This comment has been minimized.
This comment has been minimized.
zx2c4
reviewed
Aug 24, 2016
View changes
| interfaces = mkOption { | ||
| description = "Wireguard interfaces."; | ||
| default = {}; | ||
| # TODO add useful example when the module interface is stabilized |
This comment has been minimized.
This comment has been minimized.
zx2c4
Aug 24, 2016
Contributor
Seems better to add a useful interface before the module interface is stabilized.
This comment has been minimized.
This comment has been minimized.
|
@fpletz My pleasure. The latest changes look mostly good to me, but still a few things are funky:
Putting these two points together yields this rearranged section:
The descriptions of This is my personal opinion on the matter, but if NixOS developers have a good reason for the override behavior instead, I guess that's fine. My only suggestion, then, would be to call it |
ericsagnes
force-pushed the
ericsagnes:wireguard-module
branch
Aug 28, 2016
This comment has been minimized.
This comment has been minimized.
|
@zx2c4 Thanks for the feedback, updated the commit according to your last comment. I added a basic example to the Do you have any suggestion of relevant examples for |
This comment has been minimized.
This comment has been minimized.
|
Hey @ericsagnes -- excellent work! Something I missed before, that disappeared in the reworkings is that there's no longer an Unrelated question: How does As for your questions: It might be less confusing to have for the example these IPs instead:
One use of |
This comment has been minimized.
This comment has been minimized.
In a nutshell, There are two advantages in using
So using The added Changes are in a new commit to facilitate review, most important ones are:
|
This comment has been minimized.
This comment has been minimized.
|
One advantage I see, when ExecStart is used over script, that in case of an error, |
This comment has been minimized.
This comment has been minimized.
|
@Mic92 Thanks, this is indeed a valid point in favor of @zx2c4 Please let me know if you think Update:
So as an unfortunate result, the usage of I tend to think that the flexibility provided by |
This comment has been minimized.
This comment has been minimized.
|
Looks fine and mergeable to me in the current state. Will test later and merge. Thanks a lot for your work and the review! |
fpletz
removed
the
2.status: work-in-progress
label
Aug 30, 2016
This comment has been minimized.
This comment has been minimized.
|
Well, ExecStart=-${pkgs.iproute2.bin}/ip link del dev ${name} so this command is allowed to fail. |
Mic92
referenced this pull request
Sep 22, 2016
Closed
systemd.services.<service>.serviceConfig should support multiple entries per option #18838
This comment has been minimized.
This comment has been minimized.
|
@zx2c4 Could you review the latest changes? |
This comment has been minimized.
This comment has been minimized.
|
Looks mostly good to me. One question is -- with what umask does |
ericsagnes
force-pushed the
ericsagnes:wireguard-module
branch
Oct 3, 2016
ericsagnes
changed the title
[WIP] wireguard: add module
wireguard: add module
Oct 3, 2016
This comment has been minimized.
This comment has been minimized.
|
Thank you for the review, I squashed the commits and removed the WIP flag so the PR is now ready to merge.
Unfortunately, actually any file in the Nix store is world readable, handling private files in the nix store is an open and complex problem. This is well known problem and other modules also suffer this limitation, but I am afraid there is nothing that can be done in this PR scope to fix that. |
This comment has been minimized.
This comment has been minimized.
|
When I tried the example, I noticed that empty ExecStart= entries were generated. |
ericsagnes
force-pushed the
ericsagnes:wireguard-module
branch
Oct 5, 2016
This comment has been minimized.
This comment has been minimized.
|
@Mic92 Good catch, thanks! I updated the And thanks for the diff, this way indeed save some code, but might make the code harder to understand and to maintain on the long term. |
Mic92
reviewed
Oct 5, 2016
|
|
||
| postSetup = mkOption { | ||
| example = literalExample '' | ||
| printf 'nameserver 10.200.100.1' | ${pkgs.openresolv}/bin/resolvconf -a wg0 -m 0 |
This comment has been minimized.
This comment has been minimized.
Mic92
Oct 5, 2016
Contributor
this example will not work, because it is not executed within in a shell - take a look at my version.
This comment has been minimized.
This comment has been minimized.
|
this version preserves maintainability while still allowing multiple commands and not splitting user defined variables at newline. |
ericsagnes
force-pushed the
ericsagnes:wireguard-module
branch
to
e234f73
Oct 5, 2016
This comment has been minimized.
This comment has been minimized.
|
Thanks, applied! |
Mic92
closed this
in
0bd263e
Oct 6, 2016
This comment has been minimized.
This comment has been minimized.
|
Thanks. there was a typo, I made in the postSetup example. |
lbonn
added a commit
to lbonn/nixpkgs
that referenced
this pull request
Nov 30, 2016
lbonn
referenced this pull request
Nov 30, 2016
Merged
wireguard: remove dependency on ip-up.target #20825
This comment has been minimized.
This comment has been minimized.
|
One important comment from @zx2c4 that wasn't addressed is the fact that @zx2c4 one simple feature that could really help us is if you can store the private key in a file and reference it with Ideally Finally I would like to say that I'm excited that WireGuard is being integrated into NixOS. My colleague @FPtje and I are currently setting up a StrongSwan VPN and it's difficult and error prone. I'm looking forward switching over to WireGuard once it's in the next NixOS release. Thanks to anybody involved in this PR! |
This comment has been minimized.
This comment has been minimized.
|
@basvandijk note that wireguard is still experimental, which means the protocol can change in a backwards incompatible way. |
ericsagnes commentedAug 23, 2016
Motivation for this change
WIP PR for adding a wireguard module.
Things done
(nix.useChroot on NixOS,
or option
build-use-chrootinnix.confon non-NixOS)
nix-shell -p nox --run "nox-review wip"./result/bin/)