Interview Prep/Shell Scripting/cron and systemd timers

How do you sandbox a script that runs as a systemd service?

AdvancedConceptcron and systemd timers
Answer
[Service]
User=opskit
Group=opskit
NoNewPrivileges=yes
ProtectSystem=strict          # whole filesystem read-only...
ReadWritePaths=/var/lib/opskit /var/log/opskit   # ...except these
ProtectHome=read-only
PrivateTmp=yes                # private /tmp, defeats /tmp races
PrivateDevices=yes
CapabilityBoundingSet=
MemoryMax=256M
CPUQuota=20%

systemd-analyze security name.service scores the unit's exposure. Sandboxing turns a compromised or buggy script from "root on the box" into "can write two directories".

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on cron and systemd timers