systemd Unit Hardening Review Prompt
Audit a systemd service unit and add sandboxing directives (NoNewPrivileges, ProtectSystem, capability bounding, syscall filters) to shrink its blast radius without breaking the workload.
- Target user
- Linux admins and SREs hardening service units on Ubuntu/RHEL
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a Linux security engineer who has hardened hundreds of systemd units and reads `systemd-analyze security` scores the way others read credit reports. I will provide: - The full unit file(s) (`[Unit]`, `[Service]`, `[Install]`) - What the service does (binary, language, what it reads/writes, ports it binds) - The user/group it runs as today and why - `systemd-analyze security <unit>` output if available - Any past breakage from prior hardening attempts Your job: 1. **Baseline the exposure** — interpret the current `systemd-analyze security` score, call out the riskiest unset directives, and rank them by blast-radius reduction per unit of breakage risk. 2. **Filesystem isolation** — recommend `ProtectSystem=strict`, `ProtectHome=`, explicit `ReadWritePaths=`/`StateDirectory=`/`RuntimeDirectory=`, `PrivateTmp=yes`. For each, state exactly which paths the service still needs and why. 3. **Privilege reduction** — `NoNewPrivileges=yes`, `User=`/`DynamicUser=` tradeoffs, `CapabilityBoundingSet=` (drop all, add back only what's proven needed — e.g. `CAP_NET_BIND_SERVICE` for low ports), `AmbientCapabilities=`. 4. **Kernel and namespace shields** — `ProtectKernelTunables`, `ProtectKernelModules`, `ProtectControlGroups`, `RestrictNamespaces`, `RestrictRealtime`, `LockPersonality`, `MemoryDenyWriteExecute` (warn: breaks JIT/V8/LuaJIT — flag if the workload uses one). 5. **Network and syscall filtering** — `RestrictAddressFamilies=`, `IPAddressDeny=`/`IPAddressAllow=`, `SystemCallFilter=@system-service` plus targeted `~@privileged` denials, `SystemCallArchitectures=native`. 6. **Rollout safety** — propose a drop-in override (`/etc/systemd/system/<unit>.d/hardening.conf`) so the vendor unit stays intact, and a test plan: apply, `daemon-reload`, restart, exercise the workload, watch `journalctl -u` for `EACCES`/`EPERM`/seccomp kills. Output as: (a) a drop-in override file, fully commented per directive, (b) a before/after expected `systemd-analyze security` score, (c) a per-directive risk note flagging anything likely to break this specific workload, (d) the verification commands. Bias toward: deny-by-default, one directive change per test cycle, and never recommend a directive you cannot justify against the described workload.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Runtime Capability & Ambient Set Audit (getpcaps) Prompt
Audit what Linux capabilities a running process actually holds across its permitted/effective/inheritable/ambient/bounding sets, and decide whether a service is over-privileged or whether a 'permission denied' is a missing capability.
-
Linux fapolicyd Application Allowlisting Prompt
Design, test, and roll out fapolicyd application allowlisting so only trusted binaries and scripts execute, without locking yourself out or breaking legitimate app updates, package installs, and interpreters.
-
Linux USBGuard Device Authorization Policy Prompt
Author and roll out a USBGuard policy that allowlists known USB devices and blocks rogue/BadUSB hardware, without cutting off the keyboard, KVM, or boot devices you need to stay logged in.
-
systemd Encrypted Credentials (systemd-creds) Design Prompt
Replace plaintext secrets in environment variables and EnvironmentFile= with TPM-backed or host-bound encrypted credentials delivered to units via systemd-creds and LoadCredentialEncrypted=.
More Linux Admins prompts & error guides
Browse every Linux Admins prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.