forked from mirrors/nixpkgs
nixos/nebula: Add enable option defaulting to true to Nebula networks
This commit is contained in:
parent
002fe4f19d
commit
064e0af80b
|
@ -5,6 +5,7 @@ with lib;
|
||||||
let
|
let
|
||||||
|
|
||||||
cfg = config.services.nebula;
|
cfg = config.services.nebula;
|
||||||
|
enabledNetworks = filterAttrs (n: v: v.enable) cfg.networks;
|
||||||
|
|
||||||
format = pkgs.formats.yaml {};
|
format = pkgs.formats.yaml {};
|
||||||
|
|
||||||
|
@ -20,6 +21,12 @@ in
|
||||||
default = {};
|
default = {};
|
||||||
type = types.attrsOf (types.submodule {
|
type = types.attrsOf (types.submodule {
|
||||||
options = {
|
options = {
|
||||||
|
enable = mkOption {
|
||||||
|
type = types.bool;
|
||||||
|
default = true;
|
||||||
|
description = "Enable or disable this network.";
|
||||||
|
};
|
||||||
|
|
||||||
package = mkOption {
|
package = mkOption {
|
||||||
type = types.package;
|
type = types.package;
|
||||||
default = pkgs.nebula;
|
default = pkgs.nebula;
|
||||||
|
@ -137,11 +144,11 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
# Implementation
|
# Implementation
|
||||||
config = mkIf (cfg.networks != {}) {
|
config = mkIf (enabledNetworks != {}) {
|
||||||
systemd.services = mkMerge (lib.mapAttrsToList (netName: netCfg:
|
systemd.services = mkMerge (mapAttrsToList (netName: netCfg:
|
||||||
let
|
let
|
||||||
networkId = nameToId netName;
|
networkId = nameToId netName;
|
||||||
settings = lib.recursiveUpdate {
|
settings = recursiveUpdate {
|
||||||
pki = {
|
pki = {
|
||||||
ca = netCfg.ca;
|
ca = netCfg.ca;
|
||||||
cert = netCfg.cert;
|
cert = netCfg.cert;
|
||||||
|
@ -188,25 +195,25 @@ in
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}) cfg.networks);
|
}) enabledNetworks);
|
||||||
|
|
||||||
# Open the chosen ports for UDP.
|
# Open the chosen ports for UDP.
|
||||||
networking.firewall.allowedUDPPorts =
|
networking.firewall.allowedUDPPorts =
|
||||||
lib.unique (lib.mapAttrsToList (netName: netCfg: netCfg.listen.port) cfg.networks);
|
unique (mapAttrsToList (netName: netCfg: netCfg.listen.port) enabledNetworks);
|
||||||
|
|
||||||
# Create the service users and groups.
|
# Create the service users and groups.
|
||||||
users.users = mkMerge (lib.mapAttrsToList (netName: netCfg:
|
users.users = mkMerge (mapAttrsToList (netName: netCfg:
|
||||||
mkIf netCfg.tun.disable {
|
mkIf netCfg.tun.disable {
|
||||||
${nameToId netName} = {
|
${nameToId netName} = {
|
||||||
group = nameToId netName;
|
group = nameToId netName;
|
||||||
description = "Nebula service user for network ${netName}";
|
description = "Nebula service user for network ${netName}";
|
||||||
isSystemUser = true;
|
isSystemUser = true;
|
||||||
};
|
};
|
||||||
}) cfg.networks);
|
}) enabledNetworks);
|
||||||
|
|
||||||
users.groups = mkMerge (lib.mapAttrsToList (netName: netCfg:
|
users.groups = mkMerge (mapAttrsToList (netName: netCfg:
|
||||||
mkIf netCfg.tun.disable {
|
mkIf netCfg.tun.disable {
|
||||||
${nameToId netName} = {};
|
${nameToId netName} = {};
|
||||||
}) cfg.networks);
|
}) enabledNetworks);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,26 @@ in
|
||||||
}];
|
}];
|
||||||
|
|
||||||
services.nebula.networks.smoke = {
|
services.nebula.networks.smoke = {
|
||||||
|
enable = true;
|
||||||
|
staticHostMap = { "10.0.100.1" = [ "192.168.1.1:4242" ]; };
|
||||||
|
isLighthouse = false;
|
||||||
|
lighthouses = [ "10.0.100.1" ];
|
||||||
|
firewall = {
|
||||||
|
outbound = [ { port = "any"; proto = "any"; host = "lighthouse"; } ];
|
||||||
|
inbound = [ { port = "any"; proto = "any"; host = "any"; } ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
node5 = { ... } @ args:
|
||||||
|
makeNebulaNode args "node5" {
|
||||||
|
networking.interfaces.eth1.ipv4.addresses = [{
|
||||||
|
address = "192.168.1.5";
|
||||||
|
prefixLength = 24;
|
||||||
|
}];
|
||||||
|
|
||||||
|
services.nebula.networks.smoke = {
|
||||||
|
enable = false;
|
||||||
staticHostMap = { "10.0.100.1" = [ "192.168.1.1:4242" ]; };
|
staticHostMap = { "10.0.100.1" = [ "192.168.1.1:4242" ]; };
|
||||||
isLighthouse = false;
|
isLighthouse = false;
|
||||||
lighthouses = [ "10.0.100.1" ];
|
lighthouses = [ "10.0.100.1" ];
|
||||||
|
@ -170,9 +190,16 @@ in
|
||||||
${signKeysFor "node4" "10.0.100.4/24"}
|
${signKeysFor "node4" "10.0.100.4/24"}
|
||||||
${restartAndCheckNebula "node4" "10.0.100.4"}
|
${restartAndCheckNebula "node4" "10.0.100.4"}
|
||||||
|
|
||||||
# The lighthouse can ping node2 and node3
|
# Create keys for node4's nebula service and test that it does not come up.
|
||||||
|
${setUpPrivateKey "node5"}
|
||||||
|
${signKeysFor "node5" "10.0.100.5/24"}
|
||||||
|
node5.fail("systemctl status nebula@smoke.service")
|
||||||
|
node5.fail("ping -c5 10.0.100.5")
|
||||||
|
|
||||||
|
# The lighthouse can ping node2 and node3 but not node5
|
||||||
lighthouse.succeed("ping -c3 10.0.100.2")
|
lighthouse.succeed("ping -c3 10.0.100.2")
|
||||||
lighthouse.succeed("ping -c3 10.0.100.3")
|
lighthouse.succeed("ping -c3 10.0.100.3")
|
||||||
|
lighthouse.fail("ping -c3 10.0.100.5")
|
||||||
|
|
||||||
# node2 can ping the lighthouse, but not node3 because of its inbound firewall
|
# node2 can ping the lighthouse, but not node3 because of its inbound firewall
|
||||||
node2.succeed("ping -c3 10.0.100.1")
|
node2.succeed("ping -c3 10.0.100.1")
|
||||||
|
|
Loading…
Reference in a new issue