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

Tier 2: Lock the Node in a Box

Keep a compromised node from reaching your private network or starting other programs.

Goal: even if an attacker exploits a bug and takes control of the node process, they can't connect to anything on your private network, and it's very hard for them to start any other program.

Both halves of this tier matter:

  • 2A stops an attacker from starting a shell or downloading and running their own tools, which is usually the first thing they try.

  • 2B stops a compromised node from being used to attack your other servers.

What this tier can't do: an attacker who controls the node process can still use the node itself. They can read its data folder, reach the internet, and do anything their own code inside the node can do. That's why Tier 1.7 (no secrets on the machine) and Tier 3 (alerts) still matter.

Validators: that includes the signing key. The node holds it unlocked in memory to sign, so an attacker in control of the node can use or copy it. This tier keeps them from going further, and Tier 3 tells you it happened.

We'll use systemd's built-in sandboxing. You don't edit your existing service file. You add a small extra file next to it (systemd calls this a "drop-in"). That makes the change easy to review and easy to undo.

Before you start this tier:

  • The node must run as its own non-root user (Tier 1.6). Most of this tier can be undone from inside a node that runs as root.

  • ExecStart= must run sonicd directly, with no wrapper script and no ExecStartPre= lines (Before you start, step 2).

2.0 Preparation: list the files the node needs to run

The node binary depends on a few system libraries. We'll allow exactly those files to be executed and nothing else. Run this (adjust BIN if your binary is elsewhere):

BIN=/usr/local/bin/sonicd
echo "ExecPaths=$( { echo "$BIN"; ldd "$BIN" 2>/dev/null | grep -o '/[^ ]*'; } \
  | xargs -n1 readlink -f | sort -u | tr '\n' ' ')"

It prints one line similar to:

ExecPaths=/usr/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2 /usr/lib/x86_64-linux-gnu/libc.so.6 /usr/lib/x86_64-linux-gnu/libm.so.6 /usr/local/bin/sonicd

Keep that line. You'll paste it below. If the output contains only the binary path, your build is statically linked, and that's fine.

Re-run this after every Sonic upgrade or OS upgrade, in case the list of libraries changes. If the node fails to start after an upgrade with "Permission denied", this is the first thing to check.

2A + 2B: create the hardening file

Paste the following, then edit the five places marked EDIT:

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

Notes on the edits:

  • If your data folder is under /home, change ProtectHome=yes to ProtectHome=read-only. The ReadWritePaths= line still lets the node write to its own folder.

  • If the node writes logs to a file (not just the journal), add that folder to ReadWritePaths= (space-separated).

  • The block in 2B also applies to incoming connections. Any private-network machine that needs to reach the node (load balancer, monitoring, internal apps, VPN users) must be listed in IPAddressAllow=. Public-internet peers and clients aren't affected.

  • Public RPC behind a cloud load balancer: many cloud load balancers (e.g. AWS ALB/NLB, or a Hetzner load balancer on a private network) connect from private IPs that change over time. Allow the load balancer's whole subnet, e.g. IPAddressAllow=10.0.1.0/24, not single IPs. Your cloud console shows the subnet.

  • 100.64.0.0/10 is used by some VPNs (e.g. Tailscale). If you reach the node over such a VPN, allow the specific addresses you use.

  • If step 3 showed -BPF_FRAMEWORK, keep the SocketBind… lines anyway (they're harmless), but know that they aren't enforced on your system.

  • Validators, EDIT 5: keep only the two 5050 lines (plus 6060 if you use profiling or metrics). Then the node can't open an RPC port, even if a flag turns RPC on by mistake.

  • Validators, password file: it must not be under /home or /root, which ProtectHome=yes hides from the node. The options in Validator Node step 9 all keep it elsewhere.

Checking DNS. The node needs DNS to find bootnodes and peers by name. Find your DNS server:

  • 127.0.0.53 or 127.0.0.1: local resolver, already allowed by IPAddressAllow=localhost.

  • A public IP (e.g. 1.1.1.1): not affected.

  • A private IP (e.g. 10.0.0.2) or 169.254.169.253 (AWS): add it with IPAddressAllow=.

  • 169.254.169.254 (GCP): don't add it. On GCP the DNS server is also the metadata service, and allowing it would let the node reach your cloud credentials again. Switch the server to a local resolver such as systemd-resolved (the default on Ubuntu), so /etc/resolv.conf shows 127.0.0.53.

Apply it

Validators: every restart takes the validator offline until the node is back. With a named pipe (Validator Node step 9), that's until you send the password again with sudo sonic-unlock.

Test that it works

a) The node is healthy. It's syncing and answering requests:

