├── qr-btc.png ├── services ├── systemd-journald.nix ├── systemd-udevd.nix ├── blocky.nix ├── bluetooth.nix ├── accounts-daemon.nix ├── systemd-machined.nix ├── nscd.nix ├── user.nix ├── NetworkManager.nix ├── sshd.nix ├── systemd-rfkill.nix ├── rtkit.nix ├── cups.nix ├── colord.nix ├── reload-systemd-vconsole-setup.nix ├── getty.nix ├── autovt.nix ├── systemd-ask-password-wall.nix ├── systemd-ask-password-console.nix ├── rescue.nix ├── acipd.nix ├── dbus.nix ├── docker.nix ├── NetworkManager-dispatcher.nix ├── auditd.nix ├── wpa_supplicant.nix ├── display-manager.nix └── nix-daemon.nix ├── README.md └── LICENSE /qr-btc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wallago/nix-system-services-hardened/HEAD/qr-btc.png -------------------------------------------------------------------------------- /services/systemd-journald.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.systemd-journald.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectProc = "invisible"; 5 | ProtectHostname = true; 6 | PrivateMounts = true; 7 | }; 8 | } 9 | -------------------------------------------------------------------------------- /services/systemd-udevd.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.systemd-udevd.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "strict"; 5 | ProtectHome = true; 6 | ProtectKernelLogs = true; 7 | ProtectControlGroups = true; 8 | ProtectClock = true; 9 | ProtectProc = "invisible"; 10 | RestrictNamespaces = true; 11 | CapabilityBoundingSet = "~CAP_SYS_PTRACE ~CAP_SYS_PACCT"; 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /services/blocky.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.blocky.serviceConfig = { 3 | ProtectKernelTunables = true; 4 | ProtectKernelModules = true; 5 | ProtectKernelLogs = true; 6 | ProtectHostname = true; 7 | ProtectControlGroups = true; 8 | ProtectProc = "invisible"; 9 | SystemCallFilter = [ 10 | "~@obsolete" 11 | "~@cpu-emulation" 12 | "~@swap" 13 | "~@reboot" 14 | "~@mount" 15 | ]; 16 | SystemCallArchitectures = "native"; 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /services/bluetooth.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.bluetooth.serviceConfig = { 3 | ProtectKernelTunables = true; 4 | ProtectKernelModules = true; 5 | ProtectKernelLogs = true; 6 | ProtectHostname = true; 7 | ProtectControlGroups = true; 8 | ProtectProc = "invisible"; 9 | SystemCallFilter = [ 10 | "~@obsolete" 11 | "~@cpu-emulation" 12 | "~@swap" 13 | "~@reboot" 14 | "~@mount" 15 | ]; 16 | SystemCallArchitectures = "native"; 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /services/accounts-daemon.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.accounts-daemon.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "strict"; 5 | ProtectHome = true; 6 | ProtectProc = "invisible"; 7 | ProtectHostname = true; 8 | ProtectKernelLogs = true; 9 | ProtectClock = true; 10 | PrivateTmp = true; 11 | RestrictSUIDSGID = true; 12 | SystemCallFilter = [ 13 | "~@swap" 14 | "~@resources" 15 | "~@raw-io" 16 | "~@mount" 17 | "~@module" 18 | "~@reboot" 19 | "~@debug" 20 | "~@cpu-emulation" 21 | "~@clock" 22 | ]; 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /services/systemd-machined.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.systemd-machined.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "strict"; 5 | ProtectHome = true; 6 | ProtectClock = true; 7 | ProtectHostname = true; 8 | ProtectKernelTunables = true; 9 | ProtectKernelModules = true; 10 | ProtectKernelLogs = true; 11 | ProtectProc = "invisible"; 12 | PrivateTmp = true; 13 | PrivateMounts = true; 14 | PrivateUsers = true; 15 | PrivateNetwork = true; 16 | RestrictNamespaces = true; 17 | RestrictRealtime = true; 18 | RestrictSUIDSGID = true; 19 | RestrictAddressFamilies = [ "AF_UNIX" ]; 20 | MemoryDenyWriteExecute = true; 21 | SystemCallArchitectures = "native"; 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /services/nscd.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.nscd.serviceConfig = { 3 | ProtectClock = true; 4 | ProtectHostname = true; 5 | ProtectKernelTunables = true; 6 | ProtectKernelModules = true; 7 | ProtectKernelLogs = true; 8 | ProtectControlGroups = true; 9 | ProtectProc = "invisible"; 10 | RestrictNamespaces = true; 11 | RestrictRealtime = true; 12 | MemoryDenyWriteExecute = true; 13 | LockPersonality = true; 14 | SystemCallFilter = [ 15 | "~@mount" 16 | "~@swap" 17 | "~@clock" 18 | "~@obsolete" 19 | "~@cpu-emulation" 20 | ]; 21 | SystemCallArchitectures = "native"; 22 | CapabilityBoundingSet= [ 23 | "~CAP_CHOWN" 24 | "~CAP_FSETID" 25 | "~CAP_SETFCAP" 26 | ]; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /services/user.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services."user@".serviceConfig = { 3 | ProtectSystem = "strict"; 4 | ProtectClock = true; 5 | ProtectHostname = true; 6 | ProtectKernelTunables = true; 7 | ProtectKernelModules = true; 8 | ProtectKernelLogs = true; 9 | ProtectProc = "invisible"; 10 | PrivateTmp = true; 11 | PrivateNetwork = true; 12 | MemoryDenyWriteExecute = true; 13 | RestrictAddressFamilies = [ 14 | "AF_UNIX" 15 | "AF_NETLINK" 16 | "AF_BLUETOOTH" 17 | ]; 18 | RestrictNamespaces = true; 19 | RestrictRealtime = true; 20 | RestrictSUIDSGID = true; 21 | SystemCallFilter = [ 22 | "~@keyring" 23 | "~@swap" 24 | "~@debug" 25 | "~@module" 26 | "~@obsolete" 27 | "~@cpu-emulation" 28 | ]; 29 | SystemCallArchitectures = "native"; 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /services/NetworkManager.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.NetworkManager.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectHome = true; 5 | ProtectKernelModules = true; 6 | ProtectKernelLogs = true; 7 | ProtectControlGroups = true; 8 | ProtectClock = true; 9 | ProtectHostname = true; 10 | ProtectProc = "invisible"; 11 | PrivateTmp = true; 12 | RestrictRealtime = true; 13 | RestrictAddressFamilies = [ 14 | "AF_UNIX" 15 | "AF_NETLINK" 16 | "AF_INET" 17 | "AF_INET6" 18 | "AF_PACKET" 19 | ]; 20 | RestrictNamespaces = true; 21 | RestrictSUIDSGID = true; 22 | MemoryDenyWriteExecute = true; 23 | SystemCallFilter = [ 24 | "~@mount" 25 | "~@module" 26 | "~@swap" 27 | "~@obsolete" 28 | "~@cpu-emulation" 29 | "ptrace" 30 | ]; 31 | SystemCallArchitectures = "native"; 32 | LockPersonality= true; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /services/sshd.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.sshd.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "strict"; 5 | ProtectHome = "read-only"; 6 | ProtectClock = true; 7 | ProtectHostname = true; 8 | ProtectKernelTunables = true; 9 | ProtectKernelModules = true; 10 | ProtectKernelLogs = true; 11 | ProtectControlGroups = true; 12 | ProtectProc = "invisible"; 13 | PrivateTmp = true; 14 | PrivateMounts = true; 15 | PrivateDevices = true; 16 | RestrictNamespaces = true; 17 | RestrictRealtime = true; 18 | RestrictSUIDSGID = true; 19 | MemoryDenyWriteExecute = true; 20 | LockPersonality = true; 21 | DevicePolicy = "closed"; 22 | SystemCallFilter = [ 23 | "~@keyring" 24 | "~@swap" 25 | "~@clock" 26 | "~@module" 27 | "~@obsolete" 28 | "~@cpu-emulation" 29 | ]; 30 | SystemCallArchitectures = "native"; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /services/systemd-rfkill.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.systemd-rfkill.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "strict"; 5 | ProtectHome = true; 6 | ProtectKernelLogs = true; 7 | ProtectControlGroups = true; 8 | ProtectClock = true; 9 | ProtectHostname = true; 10 | ProtectProc = "invisible"; 11 | PrivateTmp = true; 12 | PrivateNetwork = true; 13 | PrivateUsers = true; 14 | RestrictNamespaces = true; 15 | RestrictRealtime = true; 16 | RestrictAddressFamilies = [ "AF_UNIX" ]; 17 | RestrictSUIDSGID = true; 18 | MemoryDenyWriteExecute = true; 19 | SystemCallFilter = [ 20 | "~@swap" 21 | "~@obsolete" 22 | "~@cpu-emulation" 23 | "~@privileged" 24 | ]; 25 | SystemCallArchitectures = "native"; 26 | LockPersonality = true; 27 | CapabilityBoundingSet = [ 28 | "~CAP_SYS_PTRACE" 29 | "~CAP_SYS_PACCT" 30 | ]; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /services/rtkit.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.rtkit-daemon.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "strict"; 5 | ProtectHome = true; 6 | ProtectClock = true; 7 | ProtectHostname = true; 8 | ProtectKernelTunables = true; 9 | ProtectKernelModules = true; 10 | ProtectKernelLogs = true; 11 | ProtectControlGroups = true; 12 | PrivateTmp = true; 13 | PrivateMounts = true; 14 | PrivateDevices = true; 15 | RestrictNamespaces = true; 16 | RestrictSUIDSGID = true; 17 | RestrictAddressFamilies = [ 18 | "~AF_INET6" 19 | "~AF_INET" 20 | "~AF_PACKET" 21 | ]; 22 | MemoryDenyWriteExecute = true; 23 | DevicePolicy = "closed"; 24 | LockPersonality = true; 25 | SystemCallFilter = [ 26 | "~@keyring" 27 | "~@swap" 28 | "~@clock" 29 | "~@module" 30 | "~@obsolete" 31 | "~@cpu-emulation" 32 | ]; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /services/cups.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.cups.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "full"; 5 | ProtectHome = true; 6 | ProtectKernelModules = true; 7 | ProtectKernelTunables = true; 8 | ProtectKernelLogs = true; 9 | ProtectControlGroups = true; 10 | ProtectHostname = true; 11 | ProtectClock = true; 12 | ProtectProc = "invisible"; 13 | RestrictRealtime = true; 14 | RestrictNamespaces = true; 15 | RestrictSUIDSGID = true; 16 | RestrictAddressFamilies = [ 17 | "AF_UNIX" 18 | "AF_NETLINK" 19 | "AF_INET" 20 | "AF_INET6" 21 | "AF_PACKET" 22 | ]; 23 | 24 | MemoryDenyWriteExecute = true; 25 | SystemCallFilter = [ 26 | "~@clock" 27 | "~@reboot" 28 | "~@debug" 29 | "~@module" 30 | "~@swap" 31 | "~@obsolete" 32 | "~@cpu-emulation" 33 | ]; 34 | SystemCallArchitectures = "native"; 35 | LockPersonality= true; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /services/colord.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.colord.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "strict"; 5 | ProtectHome = true; 6 | ProtectHostname = true; 7 | ProtectKernelTunables = true; 8 | ProtectKernelModules = true; 9 | ProtectKernelLogs = true; 10 | ProtectControlGroups = true; 11 | ProtectProc = "invisible"; 12 | PrivateTmp = true; 13 | RestrictNamespaces = true; 14 | RestrictRealtime = true; 15 | RestrictSUIDSGID = true; 16 | RestrictAddressFamilies = [ 17 | "~AF_INET6" 18 | "~AF_INET" 19 | "~AF_PACKET" 20 | ]; 21 | MemoryDenyWriteExecute = true; 22 | LockPersonality = true; 23 | SystemCallFilter = [ 24 | "~@swap" 25 | "~@obsolete" 26 | "~@cpu-emulation" 27 | "~@mount" 28 | ]; 29 | SystemCallArchitectures = "native"; 30 | CapabilityBoundingSet= [ 31 | "~CAP_CHOWN" 32 | "~CAP_FSETID" 33 | "~CAP_SETFCAP" 34 | ]; 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /services/reload-systemd-vconsole-setup.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.reload-systemd-vconsole-setup.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "strict"; 5 | ProtectHome = true; 6 | ProtectClock = true; 7 | ProtectHostname = true; 8 | ProtectKernelTunables = true; 9 | ProtectKernelModules = true; 10 | ProtectKernelLogs = true; 11 | ProtectProc = "invisible"; 12 | PrivateTmp = true; 13 | PrivateMounts = true; 14 | PrivateNetwork = true; 15 | RestrictNamespaces = true; 16 | RestrictRealtime = true; 17 | RestrictSUIDSGID = true; 18 | RestrictAddressFamilies = [ 19 | "~AF_INET6" 20 | "~AF_INET" 21 | "~AF_PACKET" 22 | ]; 23 | MemoryDenyWriteExecute = true; 24 | DevicePolicy = "closed"; 25 | LockPersonality = true; 26 | SystemCallFilter = [ 27 | "~@keyring" 28 | "~@swap" 29 | "~@obsolete" 30 | "~@cpu-emulation" 31 | ]; 32 | SystemCallArchitectures = "native"; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /services/getty.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services."getty@".serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "stric"; 5 | ProtectControlGroups = true; 6 | ProtectHome = true; 7 | ProtectHostname = true; 8 | ProtectKernelTunables = true; 9 | ProtectKernelModules = true; 10 | ProtectKernelLogs = true; 11 | ProtectClock = true; 12 | PrivateMounts = true; 13 | PrivateTmp = true; 14 | RestrictSUIDSGID = true; 15 | RestrictRealtime = true; 16 | RestrictAddressFamilies = [ 17 | "AF_UNIX" 18 | "AF_NETLINK" 19 | ]; 20 | RestrictNamespaces = true; 21 | SystemCallErrorNumber = "EPERM"; 22 | SystemCallArchitectures = "native"; 23 | SystemCallFilter = [ 24 | "~@obsolete" 25 | "~@debug" 26 | "~@reboot" 27 | "~@swap" 28 | "~@clock" 29 | "~@cpu-emulation" 30 | ]; 31 | LockPersonality = true; 32 | IPAddressDeny = ["0.0.0.0/0" "::/0"]; 33 | MemoryDenyWriteExecute = true; 34 | UMask = 0077; 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /services/autovt.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services."autovt@".serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "stric"; 5 | ProtectControlGroups = true; 6 | ProtectHome = true; 7 | ProtectHostname = true; 8 | ProtectKernelTunables = true; 9 | ProtectKernelModules = true; 10 | ProtectKernelLogs = true; 11 | ProtectClock = true; 12 | PrivateMounts = true; 13 | PrivateTmp = true; 14 | RestrictSUIDSGID = true; 15 | RestrictRealtime = true; 16 | RestrictAddressFamilies = [ 17 | "AF_UNIX" 18 | "AF_NETLINK" 19 | ]; 20 | RestrictNamespaces = true; 21 | SystemCallErrorNumber = "EPERM"; 22 | SystemCallArchitectures = "native"; 23 | SystemCallFilter = [ 24 | "~@obsolete" 25 | "~@debug" 26 | "~@reboot" 27 | "~@swap" 28 | "~@clock" 29 | "~@cpu-emulation" 30 | ]; 31 | LockPersonality = true; 32 | IPAddressDeny = ["0.0.0.0/0" "::/0"]; 33 | MemoryDenyWriteExecute = true; 34 | UMask = 0077; 35 | }; 36 | } 37 | 38 | -------------------------------------------------------------------------------- /services/systemd-ask-password-wall.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.systemd-ask-password-wall.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "strict"; 5 | ProtectHome = true; 6 | ProtectClock = true; 7 | ProtectHostname = true; 8 | ProtectKernelTunables = true; 9 | ProtectKernelModules = true; 10 | ProtectKernelLogs = true; 11 | ProtectProc = "invisible"; 12 | PrivateTmp = true; 13 | PrivateMounts = true; 14 | PrivateNetwork = true; 15 | PrivateDevices = true; 16 | RestrictNamespaces = true; 17 | RestrictRealtime = true; 18 | RestrictSUIDSGID = true; 19 | RestrictAddressFamilies = [ 20 | "~AF_INET6" 21 | "~AF_INET" 22 | "~AF_PACKET" 23 | ]; 24 | MemoryDenyWriteExecute = true; 25 | DevicePolicy = "closed"; 26 | LockPersonality = true; 27 | SystemCallFilter = [ 28 | "~@keyring" 29 | "~@swap" 30 | "~@clock" 31 | "~@module" 32 | "~@obsolete" 33 | "~@cpu-emulation" 34 | ]; 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /services/systemd-ask-password-console.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.systemd-ask-password-console.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "strict"; 5 | ProtectHome = true; 6 | ProtectClock = true; 7 | ProtectHostname = true; 8 | ProtectKernelTunables = true; 9 | ProtectKernelModules = true; 10 | ProtectKernelLogs = true; 11 | ProtectProc = "invisible"; 12 | PrivateTmp = true; 13 | PrivateMounts = true; 14 | PrivateNetwork = true; 15 | PrivateDevices = true; 16 | RestrictNamespaces = true; 17 | RestrictRealtime = true; 18 | RestrictSUIDSGID = true; 19 | RestrictAddressFamilies = [ 20 | "~AF_INET6" 21 | "~AF_INET" 22 | "~AF_PACKET" 23 | ]; 24 | MemoryDenyWriteExecute = true; 25 | DevicePolicy = "closed"; 26 | LockPersonality = true; 27 | SystemCallFilter = [ 28 | "~@keyring" 29 | "~@swap" 30 | "~@clock" 31 | "~@module" 32 | "~@obsolete" 33 | "~@cpu-emulation" 34 | ]; 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /services/rescue.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.rescue.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "full"; 5 | ProtectClock = true; 6 | ProtectHostname = true; 7 | ProtectKernelTunables = true; 8 | ProtectKernelModules = true; 9 | ProtectKernelLogs = true; 10 | ProtectControlGroups = true; 11 | ProtectProc = "invisible"; 12 | PrivateTmp = true; 13 | PrivateNetwork = true; 14 | RestrictNamespaces = true; 15 | RestrictRealtime = true; 16 | RestrictSUIDSGID = true; 17 | RestrictAddressFamilies = [ 18 | "~AF_INET6" 19 | "~AF_INET" 20 | "~AF_PACKET" 21 | ]; 22 | MemoryDenyWriteExecute = true; 23 | LockPersonality = true; 24 | SystemCallFilter = [ 25 | "~@swap" 26 | "~@clock" 27 | "~@obsolete" 28 | "~@cpu-emulation" 29 | "~@resources" 30 | ]; 31 | SystemCallArchitectures = "native"; 32 | CapabilityBoundingSet= [ 33 | "~CAP_CHOWN" 34 | "~CAP_FSETID" 35 | "~CAP_SETFCAP" 36 | ]; 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /services/acipd.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.acpid.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "strict"; 5 | ProtectHome = true; 6 | ProtectHostname = true; 7 | ProtectKernelTunables = true; 8 | ProtectKernelModules = true; 9 | ProtectKernelLogs = true; 10 | ProtectControlGroups = true; 11 | ProtectProc = "invisible"; 12 | PrivateTmp = true; 13 | PrivateNetwork = true; 14 | PrivateMounts = true; 15 | RestrictNamespaces = true; 16 | RestrictRealtime = true; 17 | RestrictSUIDSGID = true; 18 | RestrictAddressFamilies = [ 19 | "~AF_INET6" 20 | "~AF_INET" 21 | "~AF_PACKET" 22 | ]; 23 | MemoryDenyWriteExecute = true; 24 | LockPersonality = true; 25 | SystemCallFilter = [ 26 | "~@mount" 27 | "~@swap" 28 | "~@obsolete" 29 | "~@cpu-emulation" 30 | ]; 31 | SystemCallArchitectures = "native"; 32 | CapabilityBoundingSet= [ 33 | "~CAP_CHOWN" 34 | "~CAP_FSETID" 35 | "~CAP_SETFCAP" 36 | ]; 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /services/dbus.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.dbus.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "stric"; 5 | ProtectControlGroups = true; 6 | ProtectHome = true; 7 | ProtectHostname = true; 8 | ProtectKernelTunables = true; 9 | ProtectKernelModules = true; 10 | ProtectKernelLogs = true; 11 | PrivateMounts = true; 12 | PrivateDevices = true; 13 | PrivateTmp = true; 14 | RestrictSUIDSGID = true; 15 | RestrictRealtime = true; 16 | RestrictAddressFamilies = [ 17 | "AF_UNIX" 18 | ]; 19 | RestrictNamespaces = true; 20 | SystemCallErrorNumber = "EPERM"; 21 | SystemCallArchitectures = "native"; 22 | SystemCallFilter = [ 23 | "~@obsolete" 24 | "~@resources" 25 | "~@debug" 26 | "~@mount" 27 | "~@reboot" 28 | "~@swap" 29 | "~@cpu-emulation" 30 | ]; 31 | LockPersonality = true; 32 | IPAddressDeny = ["0.0.0.0/0" "::/0"]; 33 | MemoryDenyWriteExecute = true; 34 | DevicePolicy = "closed"; 35 | UMask = 0077; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /services/docker.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.docker.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "full"; 5 | ProtectHome = true; 6 | ProtectKernelModules = true; 7 | ProtectKernelLogs = true; 8 | ProtectControlGroups = true; 9 | ProtectClock = true; 10 | ProtectProc = "invisible"; 11 | PrivateTmp = true; 12 | PrivateMounts = true; 13 | RestrictRealtime = true; 14 | RestrictAddressFamilies = [ 15 | "AF_UNIX" 16 | "AF_NETLINK" 17 | "AF_INET" 18 | "AF_INET6" 19 | ]; 20 | RestrictNamespaces = [ 21 | "~user" 22 | ]; 23 | MemoryDenyWriteExecute = true; 24 | SystemCallFilter = [ 25 | "~@debug" 26 | "~@raw-io" 27 | "~@reboot" 28 | "~@clock" 29 | "~@module" 30 | "~@swap" 31 | "~@obsolete" 32 | "~@cpu-emulation" 33 | ]; 34 | SystemCallArchitectures = "native"; 35 | CapabilityBoundingSet= [ 36 | "~CAP_SYS_RAWIO" 37 | "~CAP_SYS_PTRACE" 38 | "~CAP_SYS_BOOT" 39 | ]; 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /services/NetworkManager-dispatcher.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.NetworkManager-dispatcher.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "strict"; 5 | ProtectHome = true; 6 | ProtectKernelModules = true; 7 | ProtectKernelLogs = true; 8 | ProtectControlGroups = true; 9 | ProtectClock = true; 10 | ProtectHostname = true; 11 | ProtectProc = "invisible"; 12 | PrivateTmp = true; 13 | PrivateMounts = true; 14 | RestrictRealtime = true; 15 | RestrictAddressFamilies = [ 16 | "AF_UNIX" 17 | "AF_NETLINK" 18 | "AF_INET" 19 | "AF_INET6" 20 | "AF_PACKET" 21 | ]; 22 | RestrictNamespaces = true; 23 | RestrictSUIDSGID = true; 24 | MemoryDenyWriteExecute = true; 25 | SystemCallFilter = [ 26 | "~@mount" 27 | "~@module" 28 | "~@swap" 29 | "~@obsolete" 30 | "~@cpu-emulation" 31 | "ptrace" 32 | ]; 33 | SystemCallArchitectures = "native"; 34 | LockPersonality= true; 35 | CapabilityBoundingSet = "CAP_NET_ADMIN CAP_NET_RAW"; 36 | }; 37 | } 38 | -------------------------------------------------------------------------------- /services/auditd.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.auditd.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "full"; 5 | ProtectHome = true; 6 | ProtectHostname = true; 7 | ProtectKernelTunables = true; 8 | ProtectKernelModules = true; 9 | ProtectControlGroups = true; 10 | ProtectProc = "invisible"; 11 | ProtectClock = true; 12 | PrivateTmp = true; 13 | PrivateNetwork = true; 14 | PrivateMounts = true; 15 | PrivateDevices = true; 16 | RestrictNamespaces = true; 17 | RestrictRealtime = true; 18 | RestrictSUIDSGID = true; 19 | RestrictAddressFamilies = [ 20 | "~AF_INET6" 21 | "~AF_INET" 22 | "~AF_PACKET" 23 | ]; 24 | MemoryDenyWriteExecute = true; 25 | LockPersonality = true; 26 | SystemCallFilter = [ 27 | "~@clock" 28 | "~@module" 29 | "~@mount" 30 | "~@swap" 31 | "~@obsolete" 32 | "~@cpu-emulation" 33 | ]; 34 | SystemCallArchitectures = "native"; 35 | CapabilityBoundingSet= [ 36 | "~CAP_CHOWN" 37 | "~CAP_FSETID" 38 | "~CAP_SETFCAP" 39 | ]; 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /services/wpa_supplicant.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.wpa_supplicant.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectSystem = "strict"; 5 | ProtectHome = true; 6 | ProtectKernelModules = true; 7 | ProtectKernelLogs = true; 8 | ProtectControlGroups = true; 9 | ProtectClock = true; 10 | ProtectHostname = true; 11 | ProtectProc = "invisible"; 12 | PrivateTmp = true; 13 | PrivateMounts = true; 14 | RestrictRealtime = true; 15 | RestrictAddressFamilies = [ 16 | "AF_UNIX" 17 | "AF_NETLINK" 18 | "AF_INET" 19 | "AF_INET6" 20 | "AF_PACKET" 21 | ]; 22 | RestrictNamespaces = true; 23 | RestrictSUIDSGID = true; 24 | MemoryDenyWriteExecute = true; 25 | SystemCallFilter = [ 26 | "~@mount" 27 | "~@raw-io" 28 | "~@privileged" 29 | "~@keyring" 30 | "~@reboot" 31 | "~@module" 32 | "~@swap" 33 | "~@resources" 34 | "~@obsolete" 35 | "~@cpu-emulation" 36 | "ptrace" 37 | ]; 38 | SystemCallArchitectures = "native"; 39 | LockPersonality= true; 40 | CapabilityBoundingSet = "CAP_NET_ADMIN CAP_NET_RAW"; 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /services/display-manager.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.display-manager.serviceConfig = { 3 | ProtectSystem = "full"; 4 | ProtectControlGroups = true; 5 | ProtectClock = true; 6 | ProtectKernelModules = true; 7 | PrivateMounts = true; 8 | PrivateIPC = true; 9 | RestrictSUIDSGID = true; 10 | RestrictRealtime = true; 11 | RestrictNamespaces = [ 12 | "~cgroup" 13 | ]; 14 | RestrictAddressFamilies = [ 15 | "AF_UNIX" 16 | "AF_NETLINK" 17 | "AF_INET" 18 | "AF_INET6" 19 | ]; 20 | SystemCallErrorNumber = "EPERM"; 21 | SystemCallFilter = [ 22 | "~@obsolete" 23 | "~@cpu-emulation" 24 | "~@clock" 25 | "~@swap" 26 | "~@module" 27 | "~@reboot" 28 | "~@raw-io" 29 | "~@debug" 30 | ]; 31 | SystemCallArchitectures = "native"; 32 | LockPersonality = true; 33 | IPAddressDeny = ["0.0.0.0/0" "::/0"]; 34 | CapabilityBoundingSet = [ 35 | "CAP_SYS_ADMIN" 36 | "CAP_SETUID" 37 | "CAP_SETGID" 38 | "CAP_SETPCAP" 39 | "CAP_KILL" 40 | "CAP_SYS_TTY_CONFIG" 41 | "CAP_DAC_OVERRIDE" 42 | "CAP_DAC_READ_SEARCH" 43 | "CAP_FOWNER" 44 | "CAP_IPC_OWNER" 45 | "CAP_FSETID" 46 | "CAP_SETFCAP" 47 | "CAP_CHOWN" 48 | ]; 49 | DeviceAllow = "/dev/tty7 rw"; 50 | DevicePolicy = "closed"; 51 | UMask = 0077; 52 | LogLevelMax = "debug"; 53 | KeyringMode = lib.mkForce "private"; 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /services/nix-daemon.nix: -------------------------------------------------------------------------------- 1 | { 2 | systemd.services.nix-daemon.serviceConfig = { 3 | NoNewPrivileges = true; 4 | ProtectControlGroups = true; 5 | ProtectKernelModules = true; 6 | PrivateMounts = true; 7 | PrivateTmp = true; 8 | PrivateDevices = true; 9 | RestrictSUIDSGID = true; 10 | RestrictRealtime = true; 11 | RestrictNamespaces = [ "~cgroup" ]; 12 | RestrictAddressFamilies = [ 13 | "AF_UNIX" 14 | "AF_NETLINK" 15 | "AF_INET6" 16 | "AF_INET" 17 | ]; 18 | CapabilityBoundingSet= [ 19 | "~CAP_SYS_CHROOT" 20 | "~CAP_BPF" 21 | "~CAP_AUDIT_WRITE" 22 | "~CAP_AUDIT_CONTROL" 23 | "~CAP_AUDIT_READ" 24 | "~CAP_SYS_PTRACE" 25 | "~CAP_SYS_NICE" 26 | "~CAP_SYS_RESOURCE" 27 | "~CAP_SYS_RAWIO" 28 | "~CAP_SYS_TIME" 29 | "~CAP_SYS_PACCT" 30 | "~CAP_LINUX_IMMUTABLE" 31 | "~CAP_IPC_LOCK" 32 | "~CAP_WAKE_ALARM" 33 | "~CAP_SYS_TTY_CONFIG" 34 | "~CAP_SYS_BOOT" 35 | "~CAP_LEASE" 36 | "~CAP_BLOCK_SUSPEND" 37 | "~CAP_MAC_ADMIN" 38 | "~CAP_MAC_OVERRIDE" 39 | ]; 40 | SystemCallErrorNumber = "EPERM"; 41 | SystemCallArchitectures = "native"; 42 | SystemCallFilter = [ 43 | "~@resources" 44 | "~@module" 45 | "~@obsolete" 46 | "~@debug" 47 | "~@reboot" 48 | "~@swap" 49 | "~@cpu-emulation" 50 | "~@clock" 51 | "~@raw-io" 52 | ]; 53 | LockPersonality = true; 54 | MemoryDenyWriteExecute = true; 55 | DevicePolicy = "closed"; 56 | UMask = 0077; 57 | }; 58 | } 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # nix-system-services-hardened 2 | 3 |

4 |
5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 |
17 | 18 |
19 |
20 |

21 | 22 | ## :zap: Hardening Result 23 | 24 | System services hardened (lynis BOOT-5264) under nixos.\ 25 | Suggest you to see https://linux-audit.com, if you are interested of how to hardened your config. 26 | 27 | ```sh 28 | ❯ systemd-analyze security 29 | UNIT EXPOSURE PREDICATE HAPPY 30 | -------------------------------------------------------------- 31 | NetworkManager-dispatcher.service 3.5 OK 🙂 32 | NetworkManager.service 4.2 OK 🙂 33 | accounts-daemon.service 2.9 OK 🙂 34 | acpid.service 4.8 OK 🙂 35 | auditd.service 4.0 OK 🙂 36 | blocky.service 4.2 OK 🙂 37 | bluetooth.service 4.7 OK 🙂 38 | colord.service 4.9 OK 🙂 39 | cups.service 4.8 OK 🙂 40 | dbus.service 4.2 OK 🙂 41 | display-manager.service 4.8 OK 🙂 42 | docker.service 4.8 OK 🙂 43 | getty@tty1.service 4.7 OK 🙂 44 | getty@tty2.service 4.7 OK 🙂 45 | getty@tty7.service 4.7 OK 🙂 46 | nix-daemon.service 4.9 OK 🙂 47 | nscd.service 4.9 OK 🙂 48 | polkit.service 1.2 OK 🙂 49 | reload-systemd-vconsole-setup.service 4.9 OK 🙂 50 | rescue.service 4.5 OK 🙂 51 | rtkit-daemon.service 3.1 OK 🙂 52 | sshd.service 4.9 OK 🙂 53 | systemd-ask-password-console.service 4.3 OK 🙂 54 | systemd-ask-password-wall.service 4.1 OK 🙂 55 | systemd-hostnamed.service 1.7 OK 🙂 56 | systemd-journald.service 4.5 OK 🙂 57 | systemd-logind.service 2.8 OK 🙂 58 | systemd-machined.service 3.0 OK 🙂 59 | systemd-oomd.service 1.8 OK 🙂 60 | systemd-rfkill.service 4.0 OK 🙂 61 | systemd-timesyncd.service 2.1 OK 🙂 62 | systemd-udevd.service 4.9 OK 🙂 63 | user@1000.service 4.8 OK 🙂 64 | wpa_supplicant.service 2.7 OK 🙂 65 | ``` 66 | 67 | ## ⌨️ Commands 68 | 69 | * Check service log: `journalctl -u SERVICE_NAME` 70 | * Check service security: `systemd-analyze security SERVICE_NAME` 71 | * Check services security: `systemd-analyze security` 72 | 73 | ## :book: Note 74 | 1. Why i did it: 75 | * I didn't find any repo which provide hardened system service configs. 76 | * So the idea merged i my head to do it for nix lovers and others. 77 | 2. What you can find inside this repo: 78 | * Each system service config file for listed above. 79 | 3. Keep in mind: 80 | * I know it's not perfect, i want to give you help that i couldn't find. 81 | * If you want to suggest any improvement, make a PR. 82 | * If you find any error, make an issue. 83 | 84 | ## 📜 License 85 | 86 | Apache License - see the [LICENSE](LICENSE) file for details. 87 | 88 | ## 💝 Acknowledgements 89 | 90 | Love u guys 💜.\ 91 | Buy me a coffe if you've a mind to:`1CJwob8qgoX7e897fupbyu3VbATMkgBpwM`\ 92 | \ 93 | ![image](./qr-btc.png) 94 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------