Skip to content

Commit a3499ad

Browse files
ybelMekktommytroen
andcommitted
feat: full end-to-end testing
* update docker compose * add vulnerable image by default for local testing Co-authored-by: Tommy Trøen <[email protected]>
1 parent d37b984 commit a3499ad

File tree

7 files changed

+67
-13
lines changed

7 files changed

+67
-13
lines changed

.tool-versions

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
golang 1.24.0
1+
golang 1.24.0
22
protoc-gen-go-grpc cmd/protoc-gen-go-grpc/v1.5.1
3-
protoc-gen-go 1.36.5
4-
protoc 29.3
5-
helm 3.15.1
3+
protoc-gen-go 1.36.5
4+
protoc 29.3
5+
helm 3.15.1
6+
trivy latest

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,16 @@ users can import the package with a specific version.
2222
the package from the internet. See github.com/nais/api for an example.
2323
* Should we create a new row for each workload or do a update? If we do create we have a history of all workloads and
2424
images tags. If we do a update we only have the latest image tag for each workload. We still have the history of all
25-
images tags in the image table.
25+
images tags in the image table.
26+
27+
## Commando
28+
29+
This requires that both trivy and cosing is installed
30+
31+
```shell
32+
trivy image --format cyclonedx --output vuln-nginx.json localhost:4004/vuln-nginx:1.4.2
33+
```
34+
35+
```shell
36+
cosign attest --predicate vuln-nginx.json --type cyclonedx localhost:4004/vuln-nginx:1.4.2
37+
```

cmd/api/main.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"net"
1717
"os"
1818
"os/signal"
19+
"strings"
1920
"syscall"
2021
"time"
2122

@@ -136,11 +137,12 @@ func setupLogger(log *logrus.Logger, logFormat, logLevel string) logrus.FieldLog
136137
}
137138

138139
func createGrpcServer(parentCtx context.Context, cfg config, pool *pgxpool.Pool, u *updater.Updater, field logrus.FieldLogger) *grpc.Server {
139-
serverOpts := []grpc.ServerOption{
140-
grpc.UnaryInterceptor(auth.TokenInterceptor(cfg.RequiredAudience, cfg.AuthorizedServiceAccounts, field.WithField("subsystem", "auth"))),
140+
serverOpts := make([]grpc.ServerOption, 0)
141+
if !strings.HasPrefix(cfg.ListenAddr, "http://localhost") {
142+
serverOpts = append(serverOpts, grpc.UnaryInterceptor(auth.TokenInterceptor(cfg.RequiredAudience, cfg.AuthorizedServiceAccounts, field.WithField("subsystem", "auth"))))
141143
}
142-
grpcServer := grpc.NewServer(serverOpts...)
143144

145+
grpcServer := grpc.NewServer(serverOpts...)
144146
vulnerabilities.RegisterVulnerabilitiesServer(grpcServer, grpcvulnerabilities.NewServer(pool, field.WithField("subsystem", "vulnerabilities")))
145147
management.RegisterManagementServer(grpcServer, grpcmgmt.NewServer(parentCtx, pool, u, field.WithField("subsystem", "management")))
146148

cmd/seed/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func main() {
4545
createNaisApiWorkloads(ctx, db, "superprod", "devteam")
4646
createVulnData(ctx, db, images)
4747

48-
err = uploadSboms(ctx, "")
48+
err = uploadSboms(ctx, "localhost:4004/vuln-nginx:1.4.2")
4949
if err != nil {
5050
panic(err)
5151
}

docker-compose.yaml

+35-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,40 @@ services:
6565
- "9020:8080"
6666
restart: unless-stopped
6767

68+
bootstrap:
69+
platform: linux/amd64
70+
image: europe-north1-docker.pkg.dev/nais-io/nais/images/dependencytrack-bootstrap:latest
71+
environment:
72+
- BASE_URL=http://dtrack-apiserver:8080/
73+
- DEFAULT_ADMIN_PASSWORD=admin
74+
- ADMIN_PASSWORD=yolo
75+
- TRIVY_API_TOKEN=my-token
76+
- USERS_FILE=users.yaml
77+
- TRIVY_BASE_URL=http://trivy:4005
78+
depends_on:
79+
dtrack-apiserver:
80+
condition: service_healthy
81+
volumes:
82+
- ./users.yaml:/app/users.yaml
83+
84+
registry:
85+
image: registry:latest
86+
ports:
87+
- '4004:5000'
88+
89+
trivy:
90+
image: aquasec/trivy:0.55.0
91+
command:
92+
- server
93+
- --listen
94+
- :4005
95+
- --token
96+
- my-token
97+
volumes:
98+
- "trivy-cache:/root/.cache/trivy"
99+
restart: unless-stopped
100+
68101
volumes:
69102
pgdata:
70-
dependency-track:
103+
dependency-track:
104+
trivy-cache: { }

internal/attestation/attestation.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/google/go-containerregistry/pkg/v1/google"
1212
ociremote "github.com/google/go-containerregistry/pkg/v1/remote"
1313
"github.com/in-toto/in-toto-golang/in_toto"
14-
"github.com/nais/v13s/internal/attestation/github"
1514
ssldsse "github.com/secure-systems-lab/go-securesystemslib/dsse"
1615
"github.com/sigstore/cosign/v2/cmd/cosign/cli/fulcio"
1716
"github.com/sigstore/cosign/v2/pkg/cosign"
@@ -32,8 +31,9 @@ type Verifier struct {
3231
}
3332

3433
func NewVerifier(ctx context.Context, log *logrus.Entry, organizations ...string) (*Verifier, error) {
35-
ids := github.NewCertificateIdentity(organizations).GetIdentities()
36-
opts, err := CosignOptions(ctx, "", ids)
34+
// TODO: fix for localhost
35+
//ids := github.NewCertificateIdentity(organizations).GetIdentities()
36+
opts, err := CosignOptions(ctx, "", []cosign.Identity{})
3737
if err != nil {
3838
return nil, err
3939
}

users.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
users:
2+
- username: console
3+
password: "todo"
4+
- username: slsa-verde
5+
password: "todos"

0 commit comments

Comments
 (0)