OpenSCAP Security Scanning Guide for AlmaLinux 9.4

This guide provides step-by-step instructions for installing, configuring, and running OpenSCAP security compliance scans on an AlmaLinux 9.4 server.

What is OpenSCAP?

OpenSCAP (Open Security Content Automation Protocol) is an open-source security compliance solution that helps organizations assess, measure, and enforce security baselines. It implements the SCAP (Security Content Automation Protocol) standard to automate vulnerability management and security compliance.

Prerequisites

  • AlmaLinux 9.4 server with administrative (root) access
  • Internet connectivity for package installation
  • Sufficient disk space for scan results

Installation

  1. Update your system packages:

    sudo dnf update -y
    
  2. Install OpenSCAP and related tools:

    sudo dnf install openscap-scanner scap-security-guide -y
    

    This installs:

    • openscap-scanner: The core scanning utility
    • scap-security-guide: A collection of security policies including STIG, PCI-DSS, and others

Available Security Profiles

To list available security profiles for AlmaLinux 9:

ls -la /usr/share/xml/scap/ssg/content/ssg-almalinux9-ds.xml
oscap info /usr/share/xml/scap/ssg/content/ssg-almalinux9-ds.xml

Common security profiles include:

  • xccdf_org.ssgproject.content_profile_cis: Implements the CIS AlmaLinux 9 Benchmark. Use for organizations seeking Center for
    Internet Security best practices for hardening and compliance.
  • xccdf_org.ssgproject.content_profile_ospp: Applies the OSPP (Protection Profile for General Purpose Operating Systems). Suitable for environments requiring baseline security controls for
    general-purpose OS deployments.
  • xccdf_org.ssgproject.content_profile_pci-dss: Enforces PCI-DSS requirements. Use for systems handling payment card data to meet Payment Card Industry Data Security Standard compliance.
  • xccdf_org.ssgproject.content_profile_stig: Follows the STIG (Security Technical Implementation Guide). Ideal for government or
    defense systems needing strict security configuration per DoD
    guidelines.

Running a Basic Scan

  1. Create a directory to store scan results:

    sudo mkdir -p /opt/scans/$(date +%Y-%m-%d)
    cd /opt/scans/$(date +%Y-%m-%d)
    
  2. Run a basic evaluation using the OSPP profile:

    sudo oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_ospp --report report.html --results results.xml /usr/share/xml/scap/ssg/content/ssg-almalinux9-ds.xml
    
  3. For a more comprehensive STIG compliance scan:

    sudo oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_stig --report stig-report.html --results stig-results.xml /usr/share/xml/scap/ssg/content/ssg-almalinux9-ds.xml
    

Generating Different Report Formats

OpenSCAP supports various output formats:

  1. HTML Report (human-readable):

    sudo oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_ospp --report report.html /usr/share/xml/scap/ssg/content/ssg-almalinux9-ds.xml
    
  2. XML Results:

    sudo oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_ospp --results results.xml /usr/share/xml/scap/ssg/content/ssg-almalinux9-ds.xml
    
  3. Both HTML and XML:

    sudo oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_ospp --report report.html --results results.xml /usr/share/xml/scap/ssg/content/ssg-almalinux9-ds.xml
    

Scanning for CVEs (Vulnerabilities)

To scan the system for known vulnerabilities (CVEs):

  1. Install the OVAL definitions for AlmaLinux:

    sudo dnf install almalinux-security-oval -y
    
  2. Run a vulnerability scan:

    sudo oscap oval eval --report cve-report.html /usr/share/oval/almalinux-9/almalinux-9-oval.xml
    

Remediation

OpenSCAP can generate remediation scripts to fix issues:

  1. Generate a Bash remediation script:

    sudo oscap xccdf generate fix --profile xccdf_org.ssgproject.content_profile_ospp --output fix-script.sh /usr/share/xml/scap/ssg/content/ssg-almalinux9-ds.xml
    
  2. Review the generated script carefully before running:

    sudo less fix-script.sh
    
  3. Apply the fixes (use with caution in production):

    sudo bash fix-script.sh
    

Scheduled Scans

To set up regular automated scans:

  1. Create a scan script:

    sudo nano /usr/local/bin/run-oscap-scan.sh
    
  2. Add the following content:

    #!/bin/bash
    SCAN_DATE=$(date +%Y-%m-%d)
    SCAN_DIR="/opt/scans/$SCAN_DATE"
    
    mkdir -p $SCAN_DIR
    cd $SCAN_DIR
    
    oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_ospp \
     --report "$SCAN_DIR/report.html" \
     --results "$SCAN_DIR/results.xml" \
     /usr/share/xml/scap/ssg/content/ssg-almalinux9-ds.xml
    
    # Optional: Send email with results
    # mail -s "OpenSCAP Scan Results $SCAN_DATE" admin@example.com < "$SCAN_DIR/report.html"
    
  3. Make the script executable:

    sudo chmod +x /usr/local/bin/run-oscap-scan.sh
    
  4. Create a cron job for weekly scans:

    sudo crontab -e
    
  5. Add the following line to run the scan every Sunday at 2 AM:

    0 2 * * 0 /usr/local/bin/run-oscap-scan.sh
    

Tailoring Security Profiles

To customize a security profile for your environment:

  1. Create a tailoring file:

    oscap xccdf generate tailoring --profile xccdf_org.ssgproject.content_profile_ospp --output tailoring.xml /usr/share/xml/scap/ssg/content/ssg-almalinux9-ds.xml
    
  2. Edit the tailoring file as needed (use a graphical tool like SCAP Workbench for easier editing)

  3. Run a scan with the tailored profile:

    sudo oscap xccdf eval --tailoring-file tailoring.xml --profile xccdf_org.ssgproject.content_profile_ospp-tailored --report tailored-report.html /usr/share/xml/scap/ssg/content/ssg-almalinux9-ds.xml
    

Troubleshooting

If you encounter issues:

  1. Check for errors in the OpenSCAP command output
  2. Verify that the correct profile name is used
  3. Ensure proper permissions when running scans (use sudo)
  4. Check the system logs for additional information: sudo journalctl -u openscap.service

Additional Resources

Conclusion

Regular security scanning with OpenSCAP helps ensure your AlmaLinux 9.4 server maintains compliance with security standards and identifies potential vulnerabilities before they can be exploited. By following this guide, you can implement a comprehensive security scanning strategy to protect your systems.

Filed under: Linux Tags: