Scan SBOM Files with cnspec
Query, scan, and check an existing software bill of materials (SBOM) file with cnspec as if it were a running asset.
Assess the software inventory in an existing software bill of materials (SBOM) without access to the system it describes. cnspec reads the SBOM file from disk and loads it as an asset, with the platform the SBOM describes and the operating system and Python packages it lists. You can then query its packages in the cnspec shell, evaluate policies against it, or check its packages for known vulnerabilities.
This page is part of scanning your supply chain with cnspec. To generate an SBOM from a host, container image, or other asset instead, read cnspec sbom.
Supported formats
cnspec reads these SBOM formats:
- CycloneDX (JSON or XML)
- SPDX 2 (JSON or tag-value)
- SPDX 3.0.1 (JSON-LD)
- Mondoo JSON, the
jsonoutput format ofcnspec sbom
cnspec detects the format from the file's content, so you don't need to specify it. If cnspec doesn't recognize the file, it fails with an error that lists the supported formats.
From the SBOM, cnspec loads the operating system packages (deb, rpm, apk, and Yocto packages, and Windows applications and hotfixes) and the Python packages. It doesn't load packages from other ecosystems, such as Maven or Go modules, so queries, policy checks, and vulnerability checks don't include them.
Query an SBOM file
Open a cnspec shell on the SBOM file:
cnspec shell sbom sbom.jsonTo see the asset the SBOM describes:
cnspec> asset { name platform version }To list the operating system packages in the SBOM, such as deb, rpm, and apk packages:
cnspec> packages { name version purl }To list the Python packages in the SBOM:
cnspec> python.packages { name version }Scan an SBOM file
To evaluate policies against an SBOM file:
cnspec scan sbom sbom.jsoncnspec evaluates the policies that apply to the platform the SBOM describes. If the SBOM identifies the operating system, for example with a CycloneDX component of type operating-system or with a distro qualifier in the package URLs of an SPDX SBOM, the asset takes that operating system as its platform (for example, Ubuntu 22.04), so the matching operating system policies apply. An SBOM holds only a software inventory, so checks that need other system state, such as configuration files or running services, end in an error.
If the SBOM doesn't identify an operating system, the asset's platform is the SBOM format (for example, cyclonedx for a CycloneDX file), and the operating system policies don't apply to it. To evaluate it, create your own policy and pass it with --policy-bundle, or query the SBOM in the cnspec shell.
Asset identity in Mondoo Platform
When cnspec is registered with Mondoo Platform, it reports the scan results for the SBOM as an asset in your space. If the SBOM declares the identity of the system it describes, cnspec keeps it, so scanning the same SBOM again updates the same asset. These SBOMs declare an identity:
- A Mondoo JSON SBOM (
cnspec sbom -o json), which carries the platform IDs of the asset it was generated from - A CycloneDX SBOM whose root component (
metadata.component) is of typeoperating-systemorcontainer
For any other SBOM, cnspec assigns a new random ID on each run, so each scan creates a separate asset.
Check an SBOM file for vulnerabilities
To find the known vulnerabilities (CVEs) that affect the packages in an SBOM file:
cnspec vuln sbom sbom.jsoncnspec sends the packages it loads from the SBOM to Mondoo Platform, which returns the vulnerabilities that affect them. The scan is ephemeral: nothing is stored in Mondoo Platform. Because the analysis runs in Mondoo Platform, cnspec must be registered. To learn more, read cnspec vuln.
Learn more
-
To generate an SBOM from a host, container image, or other asset, read cnspec sbom.
-
To control the output format or send results to a file or CI system, read Report Results.
-
To learn more about how the MQL query language works, read Write Effective MQL.
Last updated on