-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
server.go
366 lines (350 loc) · 18.6 KB
/
server.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
package rekortest
import (
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/CycloneDX/cyclonedx-go"
"github.com/in-toto/in-toto-golang/in_toto"
slsa "github.com/in-toto/in-toto-golang/in_toto/slsa_provenance/common"
"github.com/samber/lo"
"github.com/sigstore/rekor/pkg/generated/models"
"github.com/stretchr/testify/assert"
"github.com/aquasecurity/trivy/pkg/attestation"
)
var (
indexRes = map[string][]string{
// Contain a SBOM attestation for a container image
"sha256:782143e39f1e7a04e3f6da2d88b1c057e5657363c4f90679f3e8a071b7619e02": {
"392f8ecba72f4326eb624a7403756250b5f2ad58842a99d1653cd6f147f4ce9eda2da350bd908a55",
"392f8ecba72f4326414eaca77bd19bf5f378725d7fd79309605a81b69cc0101f5cd3119d0a216523",
},
// Contain a SBOM attestation for go.mod
"sha256:23f4e10c43c7654e33a3c9570913c8c9c528292762f1a5c4a97253e9e4e4b238": {
"24296fb24b8ad77aa715cdfd264ce34c4d544375d7bd7cd029bf5a48ef25217a13fdba562e0889ca",
},
// Contain an empty SBOM attestation
"sha256:5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03": {
"24296fb24b8ad77a8d47be2e40bfe910f0ffc842e86b5685dd85d1c903ef78bb6362125816426fe9",
},
}
imageSBOMAttestation = in_toto.Statement{
StatementHeader: in_toto.StatementHeader{
Type: "https://in-toto.io/Statement/v0.1",
PredicateType: "https://cyclonedx.org/bom",
Subject: []in_toto.Subject{
{
Name: "index.docker.io/knqyf263/cosign-test",
Digest: slsa.DigestSet{
"sha256": "a777c9c66ba177ccfea23f2a216ff6721e78a662cd17019488c417135299cd89",
},
},
},
},
Predicate: &attestation.CosignPredicate{
Data: &cyclonedx.BOM{
BOMFormat: cyclonedx.BOMFormat,
SerialNumber: "urn:uuid:6453fd82-71f4-47c8-ad12-01775619c443",
SpecVersion: cyclonedx.SpecVersion1_5,
Version: 1,
Metadata: &cyclonedx.Metadata{
Timestamp: "2022-09-15T13:53:49+00:00",
Tools: &cyclonedx.ToolsChoice{
Components: &[]cyclonedx.Component{
{
Type: cyclonedx.ComponentTypeApplication,
Name: "trivy",
Group: "aquasecurity",
Version: "dev",
},
},
},
Component: &cyclonedx.Component{
BOMRef: "pkg:oci/alpine@sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad?repository_url=index.docker.io%2Flibrary%2Falpine\u0026arch=amd64",
Type: cyclonedx.ComponentTypeContainer,
Name: "alpine:3.16",
PackageURL: "pkg:oci/alpine@sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad?repository_url=index.docker.io%2Flibrary%2Falpine\u0026arch=amd64",
Properties: &[]cyclonedx.Property{
{
Name: "aquasecurity:trivy:SchemaVersion",
Value: "2",
},
{
Name: "aquasecurity:trivy:ImageID",
Value: "sha256:9c6f0724472873bb50a2ae67a9e7adcb57673a183cea8b06eb778dca859181b5",
},
{
Name: "aquasecurity:trivy:RepoDigest",
Value: "alpine@sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad",
},
{
Name: "aquasecurity:trivy:DiffID",
Value: "sha256:994393dc58e7931862558d06e46aa2bb17487044f670f310dffe1d24e4d1eec7",
},
{
Name: "aquasecurity:trivy:RepoTag",
Value: "alpine:3.16",
},
},
},
},
Components: &[]cyclonedx.Component{
{
BOMRef: "fad4eb97-3d2a-4499-ace7-2c94444148a7",
Type: cyclonedx.ComponentTypeOS,
Name: "alpine",
Version: "3.16.2",
Properties: &[]cyclonedx.Property{
{
Name: "aquasecurity:trivy:Type",
Value: "alpine",
},
{
Name: "aquasecurity:trivy:Class",
Value: "os-pkgs",
},
},
},
{
BOMRef: "pkg:apk/alpine/musl@1.2.3-r0?distro=3.16.2",
Type: cyclonedx.ComponentTypeLibrary,
Name: "musl",
Version: "1.2.3-r0",
Licenses: &cyclonedx.Licenses{
{Expression: "MIT"},
},
PackageURL: "pkg:apk/alpine/musl@1.2.3-r0?distro=3.16.2",
Properties: &[]cyclonedx.Property{
{
Name: "aquasecurity:trivy:PkgType",
Value: "alpine",
},
{
Name: "aquasecurity:trivy:SrcName",
Value: "musl",
},
{
Name: "aquasecurity:trivy:SrcVersion",
Value: "1.2.3-r0",
},
{
Name: "aquasecurity:trivy:LayerDiffID",
Value: "sha256:994393dc58e7931862558d06e46aa2bb17487044f670f310dffe1d24e4d1eec7",
},
},
},
},
Dependencies: &[]cyclonedx.Dependency{
{
Ref: "pkg:oci/alpine@sha256:bc41182d7ef5ffc53a40b044e725193bc10142a1243f395ee852a8d9730fc2ad?repository_url=index.docker.io%2Flibrary%2Falpine&arch=amd64",
Dependencies: &[]string{
"fad4eb97-3d2a-4499-ace7-2c94444148a7",
},
},
{
Ref: "fad4eb97-3d2a-4499-ace7-2c94444148a7",
Dependencies: &[]string{
"pkg:apk/alpine/musl@1.2.3-r0?distro=3.16.2",
},
},
},
},
},
}
gomodSBOMAttestation = in_toto.Statement{
StatementHeader: in_toto.StatementHeader{
Type: "https://in-toto.io/Statement/v0.1",
PredicateType: "https://cyclonedx.org/bom",
Subject: []in_toto.Subject{
{
Name: "go.mod",
Digest: slsa.DigestSet{
"sha256": "23f4e10c43c7654e33a3c9570913c8c9c528292762f1a5c4a97253e9e4e4b238",
},
},
},
},
Predicate: &attestation.CosignPredicate{
Data: &cyclonedx.BOM{
BOMFormat: cyclonedx.BOMFormat,
SerialNumber: "urn:uuid:8b16c9a3-e957-4c85-b43d-7dd05ea0421c",
SpecVersion: cyclonedx.SpecVersion1_5,
Version: 1,
Metadata: &cyclonedx.Metadata{
Timestamp: "2022-10-21T09:50:08+00:00",
Tools: &cyclonedx.ToolsChoice{
Components: &[]cyclonedx.Component{
{
Type: cyclonedx.ComponentTypeApplication,
Name: "trivy",
Group: "aquasecurity",
Version: "dev",
},
},
},
Component: &cyclonedx.Component{
BOMRef: "ef8385d7-a56f-495a-a220-7b0a2e940d39",
Type: cyclonedx.ComponentTypeApplication,
Name: "go.mod",
Properties: &[]cyclonedx.Property{
{
Name: "aquasecurity:trivy:SchemaVersion",
Value: "2",
},
},
},
},
Components: &[]cyclonedx.Component{
{
BOMRef: "bb8b7541-2b08-4692-9363-8f79da5c1a31",
Type: cyclonedx.ComponentTypeApplication,
Name: "go.mod",
Properties: &[]cyclonedx.Property{
{
Name: "aquasecurity:trivy:Type",
Value: "gomod",
},
{
Name: "aquasecurity:trivy:Class",
Value: "lang-pkgs",
},
},
},
{
BOMRef: "pkg:golang/github.com/spf13/cobra@1.5.0",
Type: cyclonedx.ComponentTypeLibrary,
Name: "github.com/spf13/cobra",
Version: "1.5.0",
PackageURL: "pkg:golang/github.com/spf13/cobra@1.5.0",
Properties: &[]cyclonedx.Property{
{
Name: "aquasecurity:trivy:PkgType",
Value: "gomod",
},
},
},
},
Dependencies: &[]cyclonedx.Dependency{
{
Ref: "ef8385d7-a56f-495a-a220-7b0a2e940d39",
Dependencies: &[]string{
"bb8b7541-2b08-4692-9363-8f79da5c1a31",
},
},
{
Ref: "bb8b7541-2b08-4692-9363-8f79da5c1a31",
Dependencies: &[]string{
"pkg:golang/github.com/spf13/cobra@1.5.0",
},
},
},
},
},
}
emptySBOMAttestation = in_toto.Statement{
StatementHeader: in_toto.StatementHeader{
Type: "https://in-toto.io/Statement/v0.1",
PredicateType: "https://cyclonedx.org/bom",
},
Predicate: &attestation.CosignPredicate{
Data: &cyclonedx.BOM{
BOMFormat: cyclonedx.BOMFormat,
SpecVersion: cyclonedx.SpecVersion1_5,
Version: 2,
},
},
}
entries = map[string]models.LogEntryAnon{
"392f8ecba72f4326414eaca77bd19bf5f378725d7fd79309605a81b69cc0101f5cd3119d0a216523": {
Attestation: &models.LogEntryAnonAttestation{
Data: mustMarshal(imageSBOMAttestation),
},
Body: "eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiaW50b3RvIiwic3BlYyI6eyJjb250ZW50Ijp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiI3ODIxNDNlMzlmMWU3YTA0ZTNmNmRhMmQ4OGIxYzA1N2U1NjU3MzYzYzRmOTA2NzlmM2U4YTA3MWI3NjE5ZTAyIn0sInBheWxvYWRIYXNoIjp7ImFsZ29yaXRobSI6InNoYTI1NiIsInZhbHVlIjoiZWJiZmRkZGE2Mjc3YWYxOTllOTNjNWJiNWNmNTk5OGE3OTMxMWRlMjM4ZTQ5YmNjOGFjMjQxMDI2OTg3NjFiYiJ9fSwicHVibGljS2V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rZFZkVmt5T1hSTlNVZE1RbWR2Y2tKblJVVkJaRm8xQ2tGblVVTkNTREJGWlhkQ05VRklZMEZEUjBOVE9FTm9VeTh5YUVZd1pFWnlTalJUWTFKWFkxbHlRbGs1ZDNwcVUySmxZVGhKWjFreVlqTkpRVUZCUjBNS01UZHRTbWhuUVVGQ1FVMUJVMFJDUjBGcFJVRm9TMDlCU2tkV1ZsaENiMWN4VERSNGFsazVlV0pXT0daVVVYTjVUU3R2VUVwSWVEazVTMjlMWVVwVlF3cEpVVVJDWkRsbGMxUTBNazFTVG5nM1ZtOUJNMXBhS3pWNGFraE5aV1I2YW1WeFEyWm9aVGN2ZDFweFlUbFVRVXRDWjJkeGFHdHFUMUJSVVVSQmQwNXZDa0ZFUW14QmFrVkJjbkJrZVhsRlJqYzNiMkp5VEVOTVVYcHpZbUl4TTJsc05qZDNkek00WTA1MGFtZE5RbWw2WTJWVWFrUmlZMlZMZVZGU04xUktOSE1LWkVOc2Nsa3hZMUJCYWtFNGFYQjZTVVE0VlUxQ2FHeGtTbVV2WlhKR2NHZHROMnN3TldGaWMybFBOM1Y1ZFZadVMyOVZOazByVFhKNlZWVXJaVGxHZHdwSlJHaENhblZSYTFkUll6MEtMUzB0TFMxRlRrUWdRMFZTVkVsR1NVTkJWRVV0TFMwdExRbz0ifX0=",
IntegratedTime: lo.ToPtr(int64(1661476639)),
LogID: lo.ToPtr("c0d23d6ad406973f9559f3ba2d1ca01f84147d8ffc5b8445c224f98b9591801d"),
LogIndex: lo.ToPtr(int64(3280165)),
Verification: nil,
},
"392f8ecba72f4326eb624a7403756250b5f2ad58842a99d1653cd6f147f4ce9eda2da350bd908a55": {
Attestation: &models.LogEntryAnonAttestation{
Data: []byte(`{"apiVersion":"0.0.1","kind":"intoto","spec":{"content":{"hash":{"algorithm":"sha256","value":"782143e39f1e7a04e3f6da2d88b1c057e5657363c4f90679f3e8a071b7619e02"},"payloadHash":{"algorithm":"sha256","value":"ebbfddda6277af199e93c5bb5cf5998a79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SVVVSQmQwNXZDa0ZFUW14QmFrVkJjbkJrZVhsRlJqYzNiMkp5VEVOTVVYcHpZbUl4TTJsc05qZDNkek00WTA1MGFtZE5RbWw2WTJWVWFrUmlZMlZMZVZGU04xUktOSE1LWkVOc2Nsa3hZMUJCYWtFNGFYQjZTVVE0VlUxQ2FHeGtTbVV2WlhKR2NHZHROMnN3TldGaWMybFBOM1Y1ZFZadVMyOVZOazByVFhKNlZWVXJaVGxHZHdwSlJHaENhblZSYTFkUll6MEtMUzB0TFMxRlRrUWdRMFZTVkVsR1NVTkJWRVV0TFMwdExRbz0ifX0=",
IntegratedTime: lo.ToPtr(int64(1661476639)),
LogID: lo.ToPtr("c0d23d6ad406973f9559f3ba2d1ca01f84147d8ffc5b8445c224f98b9591801d"),
LogIndex: lo.ToPtr(int64(3280165)),
Verification: nil,
},
"24296fb24b8ad77aa715cdfd264ce34c4d544375d7bd7cd029bf5a48ef25217a13fdba562e0889ca": {
Attestation: &models.LogEntryAnonAttestation{
Data: mustMarshal(gomodSBOMAttestation),
},
Body: nil, // not used at the moment
IntegratedTime: lo.ToPtr(int64(1664451604)),
LogID: lo.ToPtr("c0d23d6ad406973f9559f3ba2d1ca01f84147d8ffc5b8445c224f98b9591801d"),
LogIndex: lo.ToPtr(int64(4215471)),
Verification: nil,
},
"24296fb24b8ad77a8d47be2e40bfe910f0ffc842e86b5685dd85d1c903ef78bb6362125816426fe9": {
Attestation: &models.LogEntryAnonAttestation{
Data: mustMarshal(emptySBOMAttestation),
},
Body: "eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoiaW50b3RvIiwic3BlYyI6eyJjb250ZW50Ijp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiI3ODIxNDNlMzlmMWU3YTA0ZTNmNmRhMmQ4OGIxYzA1N2U1NjU3MzYzYzRmOTA2NzlmM2U4YTA3MWI3NjE5ZTAyIn0sInBheWxvYWRIYXNoIjp7ImFsZ29yaXRobSI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G9UbXBGZUU1RlFtNWlWMFp3WWtNMWFtSXlNSGRMVVZsTFMzZFpRZ3BDUVVkRWRucEJRa0ZSVVdKaFNGSXdZMGhOTmt4NU9XaFpNazUyWkZjMU1HTjVOVzVpTWpsdVlrZFZkVmt5T1hSTlNVZE1RbWR2Y2tKblJVVkJaRm8xQ2tGblVVTkNTREJGWlhkQ05VRklZMEZEUjBOVE9FTm9VeTh5YUVZd1pFWnlTalJUWTFKWFkxbHlRbGs1ZDNwcVUySmxZVGhKWjFreVlqTkpRVUZCUjBNS01UZHRTbWhuUVVGQ1FVMUJVMFJDUjBGcFJVRm9TMDlCU2tkV1ZsaENiMWN4VERSNGFsazVlV0pXT0daVVVYTjVUU3R2VUVwSWVEazVTMjlMWVVwVlF3cEpVVVJDWkRsbGMxUTBNazFTVG5nM1ZtOUJNMXBhS3pWNGFraE5aV1I2YW1WeFEyWm9aVGN2ZDFweFlUbFVRVXRDWjJkeGFHdHFUMUJSVVVSQmQwNXZDa0ZFUW14QmFrVkJjbkJrZVhsRlJqYzNiMkp5VEVOTVVYcHpZbUl4TTJsc05qZDNkek00WTA1MGFtZE5RbWw2WTJWVWFrUmlZMlZMZVZGU04xUktOSE1LWkVOc2Nsa3hZMUJCYWtFNGFYQjZTVVE0VlUxQ2FHeGtTbVV2WlhKR2NHZHROMnN3TldGaWMybFBOM1Y1ZFZadVMyOVZOazByVFhKNlZWVXJaVGxHZHdwSlJHaENhblZSYTFkUll6MEtMUzB0TFMxRlRrUWdRMFZTVkVsR1NVTkJWRVV0TFMwdExRbz0ifX0=",
IntegratedTime: lo.ToPtr(int64(1661476639)),
LogID: lo.ToPtr("c0d23d6ad406973f9559f3ba2d1ca01f84147d8ffc5b8445c224f98b9591801d"),
LogIndex: lo.ToPtr(int64(3280165)),
Verification: nil,
},
}
)
type Server struct {
ts *httptest.Server
}
func NewServer(t *testing.T) *Server {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/api/v1/index/retrieve":
var params models.SearchIndex
err := json.NewDecoder(r.Body).Decode(¶ms)
assert.NoError(t, err)
if res, ok := indexRes[params.Hash]; ok {
w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(res)
assert.NoError(t, err)
} else {
http.Error(w, "something wrong", http.StatusNotFound)
}
case "/api/v1/log/entries/retrieve":
var params models.SearchLogQuery
err := json.NewDecoder(r.Body).Decode(¶ms)
assert.NoError(t, err)
resEntries := models.LogEntry{}
for _, uuid := range params.EntryUUIDs {
if e, ok := entries[uuid]; !ok {
http.Error(w, "no such uuid", http.StatusNotFound)
return
} else {
resEntries[uuid] = e
}
}
w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode([]models.LogEntry{resEntries})
assert.NoError(t, err)
}
return
}))
return &Server{ts: ts}
}
func (s *Server) URL() string {
return s.ts.URL
}
func (s *Server) Close() {
s.ts.Close()
}
func mustMarshal(v any) []byte {
b, err := json.Marshal(v)
if err != nil {
panic(err)
}
return b
}