From 2c1e72ee6a2eb2ad5bb58e7d1a8512f6bdc7f8e5 Mon Sep 17 00:00:00 2001 From: Linus Heckemann Date: Tue, 29 Sep 2020 10:46:59 +0200 Subject: [PATCH 1/2] prometheus exporters: always set user and group systemd.exec(5) on DynamicUser: > If a statically allocated user or group of the configured name > already exists, it is used and no dynamic user/group is allocated. Using DynamicUser while still setting a group name can be useful for granting access to resources that can otherwise only be accessed with entirely static IDs. --- nixos/modules/services/monitoring/prometheus/exporters.nix | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index cc71451bf206..c71cbafaa826 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -101,7 +101,6 @@ let default = "${name}-exporter"; description = '' User name under which the ${name} exporter shall be run. - Has no effect when is true. ''; }; group = mkOption { @@ -109,7 +108,6 @@ let default = "${name}-exporter"; description = '' Group under which the ${name} exporter shall be run. - Has no effect when is true. ''; }; }); @@ -161,10 +159,9 @@ let serviceConfig.PrivateTmp = mkDefault true; serviceConfig.WorkingDirectory = mkDefault /tmp; serviceConfig.DynamicUser = mkDefault enableDynamicUser; - } serviceOpts ] ++ optional (!enableDynamicUser) { serviceConfig.User = conf.user; serviceConfig.Group = conf.group; - }); + } serviceOpts ]); }; in { From a560936cabdc339a75a6ab9d665f296880d0e39a Mon Sep 17 00:00:00 2001 From: Linus Heckemann Date: Fri, 25 Sep 2020 12:24:09 +0200 Subject: [PATCH 2/2] nixos/prometheus-exporters/openvpn: init Co-Authored-By: Franz Pletz Co-Authored-By: Robin Gloster --- .../monitoring/prometheus/exporters.nix | 1 + .../prometheus/exporters/openvpn.nix | 39 +++++++++++++++++++ nixos/tests/prometheus-exporters.nix | 25 ++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 nixos/modules/services/monitoring/prometheus/exporters/openvpn.nix diff --git a/nixos/modules/services/monitoring/prometheus/exporters.nix b/nixos/modules/services/monitoring/prometheus/exporters.nix index c71cbafaa826..ddc92f1efe28 100644 --- a/nixos/modules/services/monitoring/prometheus/exporters.nix +++ b/nixos/modules/services/monitoring/prometheus/exporters.nix @@ -38,6 +38,7 @@ let "nextcloud" "nginx" "node" + "openvpn" "postfix" "postgres" "redis" diff --git a/nixos/modules/services/monitoring/prometheus/exporters/openvpn.nix b/nixos/modules/services/monitoring/prometheus/exporters/openvpn.nix new file mode 100644 index 000000000000..a97a753ebc37 --- /dev/null +++ b/nixos/modules/services/monitoring/prometheus/exporters/openvpn.nix @@ -0,0 +1,39 @@ +{ config, pkgs, lib, ... }: + +with lib; + +let + cfg = config.services.prometheus.exporters.openvpn; +in { + port = 9176; + extraOpts = { + statusPaths = mkOption { + type = types.listOf types.str; + description = '' + Paths to OpenVPN status files. Please configure the OpenVPN option + status accordingly. + ''; + }; + telemetryPath = mkOption { + type = types.str; + default = "/metrics"; + description = '' + Path under which to expose metrics. + ''; + }; + }; + + serviceOpts = { + serviceConfig = { + PrivateDevices = true; + ProtectKernelModules = true; + NoNewPrivileges = true; + ExecStart = '' + ${pkgs.prometheus-openvpn-exporter}/bin/openvpn_exporter \ + -openvpn.status_paths "${concatStringsSep "," cfg.statusPaths}" \ + -web.listen-address ${cfg.listenAddress}:${toString cfg.port} \ + -web.telemetry-path ${cfg.telemetryPath} + ''; + }; + }; +} diff --git a/nixos/tests/prometheus-exporters.nix b/nixos/tests/prometheus-exporters.nix index fdcc40721324..79c4ab962e95 100644 --- a/nixos/tests/prometheus-exporters.nix +++ b/nixos/tests/prometheus-exporters.nix @@ -457,6 +457,31 @@ let ''; }; + openvpn = { + exporterConfig = { + enable = true; + group = "openvpn"; + statusPaths = ["/run/openvpn-test"]; + }; + metricProvider = { + users.groups.openvpn = {}; + services.openvpn.servers.test = { + config = '' + dev tun + status /run/openvpn-test + status-version 3 + ''; + up = "chmod g+r /run/openvpn-test"; + }; + systemd.services."openvpn-test".serviceConfig.Group = "openvpn"; + }; + exporterTest = '' + wait_for_unit("openvpn-test.service") + wait_for_unit("prometheus-openvpn-exporter.service") + succeed("curl -sSf http://localhost:9176/metrics | grep -q 'openvpn_up{.*} 1'") + ''; + }; + postfix = { exporterConfig = { enable = true;