Skip to content

Commit 599e0ac

Browse files
fix: Trivy fails with "invalid tar header" when scanning Copa-patched images (#1359)
Signed-off-by: robert-cronin <robert.owen.cronin@gmail.com>
1 parent b742077 commit 599e0ac

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pkg/patch/build.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import (
1515
sourcepolicy "github.com/moby/buildkit/sourcepolicy/pb"
1616
)
1717

18+
const (
19+
attrValueTrue = "true"
20+
)
21+
1822
// BuildConfig holds configuration for building and exporting images.
1923
type BuildConfig struct {
2024
SolveOpt client.SolveOpt
@@ -45,18 +49,23 @@ func createBuildConfig(
4549
"annotation." + copaAnnotationKeyPrefix + ".image.patched": time.Now().UTC().Format(time.RFC3339),
4650
}
4751
if shouldExportOCI {
48-
attrs["oci-mediatypes"] = "true"
52+
attrs["oci-mediatypes"] = attrValueTrue
4953
}
5054

5155
if push {
52-
attrs["push"] = "true"
56+
attrs["push"] = attrValueTrue
5357
solveOpt.Exports = []client.ExportEntry{
5458
{
5559
Type: client.ExporterImage,
5660
Attrs: attrs,
5761
},
5862
}
5963
} else {
64+
// Use uncompressed layers for local export to ensure diff_id == blob digest
65+
// This fixes Trivy scanning issues where compressed layers have mismatched hashes
66+
attrs["compression"] = "uncompressed"
67+
attrs["force-compression"] = attrValueTrue
68+
6069
solveOpt.Exports = []client.ExportEntry{
6170
{
6271
Type: client.ExporterDocker,

0 commit comments

Comments
 (0)