systemd Sandboxing, Measured Against The Job It Must Not Break
The scheduler on a stock EL host scores 9.6 UNSAFE and holds every capability the kernel has. This role writes a sandboxing drop-in and proves both halves: systemd's own exposure level came down, and the service still runs its jobs. The capability set that scores best is the one that stops cron working, and the README has the table. Original role, live-tested on Rocky Linux 10.
Verification
Live-testedReally deployed to a container sandbox, proven idempotent (a second run changes nothing), verified against the role’s assertions, then torn down.
Conformance
- Static validation (yamllint · ansible-lint)
Provenance
- SHA-256 checksum
- Signature (pending)
Functional
- Live-tested - applied, verified, destroyed
Last verified 2026-09-27 · podman 4.9.3 · ansible 2.21.4 · how we verify
Cite it in your README
badge · attributionPaste this beside the module in the repository that uses it. The badge is rendered from this artifact's verification record, so it reads live-tested because the record says so, and the link lands on this page.
[](https://www.iac-bazaar.com/catalog/ansible-unit-hardening?utm_source=syndication&utm_medium=readme&utm_campaign=artifact)
Ansible role 1.0.0, live-tested on IaC Bazaar: [systemd Sandboxing, Measured Against The Job It Must Not Break](https://www.iac-bazaar.com/catalog/ansible-unit-hardening?utm_source=syndication&utm_medium=readme&utm_campaign=artifact)
```yaml
# systemd Sandboxing, Measured Against The Job It Must Not Break: https://www.iac-bazaar.com/catalog/ansible-unit-hardening (download from your IaC Bazaar account)
```Preview:
Documentation
unit-hardening
The scheduler on a stock EL host runs as root with every capability the
kernel has. systemd-analyze security crond.service says 9.6 UNSAFE:
ProtectSystem=no, PrivateTmp=no, NoNewPrivileges=no, and a
CapabilityBoundingSet holding cap_sys_admin, cap_sys_module and
cap_sys_boot among the rest. This role writes a sandboxing drop-in and proves
two things that are usually only asserted: systemd's own exposure number came
down, and the service still does its job.
No download, and no version to pin. systemd is the distribution. What the
role owns is one drop-in under /etc/systemd/system/<unit>.d/ - never the
packaged unit, which the next update replaces - and the proof that what it
describes is what systemd is applying.
A unit's sandbox is inherited by everything it spawns. That is the whole
reason this role is worth reading before running: hardening the scheduler hardens
every job on the host. Measured with a user's crontab writing to two places, a job
writing into /etc stopped working at the first step of the ladder below, and
nothing announced it.
The ladder, measured one step at a time on this role's own lane. Each row
adds to the row above it, against crond with a user's crontab writing both to a
permitted path and into /etc:
| drop-in | exposure | the permitted job | the job writing into /etc |
|---|---|---|---|
| stock, no drop-in | 9.6 UNSAFE | ran | ran |
namespace protections, ProtectSystem=full | 6.4 MEDIUM | ran | stopped |
CapabilityBoundingSet trimmed to six (shipped) | 5.0 MEDIUM | ran | stopped |
CapabilityBoundingSet=CAP_SETUID CAP_SETGID | 4.6 OK | stopped | stopped |
The best score in that table is the broken one. 4.6 is the only rating
systemd calls OK, and at that setting cron stopped running jobs at all - the
daemon stays active and reports nothing. A role that optimised the number rather
than the outcome would ship a host whose scheduler silently does nothing, which
is why the shipped CapabilityBoundingSet is the six-capability set at 5.0 and
why the live test asserts a job still runs before it asserts anything about the
number.
PrivateTmp=yes gives the unit its own /tmp AND /var/tmp, and so does every
job it starts. Anything a cron job writes there is invisible from outside the
service and gone when the service restarts. This role's own test found it the hard
way: a fixture writing into /var/tmp looked like a job that had stopped running,
because the file outside never grew. If jobs on your host use /tmp to hand data to
anything else, that is the directive to reconsider.
ProtectSystem=full, not strict. full makes /usr, /boot and /etc
read-only, which is what stopped the /etc job above. strict makes the whole
hierarchy read-only and is a much larger promise to make on behalf of jobs
somebody else wrote. Use unit_hardening_directives to go further when you know
what the unit's children do.
systemd-analyze security on a unit that does not exist exits 0. It prints
"Unit nosuch.service not found, cannot analyze" and returns success, so a typo in
a unit name yields a successful command and no number at all. The live test
parses the number out and asserts it is there before comparing it, because an
empty reading compared against anything is not a comparison.
Nothing validates a drop-in. systemd logs an unknown directive and carries
on, so the test reads the values back from systemctl show - systemd's own view
of what it is applying - rather than from the file the role just wrote.
License
Commercial - IaC Bazaar EULA. (c) IaC Bazaar.
Usage code & full reference need an account
The complete copy-paste usage, the full input/output reference, and operational notes are free with an account - shown here and bundled in the download. Sign in and this section fills in.
- Variables
- Test
Related modules
ansible-lynis
Lynis from EPEL on a systemd timer, with the units the package keeps only in its docs, your skipped tests in custom.prf, and a minimum hardening index below which the audit unit fails, so a falling score shows as a failed unit. The live test runs the audit, reads the index and the tests that ran, and finds the timer enabled. Original role, live-tested on Rocky Linux 10.
ansible-suricata
Suricata from EPEL watching the default-route interface as the suricata user, ET Open fetched at install and refreshed daily, plus a canary rule that proves the sensor is alive. A root-run check left root-owned logs and a daemon recording nothing; the role prevents it. The live test raises the canary alert while a second lookup is logged, not alerted. Original role, live-tested on Rocky Linux 10.
ansible-aide
AIDE from AppStream on EL 10: a watched tree, a baseline database built once, and the oneshot unit and timer the package does not ship. The live test passes on an unchanged host, FAILS when a file appears inside a watched path and names it, ignores one inside an excluded path, and passes again once the change is gone. Original role, live-tested on Rocky Linux 10.
ansible-389-ds
389 Directory Server from AppStream. A fresh instance listens on every interface and lets anonymous clients read the tree; this role binds both listeners to loopback and limits anonymous clients to the rootDSE. The live test adds a user who binds, sees a wrong password and an anonymous search refused, and reads the LDAPS certificate. Original role, live-tested on Rocky Linux 10.
ansible-krb5-kdc
An MIT Kerberos KDC: the realm created once with a stash, kadmind behind an ACL, a default policy that locks an account after five wrong passwords, every listener on loopback. The KDC starts on a broken config without a word, so the live test proves each setting by behaviour: the ticket lifetime, the refusals, the lockout. Original role, live-tested on Rocky Linux 10.
ansible-authelia
Authelia from the upstream release (sha256-verified) as a hardened system service on loopback with file users and sqlite; its secrets are generated once on the host and reach the service as AUTHELIA_*_FILE variables. The live test hashes a password with Authelia's hasher, logs in, sees a wrong password refused and an anonymous visitor sent to the portal. Original role, live-tested on Rocky 10.