Skip to content

Commit f9fceb5

Browse files
fix(sbom): scan results of SBOMs generated from container images are missing layers (#7635)
Signed-off-by: Fabrizio Sestito <[email protected]> Co-authored-by: DmitriyLewen <[email protected]>
1 parent 4202c4b commit f9fceb5

File tree

4 files changed

+36
-29
lines changed

4 files changed

+36
-29
lines changed

integration/sbom_test.go

-5
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,6 @@ func overrideSBOMReport(t *testing.T, want, got *types.Report) {
186186
want.Metadata.ImageID = ""
187187
want.Metadata.ImageConfig = v1.ConfigFile{}
188188
want.Metadata.DiffIDs = nil
189-
for i, result := range want.Results {
190-
for j := range result.Vulnerabilities {
191-
want.Results[i].Vulnerabilities[j].Layer.DiffID = ""
192-
}
193-
}
194189

195190
// when running on Windows FS
196191
got.ArtifactName = filepath.ToSlash(filepath.Clean(got.ArtifactName))

integration/testdata/fluentd-multiple-lockfiles-short.cdx.json.golden

+24
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@
8080
"version": "5.0-4",
8181
"purl": "pkg:deb/debian/[email protected]?distro=debian-10.2",
8282
"properties": [
83+
{
84+
"name": "aquasecurity:trivy:LayerDiffID",
85+
"value": "sha256:831c5620387fb9efec59fc82a42b948546c6be601e3ab34a87108ecf852aa15f"
86+
},
87+
{
88+
"name": "aquasecurity:trivy:LayerDigest",
89+
"value": "sha256:000eee12ec04cc914bf96e8f5dee7767510c2aca3816af6078bd9fbe3150920c"
90+
},
8391
{
8492
"name": "aquasecurity:trivy:PkgID",
8593
"value": "[email protected]"
@@ -105,6 +113,14 @@
105113
"version": "2.0.5-1",
106114
"purl": "pkg:deb/debian/[email protected]?distro=debian-10.2",
107115
"properties": [
116+
{
117+
"name": "aquasecurity:trivy:LayerDiffID",
118+
"value": "sha256:831c5620387fb9efec59fc82a42b948546c6be601e3ab34a87108ecf852aa15f"
119+
},
120+
{
121+
"name": "aquasecurity:trivy:LayerDigest",
122+
"value": "sha256:000eee12ec04cc914bf96e8f5dee7767510c2aca3816af6078bd9fbe3150920c"
123+
},
108124
{
109125
"name": "aquasecurity:trivy:PkgID",
110126
"value": "[email protected]"
@@ -141,6 +157,14 @@
141157
"name": "aquasecurity:trivy:FilePath",
142158
"value": "var/lib/gems/2.5.0/specifications/activesupport-6.0.2.1.gemspec"
143159
},
160+
{
161+
"name": "aquasecurity:trivy:LayerDiffID",
162+
"value": "sha256:75e43d55939745950bc3f8fad56c5834617c4339f0f54755e69a0dd5372624e9"
163+
},
164+
{
165+
"name": "aquasecurity:trivy:LayerDigest",
166+
"value": "sha256:a8877cad19f14a7044524a145ce33170085441a7922458017db1631dcd5f7602"
167+
},
144168
{
145169
"name": "aquasecurity:trivy:PkgID",
146170
"value": "[email protected]"

integration/testdata/fluentd-multiple-lockfiles.json.golden

+12-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@
3636
},
3737
"InstalledVersion": "5.0-4",
3838
"Status": "affected",
39-
"Layer": {},
39+
"Layer": {
40+
"Digest": "sha256:000eee12ec04cc914bf96e8f5dee7767510c2aca3816af6078bd9fbe3150920c",
41+
"DiffID": "sha256:831c5620387fb9efec59fc82a42b948546c6be601e3ab34a87108ecf852aa15f"
42+
},
4043
"SeveritySource": "debian",
4144
"PrimaryURL": "https://avd.aquasec.com/nvd/cve-2019-18276",
4245
"DataSource": {
@@ -102,7 +105,10 @@
102105
"InstalledVersion": "2.0.5-1",
103106
"FixedVersion": "2.0.5-1+deb10u1",
104107
"Status": "fixed",
105-
"Layer": {},
108+
"Layer": {
109+
"Digest": "sha256:000eee12ec04cc914bf96e8f5dee7767510c2aca3816af6078bd9fbe3150920c",
110+
"DiffID": "sha256:831c5620387fb9efec59fc82a42b948546c6be601e3ab34a87108ecf852aa15f"
111+
},
106112
"SeveritySource": "nvd",
107113
"PrimaryURL": "https://avd.aquasec.com/nvd/cve-2019-18224",
108114
"DataSource": {
@@ -173,7 +179,10 @@
173179
"InstalledVersion": "6.0.2.1",
174180
"FixedVersion": "6.0.3.1, 5.2.4.3",
175181
"Status": "fixed",
176-
"Layer": {},
182+
"Layer": {
183+
"Digest": "sha256:a8877cad19f14a7044524a145ce33170085441a7922458017db1631dcd5f7602",
184+
"DiffID": "sha256:75e43d55939745950bc3f8fad56c5834617c4339f0f54755e69a0dd5372624e9"
185+
},
177186
"SeveritySource": "ghsa",
178187
"PrimaryURL": "https://avd.aquasec.com/nvd/cve-2020-8165",
179188
"DataSource": {

pkg/scanner/scan.go

-21
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,6 @@ func (s Scanner) ScanArtifact(ctx context.Context, options types.ScanOptions) (t
178178
ptros = nil
179179
}
180180

181-
// Layer makes sense only when scanning container images
182-
if artifactInfo.Type != artifact.TypeContainerImage {
183-
removeLayer(results)
184-
}
185-
186181
return types.Report{
187182
SchemaVersion: report.SchemaVersion,
188183
CreatedAt: clock.Now(ctx),
@@ -202,19 +197,3 @@ func (s Scanner) ScanArtifact(ctx context.Context, options types.ScanOptions) (t
202197
BOM: artifactInfo.BOM,
203198
}, nil
204199
}
205-
206-
func removeLayer(results types.Results) {
207-
for i := range results {
208-
result := results[i]
209-
210-
for j := range result.Packages {
211-
result.Packages[j].Layer = ftypes.Layer{}
212-
}
213-
for j := range result.Vulnerabilities {
214-
result.Vulnerabilities[j].Layer = ftypes.Layer{}
215-
}
216-
for j := range result.Misconfigurations {
217-
result.Misconfigurations[j].Layer = ftypes.Layer{}
218-
}
219-
}
220-
}

0 commit comments

Comments
 (0)