summaryrefslogtreecommitdiff
path: root/modules/postfwd.nix
blob: 4afea0a1fd46121fccad1d32856824d0770f9883 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.postfwd;
in {
  options = {
    services.postfwd = with types; {
      enable = mkEnableOption "postfwd3 - postfix firewall daemon";

      rules = mkOption {
        type = lines;
        default = "";
      };
    };
  };

  config = mkIf cfg.enable {
    systemd.services.postfwd = {
      description = "postfwd3 - postfix firewall daemon";
      wantedBy = ["multi-user.target"];
      before = ["postfix.service"];

      serviceConfig = {
        Type = "forking";

        ExecStart = "${pkgs.postfwd}/bin/postfwd3 ${escapeShellArgs [
          "-vv"
          "--daemon" "--user" "postfwd" "--group" "postfwd"
          "--pidfile" "/run/postfwd3/postfwd3.pid"
          "--proto" "unix"
          "--port" "/run/postfwd3/postfwd3.sock"
          "--save_rates" "/var/lib/postfwd/rates"
          "--file" (pkgs.writeText "postfwd3-rules" cfg.rules)
        ]}";
        PIDFile = "/run/postfwd3/postfwd3.pid";

        Restart = "always";
        RestartSec = 5;
        TimeoutSec = 10;

        RuntimeDirectory = ["postfwd3"];
        StateDirectory = ["postfwd"];

        DynamicUser = true;
        ProtectSystem = "strict";
        SystemCallFilter = "@system-service";
        NoNewPrivileges = true;
        ProtectKernelTunables = true;
        ProtectKernelModules = true;
        ProtectKernelLogs = true;
        ProtectControlGroups = true;
        MemoryDenyWriteExecute = true;
        RestrictSUIDSGID = true;
        KeyringMode = "private";
        ProtectClock = true;
        RestrictRealtime = true;
        PrivateDevices = true;
        PrivateTmp = true;
        ProtectHostname = true;
      };
    };
  };
}