Documentation

systemd Hardening & cgroup v2 Sandboxing

ready

Production process sandboxing, Linux kernel memory caps, unprivileged DynamicUser, and filesystem lockdown.

Source reference: cli/internal/server/systemd.go, daemon/internal/daemon/


Why Bare-Metal Needs Hardening

Deploying Node.js applications directly on a bare-metal Linux server without Docker containers can raise security concerns if applications are run as root or unconstrained users.

NextDeploy achieves container-level isolation with bare-metal speed by leveraging native Linux kernel primitives and systemd security sandboxing.


Applied Security Directives

Every Next.js application service generated by NextDeploy (/etc/systemd/system/nextdeploy-<app>.service) enforces strict isolation:

[Unit]
Description=NextDeploy App - %i
After=network.target

[Service]
Type=simple
WorkingDirectory=/opt/nextdeploy/apps/%i/current

# ─── 1. Identity & Privilege Isolation ───
DynamicUser=yes
User=nextdeploy-%i
Group=nextdeploy-%i
NoNewPrivileges=yes

# ─── 2. Filesystem Lockdown ───
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectControlGroups=yes
ReadWritePaths=/opt/nextdeploy/apps/%i/current/.next/cache

# ─── 3. Network & Capability Restrictions ───
CapabilityBoundingSet=
AmbientCapabilities=
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=yes

# ─── 4. Kernel cgroup v2 Resource Caps ───
MemoryMax=1G
MemoryHigh=850M
CPUQuota=200%
TasksMax=256

Restart=always
RestartSec=5s

Directives Breakdown

1. DynamicUser=yes

NextDeploy allocates an ephemeral, unprivileged UID/GID from the dynamic user range (61184-65519) when the service starts, and deallocates it when stopped.

  • The service does not have a permanent entry in /etc/passwd.
  • The process cannot write to any system directory outside explicitly declared ReadWritePaths.

2. ProtectSystem=strict & PrivateTmp=yes

  • The entire operating system filesystem hierarchy (/usr, /boot, /etc) is mounted read-only for the application process.
  • /tmp is placed in an isolated per-process namespace, preventing cross-tenant leakage or temp file attacks.

3. Linux Kernel cgroup v2 Memory Limits

  • MemoryMax=1G: If a memory leak occurs, the Linux kernel terminates only the leaky Node.js worker rather than crashing the entire VPS host (preventing OOM panics).
  • CPUQuota=200%: Limits compute consumption to 2 vCPUs, preventing CPU starvation for Caddy or sibling applications.

Related