nixos/prometheus-exporters: use nixos-fw chain

Use nixos-fw chain instead of INPUT so that the rules don't keep
stacking everytime the firewall is reloaded.
This also adds a comment to each rule about the associated exporter.

(cherry picked from commit 9216da8928bc17878635ef50dac089f01a8c6466)
release-18.03-flake
WilliButz 2018-08-02 15:27:00 +02:00 committed by Franz Pletz
parent 4dbf327d92
commit 979d823f53
No known key found for this signature in database
GPG Key ID: 846FDED7792617B4
1 changed files with 5 additions and 4 deletions

View File

@ -70,7 +70,7 @@ let
description = ''
Specify a filter for iptables to use when
<option>services.prometheus.exporters.${name}.openFirewall</option>
is true. It is used as `ip46tables -I INPUT <option>firewallFilter</option> -j ACCEPT`.
is true. It is used as `ip46tables -I nixos-fw <option>firewallFilter</option> -j nixos-fw-accept`.
'';
};
user = mkOption {
@ -113,9 +113,10 @@ let
mkExporterConf = { name, conf, serviceOpts }:
mkIf conf.enable {
networking.firewall.extraCommands = mkIf conf.openFirewall ''
ip46tables -I INPUT ${conf.firewallFilter} -j ACCEPT
'';
networking.firewall.extraCommands = mkIf conf.openFirewall (concatStrings [
"ip46tables -I nixos-fw ${conf.firewallFilter} "
"-m comment --comment ${name}-exporter -j nixos-fw-accept"
]);
systemd.services."prometheus-${name}-exporter" = mkMerge ([{
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];