Skip to content

Conversation

@leodido
Copy link
Contributor

@leodido leodido commented Nov 21, 2025

Summary

This PR fixes SBOM generation for Docker packages when exportToCache: true is enabled. Previously, SBOM generation would fail because it tried to inspect the Docker daemon, but with OCI layout export, the image only exists as image.tar and is never loaded into the daemon.

Problem

When building Docker packages with OCI layout export enabled (exportToCache: true):

  • Docker image is exported to image.tar in OCI layout format
  • Image is NOT loaded into Docker daemon
  • SBOM generation fails with: "failed to get Docker image source for SBOM generation"

Solution

Modified pkg/leeway/sbom.go to:

  1. Detect when OCI layout export is enabled (cfg.ExportToCache == true)
  2. Use Syft's oci-archive source provider to scan the OCI archive directly
  3. Fall back to traditional Docker daemon scanning when OCI layout is not used

Testing

Added integration test TestDockerPackage_SBOM_OCI_Integration that verifies:

  • ✅ SBOM generation works with Docker daemon (regression test)
  • ✅ SBOM generation works with OCI layout (new functionality)
  • ✅ All three SBOM formats are generated (CycloneDX, SPDX, Syft)
  • ✅ SBOM files are valid JSON with expected structure

Test Results

=== RUN   TestDockerPackage_SBOM_OCI_Integration
=== RUN   TestDockerPackage_SBOM_OCI_Integration/sbom_with_docker_daemon
    ✅ Build succeeded with exportToCache=false
    ✅ All 3 SBOM formats generated successfully
=== RUN   TestDockerPackage_SBOM_OCI_Integration/sbom_with_oci_layout
    ✅ Build succeeded with exportToCache=true
    ✅ All 3 SBOM formats generated successfully
--- PASS: TestDockerPackage_SBOM_OCI_Integration (7.41s)

Files Changed

  • pkg/leeway/sbom.go - Added OCI layout detection and oci-archive source handling
  • pkg/leeway/build_integration_test.go - Added comprehensive integration test

Related

Checklist

  • Code compiles successfully
  • All existing unit tests pass
  • Integration test passes
  • No regression in traditional Docker builds
  • SBOM files generated correctly in both modes
  • Follows conventional commits spec
  • Backward compatible (no breaking changes)

@leodido leodido self-assigned this Nov 21, 2025
@leodido leodido force-pushed the ldd/fix-oci-container-extract branch from 44c5410 to 6add4dd Compare November 21, 2025 08:57
@leodido leodido force-pushed the ldd/sbom-oci-layout branch from 0c347c7 to 1843ce1 Compare November 21, 2025 08:58
@leodido leodido changed the base branch from ldd/fix-oci-container-extract to main November 21, 2025 09:15
leodido and others added 2 commits November 21, 2025 09:18
When exportToCache is enabled, Docker images are exported in OCI layout
format (image.tar) and never loaded into Docker daemon. SBOM generation
was failing because it tried to inspect the Docker daemon.

This fix detects OCI layout export and uses Syft's oci-archive source
provider to scan the image.tar directly, enabling SBOM generation for
all three formats (CycloneDX, SPDX, Syft) in SLSA L3 compliant builds.

Co-authored-by: Ona <no-reply@ona.com>
Add comprehensive integration test that verifies SBOM generation works
correctly for both Docker daemon and OCI layout export paths.

The test validates:
- Build succeeds without errors for both exportToCache modes
- All 3 SBOM formats are generated (CycloneDX, SPDX, Syft)
- SBOM files are valid JSON with expected structure
- Format-specific fields are present (bomFormat, spdxVersion)

Includes git repository initialization with fixed timestamps for
deterministic test results, following existing test patterns.

Co-authored-by: Ona <no-reply@ona.com>
@leodido leodido force-pushed the ldd/sbom-oci-layout branch from 1843ce1 to 372a050 Compare November 21, 2025 09:19
…ation

The test was failing in CI because it tried to run git commands without
first initializing a git repository. This adds the missing git init and
git config steps, following the same pattern as other integration tests.

Also adds GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM environment variables
to ensure tests work in CI environments where global git config might
not be available.

Fixes integration test failures in CI.

Co-authored-by: Ona <no-reply@ona.com>
Copy link
Member

@geropl geropl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test LGTM! ✔️

@leodido leodido merged commit c103fb2 into main Nov 23, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants