@@ -233,15 +233,50 @@ in
233233 ExecStart = "${pkgs.mosquitto}/bin/mosquitto -c ${mosquittoConf}";
234234 ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
235235
236− ProtectSystem = "strict";
237− ProtectHome = true;
236+ # Hardening
237+ CapabilityBoundingSet = "";
238+ DevicePolicy = "closed";
239+ LockPersonality = true;
240+ MemoryDenyWriteExecute = true;
241+ NoNewPrivileges = true;
238242 PrivateDevices = true;
239243 PrivateTmp = true;
240− ReadWritePaths = "${cfg.dataDir}";
244+ PrivateUsers = true;
245+ ProtectClock = true;
241246 ProtectControlGroups = true;
247+ ProtectHome = true;
248+ ProtectHostname = true;
249+ ProtectKernelLogs = true;
242250 ProtectKernelModules = true;
243251 ProtectKernelTunables = true;
244− NoNewPrivileges = true;
252+ ProtectProc = "invisible";
253+ ProcSubset = "pid";
254+ ProtectSystem = "strict";
255+ ReadWritePaths = [
256+ cfg.dataDir
257+ "/tmp" # mosquitto_passwd creates files in /tmp before moving them
258+ ];
259+ ReadOnlyPaths = with cfg.ssl; lib.optionals (enable) [
260+ certfile
261+ keyfile
262+ cafile
263+ ];
264+ RemoveIPC = true;
265+ RestrictAddressFamilies = [
266+ "AF_UNIX" # for sd_notify() call
267+ "AF_INET"
268+ "AF_INET6"
269+ ];
270+ RestrictNamespaces = true;
271+ RestrictRealtime = true;
272+ RestrictSUIDSGID = true;
273+ SystemCallArchitectures = "native";
274+ SystemCallFilter = [
275+ "@system-service"
276+ "~@privileged"
277+ "~@resources"
278+ ];
279+ UMask = "0077";
245280 };
246281 preStart = ''
247282 rm -f ${cfg.dataDir}/passwd