Files
zoneminder/misc/zoneminder.service.in
T
Isaac ConnorandClaude Opus 5 995fd54fef feat: harden zoneminder.service and pin the options ZoneMinder cannot run under
Now that the daemons reliably land in this unit rather than inheriting the web
server's namespace, the unit is worth hardening. Add the protections that do
not interfere with capture: ProtectSystem=full, ProtectClock,
ProtectControlGroups, ProtectHostname, ProtectKernelLogs, ProtectKernelModules,
ProtectKernelTunables, LockPersonality, RestrictRealtime and RestrictSUIDSGID.

Set the options that would break us explicitly rather than leaving them to a
default a distribution might override, since each fails in a way that is not
visible from the web ui:

  PrivateDevices and PrivateTmp, because zmc publishes frames in /dev/shm for a
  zms that runs under the web server, and zmaudit.pl cleans up the swap images
  zms writes under /var/tmp.

  ProcSubset and ProtectProc, because zmstats reads /proc/stat, /proc/meminfo
  and /proc/loadavg, and zmpkg.pl reads /proc/self/cgroup to decide whether
  systemd started it.

Record why NoNewPrivileges, ProtectHome and MemoryDenyWriteExecute are absent,
and warn that the mount namespace these options create hides filesystems
mounted after ZoneMinder starts.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019URmtYqza6Rzi6F7cmabSm
2026-08-14 23:37:22 -04:00

66 lines
2.4 KiB
Plaintext

# ZoneMinder systemd unit file
# This file is intended to work with all Linux distributions
[Unit]
Description=ZoneMinder CCTV recording and security system
After=network.target mysqld.service httpd.service janus.service
Requires=mysqld.service httpd.service janus.service
[Service]
User=@WEB_USER@
Type=forking
ExecStart=@BINDIR@/zmpkg.pl start
ExecReload=@BINDIR@/zmpkg.pl restart
ExecStop=@BINDIR@/zmpkg.pl stop
PIDFile=@ZM_RUNDIR@/zm.pid
Environment=TZ=:/etc/localtime
# Hardening. Several of the usual options break ZoneMinder in ways that are not
# obvious from the web ui, so the ones that must stay off are set explicitly
# rather than left to a default a distribution might override. Please read the
# comments before adding more.
# zmc publishes frames in shared memory under ZM_PATH_MAP (/dev/shm) and zms
# reads them from there. zms runs under the web server rather than here, so a
# private /dev would leave it reading an empty buffer and every stream would go
# black. zms also writes swap images under ZM_PATH_SWAP (/var/tmp/zm) which
# zmaudit.pl, which does run here, is responsible for cleaning up; PrivateTmp
# covers /var/tmp as well as /tmp, so it would leave those to accumulate.
PrivateTmp=no
PrivateDevices=no
# Local cameras need /dev/video*, hardware de/encoding needs /dev/dri.
DevicePolicy=auto
# zmstats reads /proc/stat, /proc/meminfo and /proc/loadavg, and zmpkg.pl reads
# /proc/self/cgroup to tell whether systemd started it. ProcSubset=pid hides the
# first three and ProtectProc=invisible hides pid 1; between them every recorded
# statistic silently becomes zero.
ProcSubset=all
ProtectProc=default
ProtectSystem=full
ProtectClock=yes
ProtectControlGroups=yes
ProtectHostname=yes
ProtectKernelLogs=yes
ProtectKernelModules=yes
ProtectKernelTunables=yes
LockPersonality=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
# The options above put this unit in its own mount namespace, so a filesystem
# mounted after ZoneMinder starts is not visible to it. If event storage lives
# on a late mounted or removable filesystem, name it in RequiresMountsFor= or
# drop the hardening rather than debugging empty event directories.
# Deliberately not set:
# NoNewPrivileges - filters with AutoExecute run operator supplied commands,
# and zm-sudo grants the web user shutdown.
# ProtectHome - event storage is often kept under /home.
# MemoryDenyWriteExecute - breaks some hardware accelerated codecs.
[Install]
WantedBy=multi-user.target