systemd.service 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. [Unit]
  2. Description=Small description of the service
  3. After=network.target
  4. [Service]
  5. Type=simple
  6. User=__APP__
  7. Group=__APP__
  8. WorkingDirectory=__INSTALL_DIR__/
  9. ExecStart=__INSTALL_DIR__/script
  10. StandardOutput=append:/var/log/__APP__/__APP__.log
  11. StandardError=inherit
  12. ### Depending on specificities of your service/app, you may need to tweak these
  13. ### .. but this should be a good baseline
  14. # Sandboxing options to harden security
  15. # Details for these options: https://www.freedesktop.org/software/systemd/man/systemd.exec.html
  16. NoNewPrivileges=yes
  17. PrivateTmp=yes
  18. PrivateDevices=yes
  19. RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
  20. RestrictNamespaces=yes
  21. RestrictRealtime=yes
  22. DevicePolicy=closed
  23. ProtectClock=yes
  24. ProtectHostname=yes
  25. ProtectProc=invisible
  26. ProtectSystem=full
  27. ProtectControlGroups=yes
  28. ProtectKernelModules=yes
  29. ProtectKernelTunables=yes
  30. LockPersonality=yes
  31. SystemCallArchitectures=native
  32. SystemCallFilter=~@clock @debug @module @mount @obsolete @reboot @setuid @swap @cpu-emulation @privileged
  33. # Denying access to capabilities that should not be relevant for webapps
  34. # Doc: https://man7.org/linux/man-pages/man7/capabilities.7.html
  35. CapabilityBoundingSet=~CAP_RAWIO CAP_MKNOD
  36. CapabilityBoundingSet=~CAP_AUDIT_CONTROL CAP_AUDIT_READ CAP_AUDIT_WRITE
  37. CapabilityBoundingSet=~CAP_SYS_BOOT CAP_SYS_TIME CAP_SYS_MODULE CAP_SYS_PACCT
  38. CapabilityBoundingSet=~CAP_LEASE CAP_LINUX_IMMUTABLE CAP_IPC_LOCK
  39. CapabilityBoundingSet=~CAP_BLOCK_SUSPEND CAP_WAKE_ALARM
  40. CapabilityBoundingSet=~CAP_SYS_TTY_CONFIG
  41. CapabilityBoundingSet=~CAP_MAC_ADMIN CAP_MAC_OVERRIDE
  42. CapabilityBoundingSet=~CAP_NET_ADMIN CAP_NET_BROADCAST CAP_NET_RAW
  43. CapabilityBoundingSet=~CAP_SYS_ADMIN CAP_SYS_PTRACE CAP_SYSLOG
  44. [Install]
  45. WantedBy=multi-user.target