PortGate

Blueprints · Systemd & Agents

Production 15 min · systemd

Go or Rust single-binary systemd sandbox

A dynamic-user unit with a read-only filesystem, a private tmp, and a graceful stop. The binary listens on localhost.

Live config

Baked-in protections

Step 1 · ini

systemd unit

/etc/systemd/system/app.service

StateDirectory gives the dynamic user one writable directory under /var/lib. Do not point the binary at a home directory.

[Unit]
Description=app
After=network.target

[Service]
DynamicUser=yes
StateDirectory=app
ExecStart=/usr/local/bin/app
Environment=PORT=8080
Restart=on-failure
RestartSec=2
KillSignal=SIGTERM
TimeoutStopSec=20
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=strict
ProtectHome=true

[Install]
WantedBy=multi-user.target

Step 2 · bash

Install the unit

/root/portgate-blueprints/binary-enable.sh

Enable fails if the binary is missing. Put the binary in place first.

#!/bin/sh
set -eu
systemctl daemon-reload
if [ ! -x "/usr/local/bin/app" ]; then
  echo "Binary is not installed yet. The unit is on disk."
  exit 0
fi
systemctl enable --now app.service