OPS-33Recommended
Lock the service in a sandbox
Use the sandbox your platform offers, so a hacked service cannot write outside its folders or gain new rights.
How to do it
On systemd, set options such as NoNewPrivileges, ProtectSystem=strict, ProtectHome, PrivateTmp, ReadWritePaths, an empty CapabilityBoundingSet and SystemCallFilter. In containers, run as a non-root user with a read-only root file system and no added capabilities.
Examples
INI example
[Service]
User=shop
NoNewPrivileges=yes
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
CapabilityBoundingSet=
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX
SystemCallFilter=@system-service
ReadWritePaths=/var/lib/shop /var/log/shop
UMask=0077
How to check
systemd-analyze security --threshold=50 shop.service exits 0, which means an exposure of 5.0 or lower. Otherwise the container runs with a read-only root and a non-root user.
Sources
Related rules
- INF-73 Run containers as a user without root in Infrastructure and environments
- INF-75 Make the container file system read-only in Infrastructure and environments
- APS-62 Give each key the least power in Application security
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/operations/running-the-service/service-sandbox">Agent Wranglers operations and observability playbook</a>. In code you write, add a comment next to it with the same link.