services: add finer-grained address family restrictions
Due to a possible NixOS bug, this commit has no effect on NixOS 20.09 where `RestrictAddressFamilies` is a no-op. It's only relevant for NixOS unstable with cgroups v2. bitcoind+zmq: instead of allowing all address families, only add the required AF_NETLINK family. lnd: lnd only runs a zmq client, not a server, therefore it requires no additional address families. lightning-pool, clightning-plugin-zmq: add AF_NETLINK.
This commit is contained in:
parent
020433cec6
commit
08fe9ba84a
@ -55,6 +55,8 @@ let
|
||||
# Extra options
|
||||
${cfg.extraConfig}
|
||||
'';
|
||||
|
||||
zmqServerEnabled = (cfg.zmqpubrawblock != null) || (cfg.zmqpubrawtx != null);
|
||||
in {
|
||||
options = {
|
||||
services.bitcoind = {
|
||||
@ -358,7 +360,7 @@ in {
|
||||
UMask = mkIf cfg.dataDirReadableByGroup "0027";
|
||||
ReadWritePaths = cfg.dataDir;
|
||||
} // nbLib.allowedIPAddresses cfg.enforceTor
|
||||
// optionalAttrs (cfg.zmqpubrawblock != null || cfg.zmqpubrawtx != null) nbLib.allowAnyProtocol;
|
||||
// optionalAttrs zmqServerEnabled nbLib.allowNetlink;
|
||||
};
|
||||
|
||||
# Use this to update the banlist:
|
||||
|
@ -4,6 +4,8 @@ with lib;
|
||||
let
|
||||
cfg = config.services.clightning.plugins.zmq;
|
||||
|
||||
nbLib = config.nix-bitcoin.lib;
|
||||
|
||||
endpoints = [
|
||||
"channel-opened"
|
||||
"connect"
|
||||
@ -38,5 +40,9 @@ in
|
||||
plugin=${config.nix-bitcoin.pkgs.clightning-plugins.zmq.path}
|
||||
${concatStrings (map setEndpoint endpoints)}
|
||||
'';
|
||||
|
||||
# The zmq server requires AF_NETLINK
|
||||
systemd.services.clightning.serviceConfig.RestrictAddressFamilies =
|
||||
mkForce nbLib.allowNetlink.RestrictAddressFamilies;
|
||||
};
|
||||
}
|
||||
|
@ -100,7 +100,8 @@ in {
|
||||
Restart = "on-failure";
|
||||
RestartSec = "10s";
|
||||
ReadWritePaths = cfg.dataDir;
|
||||
} // (nbLib.allowedIPAddresses cfg.enforceTor);
|
||||
} // (nbLib.allowedIPAddresses cfg.enforceTor)
|
||||
// nbLib.allowNetlink; # required by gRPC-Go
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -262,8 +262,7 @@ in {
|
||||
'') (attrNames cfg.macaroons)}
|
||||
'')
|
||||
];
|
||||
} // nbLib.allowedIPAddresses cfg.enforceTor
|
||||
// nbLib.allowAnyProtocol; # For ZMQ
|
||||
} // nbLib.allowedIPAddresses cfg.enforceTor;
|
||||
};
|
||||
|
||||
users.users.${cfg.user} = {
|
||||
|
@ -33,6 +33,10 @@ let self = {
|
||||
SystemCallArchitectures = "native";
|
||||
};
|
||||
|
||||
allowNetlink = {
|
||||
RestrictAddressFamilies = self.defaultHardening.RestrictAddressFamilies + " AF_NETLINK";
|
||||
};
|
||||
|
||||
# nodejs applications apparently rely on memory write execute
|
||||
nodejs = { MemoryDenyWriteExecute = "false"; };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user