Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(trivy): Add dbRepository flag to get advisory database from OCI registry #1064

Merged
merged 13 commits into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deploy/helm/templates/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ data:
trivy.nonSslRegistry.{{ $key }}: {{ $registry | quote }}
{{- end }}
trivy.severity: {{ .severity | quote }}
trivy.dbRepository: {{ .dbRepository | quote }}
{{- if .ignoreUnfixed }}
trivy.ignoreUnfixed: {{ .ignoreUnfixed | quote }}
{{- end }}
Expand Down
2 changes: 2 additions & 0 deletions deploy/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ trivy:
#
# serverCustomHeaders: "foo=bar"

dbRepository: "ghcr.io/aquasecurity/trivy-db"
chen-keinan marked this conversation as resolved.
Show resolved Hide resolved

kubeBench:
imageRef: docker.io/aquasec/kube-bench:v0.6.5

Expand Down
22 changes: 22 additions & 0 deletions pkg/plugin/trivy/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
keyTrivyGitHubToken = "trivy.githubToken"
keyTrivySkipFiles = "trivy.skipFiles"
keyTrivySkipDirs = "trivy.skipDirs"
keyTrivyDBRepository = "trivy.dbRepository"

keyTrivyServerURL = "trivy.serverURL"
keyTrivyServerTokenHeader = "trivy.serverTokenHeader"
Expand All @@ -56,6 +57,8 @@ const (
keyResourcesLimitsMemory = "trivy.resources.limits.memory"
)

const defaultDBRepository = "ghcr.io/aquasecurity/trivy-db"

// Mode in which Trivy client operates.
type Mode string

Expand Down Expand Up @@ -211,6 +214,10 @@ func (c Config) setResourceLimit(configKey string, k8sResourceList *corev1.Resou
return nil
}

func (c Config) GetDBRepository() (string, error) {
return c.GetRequiredData(keyTrivyDBRepository)
}

