Skip to content

Commit 63cfb27

Browse files
AliDatadoglebauce
andauthored
fix(vuln): report architecture for apk packages (#4247)
Co-authored-by: Sylvain Baubeau <[email protected]>
1 parent e136136 commit 63cfb27

File tree

12 files changed

+133
-28
lines changed

12 files changed

+133
-28
lines changed

integration/testdata/alpine-310-registry.json.golden

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"SchemaVersion": 2,
3-
"ArtifactName": "localhost:32839/alpine:3.10",
3+
"ArtifactName": "localhost:55844/alpine:3.10",
44
"ArtifactType": "container_image",
55
"Metadata": {
66
"OS": {
@@ -13,10 +13,10 @@
1313
"sha256:03901b4a2ea88eeaad62dbe59b072b28b6efa00491962b8741081c5df50c65e0"
1414
],
1515
"RepoTags": [
16-
"localhost:32839/alpine:3.10"
16+
"localhost:55844/alpine:3.10"
1717
],
1818
"RepoDigests": [
19-
"localhost:32839/alpine@sha256:b1c5a500182b21d0bfa5a584a8526b56d8be316f89e87d951be04abed2446e60"
19+
"localhost:55844/alpine@sha256:b1c5a500182b21d0bfa5a584a8526b56d8be316f89e87d951be04abed2446e60"
2020
],
2121
"ImageConfig": {
2222
"architecture": "amd64",
@@ -55,7 +55,7 @@
5555
},
5656
"Results": [
5757
{
58-
"Target": "localhost:32839/alpine:3.10 (alpine 3.10.2)",
58+
"Target": "localhost:55844/alpine:3.10 (alpine 3.10.2)",
5959
"Class": "os-pkgs",
6060
"Type": "alpine",
6161
"Vulnerabilities": [

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"specVersion": "1.4",
44
"version": 1,
55
"metadata": {
6-
"timestamp": "2023-05-15T09:50:02+00:00",
6+
"timestamp": "2023-05-19T10:38:43+00:00",
77
"tools": [
88
{
99
"vendor": "aquasecurity",

integration/testdata/conda-cyclonedx.json.golden

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"bomFormat": "CycloneDX",
33
"specVersion": "1.4",
4-
"serialNumber": "urn:uuid:c283a9bb-93f1-49fb-9605-110b5f005a74",
4+
"serialNumber": "urn:uuid:e1f49b6f-018f-4bf3-97c8-85cd92a82c7c",
55
"version": 1,
66
"metadata": {
7-
"timestamp": "2023-05-15T09:49:59+00:00",
7+
"timestamp": "2023-05-19T10:38:39+00:00",
88
"tools": [
99
{
1010
"vendor": "aquasecurity",
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"component": {
16-
"bom-ref": "6497c0eb-7ca3-401e-b1f6-29234b2ec32c",
16+
"bom-ref": "cd0ebb00-5c53-4b82-a3f7-271add663c51",
1717
"type": "application",
1818
"name": "testdata/fixtures/fs/conda",
1919
"properties": [
@@ -26,53 +26,53 @@
2626
},
2727
"components": [
2828
{
29-
"bom-ref": "pkg:conda/[email protected]?file_path=miniconda3%2Fenvs%2Ftestenv%2Fconda-meta%2Fopenssl-1.1.1q-h7f8727e_0.json",
29+
"bom-ref": "pkg:conda/[email protected]?file_path=miniconda3%2Fenvs%2Ftestenv%2Fconda-meta%2Fpip-22.2.2-py38h06a4308_0.json",
3030
"type": "library",
31-
"name": "openssl",
32-
"version": "1.1.1q",
31+
"name": "pip",
32+
"version": "22.2.2",
3333
"licenses": [
3434
{
35-
"expression": "OpenSSL"
35+
"expression": "MIT"
3636
}
3737
],
38-
"purl": "pkg:conda/[email protected]",
38+
"purl": "pkg:conda/[email protected]",
3939
"properties": [
4040
{
4141
"name": "aquasecurity:trivy:PkgType",
4242
"value": "conda-pkg"
4343
},
4444
{
4545
"name": "aquasecurity:trivy:FilePath",
46-
"value": "miniconda3/envs/testenv/conda-meta/openssl-1.1.1q-h7f8727e_0.json"
46+
"value": "miniconda3/envs/testenv/conda-meta/pip-22.2.2-py38h06a4308_0.json"
4747
}
4848
]
4949
},
5050
{
51-
"bom-ref": "pkg:conda/[email protected]?file_path=miniconda3%2Fenvs%2Ftestenv%2Fconda-meta%2Fpip-22.2.2-py38h06a4308_0.json",
51+
"bom-ref": "pkg:conda/[email protected]?file_path=miniconda3%2Fenvs%2Ftestenv%2Fconda-meta%2Fopenssl-1.1.1q-h7f8727e_0.json",
5252
"type": "library",
53-
"name": "pip",
54-
"version": "22.2.2",
53+
"name": "openssl",
54+
"version": "1.1.1q",
5555
"licenses": [
5656
{
57-
"expression": "MIT"
57+
"expression": "OpenSSL"
5858
}
5959
],
60-
"purl": "pkg:conda/[email protected]",
60+
"purl": "pkg:conda/[email protected]",
6161
"properties": [
6262
{
6363
"name": "aquasecurity:trivy:PkgType",
6464
"value": "conda-pkg"
6565
},
6666
{
6767
"name": "aquasecurity:trivy:FilePath",
68-
"value": "miniconda3/envs/testenv/conda-meta/pip-22.2.2-py38h06a4308_0.json"
68+
"value": "miniconda3/envs/testenv/conda-meta/openssl-1.1.1q-h7f8727e_0.json"
6969
}
7070
]
7171
}
7272
],
7373
"dependencies": [
7474
{
75-
"ref": "6497c0eb-7ca3-401e-b1f6-29234b2ec32c",
75+
"ref": "cd0ebb00-5c53-4b82-a3f7-271add663c51",
7676
"dependsOn": [
7777
"pkg:conda/[email protected]?file_path=miniconda3%2Fenvs%2Ftestenv%2Fconda-meta%2Fopenssl-1.1.1q-h7f8727e_0.json",
7878
"pkg:conda/[email protected]?file_path=miniconda3%2Fenvs%2Ftestenv%2Fconda-meta%2Fpip-22.2.2-py38h06a4308_0.json"

integration/testdata/conda-spdx.json.golden

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
"dataLicense": "CC0-1.0",
44
"SPDXID": "SPDXRef-DOCUMENT",
55
"name": "testdata/fixtures/fs/conda",
6-
"documentNamespace": "http://aquasecurity.github.io/trivy/filesystem/testdata/fixtures/fs/conda-f50748fc-93cb-48c4-87c5-25a03e4ddb00",
6+
"documentNamespace": "http://aquasecurity.github.io/trivy/filesystem/testdata/fixtures/fs/conda-e854267f-30a6-497d-9183-2f45dee37b09",
77
"creationInfo": {
88
"licenseListVersion": "",
99
"creators": [
1010
"Organization: aquasecurity",
1111
"Tool: trivy-dev"
1212
],
13-
"created": "2023-05-16T05:26:41Z"
13+
"created": "2023-05-19T10:38:39Z"
1414
},
1515
"packages": [
1616
{

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"specVersion": "1.4",
44
"version": 1,
55
"metadata": {
6-
"timestamp": "2023-05-15T09:50:02+00:00",
6+
"timestamp": "2023-05-19T10:38:42+00:00",
77
"tools": [
88
{
99
"vendor": "aquasecurity",

pkg/fanal/analyzer/analyzer_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ func TestAnalyzerGroup_AnalyzeFile(t *testing.T) {
344344
SrcName: "musl",
345345
SrcVersion: "1.1.24-r2",
346346
Licenses: []string{"MIT"},
347+
Arch: "x86_64",
347348
Digest: "sha1:cb2316a189ebee5282c4a9bd98794cc2477a74c6",
348349
},
349350
},

pkg/fanal/analyzer/pkg/apk/apk.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ func (a alpinePkgAnalyzer) parseApkInfo(scanner *bufio.Scanner) ([]types.Package
9494
a.parseProvides(line, pkg.ID, provides)
9595
case "D:": // dependencies (corresponds to depend in PKGINFO, concatenated by spaces into a single line)
9696
pkg.DependsOn = a.parseDependencies(line)
97+
case "A:":
98+
pkg.Arch = line[2:]
9799
case "C:":
98100
d := decodeChecksumLine(line)
99101
if d != "" {

pkg/fanal/analyzer/pkg/apk/apk_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func TestParseApkInfo(t *testing.T) {
2626
SrcName: "musl",
2727
SrcVersion: "1.1.14-r10",
2828
Licenses: []string{"MIT"},
29+
Arch: "x86_64",
2930
Digest: "sha1:d68b402f35f57750f49156b0cb4e886a2ad35d2d",
3031
},
3132
{
@@ -36,6 +37,7 @@ func TestParseApkInfo(t *testing.T) {
3637
SrcVersion: "1.24.2-r9",
3738
Licenses: []string{"GPL-2.0"},
3839
DependsOn: []string{"[email protected]"},
40+
Arch: "x86_64",
3941
Digest: "sha1:ca124719267cd0bedc2f4cb850a286ac13f0ad44",
4042
},
4143
{
@@ -46,6 +48,7 @@ func TestParseApkInfo(t *testing.T) {
4648
SrcVersion: "3.0.3-r0",
4749
Licenses: []string{"GPL-2.0"},
4850
DependsOn: []string{"[email protected]", "[email protected]"},
51+
Arch: "x86_64",
4952
Digest: "sha1:a214896150411d72dd1fafdb32d1c6c4855cccfa",
5053
},
5154
{
@@ -55,6 +58,7 @@ func TestParseApkInfo(t *testing.T) {
5558
SrcName: "alpine-keys",
5659
SrcVersion: "1.1-r0",
5760
Licenses: []string{"GPL-3.0"},
61+
Arch: "x86_64",
5862
Digest: "sha1:4def7ffaee6aeba700c1d62570326f75cbb8fa25",
5963
},
6064
{
@@ -65,6 +69,7 @@ func TestParseApkInfo(t *testing.T) {
6569
SrcVersion: "1.2.8-r2",
6670
Licenses: []string{"Zlib"},
6771
DependsOn: []string{"[email protected]"},
72+
Arch: "x86_64",
6873
Digest: "sha1:efd04d34d40aa8eb331480127364c27a8ba760ef",
6974
},
7075
{
@@ -75,6 +80,7 @@ func TestParseApkInfo(t *testing.T) {
7580
SrcVersion: "1.0.2h-r1",
7681
Licenses: []string{"openssl"},
7782
DependsOn: []string{"[email protected]", "[email protected]"},
83+
Arch: "x86_64",
7884
Digest: "sha1:65c860ff8f103b664f40ba849a3f5a51c69c8beb",
7985
},
8086
{
@@ -89,6 +95,7 @@ func TestParseApkInfo(t *testing.T) {
8995
9096
9197
},
98+
Arch: "x86_64",
9299
},
93100
{
94101
@@ -104,6 +111,7 @@ func TestParseApkInfo(t *testing.T) {
104111
105112
106113
},
114+
Arch: "x86_64",
107115
},
108116
{
109117
@@ -114,6 +122,7 @@ func TestParseApkInfo(t *testing.T) {
114122
Licenses: []string{"GPL-2.0"},
115123
Digest: "sha1:f9bab817c5ad93e92a6218bc0f7596b657c02d90",
116124
DependsOn: []string{"[email protected]"},
125+
Arch: "x86_64",
117126
},
118127
{
119128
@@ -127,6 +136,7 @@ func TestParseApkInfo(t *testing.T) {
127136
128137
129138
},
139+
Arch: "x86_64",
130140
},
131141
{
132142
@@ -137,6 +147,7 @@ func TestParseApkInfo(t *testing.T) {
137147
Licenses: []string{"GPL-3.0"},
138148
Digest: "sha1:9055bc7afd76cf2672198042f72fc4a5ed4fa961",
139149
DependsOn: []string{"[email protected]"},
150+
Arch: "x86_64",
140151
},
141152
{
142153
@@ -147,6 +158,7 @@ func TestParseApkInfo(t *testing.T) {
147158
Licenses: []string{"ISC"},
148159
Digest: "sha1:e6242ac29589c8a84a4b179b491ea7c29fce66a9",
149160
DependsOn: []string{"[email protected]"},
161+
Arch: "x86_64",
150162
},
151163

152164
{
@@ -158,6 +170,7 @@ func TestParseApkInfo(t *testing.T) {
158170
Licenses: []string{"Public-Domain"},
159171
Digest: "sha1:1464946c3a5f0dd5a67ca1af930fc17af7a74474",
160172
DependsOn: []string{"[email protected]"},
173+
Arch: "x86_64",
161174
},
162175

163176
{
@@ -172,6 +185,7 @@ func TestParseApkInfo(t *testing.T) {
172185
173186
174187
},
188+
Arch: "x86_64",
175189
},
176190
},
177191
wantFiles: []string{

pkg/fanal/artifact/image/image_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func TestArtifact_Inspect(t *testing.T) {
4646
4747
4848
},
49+
Arch: "x86_64",
4950
},
5051
{
5152
@@ -54,6 +55,7 @@ func TestArtifact_Inspect(t *testing.T) {
5455
SrcName: "alpine-keys",
5556
SrcVersion: "2.1-r2",
5657
Licenses: []string{"MIT"},
58+
Arch: "x86_64",
5759
Digest: "sha1:64929f85b7f8b4adbb664d905410312936b79d9b",
5860
},
5961
{
@@ -70,6 +72,7 @@ func TestArtifact_Inspect(t *testing.T) {
7072
7173
7274
},
75+
Arch: "x86_64",
7376
},
7477
{
7578
@@ -82,6 +85,7 @@ func TestArtifact_Inspect(t *testing.T) {
8285
DependsOn: []string{
8386
8487
},
88+
Arch: "x86_64",
8589
},
8690
{
8791
ID: "ca-certificates-cacert@20191127-r1",
@@ -93,6 +97,7 @@ func TestArtifact_Inspect(t *testing.T) {
9397
"MPL-2.0",
9498
"GPL-2.0",
9599
},
100+
Arch: "x86_64",
96101
Digest: "sha1:3aeb8a90d7179d2a187782e980a964494e08c5fb",
97102
},
98103
{
@@ -106,6 +111,7 @@ func TestArtifact_Inspect(t *testing.T) {
106111
DependsOn: []string{
107112
108113
},
114+
Arch: "x86_64",
109115
},
110116
{
111117
@@ -118,6 +124,7 @@ func TestArtifact_Inspect(t *testing.T) {
118124
DependsOn: []string{
119125
120126
},
127+
Arch: "x86_64",
121128
},
122129
{
123130
@@ -131,6 +138,7 @@ func TestArtifact_Inspect(t *testing.T) {
131138
132139
133140
},
141+
Arch: "x86_64",
134142
},
135143
{
136144
@@ -146,6 +154,7 @@ func TestArtifact_Inspect(t *testing.T) {
146154
147155
148156
},
157+
Arch: "x86_64",
149158
},
150159
{
151160
@@ -154,6 +163,7 @@ func TestArtifact_Inspect(t *testing.T) {
154163
SrcName: "musl",
155164
SrcVersion: "1.1.24-r2",
156165
Licenses: []string{"MIT"},
166+
Arch: "x86_64",
157167
Digest: "sha1:cb2316a189ebee5282c4a9bd98794cc2477a74c6",
158168
},
159169
{
@@ -172,6 +182,7 @@ func TestArtifact_Inspect(t *testing.T) {
172182
173183
174184
},
185+
Arch: "x86_64",
175186
},
176187
{
177188
@@ -184,6 +195,7 @@ func TestArtifact_Inspect(t *testing.T) {
184195
DependsOn: []string{
185196
186197
},
198+
Arch: "x86_64",
187199
},
188200
{
189201
@@ -197,6 +209,7 @@ func TestArtifact_Inspect(t *testing.T) {
197209
198210
199211
},
212+
Arch: "x86_64",
200213
},
201214
{
202215
@@ -209,6 +222,7 @@ func TestArtifact_Inspect(t *testing.T) {
209222
DependsOn: []string{
210223
211224
},
225+
Arch: "x86_64",
212226
},
213227
}
214228

0 commit comments

Comments
 (0)