Skip to content

Commit a95cab0

Browse files
feat(image): save layers metadata into report (#8394)
Co-authored-by: knqyf263 <knqyf263@gmail.com>
1 parent 7abf5f0 commit a95cab0

File tree

71 files changed

+1970
-1066
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1970
-1066
lines changed

integration/integration_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ func readReport(t *testing.T, filePath string) types.Report {
153153
// We don't compare repo tags because the archive doesn't support it
154154
report.Metadata.RepoTags = nil
155155
report.Metadata.RepoDigests = nil
156+
for i := range report.Metadata.Layers {
157+
report.Metadata.Layers[i].Digest = ""
158+
}
156159

157160
for i, result := range report.Results {
158161
for j := range result.Vulnerabilities {

integration/sbom_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ func TestSBOM(t *testing.T) {
4747
want.Results[0].Vulnerabilities[0].PkgIdentifier.BOMRef = "pkg:rpm/centos/bash@4.2.46-31.el7?arch=x86_64&distro=centos-7.6.1810"
4848
want.Results[0].Vulnerabilities[1].PkgIdentifier.BOMRef = "pkg:rpm/centos/openssl-libs@1.0.2k-16.el7?arch=x86_64&epoch=1&distro=centos-7.6.1810"
4949
want.Results[0].Vulnerabilities[2].PkgIdentifier.BOMRef = "pkg:rpm/centos/openssl-libs@1.0.2k-16.el7?arch=x86_64&epoch=1&distro=centos-7.6.1810"
50+
51+
// SBOM file doesn't contain info about layers
52+
want.Metadata.Size = 0
53+
want.Metadata.Layers = nil
5054
},
5155
},
5256
{
@@ -96,6 +100,10 @@ func TestSBOM(t *testing.T) {
96100
want.Results[0].Vulnerabilities[0].PkgIdentifier.BOMRef = "pkg:rpm/centos/bash@4.2.46-31.el7?arch=x86_64&distro=centos-7.6.1810"
97101
want.Results[0].Vulnerabilities[1].PkgIdentifier.BOMRef = "pkg:rpm/centos/openssl-libs@1.0.2k-16.el7?arch=x86_64&epoch=1&distro=centos-7.6.1810"
98102
want.Results[0].Vulnerabilities[2].PkgIdentifier.BOMRef = "pkg:rpm/centos/openssl-libs@1.0.2k-16.el7?arch=x86_64&epoch=1&distro=centos-7.6.1810"
103+
104+
// SBOM file doesn't contain info about layers
105+
want.Metadata.Size = 0
106+
want.Metadata.Layers = nil
99107
},
100108
},
101109
{
@@ -112,6 +120,10 @@ func TestSBOM(t *testing.T) {
112120

113121
require.Len(t, got.Results, 1)
114122
want.Results[0].Target = "testdata/fixtures/sbom/centos-7-spdx.txt (centos 7.6.1810)"
123+
124+
// SBOM file doesn't contain info about layers
125+
want.Metadata.Size = 0
126+
want.Metadata.Layers = nil
115127
},
116128
},
117129
{
@@ -128,6 +140,10 @@ func TestSBOM(t *testing.T) {
128140

129141
require.Len(t, got.Results, 1)
130142
want.Results[0].Target = "testdata/fixtures/sbom/centos-7-spdx.json (centos 7.6.1810)"
143+
144+
// SBOM file doesn't contain info about layers
145+
want.Metadata.Size = 0
146+
want.Metadata.Layers = nil
131147
},
132148
},
133149
{

integration/testdata/almalinux-8.json.golden

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ArtifactName": "testdata/fixtures/images/almalinux-8.tar.gz",
55
"ArtifactType": "container_image",
66
"Metadata": {
7+
"Size": 204637184,
78
"OS": {
89
"Family": "alma",
910
"Name": "8.5"
@@ -44,7 +45,14 @@
4445
],
4546
"Image": "sha256:d38d2eac03bc19e080df596d6148863a0f8293f3a277a7524f378da79a1feb0f"
4647
}
47-
}
48+
},
49+
"Layers": [
50+
{
51+
"Size": 204637184,
52+
"Digest": "sha256:a1f18d9dc5496c63197eb9a4f1d4bf5cc88c6a34f64f0fe11ea233070392ce48",
53+
"DiffID": "sha256:124d41c237c5e823577dda97e87cebaecce62d585c725d07e709ce410681de4d"
54+
}
55+
]
4856
},
4957
"Results": [
5058
{

integration/testdata/alpine-310.json.golden

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ArtifactName": "testdata/fixtures/images/alpine-310.tar.gz",
55
"ArtifactType": "container_image",
66
"Metadata": {
7+
"Size": 5843968,
78
"OS": {
89
"Family": "alpine",
910
"Name": "3.10.2",
@@ -46,7 +47,14 @@
4647
"Image": "sha256:06f4121dff4d0123ce11bd2e44f48da9ba9ddcd23ae376ea1f363f63ea0849b5",
4748
"ArgsEscaped": true
4849
}
49-
}
50+
},
51+
"Layers": [
52+
{
53+
"Size": 5843968,
54+
"Digest": "sha256:9d48c3bd43c520dc2784e868a780e976b207cbf493eaff8c6596eb871cbd9609",
55+
"DiffID": "sha256:03901b4a2ea88eeaad62dbe59b072b28b6efa00491962b8741081c5df50c65e0"
56+
}
57+
]
5058
},
5159
"Results": [
5260
{

integration/testdata/alpine-39-high-critical.json.golden

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ArtifactName": "testdata/fixtures/images/alpine-39.tar.gz",
55
"ArtifactType": "container_image",
66
"Metadata": {
7+
"Size": 5796352,
78
"OS": {
89
"Family": "alpine",
910
"Name": "3.9.4",
@@ -46,7 +47,14 @@
4647
"Image": "sha256:09f2bbe58e774849d74dc1391c2e01731896c745c4aba1ecf69a283bdb4b537a",
4748
"ArgsEscaped": true
4849
}
49-
}
50+
},
51+
"Layers": [
52+
{
53+
"Size": 5796352,
54+
"Digest": "sha256:e7c96db7181be991f19a9fb6975cdbbd73c65f4a2681348e63a141a2192a5f10",
55+
"DiffID": "sha256:f1b5933fe4b5f49bbe8258745cf396afe07e625bdab3168e364daf7c956b6b81"
56+
}
57+
]
5058
},
5159
"Results": [
5260
{

integration/testdata/alpine-39-ignore-cveids.json.golden

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ArtifactName": "testdata/fixtures/images/alpine-39.tar.gz",
55
"ArtifactType": "container_image",
66
"Metadata": {
7+
"Size": 5796352,
78
"OS": {
89
"Family": "alpine",
910
"Name": "3.9.4",
@@ -46,7 +47,14 @@
4647
"Image": "sha256:09f2bbe58e774849d74dc1391c2e01731896c745c4aba1ecf69a283bdb4b537a",
4748
"ArgsEscaped": true
4849
}
49-
}
50+
},
51+
"Layers": [
52+
{
53+
"Size": 5796352,
54+
"Digest": "sha256:e7c96db7181be991f19a9fb6975cdbbd73c65f4a2681348e63a141a2192a5f10",
55+
"DiffID": "sha256:f1b5933fe4b5f49bbe8258745cf396afe07e625bdab3168e364daf7c956b6b81"
56+
}
57+
]
5058
},
5159
"Results": [
5260
{

integration/testdata/alpine-39-skip.json.golden

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ArtifactName": "testdata/fixtures/images/alpine-39.tar.gz",
55
"ArtifactType": "container_image",
66
"Metadata": {
7+
"Size": 5796352,
78
"OS": {
89
"Family": "none",
910
"Name": ""
@@ -45,6 +46,13 @@
4546
"Image": "sha256:09f2bbe58e774849d74dc1391c2e01731896c745c4aba1ecf69a283bdb4b537a",
4647
"ArgsEscaped": true
4748
}
48-
}
49+
},
50+
"Layers": [
51+
{
52+
"Size": 5796352,
53+
"Digest": "sha256:e7c96db7181be991f19a9fb6975cdbbd73c65f4a2681348e63a141a2192a5f10",
54+
"DiffID": "sha256:f1b5933fe4b5f49bbe8258745cf396afe07e625bdab3168e364daf7c956b6b81"
55+
}
56+
]
4957
}
5058
}

