متقدم
البحث فيأدلة «كيف»
طريقة البحث
  • اكتب المهمة بكلماتك (find port، open firewall، disk full) أو الصق رسالة الخطأ بين علامتي تنصيص.
  • اختر «الإجابة السريعة» لترى الأوامر فقط، أو مجالًا لتبقى في مجال واحد.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

كيف 211Security · Compliance

How to scan a server for compliance with OpenSCAP

An auditor asks: "Do your servers follow the CIS benchmark?" Checking hundreds of settings by hand is impossible. OpenSCAP (oscap) checks a server against a ready profile (CIS, PCI-DSS, STIG, ANSSI) from the SCAP Security Guide, writes an HTML report with pass/fail and the fix for every rule, and can generate a Bash or Ansible fix. This how-to scans a RHEL server against CIS, reads the report, and fixes the findings in a controlled way.

  • 5 الدروس
  • 6 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

211.1

The quick answer

dnf install -y openscap-scanner scap-security-guide
oscap info /usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml | grep -i 'profile' | head -20
oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_cis_server_l1 --results /root/cis-results.xml --report /root/cis-report.html /usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml

211.2

Step by step

  1. Install the scanner and the content (quick answer). The content file matches the OS: ssg-rhel9-ds.xml, ssg-rhel8-ds.xml … For Ubuntu use the content from the ComplianceAsCode project releases or Ubuntu's own USG tool.
  2. Choose a profile — oscap info lists them with their IDs. CIS Level 1 Server is a good start; Level 2 and STIG are stricter.
  3. Scan as root (quick answer, line 3) — takes a few minutes. The exit code is 2 when some rules failed — that is normal for a first scan.
  4. Read the report — copy cis-report.html to your laptop (scp) and open it. Each rule shows pass, fail or notapplicable, the severity, why it matters and how to fix it. Sort by severity; start with high.
  5. Generate a fix — then review it — never run it blind on production:
oscap xccdf generate fix --fix-type ansible --profile xccdf_org.ssgproject.content_profile_cis_server_l1 --output cis-fix.yml /usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml

Remove the rules you cannot apply (for example a separate /tmp partition on an existing server), test the playbook on a copy, then roll it out.

  1. Document exceptions — some rules do not fit your servers. Write down which and why; a tailoring file (made with SCAP Workbench or autotailor) removes them from future scans.
  2. New servers compliant from the start — the RHEL installer and Image Builder can apply a profile at install time.
  3. Scan regularly — a weekly systemd timer, and keep the results to show progress (and to spot drift).

الأوامر في هذا الدرس

211.3

Check that it worked

The report shows the score and the number of failed rules; after the fix and a new scan the score is higher and the high-severity failures are gone or listed as documented exceptions.

211.4

Common problems

ProblemCauseFix
No such file for the contentWrong OS version file, or package missing.Install scap-security-guide; use the ssg- file of your OS.
Profile not foundProfile ID typo or not in this content.Copy the ID from oscap info.
Exit code 2Some rules failed.Normal; read the report.
Server breaks after the fixFix applied without review (SSH, password, mount rules).Review and test on a copy; apply in small steps.
Many notchecked rulesRules that need a person (for example a policy document).Check those by hand; document them.
Scan very slowRules that search the whole file system.Run at night; it is a one-off cost per scan.

الأوامر في هذا الدرس

211.5

Go further

1What is an OpenSCAP profile?

A ready set of rules for one standard (for example CIS Level 1 Server) that oscap checks the server against.

2Why should a generated fix not run straight on production?

Some rules change SSH, passwords or mounts and can lock you out; review and test the fix on a copy first.

كل الأوامر في هذا الفصل