Skip to content

Commit 4ee4883

Browse files
leodidoona-agent
andcommitted
fix: respect Docker export mode in SBOM generation
SBOM generation was not checking the LEEWAY_DOCKER_EXPORT_TO_CACHE environment variable, causing it to always use the Docker daemon path even when SLSA was enabled and images were exported as OCI layout. The issue: buildDocker() calls determineDockerExportMode() which checks the environment variable and CLI flags, but writeSBOM() only checked p.Config.ExportToCache (which is nil when not explicitly set in BUILD.yaml). This fix makes writeSBOM() use the same precedence logic: 1. Package config (if explicitly set) 2. Environment variable (LEEWAY_DOCKER_EXPORT_TO_CACHE) 3. CLI flag (--docker-export-to-cache) Additionally, for the Docker daemon path, explicitly configure syft to use the 'docker' source provider to avoid ambiguity when the image tag is a content hash. Fixes the CI failure in gitpod-next PR #11869 where SLSA is enabled via workflow but SBOM generation was trying to scan from Docker daemon instead of the OCI layout. Co-authored-by: Ona <[email protected]>
1 parent 9a7c4df commit 4ee4883

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

pkg/leeway/sbom.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,25 @@ func writeSBOM(buildctx *buildContext, p *Package, builddir string) (err error)
240240
return xerrors.Errorf("package should have Docker config")
241241
}
242242

243+
// Determine if OCI export is enabled using the same logic as buildDocker
244+
// Check: package config > environment variable > default
245+
exportToCache := false
246+
if cfg.ExportToCache != nil {
247+
// Package explicitly sets exportToCache
248+
exportToCache = *cfg.ExportToCache
249+
} else {
250+
// Check environment variable (set by SLSA or user)
251+
envExport := os.Getenv(EnvvarDockerExportToCache)
252+
exportToCache = (envExport == "true" || envExport == "1")
253+
}
254+
255+
// Override with CLI flag if set
256+
if buildctx.DockerExportSet {
257+
exportToCache = buildctx.DockerExportToCache
258+
}
259+
243260
// Check if OCI layout export is enabled
244-
if cfg.ExportToCache != nil && *cfg.ExportToCache {
261+
if exportToCache {
245262
// OCI layout path - scan from oci-archive
246263
buildctx.Reporter.PackageBuildLog(p, false, []byte("Generating SBOM from OCI layout\n"))
247264

@@ -266,7 +283,10 @@ func writeSBOM(buildctx *buildContext, p *Package, builddir string) (err error)
266283
return xerrors.Errorf("failed to get package version: %w", err)
267284
}
268285

269-
src, err = syft.GetSource(context.Background(), version, nil)
286+
// Use explicit source provider configuration to ensure docker daemon is used
287+
// The version is a content hash that exists as a tag in the local Docker daemon
288+
srcCfg := syft.DefaultGetSourceConfig().WithSources("docker")
289+
src, err = syft.GetSource(context.Background(), version, srcCfg)
270290
if err != nil {
271291
return xerrors.Errorf("failed to get Docker image source for SBOM generation: %w", err)
272292
}

0 commit comments

Comments
 (0)