fix: extract digest from OCI layout for SLSA provenance #289
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When
exportToCache: trueis enabled, Docker images are exported as OCI layout and not loaded into the Docker daemon. This causesdocker inspectto fail when generating SLSA provenance subjects.Error in CI:
Root cause:
docker buildx build --output type=oci,dest=image.tar✅createDockerSubjectsFunctioncallsdocker inspect <version>❌Why Wasn't This Caught?
The integration test
TestDockerPackage_OCILayout_Determinism_Integrationdoesn't enable SLSA, so theSubjectsfunction is never called during testing. The bug only manifests when:exportToCache: true(OCI layout)Solution
Extract the image digest from OCI layout files instead of using
docker inspect.Design Decision: Separate Functions
Instead of one function with conditional logic, we now have two separate functions:
createDockerInspectSubjectsFunction()- Legacy push workflowdocker inspectto get digestexportToCache: falsecreateOCILayoutSubjectsFunction()- OCI layout exportexportToCache: trueWhy separate functions?
Changes
New function:
extractDigestFromOCILayout()index.jsonfrom OCI layout directoryNew function:
createDockerInspectSubjectsFunction()docker inspect(unchanged behavior)New function:
createOCILayoutSubjectsFunction()image.tarto temporary directoryextractDigestFromOCILayout()to get digestUpdated call sites:
createDockerInspectSubjectsFunction(version, cfg)PostProcesswithbuildDiravailableOCI Layout Structure
Digest extraction:
Testing
Unit Tests (10 tests)
New file:
pkg/leeway/build_oci_test.go1. extractDigestFromOCILayout() - 6 tests
2. createOCILayoutSubjectsFunction() - 2 tests
3. createDockerInspectSubjectsFunction() - 1 test
4. Behavior documentation - 1 test
Integration Test (1 test)
New test:
TestDockerPackage_OCILayout_SLSA_IntegrationTests the full workflow:
exportToCache: trueand SLSA enableddocker inspecterrorTest Coverage Summary
✅ Both code paths tested:
✅ Both SLSA scenarios tested:
✅ All edge cases covered:
Backward Compatibility
Impact
Enables:
Related