Sub topic 4
Scanning with OpenSCAP and reading the results
This chapter assumes you can use the Linux command line, know the basics of systemd, and have root or sudo access to a test server running RHEL 9 or a compatible clone. You should also know what a CIS profile is and have a baseline snapshot of the machine, both covered in earlier chapters.
What OpenSCAP is and how the pieces fit
OpenSCAP is an open-source toolkit that evaluates a system against security content written in the SCAP standard (Security Content Automation Protocol). Three terms matter for reading its output:
- SCAP content is an XML file that holds the checks. On RHEL 9 the SCAP Security Guide package ships it as a "data stream" file named
ssg-rhel9-ds.xml. - Profile is a named subset of rules inside the content, such as CIS Server Level 1. The profile decides which rules run.
- Rule is one check, such as "SSH root login is disabled". Each rule produces one result.
The oscap command-line tool reads the content, runs the rules of the chosen profile against the local system, and writes the results. CIS-CAT is the CIS vendor's own assessor. OpenSCAP is free and scriptable, so this chapter uses it.
Installing the tools and finding the profile
Install the scanner and the content on RHEL 9:
sudo dnf install -y openscap-scanner scap-security-guideThe content is only useful if it contains the profile you want. List what the data stream offers:
oscap info /usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xmlThe output lists profile IDs, each starting with xccdf_org.ssgproject.content_profile_. Look for cis_server_l1, cis_server_l2, cis_workstation_l1 and cis_workstation_l2. Pick the one that matches the server role and level you chose earlier. If the profile is missing, your installed content may be older than your OS release. Update the scap-security-guide package first.
Running the scan
Run the scan as root, because many rules read files and kernel settings that normal users cannot see:
sudo oscap xccdf eval \
--profile xccdf_org.ssgproject.content_profile_cis_server_l1 \
--results results.xml \
--report report.html \
/usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xmlThe options do the following:
| Option | Purpose |
|---|---|
| `--profile` | Selects the profile by its full ID |
| `--results` | Writes machine-readable XCCDF results, useful for diffing and automation |
| `--report` | Writes a human-readable HTML report |
| last argument | The data stream to evaluate |
The scan prints one line per rule to the terminal and can take a few minutes. It only reads the system. It does not change anything unless you add --remediate, which you should not use yet.
The exit code is meaningful for scripts. 0 means all rules passed, 2 means at least one rule failed or returned an unknown result, and 1 means the scan itself had an error.
Reading the results
Each rule ends in one of these states:
| Result | Meaning |
|---|---|
| `pass` | The system meets the rule |
| `fail` | The system does not meet the rule |
| `notapplicable` | The rule does not apply, for example a rule about a package that is not installed |
| `notchecked` | No automated check exists. Many CIS "manual" recommendations land here |
| `error` | The check itself broke and the result cannot be trusted |
| `unknown` | The scanner could not determine a result |
| `notselected` | The rule is in the content but not in your profile |
Do not treat notchecked as a pass. A manual recommendation still needs a person to review it, and you should record the outcome in your documentation.
Open report.html in a browser. It shows a compliance score, a count per result, and a list of rules you can filter by result. Click a failing rule to see its description, severity, rationale, and often the remediation as a shell snippet or an Ansible task. The rationale explains why the rule exists, which you need when deciding whether to accept or reject a change.
A high score is not the goal. A score only counts rules in the chosen profile, and every rule weighs the same in the percentage regardless of severity. Sort by severity and read the failures one at a time.
Working from the command line
You can inspect the XML results without a browser. This lists the failing rules:
oscap xccdf generate report results.xml > /dev/null
grep -B1 '<result>fail</result>' results.xml | grep -o 'idref="[^"]*"'For a rule that fails, ask the scanner for details. Add --verbose WARNING to the scan to see why a check could not run, and add --oval-results to write the low-level evidence for each check:
sudo oscap xccdf eval \
--profile xccdf_org.ssgproject.content_profile_cis_server_l1 \
--oval-results \
--results results.xml \
/usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xmlThe OVAL results (written next to the results file as *.oval.xml) record the exact files and values the check examined. This is how you tell a real failure from a rule that looks at a path your system does not use.
Edge cases and common errors
- Profile not found. The error "No profile found" or "Profile not found" usually means a typo in the ID or content that predates the profile. Copy the ID from
oscap info. - Scanning without root. Many rules return
errororunknown, and the score looks better or worse than reality. Always scan withsudo. - False failures. Rules can fail because the system uses a different but equivalent mechanism, for example
chronyconfigured through a drop-in file the check does not read. Confirm by hand before you change anything. If the setting is truly equivalent, record it as an exception (see the exceptions chapter). - Comparing scans. Keep each
results.xmlwith a date in its name, such asresults-2026-11-28.xml. Comparing two runs shows which changes fixed rules and which broke others. - Containers and minimal images. Many rules about partitions and the bootloader do not make sense inside a container. Use the container-specific mode,
oscap-podman, for container images instead of scanning the host profile. - Scan load. The scan reads many files and can be slow on large filesystems. Run it in a quiet period on production hosts.
A practical loop
- Scan and save
results.xmlandreport.htmlas the baseline. - Pick a group of related failing rules, such as filesystem mount options.
- Apply the fix and verify it with the command the rule's description gives.
- Rescan and compare to the baseline.
- Repeat until only deliberate exceptions remain.
Exercise
A scan of your server returns a 92% score, but 14 rules show notchecked and 3 show error. Why can you not call the server compliant yet, and what should you do about each group?
Show answer
The score only reflects rules that were evaluated. The 14 notchecked rules are manual recommendations that have no automated check, so a person must review each one and record the outcome. The 3 error rules mean the check itself failed, often because the scan ran without root or a file was missing, so their real state is unknown. Rerun with sudo and --verbose WARNING to find the cause, fix the check or inspect the setting by hand, and rescan. The server can be called compliant only after all of these are resolved or documented as exceptions.
Exercise
Which command-line option writes the low-level evidence that shows exactly which files and values a check examined, and why is that useful for a rule you think is a false failure?
Show answer
--oval-results. It writes OVAL result files that record what each check looked at. You can compare that evidence with your system's real configuration to see whether the rule examined the wrong path or whether the setting truly fails.