···
serverConfigFile = settingsFormat.generate "server.toml" (filterConfig cfg.serverSettings);
clientConfigFile = settingsFormat.generate "kanidm-config.toml" (filterConfig cfg.clientSettings);
unixConfigFile = settingsFormat.generate "kanidm-unixd.toml" (filterConfig cfg.unixSettings);
10
+
certPaths = builtins.map builtins.dirOf [ cfg.serverSettings.tls_chain cfg.serverSettings.tls_key ];
12
+
# Merge bind mount paths and remove paths where a prefix is already mounted.
13
+
# This makes sure that if e.g. the tls_chain is in the nix store and /nix/store is alread in the mount
14
+
# paths, no new bind mount is added. Adding subpaths caused problems on ofborg.
15
+
hasPrefixInList = list: newPath: lib.any (path: lib.hasPrefix (builtins.toString path) (builtins.toString newPath)) list;
16
+
mergePaths = lib.foldl' (merged: newPath: let
17
+
# If the new path is a prefix to some existing path, we need to filter it out
18
+
filteredPaths = lib.filter (p: !lib.hasPrefix (builtins.toString newPath) (builtins.toString p)) merged;
19
+
# If a prefix of the new path is already in the list, do not add it
20
+
filteredNew = if hasPrefixInList filteredPaths newPath then [] else [ newPath ];
21
+
in filteredPaths ++ filteredNew) [];
···
19
-
CapabilityBoundingSet = "";
31
+
CapabilityBoundingSet = [];
# ProtectClock= adds DeviceAllow=char-rtc r
# Implies ProtectSystem=strict, which re-mounts all paths
···
description = "kanidm identity management daemon";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
219
-
serviceConfig = defaultServiceConfig // {
220
-
StateDirectory = "kanidm";
221
-
StateDirectoryMode = "0700";
222
-
ExecStart = "${pkgs.kanidm}/bin/kanidmd server -c ${serverConfigFile}";
231
+
serviceConfig = lib.mkMerge [
232
+
# Merge paths and ignore existing prefixes needs to sidestep mkMerge
233
+
(defaultServiceConfig // {
234
+
BindReadOnlyPaths = mergePaths (defaultServiceConfig.BindReadOnlyPaths ++ certPaths);
237
+
StateDirectory = "kanidm";
238
+
StateDirectoryMode = "0700";
239
+
ExecStart = "${pkgs.kanidm}/bin/kanidmd server -c ${serverConfigFile}";
226
-
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
227
-
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
228
-
# This would otherwise override the CAP_NET_BIND_SERVICE capability.
229
-
PrivateUsers = false;
230
-
# Port needs to be exposed to the host network
231
-
PrivateNetwork = false;
232
-
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
233
-
TemporaryFileSystem = "/:ro";
243
+
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
244
+
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
245
+
# This would otherwise override the CAP_NET_BIND_SERVICE capability.
246
+
PrivateUsers = lib.mkForce false;
247
+
# Port needs to be exposed to the host network
248
+
PrivateNetwork = lib.mkForce false;
249
+
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
250
+
TemporaryFileSystem = "/:ro";
environment.RUST_LOG = "info";
···
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
restartTriggers = [ unixConfigFile clientConfigFile ];
243
-
serviceConfig = defaultServiceConfig // {
244
-
CacheDirectory = "kanidm-unixd";
245
-
CacheDirectoryMode = "0700";
246
-
RuntimeDirectory = "kanidm-unixd";
247
-
ExecStart = "${pkgs.kanidm}/bin/kanidm_unixd";
248
-
User = "kanidm-unixd";
249
-
Group = "kanidm-unixd";
261
+
serviceConfig = lib.mkMerge [
262
+
defaultServiceConfig
264
+
CacheDirectory = "kanidm-unixd";
265
+
CacheDirectoryMode = "0700";
266
+
RuntimeDirectory = "kanidm-unixd";
267
+
ExecStart = "${pkgs.kanidm}/bin/kanidm_unixd";
268
+
User = "kanidm-unixd";
269
+
Group = "kanidm-unixd";
251
-
BindReadOnlyPaths = [
253
-
"-/etc/resolv.conf"
254
-
"-/etc/nsswitch.conf"
258
-
"-/etc/static/kanidm"
263
-
# To create the socket
264
-
"/run/kanidm-unixd:/var/run/kanidm-unixd"
266
-
# Needs to connect to kanidmd
267
-
PrivateNetwork = false;
268
-
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ];
269
-
TemporaryFileSystem = "/:ro";
271
+
BindReadOnlyPaths = [
273
+
"-/etc/static/kanidm"
278
+
# To create the socket
279
+
"/run/kanidm-unixd:/var/run/kanidm-unixd"
281
+
# Needs to connect to kanidmd
282
+
PrivateNetwork = lib.mkForce false;
283
+
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ];
284
+
TemporaryFileSystem = "/:ro";
environment.RUST_LOG = "info";