integration/testdata/alpine-39.json.golden

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ArtifactName": "testdata/fixtures/images/alpine-39.tar.gz",
55
"ArtifactType": "container_image",
66
"Metadata": {
7+
"Size": 5796352,
78
"OS": {
89
"Family": "alpine",
910
"Name": "3.9.4",
@@ -46,7 +47,14 @@
4647
"Image": "sha256:09f2bbe58e774849d74dc1391c2e01731896c745c4aba1ecf69a283bdb4b537a",
4748
"ArgsEscaped": true
4849
}
49-
}
50+
},
51+
"Layers": [
52+
{
53+
"Size": 5796352,
54+
"Digest": "sha256:e7c96db7181be991f19a9fb6975cdbbd73c65f4a2681348e63a141a2192a5f10",
55+
"DiffID": "sha256:f1b5933fe4b5f49bbe8258745cf396afe07e625bdab3168e364daf7c956b6b81"
56+
}
57+
]
5058
},
5159
"Results": [
5260
{

integration/testdata/alpine-distroless.json.golden

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ArtifactName": "testdata/fixtures/images/alpine-distroless.tar.gz",
55
"ArtifactType": "container_image",
66
"Metadata": {
7+
"Size": 35812864,
78
"OS": {
89
"Family": "alpine",
910
"Name": "3.16"
@@ -41,7 +42,14 @@
4142
],
4243
"User": "65532"
4344
}
44-
}
45+
},
46+
"Layers": [
47+
{
48+
"Size": 35812864,
49+
"Digest": "sha256:6c6f69aa25501b090c54c62a9c17e978064c2f1328f67a7ef88c81ce5f2d7983",
50+
"DiffID": "sha256:89da7cc836da4b53ab1ceb572576458c005e7e444b8bb79abda196668a2f0c92"
51+
}
52+
]
4553
},
4654
"Results": [
4755
{

integration/testdata/amazon-1.json.golden

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ArtifactName": "testdata/fixtures/images/amazon-1.tar.gz",
55
"ArtifactType": "container_image",
66
"Metadata": {
7+
"Size": 172655616,
78
"OS": {
89
"Family": "amazon",
910
"Name": "AMI release 2018.03"
@@ -45,7 +46,14 @@
4546
"Image": "sha256:8db654f611aca1693ac658bd981ee35e4b6517e6ef74fa608c4b3b3595a986c8",
4647
"ArgsEscaped": true
4748
}
48-
}
49+
},
50+
"Layers": [
51+
{
52+
"Size": 172655616,
53+
"Digest": "sha256:105ff6bf468b1422ad7c47ea9d63eae82f875c93310cb8d34551951e754ef43b",
54+
"DiffID": "sha256:984fe1509738f6f00f34d9be7398b07ebeb8b98dda077ff6be2cdb87111b73cf"
55+
}
56+
]
4957
},
5058
"Results": [
5159
{

integration/testdata/amazon-2.json.golden

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ArtifactName": "testdata/fixtures/images/amazon-2.tar.gz",
55
"ArtifactType": "container_image",
66
"Metadata": {
7+
"Size": 168852480,
78
"OS": {
89
"Family": "amazon",
910
"Name": "2 (Karoo)"
@@ -45,7 +46,14 @@
4546
"Image": "sha256:648b8b37f8b5087423bec7f4331271253f8aff63154761a67c22cd0c3ba2661b",
4647
"ArgsEscaped": true
4748
}
48-
}
49+
},
50+
"Layers": [
51+
{
52+
"Size": 168852480,
53+
"Digest": "sha256:72d97abdfae3b3c933ff41e39779cc72853d7bd9dc1e4800c5294d6715257799",
54+
"DiffID": "sha256:f387c8b346c85cae37abd1f1a63015acb69f593dc425d0269f57d1012c3a81f6"
55+
}
56+
]
4957
},
5058
"Results": [
5159
{

integration/testdata/busybox-with-lockfile.json.golden

+14-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ArtifactName": "testdata/fixtures/images/busybox-with-lockfile.tar.gz",
55
"ArtifactType": "container_image",
66
"Metadata": {
7+
"Size": 1491456,
78
"ImageID": "sha256:88702f6b6133bf06cc46af48437d0c0fc661239155548757c65916504a0e5eee",
89
"DiffIDs": [
910
"sha256:797ac4999b67d8c38a596919efa5b7b6a4a8fd5814cb8564efa482c5d8403e6d",
@@ -45,7 +46,19 @@
4546
],
4647
"Image": "sha256:2fb6fc2d97e10c79983aa10e013824cc7fc8bae50630e32159821197dda95fe3"
4748
}
48-
}
49+
},
50+
"Layers": [
51+
{
52+
"Size": 1459200,
53+
"Digest": "sha256:554879bb300427c7301c1cbdf266a7eba24a85b10d19f270b3d348b9eb9ca7df",
54+
"DiffID": "sha256:797ac4999b67d8c38a596919efa5b7b6a4a8fd5814cb8564efa482c5d8403e6d"
55+
},
56+
{
57+
"Size": 32256,
58+
"Digest": "sha256:fd2e3bc9bccc9c677572a542d020998389de94f127ca2c252ae627fc7c241cee",
59+
"DiffID": "sha256:ea6f6933da66090da8bfe233d68f083792a68f944cd2d8f9fbb52da795813a4f"
60+
}
61+
]
4962
},
5063
"Results": [
5164
{

integration/testdata/centos-6.json.golden

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ArtifactName": "testdata/fixtures/images/centos-6.tar.gz",
55
"ArtifactType": "container_image",
66
"Metadata": {
7+
"Size": 201540608,
78
"OS": {
89
"Family": "centos",
910
"Name": "6.10",
@@ -67,7 +68,14 @@
6768
"org.label-schema.vendor": "CentOS"
6869
}
6970
}
70-
}
71+
},
72+
"Layers": [
73+
{
74+
"Size": 201540608,
75+
"Digest": "sha256:ff50d722b38227ec8f2bbf0cdbce428b66745077c173d8117d91376128fa532e",
76+
"DiffID": "sha256:af6bf1987c2eb07d73f33836b0d8fd825d7c785273526b077e46780e8b4b2ae9"
77+
}
78+
]
7179
},
7280
"Results": [
7381
{

integration/testdata/centos-7-ignore-unfixed.json.golden

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ArtifactName": "testdata/fixtures/images/centos-7.tar.gz",
55
"ArtifactType": "container_image",
66
"Metadata": {
7+
"Size": 209451008,
78
"OS": {
89
"Family": "centos",
910
"Name": "7.6.1810"
@@ -57,7 +58,14 @@
5758
},
5859
"ArgsEscaped": true
5960
}
60-
}
61+
},
62+
"Layers": [
63+
{
64+
"Size": 209451008,
65+
"Digest": "sha256:ac9208207adaac3a48e54a4dc6b49c69e78c3072d2b3add7efdabf814db2133b",
66+
"DiffID": "sha256:89169d87dbe2b72ba42bfbb3579c957322baca28e03a1e558076542a1c1b2b4a"
67+
}
68+
]
6169
},
6270
"Results": [
6371
{

integration/testdata/centos-7-medium.json.golden

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ArtifactName": "testdata/fixtures/images/centos-7.tar.gz",
55
"ArtifactType": "container_image",
66
"Metadata": {
7+
"Size": 209451008,
78
"OS": {
89
"Family": "centos",
910
"Name": "7.6.1810"
@@ -57,7 +58,14 @@
5758
},
5859
"ArgsEscaped": true
5960
}
60-
}
61+
},
62+
"Layers": [
63+
{
64+
"Size": 209451008,
65+
"Digest": "sha256:ac9208207adaac3a48e54a4dc6b49c69e78c3072d2b3add7efdabf814db2133b",
66+
"DiffID": "sha256:89169d87dbe2b72ba42bfbb3579c957322baca28e03a1e558076542a1c1b2b4a"
67+
}
68+
]
6169
},
6270
"Results": [
6371
{

integration/testdata/centos-7.json.golden

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"ArtifactName": "testdata/fixtures/images/centos-7.tar.gz",
55
"ArtifactType": "container_image",
66
"Metadata": {
7+
"Size": 209451008,
78
"OS": {
89
"Family": "centos",
910
"Name": "7.6.1810"
@@ -57,7 +58,14 @@
5758
},
5859
"ArgsEscaped": true
5960
}
60-
}
61+
},
62+
"Layers": [
63+
{
64+
"Size": 209451008,
65+
"Digest": "sha256:ac9208207adaac3a48e54a4dc6b49c69e78c3072d2b3add7efdabf814db2133b",
66+
"DiffID": "sha256:89169d87dbe2b72ba42bfbb3579c957322baca28e03a1e558076542a1c1b2b4a"
67+
}
68+
]
6169
},
6270
"Results": [
6371
{

0 commit comments

Comments
 (0)