Skip to content

Commit 05dcd9a

Browse files
committed
nixos/iocs: add systemd hardening
1 parent acb9e5a commit 05dcd9a

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

nixos/modules/iocs.nix

+49-5
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,14 @@
140140

141141
wantedBy = lib.mkIf config.enable (lib.mkDefault ["multi-user.target"]);
142142

143-
# When initializing the IOC, PV Access looks for network interfaces that
144-
# have IP addresses. "network.target" may be too early, especially for
145-
# systems with DHCP.
143+
# When initializing the IOC,
144+
# PV Access looks for network interfaces that have IP addresses.
145+
# "network.target" may be too early,
146+
# especially for systems with DHCP.
146147
wants = lib.mkDefault ["network-online.target"];
147148
after = lib.mkDefault ["network-online.target"];
148149

149150
serviceConfig = {
150-
Restart = "always";
151151
ExecStart = let
152152
procServ = lib.getExe pkgs.epnix.procServ;
153153
in ''
@@ -156,8 +156,52 @@
156156
${config.startupScript}
157157
'';
158158

159-
DynamicUser = true;
159+
Restart = lib.mkDefault "always";
160160
StateDirectory = ["epics/${name}"];
161+
162+
# Hardening options,
163+
# can be disabled by the end user, if needed
164+
165+
DynamicUser = lib.mkDefault true;
166+
167+
PrivateUsers = lib.mkDefault true;
168+
PrivateMounts = lib.mkDefault true;
169+
170+
ProtectKernelLogs = lib.mkDefault true;
171+
ProtectKernelModules = lib.mkDefault true;
172+
ProtectKernelTunables = lib.mkDefault true;
173+
ProtectClock = lib.mkDefault true;
174+
ProtectControlGroups = lib.mkDefault true;
175+
ProtectHostname = lib.mkDefault true;
176+
ProtectHome = lib.mkDefault true;
177+
ProtectProc = lib.mkDefault true;
178+
179+
RestrictNamespaces = lib.mkDefault true;
180+
181+
LockPersonality = lib.mkDefault true;
182+
183+
SystemCallArchitectures = lib.mkDefault "native";
184+
185+
# Don't allow these syscalls by default
186+
SystemCallFilter = lib.mkDefault [
187+
"~@clock"
188+
"~@cpu-emulation"
189+
"~@debug"
190+
"~@module"
191+
"~@obsolete"
192+
"~@reboot"
193+
"~@swap"
194+
];
195+
# Don't allow these capabilities by default
196+
CapabilityBoundingSet = lib.mkDefault [
197+
"~CAP_SYS_PACCT"
198+
"~CAP_SETUID"
199+
"~CAP_SETGID"
200+
"~CAP_SETPCAP"
201+
"~CAP_SYS_PTRACE"
202+
"~CAP_NET_ADMIN"
203+
"~CAP_SYS_ADMIN"
204+
];
161205
};
162206
};
163207

0 commit comments

Comments
 (0)