For the complete documentation index, see llms.txt. This page is also available as Markdown.

Appendix B: Hardening File

The complete Tier 2 drop-in file, for configuration management.

The same file as in Tier 2 without explanations, for copying into configuration management. Edit the marked lines.

# /etc/systemd/system/sonic.service.d/10-hardening.conf
[Service]
NoExecPaths=/
# EDIT: output of step 2.0
ExecPaths=/usr/local/bin/sonicd
MemoryDenyWriteExecute=yes
SystemCallFilter=~memfd_create
SystemCallErrorNumber=EPERM
Environment=GODEBUG=netdns=go
NoNewPrivileges=yes
RestrictSUIDSGID=yes
# EDIT: CapabilityBoundingSet=CAP_NET_BIND_SERVICE only if listening on a port below 1024
CapabilityBoundingSet=
ProtectSystem=strict
# EDIT: data folder
ReadWritePaths=/var/lib/sonic
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
ProtectProc=invisible
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectKernelLogs=yes
ProtectControlGroups=yes
ProtectClock=yes
ProtectHostname=yes
RestrictNamespaces=yes
LockPersonality=yes
RestrictRealtime=yes
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX AF_NETLINK
IPAddressDeny=10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 100.64.0.0/10 169.254.0.0/16 fc00::/7 fe80::/10
IPAddressAllow=localhost
# EDIT: required internal machines (or load balancer subnets) only, one per line
#IPAddressAllow=10.0.1.20
SocketBindDeny=any
# EDIT: your ports (validators: only 5050, plus 6060 if used)
SocketBindAllow=tcp:5050
SocketBindAllow=udp:5050
SocketBindAllow=tcp:18545
SocketBindAllow=tcp:18546
SocketBindAllow=tcp:6060

systemd only accepts comments on their own line, starting with #. Never put a comment at the end of a setting line.