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

zerotier module: add option to join network and open port #37949

Merged
merged 1 commit into from Mar 28, 2018

Conversation

obadz
Copy link
Contributor

@obadz obadz commented Mar 27, 2018

Motivation for this change

Open firewall port for UDP channel.
Ability to join network declaratively is useful for new hosts.

Will merge in a few days if no objections.

cc @sjmackenzie @zimbatm @roblabla @ehmry

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-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 nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@danielfullmer
Copy link
Contributor

One alternative to using zerotier-cli join is to run touch /var/lib/zerotier-one/networks.d/${cfg.joinNetwork}.conf in preStart.

See zerotier/ZeroTierOne#161 as well as the zerotier-one manpage under the "networks.d" section. It looks like this is a supported alternative.

@obadz
Copy link
Contributor Author

obadz commented Mar 27, 2018

@danielfullmer, yes that's much nicer. Will amend.

@obadz
Copy link
Contributor Author

obadz commented Mar 27, 2018

Amended.

Copy link
Member

@zimbatm zimbatm left a comment

Choose a reason for hiding this comment

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

cool idea, I just have one comment.

@@ -7,6 +7,16 @@ let
in
{
options.services.zerotierone.enable = mkEnableOption "ZeroTierOne";

options.services.zerotierone.joinNetwork = mkOption {
default = null;
Copy link
Member

Choose a reason for hiding this comment

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

can you make this an array? It's possible to join multiple networks at the same time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

mkdir -p /var/lib/zerotier-one
chmod 700 /var/lib/zerotier-one
chown -R root:root /var/lib/zerotier-one
'';
'' + optionalString (cfg.joinNetwork != null) ''
touch "/var/lib/zerotier-one/networks.d/${cfg.joinNetwork}.conf"
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, the networks.d subdirectory would not exist on the first startup of zerotier. Maybe just add it to the mkdir -p above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup just noticed that too. Done.

@obadz obadz merged commit 0a9d7f0 into NixOS:master Mar 28, 2018
@@ -38,6 +49,9 @@ in
# ZeroTier does not issue DHCP leases, but some strangers might...
networking.dhcpcd.denyInterfaces = [ "zt0" ];

# ZeroTier receives UDP transmissions on port 9993 by default
networking.firewall.allowedUDPPorts = [ 9993 ];
Copy link
Member

Choose a reason for hiding this comment

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

We do not open firewall ports by default except for ssh. I am not sure if should make an exception here.

Copy link
Contributor

Choose a reason for hiding this comment

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

The ZeroTier service should have a parameter for port, so networking.firewall.allowedUDPPorts could be used at a higher level when really needed.

@obadz obadz deleted the zerotier-module branch December 24, 2018 00:33
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

6 participants