Skip to content

Commit 94b04c6

Browse files
committed
feat: add support for trivy dbRepository and javaDBRepository
Signed-off-by: Benjamin Bordes <benjaminbordes78@gmail.com>
1 parent b051a07 commit 94b04c6

File tree

7 files changed

+109
-81
lines changed

7 files changed

+109
-81
lines changed

README.md

Lines changed: 41 additions & 39 deletions
Large diffs are not rendered by default.

helm/harbor-scanner-trivy/README.md

Lines changed: 44 additions & 42 deletions
Large diffs are not rendered by default.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ spec:
7777
value: {{ .Values.scanner.trivy.skipJavaDBUpdate | quote }}
7878
- name: "SCANNER_TRIVY_OFFLINE_SCAN"
7979
value: {{ .Values.scanner.trivy.offlineScan | quote }}
80+
- name: "SCANNER_TRIVY_DB_REPOSITORY"
81+
value: {{ .Values.scanner.trivy.dbRepository | quote }}
82+
- name: "SCANNER_TRIVY_JAVA_DB_REPOSITORY"
83+
value: {{ .Values.scanner.trivy.javaDBRepository | quote }}
8084
- name: "SCANNER_TRIVY_GITHUB_TOKEN"
8185
valueFrom:
8286
secretKeyRef:

helm/harbor-scanner-trivy/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ scanner:
7878
## If the flag is enabled you have to manually download the `trivy-java.db` file and mount it in the
7979
## `/home/scanner/.cache/trivy/java-db/trivy-java.db` path (see `cacheDir`).
8080
skipJavaDBUpdate: false
81+
# OCI repository to retrieve the trivy vulnerability database from
82+
dbRepository: "ghcr.io/aquasecurity/trivy-db"
83+
# OCI repository to retrieve the Java trivy vulnerability database from
84+
javaDBRepository: "ghcr.io/aquasecurity/trivy-java-db"
8185
# offlineScan the flag to disable external API requests to identify dependencies.
8286
offlineScan: false
8387
## gitHubToken the GitHub access token to download Trivy DB

pkg/etc/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ type Trivy struct {
3434
IgnorePolicy string `env:"SCANNER_TRIVY_IGNORE_POLICY"`
3535
SkipDBUpdate bool `env:"SCANNER_TRIVY_SKIP_UPDATE" envDefault:"false"`
3636
SkipJavaDBUpdate bool `env:"SCANNER_TRIVY_SKIP_JAVA_DB_UPDATE" envDefault:"false"`
37+
DBRepository string `env:"SCANNER_TRIVY_DB_REPOSITORY" envDefault:"ghcr.io/aquasecurity/trivy-db"`
38+
JavaDBRepository string `env:"SCANNER_TRIVY_JAVA_DB_REPOSITORY" envDefault:"ghcr.io/aquasecurity/trivy-java-db"`
3739
OfflineScan bool `env:"SCANNER_TRIVY_OFFLINE_SCAN" envDefault:"false"`
3840
GitHubToken string `env:"SCANNER_TRIVY_GITHUB_TOKEN"`
3941
Insecure bool `env:"SCANNER_TRIVY_INSECURE" envDefault:"false"`

pkg/trivy/wrapper.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,14 @@ func (w *wrapper) prepareScanCmd(target ScanTarget, outputFile string, opt ScanO
203203
args = append(args, "--ignore-policy", w.config.IgnorePolicy)
204204
}
205205

206+
if w.config.DBRepository != "" {
207+
args = append(args, "--db-repository", w.config.DBRepository)
208+
}
209+
210+
if w.config.JavaDBRepository != "" {
211+
args = append(args, "--java-db-repository", w.config.JavaDBRepository)
212+
}
213+
206214
if w.config.DebugMode {
207215
args = append(args, "--debug")
208216
}

pkg/trivy/wrapper_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ func TestWrapper_Scan(t *testing.T) {
115115
IgnorePolicy: "/home/scanner/opa/policy.rego",
116116
SkipDBUpdate: true,
117117
SkipJavaDBUpdate: true,
118+
DBRepository: "ghcr.io/aquasecurity/trivy-db",
119+
JavaDBRepository: "ghcr.io/aquasecurity/trivy-java-db",
118120
GitHubToken: "<github_token>",
119121
Insecure: true,
120122
Timeout: 5 * time.Minute,
@@ -153,6 +155,10 @@ func TestWrapper_Scan(t *testing.T) {
153155
"--ignore-unfixed",
154156
"--skip-db-update",
155157
"--skip-java-db-update",
158+
"--db-repository",
159+
"ghcr.io/aquasecurity/trivy-db",
160+
"--java-db-repository",
161+
"ghcr.io/aquasecurity/trivy-java-db",
156162
"--ignore-policy",
157163
"/home/scanner/opa/policy.rego",
158164
"--debug",

0 commit comments

Comments
 (0)