type plugin struct {
clock ext.Clock
idGenerator ext.IDGenerator
Expand Down Expand Up @@ -244,6 +251,7 @@ func (p *plugin) Init(ctx starboard.PluginContext) error {
keyTrivySeverity: "UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL",
keyTrivyMode: string(Standalone),
keyTrivyTimeout: "5m0s",
keyTrivyDBRepository: defaultDBRepository,

keyResourcesRequestsCPU: "100m",
keyResourcesRequestsMemory: "100M",
Expand Down Expand Up @@ -342,6 +350,11 @@ func (p *plugin) getPodSpecForStandaloneMode(ctx starboard.PluginContext, config

trivyConfigName := starboard.GetPluginConfigMapName(Plugin)

dbRepository, err := config.GetDBRepository()
if err != nil {
return corev1.PodSpec{}, nil, err
}

requirements, err := config.GetResourceRequirements()
if err != nil {
return corev1.PodSpec{}, nil, err
Expand Down Expand Up @@ -410,6 +423,8 @@ func (p *plugin) getPodSpecForStandaloneMode(ctx starboard.PluginContext, config
"/tmp/trivy/.cache",
"image",
"--download-db-only",
"--db-repository",
dbRepository,
},
Resources: requirements,
VolumeMounts: []corev1.VolumeMount{
Expand Down Expand Up @@ -993,6 +1008,11 @@ func (p *plugin) getPodSpecForStandaloneFSMode(ctx starboard.PluginContext, conf

trivyConfigName := starboard.GetPluginConfigMapName(Plugin)

dbRepository, err := config.GetDBRepository()
if err != nil {
return corev1.PodSpec{}, nil, err
}

requirements, err := config.GetResourceRequirements()
if err != nil {
return corev1.PodSpec{}, nil, err
Expand Down Expand Up @@ -1050,6 +1070,8 @@ func (p *plugin) getPodSpecForStandaloneFSMode(ctx starboard.PluginContext, conf
"--download-db-only",
"--cache-dir",
"/var/starboard/trivy-db",
"--db-repository",
dbRepository,
},
Resources: requirements,
VolumeMounts: volumeMounts,
Expand Down
30 changes: 25 additions & 5 deletions pkg/plugin/trivy/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ func TestConfig_GetResourceRequirements(t *testing.T) {
config: trivy.Config{
PluginConfig: starboard.PluginConfig{
Data: map[string]string{
"trivy.dbRepository": "ghcr.io/aquasecurity/trivy-db",
"trivy.resources.requests.cpu": "800m",
"trivy.resources.requests.memory": "200M",
"trivy.resources.limits.cpu": "600m",
Expand Down Expand Up @@ -470,10 +471,11 @@ func TestPlugin_Init(t *testing.T) {
ResourceVersion: "1",
},
Data: map[string]string{
"trivy.imageRef": "docker.io/aquasec/trivy:0.24.2",
"trivy.severity": "UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL",
"trivy.mode": "Standalone",
"trivy.timeout": "5m0s",
"trivy.imageRef": "docker.io/aquasec/trivy:0.24.2",
"trivy.severity": "UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL",
"trivy.mode": "Standalone",
"trivy.timeout": "5m0s",
"trivy.dbRepository": "ghcr.io/aquasecurity/trivy-db",

"trivy.resources.requests.cpu": "100m",
"trivy.resources.requests.memory": "100M",
Expand Down Expand Up @@ -582,7 +584,7 @@ func TestPlugin_GetScanJobSpec(t *testing.T) {
config: map[string]string{
"trivy.imageRef": "docker.io/aquasec/trivy:0.14.0",
"trivy.mode": string(trivy.Standalone),

"trivy.dbRepository": "ghcr.io/aquasecurity/trivy-db",
"trivy.resources.requests.cpu": "100m",
"trivy.resources.requests.memory": "100M",
"trivy.resources.limits.cpu": "500m",
Expand Down Expand Up @@ -682,6 +684,7 @@ func TestPlugin_GetScanJobSpec(t *testing.T) {
"--cache-dir", "/tmp/trivy/.cache",
"image",
"--download-db-only",
"--db-repository", "ghcr.io/aquasecurity/trivy-db",
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
Expand Down Expand Up @@ -834,6 +837,7 @@ func TestPlugin_GetScanJobSpec(t *testing.T) {
"trivy.imageRef": "docker.io/aquasec/trivy:0.14.0",
"trivy.mode": string(trivy.Standalone),
"trivy.insecureRegistry.pocRegistry": "poc.myregistry.harbor.com.pl",
"trivy.dbRepository": "ghcr.io/aquasecurity/trivy-db",

"trivy.resources.requests.cpu": "100m",
"trivy.resources.requests.memory": "100M",
Expand Down Expand Up @@ -928,6 +932,7 @@ func TestPlugin_GetScanJobSpec(t *testing.T) {
"--cache-dir", "/tmp/trivy/.cache",
"image",
"--download-db-only",
"--db-repository", "ghcr.io/aquasecurity/trivy-db",
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
Expand Down Expand Up @@ -1084,6 +1089,7 @@ func TestPlugin_GetScanJobSpec(t *testing.T) {
"trivy.imageRef": "docker.io/aquasec/trivy:0.14.0",
"trivy.mode": string(trivy.Standalone),
"trivy.nonSslRegistry.pocRegistry": "poc.myregistry.harbor.com.pl",
"trivy.dbRepository": "ghcr.io/aquasecurity/trivy-db",
"trivy.resources.requests.cpu": "100m",
"trivy.resources.requests.memory": "100M",
"trivy.resources.limits.cpu": "500m",
Expand Down Expand Up @@ -1178,6 +1184,7 @@ func TestPlugin_GetScanJobSpec(t *testing.T) {
"--cache-dir", "/tmp/trivy/.cache",
"image",
"--download-db-only",
"--db-repository", "ghcr.io/aquasecurity/trivy-db",
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
Expand Down Expand Up @@ -1338,6 +1345,7 @@ CVE-2018-14618

# No impact in our settings
CVE-2019-1543`,
"trivy.dbRepository": "ghcr.io/aquasecurity/trivy-db",
"trivy.resources.requests.cpu": "100m",
"trivy.resources.requests.memory": "100M",
"trivy.resources.limits.cpu": "500m",
Expand Down Expand Up @@ -1448,6 +1456,7 @@ CVE-2019-1543`,
"--cache-dir", "/tmp/trivy/.cache",
"image",
"--download-db-only",
"--db-repository", "ghcr.io/aquasecurity/trivy-db",
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
Expand Down Expand Up @@ -1609,6 +1618,7 @@ CVE-2019-1543`,
"trivy.imageRef": "docker.io/aquasec/trivy:0.14.0",
"trivy.mode": string(trivy.Standalone),

"trivy.dbRepository": "ghcr.io/aquasecurity/trivy-db",
"trivy.resources.requests.cpu": "100m",
"trivy.resources.requests.memory": "100M",
"trivy.resources.limits.cpu": "500m",
Expand Down Expand Up @@ -1706,6 +1716,7 @@ CVE-2019-1543`,
"--cache-dir", "/tmp/trivy/.cache",
"image",
"--download-db-only",
"--db-repository", "ghcr.io/aquasecurity/trivy-db",
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
Expand Down Expand Up @@ -1858,6 +1869,7 @@ CVE-2019-1543`,
"trivy.imageRef": "docker.io/aquasec/trivy:0.14.0",
"trivy.mode": string(trivy.ClientServer),
"trivy.serverURL": "http://trivy.trivy:4954",
"trivy.dbRepository": "ghcr.io/aquasecurity/trivy-db",
"trivy.resources.requests.cpu": "100m",
"trivy.resources.requests.memory": "100M",
"trivy.resources.limits.cpu": "500m",
Expand Down Expand Up @@ -2047,6 +2059,7 @@ CVE-2019-1543`,
"trivy.imageRef": "docker.io/aquasec/trivy:0.14.0",
"trivy.mode": string(trivy.ClientServer),
"trivy.serverURL": "http://trivy.trivy:4954",
"trivy.dbRepository": "ghcr.io/aquasecurity/trivy-db",
"trivy.resources.requests.cpu": "100m",
"trivy.resources.requests.memory": "100M",
"trivy.resources.limits.cpu": "500m",
Expand Down Expand Up @@ -2237,6 +2250,7 @@ CVE-2019-1543`,
"trivy.mode": string(trivy.ClientServer),
"trivy.serverURL": "https://trivy.trivy:4954",
"trivy.serverInsecure": "true",
"trivy.dbRepository": "ghcr.io/aquasecurity/trivy-db",
"trivy.resources.requests.cpu": "100m",
"trivy.resources.requests.memory": "100M",
"trivy.resources.limits.cpu": "500m",
Expand Down Expand Up @@ -2431,6 +2445,7 @@ CVE-2019-1543`,
"trivy.mode": string(trivy.ClientServer),
"trivy.serverURL": "http://trivy.trivy:4954",
"trivy.nonSslRegistry.pocRegistry": "poc.myregistry.harbor.com.pl",
"trivy.dbRepository": "ghcr.io/aquasecurity/trivy-db",
"trivy.resources.requests.cpu": "100m",
"trivy.resources.requests.memory": "100M",
"trivy.resources.limits.cpu": "500m",
Expand Down Expand Up @@ -2629,6 +2644,7 @@ CVE-2018-14618

# No impact in our settings
CVE-2019-1543`,
"trivy.dbRepository": "ghcr.io/aquasecurity/trivy-db",
"trivy.resources.requests.cpu": "100m",
"trivy.resources.requests.memory": "100M",
"trivy.resources.limits.cpu": "500m",
Expand Down Expand Up @@ -2847,6 +2863,7 @@ CVE-2019-1543`,
"trivy.imageRef": "docker.io/aquasec/trivy:0.24.2",
"trivy.mode": string(trivy.Standalone),
"trivy.command": string(trivy.Filesystem),
"trivy.dbRepository": "ghcr.io/aquasecurity/trivy-db",
"trivy.resources.requests.cpu": "100m",
"trivy.resources.requests.memory": "100M",
"trivy.resources.limits.cpu": "500m",
Expand Down Expand Up @@ -2978,6 +2995,7 @@ CVE-2019-1543`,
"--download-db-only",
"--cache-dir",
"/var/starboard/trivy-db",
"--db-repository", "ghcr.io/aquasecurity/trivy-db",
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
Expand Down Expand Up @@ -3162,6 +3180,7 @@ CVE-2019-1543`,
"trivy.imageRef": "docker.io/aquasec/trivy:0.22.0",
"trivy.mode": string(trivy.Standalone),
"trivy.command": string(trivy.Filesystem),
"trivy.dbRepository": "ghcr.io/aquasecurity/trivy-db",
"trivy.resources.requests.cpu": "100m",
"trivy.resources.requests.memory": "100M",
"trivy.resources.limits.cpu": "500m",
Expand Down Expand Up @@ -3294,6 +3313,7 @@ CVE-2019-1543`,
"--download-db-only",
"--cache-dir",
"/var/starboard/trivy-db",
"--db-repository", "ghcr.io/aquasecurity/trivy-db",
},
Resources: corev1.ResourceRequirements{
Requests: corev1.ResourceList{
Expand Down