Skip to content

Commit 40c4d7f

Browse files
candrewscmb69
authored andcommitted
Implement FR #72510: systemd service should be hardened
1 parent 4d0a2f6 commit 40c4d7f

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ PHP NEWS
99
- Date:
1010
. Fixed bug #75232 (print_r of DateTime creating side-effect). (Nikita)
1111

12+
- FPM:
13+
. Implemented FR #72510 (systemd service should be hardened). (Craig Andrews)
14+
1215
- GD:
1316
. Fixed bug #73291 (imagecropauto() $threshold differs from external libgd).
1417
(cmb)

sapi/fpm/php-fpm.service.in

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,61 @@ Type=@php_fpm_systemd@
1111
PIDFile=@EXPANDED_LOCALSTATEDIR@/run/php-fpm.pid
1212
ExecStart=@EXPANDED_SBINDIR@/php-fpm --nodaemonize --fpm-config @EXPANDED_SYSCONFDIR@/php-fpm.conf
1313
ExecReload=/bin/kill -USR2 $MAINPID
14+
15+
# Set up a new file system namespace and mounts private /tmp and /var/tmp directories
16+
# so this service cannot access the global directories and other processes cannot
17+
# access this service's directories.
1418
PrivateTmp=true
1519

20+
# The directories /home, /root and /run/user are made inaccessible and empty for processes
21+
# invoked by this unit.
22+
ProtectHome=true
23+
24+
# Mounts the /usr, /boot, and /etc directories read-only for processes invoked by this unit.
25+
ProtectSystem=full
26+
27+
# Ensures that the service process and all its children can never gain new privileges
28+
NoNewPrivileges=true
29+
30+
# Sets up a new /dev namespace for the executed processes and only adds API pseudo devices
31+
# such as /dev/null, /dev/zero or /dev/random (as well as the pseudo TTY subsystem) to it,
32+
# but no physical devices such as /dev/sda.
33+
PrivateDevices=true
34+
35+
# Required for dropping privileges and running as a different user
36+
CapabilityBoundingSet=CAP_SETGID CAP_SETUID
37+
38+
# Attempts to create memory mappings that are writable and executable at the same time,
39+
# or to change existing memory mappings to become executable are prohibited.
40+
MemoryDenyWriteExecute=true
41+
42+
# Explicit module loading will be denied. This allows to turn off module load and unload
43+
# operations on modular kernels. It is recommended to turn this on for most services that
44+
# do not need special file systems or extra kernel modules to work.
45+
ProtectKernelModules=true
46+
47+
# Kernel variables accessible through /proc/sys, /sys, /proc/sysrq-trigger, /proc/latency_stats,
48+
# /proc/acpi, /proc/timer_stats, /proc/fs and /proc/irq will be made read-only to all processes
49+
# of the unit. Usually, tunable kernel variables should only be written at boot-time, with the
50+
# sysctl.d(5) mechanism. Almost no services need to write to these at runtime; it is hence
51+
# recommended to turn this on for most services.
52+
ProtectKernelTunables=true
53+
54+
# The Linux Control Groups (cgroups(7)) hierarchies accessible through /sys/fs/cgroup will be
55+
# made read-only to all processes of the unit. Except for container managers no services should
56+
# require write access to the control groups hierarchies; it is hence recommended to turn this on
57+
# for most services
58+
ProtectControlGroups=true
59+
60+
# Any attempts to enable realtime scheduling in a process of the unit are refused.
61+
RestrictRealtime=true
62+
63+
# Restricts the set of socket address families accessible to the processes of this unit.
64+
# Protects against vulnerabilities such as CVE-2016-8655
65+
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
66+
67+
# Takes away the ability to create or manage any kind of namespace
68+
RestrictNamespaces=true
69+
1670
[Install]
1771
WantedBy=multi-user.target

0 commit comments

Comments
 (0)