Skip to content

Commit

Permalink
nixos/nebula: add DNS options
Browse files Browse the repository at this point in the history
Add the options:

- lighthouse.serve_dns
- lighthouse.dns.host
- lighthouse.dns.port

Improve systemd capabilities handling:

- do not give CAP_NET_ADMIN when tunnel interface is disabled
- give CAP_NET_BIND_SERVICE when DNS is enabled

Add self as maintainer: I'm using Nebula on NixOS in prod.

Signed-off-by: Sirio Balmelli <[email protected]>
  • Loading branch information
siriobalmelli committed Dec 21, 2024
1 parent da676f2 commit ae7d05c
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions nixos/modules/services/networking/nebula.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ in
description = "Whether this node is a relay.";
};

lighthouse.serveDns = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether this lighthouse node should serve DNS.";
};

lighthouse.dns.host = lib.mkOption {
type = lib.types.str;
default = "0.0.0.0";
description = "IP address on which nebula lighthouse should serve DNS.";
};

lighthouse.dns.port = lib.mkOption {
type = lib.types.nullOr lib.types.port;
default = 53;
description = "UDP port number for lighthouse DNS server.";
};

lighthouses = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
Expand Down Expand Up @@ -172,10 +190,7 @@ in
'';
example = lib.literalExpression ''
{
lighthouse.dns = {
host = "0.0.0.0";
port = 53;
};
lighthouse.interval = 15;
}
'';
};
Expand Down Expand Up @@ -203,6 +218,9 @@ in
lighthouse = {
am_lighthouse = netCfg.isLighthouse;
hosts = netCfg.lighthouses;
serve_dns = netCfg.serveDns;
dns.host = netCfg.lighthouse.dns.host;
dns.port = netCfg.lighthouse.dns.port;
};
relay = {
am_relay = netCfg.isRelay;
Expand Down Expand Up @@ -231,6 +249,10 @@ in
''
settings
);
capabilities = lib.concatStringsSep " " (
(lib.optional (!settings.tun.disabled) "CAP_NET_ADMIN")
++ (lib.optional settings.lighthouse.serve_dns "CAP_NET_BIND_SERVICE")
);
in
{
# Create the systemd service for Nebula.
Expand All @@ -248,8 +270,8 @@ in
Restart = "always";
ExecStart = "${netCfg.package}/bin/nebula -config ${configFile}";
UMask = "0027";
CapabilityBoundingSet = "CAP_NET_ADMIN";
AmbientCapabilities = "CAP_NET_ADMIN";
CapabilityBoundingSet = capabilities;
AmbientCapabilities = capabilities;
LockPersonality = true;
NoNewPrivileges = true;
PrivateDevices = false; # needs access to /dev/net/tun (below)
Expand Down Expand Up @@ -302,5 +324,5 @@ in
);
};

meta.maintainers = with lib.maintainers; [ numinit ];
meta.maintainers = with lib.maintainers; [ numinit siriobalmelli ];
}

0 comments on commit ae7d05c

Please sign in to comment.