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-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-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.
ansible-bandit
bandit on EL 10 from PyPI into a venv of its own with a link in the PATH; the live test runs pip check, then scans a module that passes a string to subprocess.call with shell=True (B602, High, exit 1) and a clean module (exit 0). Pinned. Original role, live-tested on Rocky Linux 10.
ansible-boundary
boundary on EL 10 from releases.hashicorp.com; SHA256SUMS is signature-checked against HashiCorp's key before get_url trusts it, the live test re-checks both, then runs authenticate against a dead address ('connection refused') and database init with a throwaway config (parsed, root key loaded, then the database refused). Pinned. Original role, live-tested on Rocky Linux 10.
ansible-dockle
dockle on EL 10 from the GitHub release; get_url refuses it unless its SHA-256 is in the vendor's checksums file, and the live test re-checks it, then scans a one-layer image whose config names no user, expecting CIS-DI-0001 in the output, exit code 1 with --exit-level warn, and the warning counted in the JSON form. Pinned. Original role, live-tested on Rocky Linux 10.
ansible-gitleaks
gitleaks on EL 10 from the GitHub release, refused by Ansible's get_url unless its SHA-256 is the one in the project's checksums file, and re-checked with sha256sum -c by the live test, which then plants a file holding an AWS access key that is not one and runs gitleaks detect over it, expecting 'leaks found: 1'. Original role, live-tested on Rocky Linux 10.