Run it twice a few seconds apart. The block number should increase. Also check that the peer count recovers (net_peerCount).

Validators have no RPC, so check the log instead:

Once the node has caught up, New block lines show an age of a few seconds, and New event emitted lines show that the validator is signing again.

b) The node can't start other programs. This tries to start a shell inside the node's sandbox:

✅ Expected: nsenter: failed to execute /bin/sh: Permission denied

❌ If you see NOT PROTECTED, the setting didn't apply. Check systemctl cat sonic shows your file, and your systemd version.

An attacker's next move is to save their own program somewhere the node can write, and run it from there. Check those places too:

✅ Expected: two Permission denied messages, and no NOT PROTECTED.

c) The network block works. Pick a private IP and port on your network that you know is reachable from this server (e.g. another server's SSH port), and try it once normally and once with the same block applied:

❌ If you see REACHABLE (BAD), your system can't enforce 2B. See "Older systems" below.

Also confirm the live service picked up the settings:

d) The port restriction works (optional). This needs python3, which Ubuntu installs by default:

NOT ENFORCED is expected if step 3 of Before you start showed -BPF_FRAMEWORK.

e) Get an overall score (optional).

Lower is better. Don't chase a perfect score; the settings above cover what matters most.

If something breaks: roll back

Common causes:

Symptom
Likely cause
Fix

Fails to start, "Permission denied" / status 203/EXEC

Library missing from ExecPaths=

Re-run step 2.0 and update the line

Fails to start, status 203/EXEC, and ExecStart= is a script or bash -c

Scripts can't run in the sandbox

Put the sonicd command line directly in ExecStart=

Starts, but no peers / can't resolve names

DNS server on a private IP is blocked

Add it to IPAddressAllow=

Fails with "Address already in use" / bind error

A port is missing from SocketBindAllow=

Compare with ss -tulpn output from before

Fails with "permission denied" on a port below 1024 (e.g. 80)

CapabilityBoundingSet= is empty

See EDIT 2, or move RPC to a high port

Internal app / monitoring / load balancer can't connect anymore

Its IP is blocked by 2B

Add its IP (or subnet) to IPAddressAllow=

Fails with "Read-only file system"

Node writes somewhere outside its data folder

Add that folder to ReadWritePaths=

Crashes with a memory error or "operation not permitted", and works after rollback

MemoryDenyWriteExecute= or SystemCallFilter=

Remove those lines one at a time to find which, and report it to the Sonic team at [email protected]

Older systems

On the outdated systems in Before you start step 3, systemd can't block program starts (2A), and the network block (2B) may not be enforced either (test (c) tells you). The protections in this tier depend on a recent OS, so don't run Sonic nodes on these systems. Move to the recommended Ubuntu 24.04 LTS.

Until you've upgraded, Tiers 1, 3 and 4 still apply. The sonic-guard rules from Tier 3.2 also block the node's outgoing connections to your private network, so set them up first.

2C. Optional extras (test before relying on them)

These allow only the kernel functions that normal services need. Add them, restart, and watch the node for a day:

Replace the SystemCallFilter=~memfd_create line from 2A with these three lines, and keep SystemCallErrorNumber=EPERM. The order matters: the @system-service line must come before any line starting with ~, or systemd treats the whole list differently and blocks much less.

Remove privileged-port access. If the node listens on a port below 1024 (EDIT 2 and Tier 1.6), move RPC to a high port, for example behind a proxy (Tier 4). Then remove AmbientCapabilities=CAP_NET_BIND_SERVICE and set CapabilityBoundingSet= back to empty, so the node has no special privileges at all.

✅ Tier 2 checklist

Last updated