systemd:security_overview_of_systemd_services
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
systemd:security_overview_of_systemd_services [2021/01/13 13:01] β [Check current security] peter | systemd:security_overview_of_systemd_services [2023/07/17 14:21] (current) β removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== systemd - Security overview of systemd services ====== | ||
- | **systemd** enable services to run with a whole suite of hardening and sandboxing features from the Linux kernel. | ||
- | |||
- | The Linux kernel can filter and limit access to file systems, networks, devices, kernel capabilities and system calls (syscalls), and more. | ||
- | |||
- | ---- | ||
- | |||
- | ===== Check current security ===== | ||
- | |||
- | <code bash> | ||
- | systemd-analyze security | ||
- | </ | ||
- | |||
- | returns: | ||
- | |||
- | <code bash> | ||
- | UNIT EXPOSURE PREDICATE HAPPY | ||
- | ModemManager.service | ||
- | NetworkManager.service | ||
- | accounts-daemon.service | ||
- | acpid.service | ||
- | alsa-state.service | ||
- | anacron.service | ||
- | apache2.service | ||
- | apport.service | ||
- | avahi-daemon.service | ||
- | bluetooth.service | ||
- | colord.service | ||
- | cron.service | ||
- | cups-browsed.service | ||
- | cups.service | ||
- | dbus.service | ||
- | dm-event.service | ||
- | dmesg.service | ||
- | emergency.service | ||
- | expressvpn.service | ||
- | gdm.service | ||
- | geoclue.service | ||
- | getty@tty1.service | ||
- | grub-common.service | ||
- | hddtemp.service | ||
- | irqbalance.service | ||
- | kerneloops.service | ||
- | libvirtd.service | ||
- | lvm2-lvmpolld.service | ||
- | lxcfs.service | ||
- | networkd-dispatcher.service | ||
- | nvidia-persistenced.service | ||
- | ondemand.service | ||
- | php7.4-fpm.service | ||
- | plymouth-start.service | ||
- | polkit.service | ||
- | rc-local.service | ||
- | rescue.service | ||
- | resolvconf.service | ||
- | rsync.service | ||
- | rsyslog.service | ||
- | rtkit-daemon.service | ||
- | snap.lxd.daemon.service | ||
- | snapd.service | ||
- | switcheroo-control.service | ||
- | systemd-ask-password-console.service | ||
- | systemd-ask-password-plymouth.service | ||
- | systemd-ask-password-wall.service | ||
- | systemd-fsckd.service | ||
- | systemd-initctl.service | ||
- | systemd-journald.service | ||
- | systemd-logind.service | ||
- | systemd-machined.service | ||
- | systemd-networkd.service | ||
- | systemd-resolved.service | ||
- | systemd-rfkill.service | ||
- | systemd-timesyncd.service | ||
- | systemd-udevd.service | ||
- | thermald.service | ||
- | udisks2.service | ||
- | unattended-upgrades.service | ||
- | upower.service | ||
- | user@1000.service | ||
- | user@125.service | ||
- | uuidd.service | ||
- | virtlockd.service | ||
- | virtlogd.service | ||
- | whoopsie.service | ||
- | wpa_supplicant.service | ||
- | </ | ||
- | |||
- | <WRAP info> | ||
- | **NOTE: | ||
- | |||
- | * **Exposure score**: is entirely based on a serviceβs utilization of security features provided by systemd. | ||
- | * It doesnβt consider security features built-in to the program or enforced by access control policies like Security-Enhanced Linux (SELinux) or AppArmor. | ||
- | * Nor does the score in any way evaluate the risk factors of a program or its configuration. | ||
- | |||
- | Notice that many daemons, such as crond, are considered to be unsafe. | ||
- | |||
- | * Thatβs an accurate assessment as these services are designed to allow unrestricted execution of arbitrary commands. | ||
- | * You may want to disable these services entirely unless you need them. | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Analyze security of a specific service ===== | ||
- | |||
- | Using Apache2 as an example: | ||
- | |||
- | <code bash> | ||
- | systemd-analyze security apache2.service | ||
- | </ | ||
- | |||
- | returns: | ||
- | |||
- | <code bash> | ||
- | NAME DESCRIPTION | ||
- | β PrivateNetwork= | ||
- | β User=/ | ||
- | β CapabilityBoundingSet=~CAP_SET(UID|GID|PCAP) | ||
- | β CapabilityBoundingSet=~CAP_SYS_ADMIN | ||
- | β CapabilityBoundingSet=~CAP_SYS_PTRACE | ||
- | β RestrictAddressFamilies=~AF_(INET|INET6) | ||
- | β RestrictNamespaces=~CLONE_NEWUSER | ||
- | β RestrictAddressFamilies=~β¦ | ||
- | β CapabilityBoundingSet=~CAP_(CHOWN|FSETID|SETFCAP) | ||
- | β CapabilityBoundingSet=~CAP_(DAC_*|FOWNER|IPC_OWNER) | ||
- | β CapabilityBoundingSet=~CAP_NET_ADMIN | ||
- | β CapabilityBoundingSet=~CAP_RAWIO | ||
- | β CapabilityBoundingSet=~CAP_SYS_MODULE | ||
- | β CapabilityBoundingSet=~CAP_SYS_TIME | ||
- | β DeviceAllow= | ||
- | β IPAddressDeny= | ||
- | β KeyringMode= | ||
- | β NoNewPrivileges= | ||
- | β NotifyAccess= | ||
- | β PrivateDevices= | ||
- | β PrivateMounts= | ||
- | β PrivateTmp= | ||
- | β PrivateUsers= | ||
- | β ProtectClock= | ||
- | β ProtectControlGroups= | ||
- | β ProtectHome= | ||
- | β ProtectKernelLogs= | ||
- | β ProtectKernelModules= | ||
- | β ProtectKernelTunables= | ||
- | β ProtectSystem= | ||
- | β RestrictAddressFamilies=~AF_PACKET | ||
- | β RestrictSUIDSGID= | ||
- | β SystemCallArchitectures= | ||
- | β SystemCallFilter=~@clock | ||
- | β SystemCallFilter=~@debug | ||
- | β SystemCallFilter=~@module | ||
- | β SystemCallFilter=~@mount | ||
- | β SystemCallFilter=~@raw-io | ||
- | β SystemCallFilter=~@reboot | ||
- | β SystemCallFilter=~@swap | ||
- | β SystemCallFilter=~@privileged | ||
- | β SystemCallFilter=~@resources | ||
- | β AmbientCapabilities= | ||
- | β CapabilityBoundingSet=~CAP_AUDIT_* | ||
- | β CapabilityBoundingSet=~CAP_KILL | ||
- | β CapabilityBoundingSet=~CAP_MKNOD | ||
- | β CapabilityBoundingSet=~CAP_NET_(BIND_SERVICE|BROADCAST|RAW) Service has elevated networking privileges | ||
- | β CapabilityBoundingSet=~CAP_SYSLOG | ||
- | β CapabilityBoundingSet=~CAP_SYS_(NICE|RESOURCE) | ||
- | β RestrictNamespaces=~CLONE_NEWCGROUP | ||
- | β RestrictNamespaces=~CLONE_NEWIPC | ||
- | β RestrictNamespaces=~CLONE_NEWNET | ||
- | β RestrictNamespaces=~CLONE_NEWNS | ||
- | β RestrictNamespaces=~CLONE_NEWPID | ||
- | β RestrictRealtime= | ||
- | β SystemCallFilter=~@cpu-emulation | ||
- | β SystemCallFilter=~@obsolete | ||
- | β RestrictAddressFamilies=~AF_NETLINK | ||
- | β RootDirectory=/ | ||
- | SupplementaryGroups= | ||
- | β CapabilityBoundingSet=~CAP_MAC_* | ||
- | β CapabilityBoundingSet=~CAP_SYS_BOOT | ||
- | β Delegate= | ||
- | β LockPersonality= | ||
- | β MemoryDenyWriteExecute= | ||
- | RemoveIPC= | ||
- | β RestrictNamespaces=~CLONE_NEWUTS | ||
- | β UMask= | ||
- | β CapabilityBoundingSet=~CAP_LINUX_IMMUTABLE | ||
- | β CapabilityBoundingSet=~CAP_IPC_LOCK | ||
- | β CapabilityBoundingSet=~CAP_SYS_CHROOT | ||
- | β ProtectHostname= | ||
- | ... | ||
- | </ | ||
- | |||
- | <WRAP info> | ||
- | **NOTE: | ||
- | |||
- | This example shows **β PrivateTmp=**; | ||
- | |||
- | There are however many places where this could be configured to be more secure. | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Service unit security hardening ===== | ||
- | |||
- | Your web server probably doesnβt need write-access to most locations in your file hierarchy. It probably doesnβt even need read-access. | ||
- | |||
- | <code bash> | ||
- | sudo systemctl edit apache2.service | ||
- | </ | ||
- | |||
- | <WRAP info> | ||
- | **NOTE: | ||
- | |||
- | It will use your default text editor as specified in the **EDITOR** environmental variable. | ||
- | </ | ||
- | |||
- | and add: | ||
- | |||
- | <file bash> | ||
- | [Service] | ||
- | PrivateDevices=true | ||
- | ProtectControlGroups=true | ||
- | ProtectHome=true | ||
- | ProtectKernelTunables=true | ||
- | ProtectSystem=full | ||
- | RestrictSUIDSGID=true | ||
- | </ | ||
- | |||
- | Save the file. | ||
- | |||
- | **NOTE: | ||
- | |||
- | ===== Reload the systemctl daemon ===== | ||
- | |||
- | <code bash> | ||
- | sudo systemctl daemon-reload | ||
- | </ | ||
- | |||
- | <WRAP info> | ||
- | **NOTE: | ||
- | </ | ||
- | |||
- | |||
- | ---- | ||
- | |||
- | ===== Restart httpd ===== | ||
- | |||
- | <code bash> | ||
- | sudo systemctl restart httpd.service | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Recheck the security ===== | ||
- | |||
- | <code bash> | ||
- | systemd-analyze security | ||
- | </ | ||
- | |||
- | <WRAP info> | ||
- | **NOTE: | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== References ===== | ||
- | |||
- | https:// |
systemd/security_overview_of_systemd_services.1610542865.txt.gz Β· Last modified: 2021/01/13 13:01 by peter