Skip to content

Commit 3531ebc

Browse files
author
Henrik Teichmann
committed
feat: Add config option to enable vex-support for trivy
Signed-off-by: Henrik Teichmann <teichmann@strato.de>
1 parent 166cdd2 commit 3531ebc

File tree

7 files changed

+20
-3
lines changed

7 files changed

+20
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ Configuration of the adapter is done via environment variables at startup.
102102
| `SCANNER_TRIVY_GITHUB_TOKEN` | N/A | The GitHub access token to download [Trivy DB] (see [GitHub rate limiting][gh-rate-limit]) |
103103
| `SCANNER_TRIVY_INSECURE` | `false` | The flag to skip verifying registry certificate |
104104
| `SCANNER_TRIVY_TIMEOUT` | `5m0s` | The duration to wait for scan completion |
105+
| `SCANNER_TRIVY_VEX_SOURCE` | N/A | Enable VEX, possible values are `oci` and `repo` [EXPERIMENTAL]
105106
| `SCANNER_STORE_REDIS_NAMESPACE` | `harbor.scanner.trivy:store` | The namespace for keys in the Redis store |
106107
| `SCANNER_STORE_REDIS_SCAN_JOB_TTL` | `1h` | The time to live for persisting scan jobs and associated scan reports |
107108
| `SCANNER_JOB_QUEUE_REDIS_NAMESPACE` | `harbor.scanner.trivy:job-queue` | The namespace for keys in the scan jobs queue backed by Redis |

helm/harbor-scanner-trivy/templates/statefulset.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ spec:
121121
value: "/certs/tls.crt"
122122
- name: "SCANNER_API_SERVER_TLS_KEY"
123123
value: "/certs/tls.key"
124+
- name: "SCANNER_TRIVY_VEX_SOURCE"
125+
value: {{ .Values.scanner.trivy.VEXSource | default "" | quote }}
124126
{{- end }}
125127
ports:
126128
- name: api-server

pkg/etc/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type Trivy struct {
3939
OfflineScan bool `env:"SCANNER_TRIVY_OFFLINE_SCAN" envDefault:"false"`
4040
GitHubToken string `env:"SCANNER_TRIVY_GITHUB_TOKEN"`
4141
Insecure bool `env:"SCANNER_TRIVY_INSECURE" envDefault:"false"`
42+
VEXSource string `env:"SCANNER_TRIVY_VEX_SOURCE"`
4243
Timeout time.Duration `env:"SCANNER_TRIVY_TIMEOUT" envDefault:"5m0s"`
4344
}
4445

pkg/etc/config_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ func TestGetConfig(t *testing.T) {
160160
"SCANNER_TRIVY_OFFLINE_SCAN": "true",
161161
"SCANNER_TRIVY_GITHUB_TOKEN": "<GITHUB_TOKEN>",
162162
"SCANNER_TRIVY_TIMEOUT": "15m30s",
163+
"SCANNER_TRIVY_VEX_SOURCE": "oci",
163164

164165
"SCANNER_STORE_REDIS_NAMESPACE": "store.ns",
165166
"SCANNER_STORE_REDIS_SCAN_JOB_TTL": "2h45m15s",
@@ -201,6 +202,7 @@ func TestGetConfig(t *testing.T) {
201202
Insecure: true,
202203
GitHubToken: "<GITHUB_TOKEN>",
203204
Timeout: parseDuration(t, "15m30s"),
205+
VEXSource: "oci",
204206
},
205207
RedisPool: RedisPool{
206208
URL: "redis://harbor-harbor-redis:6379",

pkg/http/api/v1/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ func (h *requestHandler) GetMetadata(res http.ResponseWriter, _ *http.Request) {
316316
"env.SCANNER_TRIVY_SECURITY_CHECKS": h.config.Trivy.Scanners,
317317
"env.SCANNER_TRIVY_SEVERITY": h.config.Trivy.Severity,
318318
"env.SCANNER_TRIVY_TIMEOUT": h.config.Trivy.Timeout.String(),
319+
"env.SCANNER_TRIVY_VEX_SOURCE": h.config.Trivy.VEXSource,
319320
}
320321

321322
vi, err := h.wrapper.GetVersion()

pkg/http/api/v1/handler_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ func TestRequestHandler_GetMetadata(t *testing.T) {
719719
Scanners: "vuln",
720720
Severity: "UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL",
721721
Timeout: 5 * time.Minute,
722+
VEXSource: "oci",
722723
},
723724
},
724725
expectedHTTPCode: http.StatusOK,
@@ -773,7 +774,8 @@ func TestRequestHandler_GetMetadata(t *testing.T) {
773774
"env.SCANNER_TRIVY_VULN_TYPE": "os,library",
774775
"env.SCANNER_TRIVY_SECURITY_CHECKS": "vuln",
775776
"env.SCANNER_TRIVY_SEVERITY": "UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL",
776-
"env.SCANNER_TRIVY_TIMEOUT": "5m0s"
777+
"env.SCANNER_TRIVY_TIMEOUT": "5m0s",
778+
"env.SCANNER_TRIVY_VEX_SOURCE": "oci"
777779
}
778780
}`,
779781
},
@@ -798,6 +800,7 @@ func TestRequestHandler_GetMetadata(t *testing.T) {
798800
Scanners: "vuln",
799801
Severity: "UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL",
800802
Timeout: 5 * time.Minute,
803+
VEXSource: "repo",
801804
},
802805
},
803806
expectedHTTPCode: http.StatusOK,
@@ -850,7 +853,8 @@ func TestRequestHandler_GetMetadata(t *testing.T) {
850853
"env.SCANNER_TRIVY_VULN_TYPE": "os,library",
851854
"env.SCANNER_TRIVY_SECURITY_CHECKS": "vuln",
852855
"env.SCANNER_TRIVY_SEVERITY": "UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL",
853-
"env.SCANNER_TRIVY_TIMEOUT": "5m0s"
856+
"env.SCANNER_TRIVY_TIMEOUT": "5m0s",
857+
"env.SCANNER_TRIVY_VEX_SOURCE": "repo"
854858
}
855859
}`,
856860
},
@@ -921,7 +925,8 @@ func TestRequestHandler_GetMetadata(t *testing.T) {
921925
"env.SCANNER_TRIVY_VULN_TYPE": "os,library",
922926
"env.SCANNER_TRIVY_SECURITY_CHECKS": "vuln",
923927
"env.SCANNER_TRIVY_SEVERITY": "UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL",
924-
"env.SCANNER_TRIVY_TIMEOUT": "5m0s"
928+
"env.SCANNER_TRIVY_TIMEOUT": "5m0s",
929+
"env.SCANNER_TRIVY_VEX_SOURCE": ""
925930
}
926931
}`,
927932
},

pkg/trivy/wrapper.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@ func (w *wrapper) prepareScanCmd(target ScanTarget, outputFile string, opt ScanO
219219
args = append(args, "--insecure")
220220
}
221221

222+
if w.config.VEXSource != "" {
223+
args = append(args, "--vex", w.config.VEXSource)
224+
}
225+
226+
222227
targetName, err := target.Name()
223228
if err != nil {
224229
return nil, xerrors.Errorf("get target name: %w", err)

0 commit comments

Comments
 (0)