mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-26 19:16:47 +03:00
nixos/prometheus: Harden alertmanager/webhook-logger/pushgateway systemd definitions
This commit is contained in:
parent
7ce4fe5463
commit
008ea18566
3 changed files with 100 additions and 7 deletions
|
@ -32,9 +32,15 @@ in
|
||||||
${escapeShellArgs cfg.extraFlags}
|
${escapeShellArgs cfg.extraFlags}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
CapabilityBoundingSet = [ "" ];
|
||||||
|
DeviceAllow = [ "" ];
|
||||||
DynamicUser = true;
|
DynamicUser = true;
|
||||||
NoNewPrivileges = true;
|
NoNewPrivileges = true;
|
||||||
|
|
||||||
|
MemoryDenyWriteExecute = true;
|
||||||
|
|
||||||
|
LockPersonality = true;
|
||||||
|
|
||||||
ProtectProc = "invisible";
|
ProtectProc = "invisible";
|
||||||
ProtectSystem = "strict";
|
ProtectSystem = "strict";
|
||||||
ProtectHome = "tmpfs";
|
ProtectHome = "tmpfs";
|
||||||
|
@ -43,6 +49,8 @@ in
|
||||||
PrivateDevices = true;
|
PrivateDevices = true;
|
||||||
PrivateIPC = true;
|
PrivateIPC = true;
|
||||||
|
|
||||||
|
ProcSubset = "pid";
|
||||||
|
|
||||||
ProtectHostname = true;
|
ProtectHostname = true;
|
||||||
ProtectClock = true;
|
ProtectClock = true;
|
||||||
ProtectKernelTunables = true;
|
ProtectKernelTunables = true;
|
||||||
|
@ -50,7 +58,10 @@ in
|
||||||
ProtectKernelLogs = true;
|
ProtectKernelLogs = true;
|
||||||
ProtectControlGroups = true;
|
ProtectControlGroups = true;
|
||||||
|
|
||||||
|
Restart = "on-failure";
|
||||||
|
|
||||||
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
|
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
|
||||||
|
RestrictNamespaces = true;
|
||||||
RestrictRealtime = true;
|
RestrictRealtime = true;
|
||||||
RestrictSUIDSGID = true;
|
RestrictSUIDSGID = true;
|
||||||
|
|
||||||
|
|
|
@ -181,15 +181,57 @@ in {
|
||||||
-i "${alertmanagerYml}"
|
-i "${alertmanagerYml}"
|
||||||
'';
|
'';
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Restart = "always";
|
|
||||||
StateDirectory = "alertmanager";
|
|
||||||
DynamicUser = true; # implies PrivateTmp
|
|
||||||
EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
|
|
||||||
WorkingDirectory = "/tmp";
|
|
||||||
ExecStart = "${cfg.package}/bin/alertmanager" +
|
ExecStart = "${cfg.package}/bin/alertmanager" +
|
||||||
optionalString (length cmdlineArgs != 0) (" \\\n " +
|
optionalString (length cmdlineArgs != 0) (" \\\n " +
|
||||||
concatStringsSep " \\\n " cmdlineArgs);
|
concatStringsSep " \\\n " cmdlineArgs);
|
||||||
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
||||||
|
|
||||||
|
EnvironmentFile = lib.mkIf (cfg.environmentFile != null) cfg.environmentFile;
|
||||||
|
|
||||||
|
CapabilityBoundingSet = [ "" ];
|
||||||
|
DeviceAllow = [ "" ];
|
||||||
|
DynamicUser = true;
|
||||||
|
NoNewPrivileges = true;
|
||||||
|
|
||||||
|
MemoryDenyWriteExecute = true;
|
||||||
|
|
||||||
|
LockPersonality = true;
|
||||||
|
|
||||||
|
ProtectProc = "invisible";
|
||||||
|
ProtectSystem = "strict";
|
||||||
|
ProtectHome = "tmpfs";
|
||||||
|
|
||||||
|
PrivateTmp = true;
|
||||||
|
PrivateDevices = true;
|
||||||
|
PrivateIPC = true;
|
||||||
|
|
||||||
|
ProcSubset = "pid";
|
||||||
|
|
||||||
|
ProtectHostname = true;
|
||||||
|
ProtectClock = true;
|
||||||
|
ProtectKernelTunables = true;
|
||||||
|
ProtectKernelModules = true;
|
||||||
|
ProtectKernelLogs = true;
|
||||||
|
ProtectControlGroups = true;
|
||||||
|
|
||||||
|
Restart = "always";
|
||||||
|
|
||||||
|
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_NETLINK" ];
|
||||||
|
RestrictNamespaces = true;
|
||||||
|
RestrictRealtime = true;
|
||||||
|
RestrictSUIDSGID = true;
|
||||||
|
|
||||||
|
StateDirectory = "alertmanager";
|
||||||
|
SystemCallFilter = [
|
||||||
|
"@system-service"
|
||||||
|
"~@cpu-emulation"
|
||||||
|
"~@privileged"
|
||||||
|
"~@reboot"
|
||||||
|
"~@setuid"
|
||||||
|
"~@swap"
|
||||||
|
];
|
||||||
|
|
||||||
|
WorkingDirectory = "/tmp";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
|
@ -147,12 +147,52 @@ in {
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Restart = "always";
|
|
||||||
DynamicUser = true;
|
|
||||||
ExecStart = "${cfg.package}/bin/pushgateway" +
|
ExecStart = "${cfg.package}/bin/pushgateway" +
|
||||||
optionalString (length cmdlineArgs != 0) (" \\\n " +
|
optionalString (length cmdlineArgs != 0) (" \\\n " +
|
||||||
concatStringsSep " \\\n " cmdlineArgs);
|
concatStringsSep " \\\n " cmdlineArgs);
|
||||||
|
|
||||||
|
CapabilityBoundingSet = [ "" ];
|
||||||
|
DeviceAllow = [ "" ];
|
||||||
|
DynamicUser = true;
|
||||||
|
NoNewPrivileges = true;
|
||||||
|
|
||||||
|
MemoryDenyWriteExecute = true;
|
||||||
|
|
||||||
|
LockPersonality = true;
|
||||||
|
|
||||||
|
ProtectProc = "invisible";
|
||||||
|
ProtectSystem = "strict";
|
||||||
|
ProtectHome = "tmpfs";
|
||||||
|
|
||||||
|
PrivateTmp = true;
|
||||||
|
PrivateDevices = true;
|
||||||
|
PrivateIPC = true;
|
||||||
|
|
||||||
|
ProcSubset = "pid";
|
||||||
|
|
||||||
|
ProtectHostname = true;
|
||||||
|
ProtectClock = true;
|
||||||
|
ProtectKernelTunables = true;
|
||||||
|
ProtectKernelModules = true;
|
||||||
|
ProtectKernelLogs = true;
|
||||||
|
ProtectControlGroups = true;
|
||||||
|
|
||||||
|
Restart = "always";
|
||||||
|
|
||||||
|
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
|
||||||
|
RestrictNamespaces = true;
|
||||||
|
RestrictRealtime = true;
|
||||||
|
RestrictSUIDSGID = true;
|
||||||
|
|
||||||
StateDirectory = if cfg.persistMetrics then cfg.stateDir else null;
|
StateDirectory = if cfg.persistMetrics then cfg.stateDir else null;
|
||||||
|
SystemCallFilter = [
|
||||||
|
"@system-service"
|
||||||
|
"~@cpu-emulation"
|
||||||
|
"~@privileged"
|
||||||
|
"~@reboot"
|
||||||
|
"~@setuid"
|
||||||
|
"~@swap"
|
||||||
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue