-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule.nix
99 lines (94 loc) · 2.64 KB
/
module.nix
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{ config, pkgs, lib, ... }:
let
name = "crtpin";
cfg = config.services.crtpin;
host = toString cfg.host;
port = toString cfg.port;
allowRebind = if cfg.allowRebind then "true" else "false";
in
{
options.services."${name}" = with lib; {
enable = mkEnableOption "${name} service";
host = mkOption {
type = types.str;
default = "::1";
description = "Listening address.";
};
port = mkOption {
type = types.ints.positive;
default = 8000;
description = "Listening port.";
};
allowRebind = mkOption {
type = types.bool;
default = false;
description = "Whether to filter requests which resolve to private IPv4/IPv6 ranges.";
};
};
config = lib.mkIf cfg.enable {
systemd.services."${name}" = {
description = "${name} - certificate pinning service";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
ExecStart = ''${pkgs.crtpin-http}/bin/crtpin-http \
-host="${host}" \
-port=${port} \
-allow-rebind=${allowRebind}
'';
Restart = "on-failure";
# Accounting
CPUAccounting = true;
IPAccounting = true;
MemoryAccounting = true;
# Security
CapabilityBoundingSet = "";
DynamicUser = true;
LockPersonality = true;
MemoryDenyWriteExecute = true;
NoNewPrivileges = true;
PrivateDevices = true;
PrivateMounts = true;
PrivateTmp = true;
PrivateUsers = true;
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectSystem = "strict";
RestrictNamespaces = true;
RestrictRealtime = true;
SystemCallArchitectures = "native";
SystemCallErrorNumber = "EPERM";
UMask = "0077";
# Needs network access
IPAddressDeny = lib.optionals (cfg.allowRebind == false) [
# deny private ipv4
"10.0.0.0/8"
"172.16.0.0/12"
"192.168.0.0/16"
# deny private ipv6
"fd00::/8"
"link-local"
# deny multicast for ipv4/ipv6
"multicast"
];
SystemCallFilter = [
"@system-service"
"~@aio"
"~@chown"
"~@keyring"
"~@memlock"
"~@resources"
"~@setuid"
"~@timer"
];
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
PrivateNetwork = false;
};
};
};
}