Software Bill of Materials SBOM Generation

Production-ready guide covering software bill of materials sbom generation with implementation patterns, code examples, and anti-patterns for enterprise engineering teams.

Software Bill of Materials SBOM Generation

A Software Bill of Materials (SBOM) is a structured inventory of all components, libraries, and dependencies within a software artifact. It maps the supply chain from source code to runtime, identifying every piece of code that executes, not just the top-level application. SBOM generation matters when you need to prove what is inside a container, a binary, or a deployment package during security audits, vulnerability management, and incident response. Unlike dependency resolution, which determines what *can* run, SBOM generation records what *does* run, capturing transitive dependencies and their specific versions. The output is typically a machine-readable document, most commonly in SPDX or CycloneDX formats, which serves as a single source of truth for downstream security tools.

Choosing the Generation Strategy

SBOMs are generated using three primary strategies: static analysis, dynamic analysis, and image inspection. Each approach has distinct trade-offs regarding accuracy, speed, and coverage.

Static Analysis

Static analysis parses source code files and build artifacts to identify dependencies. It is the most common method for container images and native binaries. Tools like syft and anchore-syft scan directories or container images by reading filesystem metadata and parsing package manifests. When scanning a directory, the tool traverses the file tree, identifying package managers such as npm, pip, maven, or go modules, and extracts version strings directly from lockfiles or runtime environments.

For container images, static analysis operates on the layers. The tool reads the layer metadata and the filesystem content within each layer. It does not execute the image; it inspects the files. This makes it fast and reproducible. However, static analysis can miss dependencies that are downloaded at runtime or installed via non-standard paths. It also may include build-time dependencies that are not present in the final runtime image if the build process does not strip them.

Dynamic Analysis

Dynamic analysis monitors the running application to capture dependencies as they are loaded into memory. This method is essential for languages with complex runtime environments, such as Python or Java, where dependencies may be resolved lazily or via virtual environments. Tools like syft can also perform dynamic scanning by executing the binary or starting the container and observing the system calls.

Dynamic scanning is more accurate for runtime composition because it reflects the actual state of the application. It captures dependencies that are installed but not referenced in the manifest files, as well as those that are loaded from network locations. The downside is that dynamic scanning is slower and requires the application to be running or executable. It is also sensitive to the environment; if the runtime environment differs from the build environment, the dynamic SBOM may differ from the static one.

Image Inspection

Image inspection is a specialized form of static analysis tailored for container images. It leverages the container image format (OCI or Docker) to extract metadata efficiently. The tool reads the image manifest and the configuration JSON to determine the base image, the layers, and the entry point. It then scans each layer for package information.

Image inspection is highly efficient because it can skip layers that have not changed. It is particularly useful in CI/CD pipelines where incremental builds are common. The tool can compare the new SBOM with the previous one to identify changes, reducing the amount of data transferred and stored. This method is ideal for large-scale deployments where consistency and speed are critical.

Executing SBOM Generation

The most widely used command-line tool for SBOM generation is syft. It supports multiple input formats, including directories, container images, and tarballs. The output can be in SPDX JSON, CycloneDX JSON, or other supported formats.

To generate an SBOM for a local directory, run:

syft dir ./my-app --output spdx-json > sbom.json

To scan a container image from a registry:

syft ghcr.io/my-org/my-app:latest --output cyclonedx-json > sbom.json

To scan a local Docker image:

syft docker:my-local-image:tag --output spdx-json > sbom.json

The --output flag specifies the format. spdx-json is the default and is widely supported by vulnerability scanners. cyclonedx-json is preferred for DevSecOps workflows due to its rich metadata and support for complex relationships.

Configuring the Scan Scope

Controlling which components are included in the SBOM is crucial for reducing noise and improving accuracy. The syft tool provides several options to fine-tune the scan.

Excluding Paths

To exclude specific directories or files, use the --exclude flag. This is useful for ignoring test files, documentation, or build artifacts that are not part of the runtime.

syft dir ./my-app --exclude "./tests" --exclude "*.md"

Including Only Runtime Dependencies

By default, static analysis includes all dependencies found in the file system. To include only runtime dependencies, use the --scope flag.

syft dir ./my-app --scope all-layers

The all-layers scope includes dependencies from all layers. The squashed scope includes only dependencies from the final layer, which is useful for minimizing the SBOM size.

Cataloging Sources

The --cataloger flag allows you to specify the cataloging strategy. The default is to use all available catalogers. You can limit the catalogers to specific package types.

syft dir ./my-app --cataloger golang

This command limits the scan to Go modules, ignoring other package managers. This is useful when you want to focus on a specific language ecosystem.

Handling Common Failure Modes

SBOM generation is generally robust, but several failure modes can lead to inaccurate or incomplete bills of materials.

Missing Dependencies

Static analysis may miss dependencies that are installed via non-standard methods or located in non-standard paths. For example, Python packages installed via pip in a virtual environment may not be detected if the virtual environment is not in the standard location. To mitigate this, use dynamic analysis or specify the virtual environment path explicitly.

syft dir ./my-app --path /path/to/venv

Version Mismatches

Version strings can be inconsistent across different package managers. For example, npm uses semantic versioning with prefixes (e.g., ^1.2.3), while pip uses exact versions (e.g., 1.2.3). SBOM tools normalize these versions, but discrepancies can still occur. Always verify the version normalization settings for your specific use case.

Duplicate Entries

Duplicate entries can occur when the same package is present in multiple layers or when the same package is detected by multiple catalogers. SBOM tools deduplicate entries by default, but the deduplication logic may vary. Check the deduplication settings to ensure that duplicates are resolved correctly.

Integrating SBOMs into CI/CD

SBOMs are most valuable when integrated into the CI/CD pipeline. They can be generated as part of the build process and stored as artifacts. This allows for traceability from source code to deployment.

Storing SBOMs

SBOMs can be stored in the same registry as the container images. This ensures that the SBOM is always available alongside the image. Tools like syft can push the SBOM directly to the registry.

syft dir ./my-app --output spdx-json | docker push my-registry/my-app:sbom

Using SBOMs for Vulnerability Scanning

SBOMs are used by vulnerability scanners to identify known vulnerabilities in the dependencies. The scanner reads the SBOM and cross-references the dependencies with a vulnerability database. This process is faster and more accurate than scanning the entire file system.

SBOM Validation

Validate the SBOM to ensure it conforms to the specified schema. Most SBOM tools provide a validation command.

syft validate sbom.json --schema spdx-2.3

This command checks the SBOM for structural correctness and ensures that all required fields are present.

Summary

SBOM generation is a foundational practice for modern software supply chain security. By choosing the right generation strategy, configuring the scan scope, and handling common failure modes, you can produce accurate and comprehensive bills of materials. Integrating SBOMs into your CI/CD pipeline ensures that your software assets are always documented and ready for security audits and vulnerability management.

This page was rewritten on 26 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.