DEV Community

ANKUSH CHOUDHARY JOHAL
ANKUSH CHOUDHARY JOHAL

Posted on • Originally published at johal.in

OpenSCAP and Trivy: The Definitive Guide to compliance for Security

OpenSCAP and Trivy: The Definitive Guide to Security Compliance

Security compliance is a non-negotiable requirement for organizations across every industry, from healthcare to finance to government. Regulatory frameworks like PCI-DSS, HIPAA, NIST 800-53, and CIS Controls mandate strict controls for system configuration, vulnerability management, and data protection. Yet manual compliance checks are time-consuming, error-prone, and impossible to scale for modern hybrid cloud infrastructure.

Two open-source tools have emerged as industry leaders for automating compliance and security workflows: OpenSCAP and Trivy. While they serve distinct primary use cases, they are highly complementary when used together to deliver end-to-end security coverage. This guide breaks down everything you need to know to leverage both tools for comprehensive compliance.

What is OpenSCAP?

OpenSCAP is an open-source implementation of the Security Content Automation Protocol (SCAP), a standardized framework defined by NIST for automating security compliance checks. It is purpose-built for configuration compliance and policy enforcement, focusing on validating that systems meet predefined security benchmarks.

Core OpenSCAP Capabilities

  • SCAP Content Support: Natively supports XCCDF (Extensible Configuration Checklist Description Format) for policy definition, OVAL (Open Vulnerability and Assessment Language) for vulnerability and configuration checks, and CPE (Common Platform Enumeration) for system identification.
  • OS and Host Compliance: Scans Linux, Windows, and macOS systems to validate alignment with CIS Benchmarks, STIGs (Security Technical Implementation Guides), and custom organizational policies.
  • Remediation: Generates actionable remediation scripts to fix non-compliant configurations automatically.
  • Reporting: Produces standardized ARF (Asset Reporting Format) reports for audit trails and compliance documentation.

Example OpenSCAP scan command for a local RHEL system against CIS Benchmark:

oscap xccdf eval --profile cis-rhel8-level1-server --results results.xml --report report.html /usr/share/xml/scap/ssg/content/ssg-rhel8-ds.xml
Enter fullscreen mode Exit fullscreen mode

What is Trivy?

Trivy is a lightweight, open-source vulnerability scanner designed for modern cloud-native workloads. It has quickly become the go-to tool for scanning container images, but its capabilities extend far beyond containers to cover almost every artifact in your infrastructure.

Core Trivy Capabilities

  • Artifact Scanning: Scans container images, filesystems, virtual machine images, and SBOMs (Software Bill of Materials) for known vulnerabilities (CVEs).
  • IaC Scanning: Validates Infrastructure as Code (Terraform, Kubernetes manifests, CloudFormation) for misconfigurations that could lead to security gaps.
  • CI/CD Integration: Easily integrates into pipelines (GitHub Actions, GitLab CI, Jenkins) to block vulnerable or misconfigured artifacts before deployment.
  • Comprehensive Coverage: Detects vulnerabilities in OS packages, language-specific dependencies (npm, pip, Maven), and proprietary binaries.

Example Trivy scan command for a container image:

trivy image --severity HIGH,CRITICAL --format json --output trivy-report.json nginx:latest
Enter fullscreen mode Exit fullscreen mode

OpenSCAP vs. Trivy: Key Differences

While both tools improve security posture, they address different layers of the compliance stack:

Feature

OpenSCAP

Trivy

Primary Focus

Configuration compliance, policy enforcement

Vulnerability detection, artifact scanning

Target Workloads

Host operating systems, on-prem/cloud VMs

Containers, IaC, SBOMs, cloud-native artifacts

Compliance Standards

CIS, STIG, NIST, custom organizational policies

Vulnerability databases (NVD, Red Hat, Debian), CIS IaC benchmarks

Remediation

Automated configuration fix scripts

Vulnerability prioritization, fix version recommendations

Using OpenSCAP and Trivy Together for End-to-End Compliance

The real power of these tools lies in their integration. Combining OpenSCAP’s configuration compliance checks with Trivy’s vulnerability and artifact scanning creates a unified security workflow that covers both host-level policy enforcement and artifact-level risk detection.

Example Integrated Workflow

  1. CI/CD Pipeline Scanning: Trivy scans container images and IaC templates during the build phase. If high/critical vulnerabilities or misconfigurations are detected, the pipeline fails, blocking deployment.
  2. Host Compliance Checks: OpenSCAP scans underlying host OS (e.g., RHEL, Ubuntu) on a scheduled basis to validate alignment with CIS Benchmarks or STIGs.
  3. Unified Reporting: Aggregate Trivy vulnerability reports and OpenSCAP compliance reports into a single dashboard to map findings to regulatory requirements (e.g., PCI-DSS Requirement 2 for system configuration, Requirement 6 for vulnerability management).
  4. Automated Remediation: Use OpenSCAP-generated scripts to fix non-compliant host configurations, and Trivy’s fix recommendations to update vulnerable packages in container images.

Step-by-Step: Getting Started with OpenSCAP and Trivy

1. Install OpenSCAP

On RHEL/CentOS:

sudo yum install openscap-scanner scap-security-guide
Enter fullscreen mode Exit fullscreen mode

On Ubuntu/Debian:

sudo apt install libopenscap8 scap-security-guide
Enter fullscreen mode Exit fullscreen mode

2. Install Trivy

On Linux (using apt):

sudo apt install trivy
Enter fullscreen mode Exit fullscreen mode

Or using the official script:

curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
Enter fullscreen mode Exit fullscreen mode

3. Run Your First Scans

Run a Trivy scan on a local directory:

trivy fs /path/to/your/project
Enter fullscreen mode Exit fullscreen mode

Run an OpenSCAP scan on your local system:

oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_cis_workstation_l1 --report workstation-scan.html /usr/share/xml/scap/ssg/content/ssg-ubuntu2004-ds.xml
Enter fullscreen mode Exit fullscreen mode

Best Practices for Compliance with OpenSCAP and Trivy

  • Automate Scanning: Schedule regular scans for hosts (OpenSCAP) and integrate Trivy into every CI/CD pipeline to catch issues early.
  • Map Findings to Regulations: Use OpenSCAP’s built-in regulatory mappings and Trivy’s severity ratings to align scan results with PCI-DSS, HIPAA, or NIST requirements.
  • Prioritize Remediation: Focus on high/critical Trivy vulnerabilities and OpenSCAP failures that directly impact compliance requirements first.
  • Maintain Up-to-Date Content: Regularly update SCAP content for OpenSCAP and Trivy’s vulnerability database to detect the latest threats.
  • Document Audit Trails: Store all OpenSCAP ARF reports and Trivy JSON outputs to demonstrate compliance during audits.

Conclusion

OpenSCAP and Trivy are not competing tools—they are complementary pillars of a modern security compliance strategy. OpenSCAP ensures your systems are configured correctly to meet policy requirements, while Trivy ensures your artifacts are free from known vulnerabilities and misconfigurations. By integrating both into your workflows, you can automate compliance, reduce manual overhead, and build a more secure, audit-ready infrastructure.

Top comments (0)