Skip to content

Commit d37b984

Browse files
tommytroenybelMekk
andcommitted
feat: download sboms with verifier
* todo: add a image with vulnz * expand dependencytrack client with upload sbom * seed local dependencytrack with real data from sbom Co-authored-by: ybelmekk <[email protected]>
1 parent 0d1fe83 commit d37b984

File tree

10 files changed

+1343
-39
lines changed

10 files changed

+1343
-39
lines changed

cmd/cli/main.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func main() {
7878
Usage: "list vulnerabilities for image",
7979
Flags: commonFlags(opts, "cluster", "namespace", "workload"),
8080
Action: func(ctx context.Context, cmd *cli.Command) error {
81-
return listVulnerabilities(ctx, cmd, c, opts)
81+
return listVulnerabilitiesForImage(ctx, cmd, c, opts)
8282
},
8383
},
8484
{
@@ -149,7 +149,7 @@ func main() {
149149
}
150150
}
151151

152-
func listVulnerabilities(ctx context.Context, cmd *cli.Command, c vulnerabilities.Client, o *options) error {
152+
func listVulnerabilitiesForImage(ctx context.Context, cmd *cli.Command, c vulnerabilities.Client, o *options) error {
153153
opts := parseOptions(cmd, o)
154154
if cmd.Args().Len() == 0 {
155155
return fmt.Errorf("missing image name")
@@ -244,9 +244,12 @@ func getSummary(ctx context.Context, cmd *cli.Command, c vulnerabilities.Client,
244244
}
245245

246246
func listSummaries(ctx context.Context, cmd *cli.Command, c vulnerabilities.Client, o *options) error {
247-
opts := parseOptions(cmd, o)
247+
offset := 0
248248
for {
249249
//opts = append(opts, vulnerabilities.Limit(int32(limit)), vulnerabilities.Offset(int32(offset)))
250+
opts := parseOptions(cmd, o)
251+
opts = append(opts, vulnerabilities.Offset(int32(offset)))
252+
250253
start := time.Now()
251254
resp, err := c.ListVulnerabilitySummaries(ctx, opts...)
252255
if err != nil {
@@ -277,7 +280,6 @@ func listSummaries(ctx context.Context, cmd *cli.Command, c vulnerabilities.Clie
277280
}
278281

279282
tbl.Print()
280-
offset := 0
281283
numFetched := offset + int(o.limit)
282284
if numFetched > int(resp.PageInfo.TotalCount) {
283285
numFetched = int(resp.PageInfo.TotalCount)
@@ -308,9 +310,11 @@ func listSummaries(ctx context.Context, cmd *cli.Command, c vulnerabilities.Clie
308310
}
309311

310312
func listVulnz(ctx context.Context, cmd *cli.Command, c vulnerabilities.Client, o *options) error {
311-
opts := parseOptions(cmd, o)
313+
offset := 0
312314
for {
313315
start := time.Now()
316+
opts := parseOptions(cmd, o)
317+
opts = append(opts, vulnerabilities.Offset(int32(offset)))
314318
resp, err := c.ListVulnerabilities(ctx, opts...)
315319
if err != nil {
316320
return err
@@ -340,7 +344,6 @@ func listVulnz(ctx context.Context, cmd *cli.Command, c vulnerabilities.Client,
340344
}
341345

342346
tbl.Print()
343-
offset := 0
344347
numFetched := offset + int(o.limit)
345348
if numFetched > int(resp.PageInfo.TotalCount) {
346349
numFetched = int(resp.PageInfo.TotalCount)

cmd/seed/main.go

+44
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"github.com/nais/v13s/internal/attestation"
67
"github.com/nais/v13s/internal/database/typeext"
78
"math"
89
"os"
@@ -43,6 +44,49 @@ func main() {
4344
images := createNaisApiWorkloads(ctx, db, "dev", "devteam")
4445
createNaisApiWorkloads(ctx, db, "superprod", "devteam")
4546
createVulnData(ctx, db, images)
47+
48+
err = uploadSboms(ctx, "")
49+
if err != nil {
50+
panic(err)
51+
}
52+
}
53+
54+
func uploadSboms(ctx context.Context, images ...string) error {
55+
c, err := dependencytrack.NewClient(
56+
"http://localhost:9010/api",
57+
"Administrators",
58+
"admin",
59+
"yolo",
60+
log.WithField("subsystem", "dp-client"),
61+
)
62+
if err != nil {
63+
return err
64+
}
65+
66+
verifier, err := attestation.NewVerifier(ctx, log.WithField("subsystem", "cosign-verifier"), "navikt", "nais")
67+
if err != nil {
68+
return err
69+
}
70+
71+
for _, image := range images {
72+
parts := strings.Split(image, ":")
73+
ref := &dependencytrack.WorkloadRef{
74+
Cluster: "dev",
75+
Namespace: "devteam",
76+
Type: "app",
77+
Name: "nais-deploy-chicken-1",
78+
}
79+
att, err := verifier.GetAttestation(ctx, image)
80+
if err != nil {
81+
return err
82+
}
83+
err = c.CreateProjectWithSbom(ctx, parts[0], parts[1], att, ref)
84+
if err != nil {
85+
return err
86+
}
87+
}
88+
89+
return nil
4690
}
4791

4892
func seedFromDependencyTrack(ctx context.Context, db sql.Querier) {

docker-compose.yaml

+47-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,51 @@ services:
2020
environment:
2121
ADMINER_DEFAULT_SERVER: postgres
2222

23+
swagger:
24+
image: swaggerapi/swagger-ui
25+
environment:
26+
SWAGGER_JSON_URL: http://localhost:9001/api/swagger.json
27+
volumes:
28+
- ./swagger.json:/swagger.json
29+
ports:
30+
- '9002:8080'
31+
32+
dtrack-apiserver:
33+
image: dependencytrack/apiserver:4.11.7
34+
deploy:
35+
resources:
36+
limits:
37+
memory: 12288m
38+
reservations:
39+
memory: 8192m
40+
restart_policy:
41+
condition: on-failure
42+
ports:
43+
- '9010:8080'
44+
environment:
45+
- LOGGING_LEVEL=INFO
46+
healthcheck:
47+
test: wget --no-verbose --tries=1 --spider http://localhost:8080 || exit 1
48+
interval: 10s
49+
retries: 5
50+
start_period: 20s
51+
timeout: 10s
52+
volumes:
53+
# Optional volume mount to override default notification publisher templates
54+
# - "/host/path/to/template/base/dir:/data/templates"
55+
- 'dependency-track:/data'
56+
restart: unless-stopped
57+
58+
dtrack-frontend:
59+
image: dependencytrack/frontend:4.11.7
60+
depends_on:
61+
- dtrack-apiserver
62+
environment:
63+
- API_BASE_URL=http://localhost:9010
64+
ports:
65+
- "9020:8080"
66+
restart: unless-stopped
67+
2368
volumes:
24-
pgdata:
69+
pgdata:
70+
dependency-track:

0 commit comments

Comments
 (0)