-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubnetrad.service
More file actions
69 lines (61 loc) · 3.08 KB
/
Copy pathsubnetrad.service
File metadata and controls
69 lines (61 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
[Unit]
Description=Subnetra pure-Zig L3 UDP tunnel
Documentation=https://github.com/jamiesun/subnetra
# network-online: the underlay must be up before the daemon binds its UDP socket.
# time-sync: the session key is derived from a CLOCK_REALTIME boot epoch and peers
# order sessions forward-only, so a clock that runs backward across a restart makes
# the new (lower) epoch be rejected until peers' clocks catch up. Ordering after
# time-sync.target keeps the clock monotonic across restarts on RTC-less hardware
# (see "Time synchronization (required)" in docs/deployment.md).
After=network-online.target time-sync.target
Wants=network-online.target time-sync.target
[Service]
Type=simple
# The daemon reads ./config.json from its working directory. Keep the per-node
# config (with its private PSKs) here, root-owned and mode 0600 (see the
# deployment guide). The control socket and policy snapshot live under /run.
WorkingDirectory=/etc/subnetra
RuntimeDirectory=subnetra
# RuntimeDirectory= creates/owns /run/subnetra (0700, root). This is also the
# compiled-in default socket path on Linux, so SUBNETRA_SOCK is redundant for a
# current binary — kept explicit as self-documentation and to pin the path for
# any older binary whose default differs.
Environment=SUBNETRA_SOCK=/run/subnetra/subnetra.sock
# Fail fast on a bad config instead of crash-looping the data plane. The config
# path is explicit (--config) so it does not silently depend on WorkingDirectory.
ExecStartPre=/usr/local/bin/subnetrad --check --config /etc/subnetra/config.json
ExecStart=/usr/local/bin/subnetrad --config /etc/subnetra/config.json
# subnetra only PRINTS the host network plan (`--print-network-plan`); it never
# mutates routes itself. The TUN device exists only while the daemon runs, so
# configure addressing/routes AFTER start. Replace the commands below with the
# output of `subnetrad --print-network-plan` for this node (spokes only; a relay
# hub usually needs no overlay address). Uncomment to enable:
# ExecStartPost=/sbin/ip link set snr0 mtu 1400 up
# ExecStartPost=/sbin/ip addr add 10.0.0.2/24 dev snr0
# ExecStartPost=/sbin/ip route add 192.168.31.0/24 dev snr0
Restart=on-failure
RestartSec=2
# --- Privileges: the ONLY capability subnetra needs is CAP_NET_ADMIN (create the
# TUN device and, if you enable the ExecStartPost hooks, configure routes). ---
AmbientCapabilities=CAP_NET_ADMIN
CapabilityBoundingSet=CAP_NET_ADMIN
DeviceAllow=/dev/net/tun rw
# --- Sandboxing: subnetra is a single static binary with no dynamic allocation
# on the data path and no need to touch the filesystem beyond its config + /run. ---
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true
ProtectControlGroups=true
ProtectKernelModules=true
ProtectKernelTunables=true
RestrictNamespaces=true
RestrictRealtime=true
RestrictSUIDSGID=true
LockPersonality=true
MemoryDenyWriteExecute=true
# Allow only the address families subnetra uses (UDP/IP + the AF_UNIX control plane).
RestrictAddressFamilies=AF_INET AF_UNIX
# /run/subnetra is writable via RuntimeDirectory; everything else stays read-only.
[Install]
WantedBy=multi-user.target