Skip to content

Commit 95ba871

Browse files
committed
feat(systemd/smartdns.service.in): securing systemd service
1 parent 05e0766 commit 95ba871

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

systemd/smartdns.service.in

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,45 @@ StartLimitIntervalSec=60
99

1010
[Service]
1111
Type=forking
12-
PIDFile=@RUNSTATEDIR@/smartdns.pid
12+
DynamicUser=true
13+
RuntimeDirectory=smartdns
14+
LogsDirectory=smartdns
15+
CacheDirectory=smartdns
16+
PIDFile=/run/smartdns/smartdns.pid
1317
EnvironmentFile=@SYSCONFDIR@/default/smartdns
14-
ExecStart=@SBINDIR@/smartdns -p @RUNSTATEDIR@/smartdns.pid $SMART_DNS_OPTS
18+
LoadCredential=smartdns.conf:@SYSCONFDIR@/smartdns/smartdns.conf
19+
ExecStart=@SBINDIR@/smartdns -p $PIDFILE -c "${CREDENTIALS_DIRECTORY}/smartdns.conf" $SMART_DNS_OPTS
1520
Restart=always
1621
RestartSec=2
1722
TimeoutStopSec=15
1823

24+
# Capabilities
25+
CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_NET_ADMIN
26+
AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_ADMIN
27+
28+
# Hardening options
29+
DevicePolicy=closed
30+
LockPersonality=true
31+
MemoryAccounting=true
32+
MemoryDenyWriteExecute=true
33+
NoNewPrivileges=true
34+
PrivateDevices=true
35+
PrivateTmp=true
36+
ProcSubset=pid
37+
ProtectClock=true
38+
ProtectControlGroups=true
39+
ProtectHome=true
40+
ProtectHostname=true
41+
ProtectKernelLogs=true
42+
ProtectKernelModules=true
43+
ProtectKernelTunables=true
44+
ProtectProc=invisible
45+
ProtectSystem=strict
46+
RemoveIPC=true
47+
RestrictNamespaces=true
48+
RestrictRealtime=true
49+
RestrictSUIDSGID=true
50+
1951
[Install]
2052
WantedBy=multi-user.target
2153
Alias=smartdns.service

0 commit comments

Comments
 (0)