Skip to content

Applying a CIS Benchmark without losing a weekend

How to scope, apply, and verify a Center for Internet Security benchmark on a Linux host — using OpenSCAP and ansible-lockdown rather than reading 400 pages.

The Center for Internet Security publishes prescriptive hardening benchmarks for every common Linux distro — Ubuntu, RHEL, Debian, Amazon Linux. The benchmark documents are 300–500 pages each. No team applies them by hand. The practical path is OpenSCAP for the audit and ansible-lockdown for the remediation, with a habit of running the audit nightly so drift surfaces before the next compliance review.

How to verify

Check whether OpenSCAP is installed and what the most recent scan said:

sudo dpkg -l libopenscap8 ssg-debderived 2>/dev/null  # Debian
sudo dnf list installed openscap-scanner scap-security-guide 2>/dev/null  # RHEL
sudo oscap info /usr/share/xml/scap/ssg/content/ssg-ubuntu2204-ds.xml | head -20
ls -lh /var/lib/openscap/*.html 2>/dev/null
sudo grep -E 'pass|fail' /var/lib/openscap/last-report.txt 2>/dev/null | sort | uniq -c

If the SCAP Security Guide content is missing, install it — apt install scap-security-guide-debian or dnf install scap-security-guide ships the XML profiles that map a CIS or STIG benchmark to checks the scanner can execute.

What’s happening

The CIS benchmark is a list of recommendations grouped into levels (Level 1 — practical hardening with low operational impact; Level 2 — defence in depth, may break some workflows). Each recommendation has a rationale, an audit procedure (how to check), and a remediation (how to fix). The SCAP Security Guide (SSG) project ships an XML translation of every CIS recommendation as an OVAL check and an Ansible/Bash remediation. OpenSCAP runs the checks; ansible-lockdown (the project by the same maintainers) applies the remediations.

The right loop is: scan, review the report, apply only the controls you have explicitly accepted, scan again, then commit the playbook variables that document which controls you skipped and why. That paper trail is what passes a compliance review — not “we ran the script”.

CIS scores a benchmark from 0 to 100. A new host with no hardening typically scores 35–45. A reasonable target for an internet-facing host is 75–85; pushing to 95+ tends to introduce friction (e.g. disabling wget because the benchmark prefers curl).

The procedure

  1. Install the scanner and content. On Ubuntu 22.04: sudo apt install libopenscap8 ssg-debderived. On RHEL family: sudo dnf install openscap-scanner scap-security-guide.
  2. Pick the profile. sudo oscap info /usr/share/xml/scap/ssg/content/ssg-ubuntu2204-ds.xml lists every profile in the data stream. For CIS Level 1, look for xccdf_org.ssgproject.content_profile_cis_level1_server.
  3. Run the audit. sudo oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_cis_level1_server --results /var/lib/openscap/results.xml --report /var/lib/openscap/report.html /usr/share/xml/scap/ssg/content/ssg-ubuntu2204-ds.xml. The HTML report is the readable version.
  4. Triage failures. Open the report and bucket each failure: accept and remediate, accept the risk with documented rationale, or out-of-scope (the benchmark assumes a desktop, you’re a server). Track the rationale in your hardening repo.
  5. Generate the Ansible remediation. sudo oscap xccdf generate fix --profile xccdf_org.ssgproject.content_profile_cis_level1_server --fix-type ansible /usr/share/xml/scap/ssg/content/ssg-ubuntu2204-ds.xml > remediate.yml. Read every line — the generated playbook is a starting point, not a production artefact.
  6. Apply selectively. The ansible-lockdown role (UbuntuCIS, RHEL9-CIS, etc.) takes a long list of cis_*_enable variables, one per control. Set each to true or false based on your triage. Commit the variable file; it IS your compliance documentation.
  7. Re-scan after remediation. Same command as step 3. Diff the two reports. Anything that still fails either needs a deeper fix or moved to “accepted risk”.
  8. Schedule the scan. A nightly systemd timer that runs oscap xccdf eval --profile ... --report /var/lib/openscap/$(date +%F).html builds a per-day drift log. A non-zero diff vs yesterday is a question for the operator who deployed the change.

Common pitfalls

  • The SSG profile lags the CIS benchmark by 1–2 quarters. A “CIS Level 1” report against an SSG that ships a 2-year-old profile is not the current benchmark — confirm versions before signing off.
  • The auto-generated Ansible playbook will happily disable IPv6, ICMPv6, and Avahi on a host that needs them. Read every task before running.
  • A failing check is not always a real failure. The SSG check for “ensure SSH PermitRootLogin is disabled” fails if your sshd_config has PermitRootLogin without-password (a valid hardening choice) because the OVAL check looks for no. Read the rule definition.
  • CIS Level 2 controls include things like “disable USB storage” — on a server, the right answer is yes; on a developer laptop posing as a server, you’ll break the build pipeline. Profile your hosts by role.
  • The report includes a CVE-mapped scan only if you provide the OVAL CVE feed. oscap oval eval against the official Red Hat or Canonical CVE OVAL is a separate command from the XCCDF benchmark scan.

In the engagements we run, CIS scans are scheduled, archived, and diff’d day-over-day. A drift from an accepted baseline becomes a ticket, not a quarterly surprise. That cadence is the kind of discipline that lives in Managed Operations — running the benchmark once is an audit; running it nightly is a security posture.