- Home
- Skills
- DevOps & Cloud
- systemd Service Sandboxing Hardener
systemd Service Sandboxing Hardener
Most hardening guides paste thirty directives at once; the service crashes, the operator deletes them all, and nothing is learned.
$29
Works with the AI Agents you already use
systemd Service Sandboxing Hardener
Example session with this skill installed
Our Node API runs as myapp-web.service on an Ubuntu 24.04 VPS with secrets in an EnvironmentFile. Harden it as far as it will go without breaking it, and tell me what you had to allow.
- Read your context and instructions
- Compiled the systemd service sandboxing
Summary
myapp-web.service went from systemd-analyze security 9.6 UNSAFE to 1.9 OK across three tiers. Two allowances were needed and both are recorded. Secrets moved from the EnvironmentFile to encrypted credentials.
Before
$ python3 scripts/audit_unit.py --unit myapp-web.service --profile strict
baseline 1 / 13
strict 1 / 12
FAIL: 23 directive(s) missing for profile 'strict'.
Secrets LoadCredentialEncrypted=, not Environment= missing EnvironmentFile= /etc/myapp/app.env; secret-shaped names: SESSION_SECRET, STRIPE_API_KEY
Tiers applied
| Tier | Drop-in | Result | Broke | Allowance |
|---|---|---|---|---|
| baseline | 10-baseline.conf | 13/13 | PDF export wrote to /var/lib/myapp/exports | ReadWritePaths=/var/lib/myapp |
| strict | 15-strict.conf + ExecStart=/usr/bin/node --jitless | 12/12 | first attempt: SIGSEGV at start (MemoryDenyWriteExecute without --jitless) | --jitless; measured +18% CPU on the render endpoint, +2% elsewhere |
| locked | 18-locked.conf | 7/7 | nothing; MemoryMax=512M sized from 310 MB observed peak | none |
Secrets
systemd-creds setup
printf '%s' "$SESSION_SECRET" | systemd-creds encrypt --name=session_secret - /etc/credstore.encrypted/myapp-web-session
printf '%s' "$STRIPE_API_KEY" | systemd-creds encrypt --name=stripe_api_key - /etc/credstore.encrypted/myapp-web-stripe
20-encrypted-credentials.conf installed; src/config.mjs now reads $CREDENTIALS_DIRECTORY/session_secret and .../stripe_api_key; EnvironmentFile= removed. systemctl show myapp-web no longer exposes either value.
After
$ python3 scripts/audit_unit.py --unit myapp-web.service --profile locked
baseline 13 / 13 strict 12 / 12 locked 7 / 7
OK: profile 'locked' satisfied. Confirm with: systemd-analyze security myapp-web.service
$ systemd-analyze security myapp-web.service | tail -1
→ Overall exposure level for myapp-web.service: 1.9 OK
nginx
check-nginx-conflicts.sh /etc/nginx found api.example.com:443 declared in both sites-enabled/api.conf and sites-enabled/legacy-api.conf; removed the legacy file, nginx -t clean, reloaded.
Not done
No privilege split was needed; the service holds no capability. Re-run journalctl -u myapp-web | grep -i oom after 24 h to confirm MemoryMax headroom.
Connects securely to your tools. The creator never sees your data.
About this skill
A stock unit file runs your service with the whole filesystem, every address family, every syscall and whatever secrets you put in Environment= visible to anything that can read /proc. Most hardening guides paste thirty directives at once; the service crashes, the operator deletes them all, and nothing is learned. This skill applies hardening in three cumulative tiers, verifying the service still does its real work after each one, and gives your agent the two patterns that make strict sandboxing possible for real workloads.
You get
scripts/audit_unit.py(Python, stdlib, offline): audits a unit's effective settings fromsystemctl showoutput against a tiered profile (baseline, strict, locked), flags secret-shaped environment variable names without ever printing values, and exits non-zero on gaps. Works offline on captured output.- Drop-in templates per tier for a web service, so each tier can be applied and reverted on its own.
- A complete unprivileged agent unit and a one-capability helper unit (CAP_NET_ADMIN over a peer-credential-checked Unix socket) for the privilege-split pattern.
- A Node.js unit that keeps
MemoryDenyWriteExecute=yesby runningnode --jitless, with guidance on measuring the cost. - An encrypted-credentials drop-in with the exact
systemd-credscommands that replaceEnvironment=secrets. sysusers.dandtmpfiles.dfiles so users and directory modes are reproducible on a fresh host.scripts/check-nginx-conflicts.sh: finds duplicateserver_name:portblocks and duplicate rate-limit zones that nginx accepts silently.
Requires systemd 250+ for encrypted credentials; the audit works on older versions. Not for containerized services.
Requires systemd v250+ for full feature set. Auditor detects configuration presence, not binary runtime safety. Templates use Debian/Ubuntu paths. Not for containerized (Docker/Podman) services.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 19 days ago
Requires