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

Add support for --db-repository and --java-db-repository #3

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
80 changes: 41 additions & 39 deletions README.md

Large diffs are not rendered by default.

86 changes: 44 additions & 42 deletions helm/harbor-scanner-trivy/README.md

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions helm/harbor-scanner-trivy/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ spec:
value: {{ .Values.scanner.trivy.skipJavaDBUpdate | quote }}
- name: "SCANNER_TRIVY_OFFLINE_SCAN"
value: {{ .Values.scanner.trivy.offlineScan | quote }}
- name: "SCANNER_TRIVY_DB_REPOSITORY"
value: {{ .Values.scanner.trivy.dbRepository | quote }}
- name: "SCANNER_TRIVY_JAVA_DB_REPOSITORY"
value: {{ .Values.scanner.trivy.javaDBRepository | quote }}
- name: "SCANNER_TRIVY_GITHUB_TOKEN"
valueFrom:
secretKeyRef:
Expand Down
4 changes: 4 additions & 0 deletions helm/harbor-scanner-trivy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ scanner:
## If the flag is enabled you have to manually download the `trivy-java.db` file and mount it in the
## `/home/scanner/.cache/trivy/java-db/trivy-java.db` path (see `cacheDir`).
skipJavaDBUpdate: false
# OCI repository to retrieve the trivy vulnerability database from
dbRepository: "ghcr.io/aquasecurity/trivy-db"
# OCI repository to retrieve the Java trivy vulnerability database from
javaDBRepository: "ghcr.io/aquasecurity/trivy-java-db"
# offlineScan the flag to disable external API requests to identify dependencies.
offlineScan: false
## gitHubToken the GitHub access token to download Trivy DB
Expand Down
2 changes: 2 additions & 0 deletions pkg/etc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type Trivy struct {
IgnorePolicy string `env:"SCANNER_TRIVY_IGNORE_POLICY"`
SkipDBUpdate bool `env:"SCANNER_TRIVY_SKIP_UPDATE" envDefault:"false"`
SkipJavaDBUpdate bool `env:"SCANNER_TRIVY_SKIP_JAVA_DB_UPDATE" envDefault:"false"`
DBRepository string `env:"SCANNER_TRIVY_DB_REPOSITORY" envDefault:"ghcr.io/aquasecurity/trivy-db"`
JavaDBRepository string `env:"SCANNER_TRIVY_JAVA_DB_REPOSITORY" envDefault:"ghcr.io/aquasecurity/trivy-java-db"`
OfflineScan bool `env:"SCANNER_TRIVY_OFFLINE_SCAN" envDefault:"false"`
GitHubToken string `env:"SCANNER_TRIVY_GITHUB_TOKEN"`
Insecure bool `env:"SCANNER_TRIVY_INSECURE" envDefault:"false"`
Expand Down
8 changes: 8 additions & 0 deletions pkg/trivy/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ func (w *wrapper) prepareScanCmd(target ScanTarget, outputFile string, opt ScanO
args = append(args, "--ignore-policy", w.config.IgnorePolicy)
}

if w.config.DBRepository != "" {
args = append(args, "--db-repository", w.config.DBRepository)
}

if w.config.JavaDBRepository != "" {
args = append(args, "--java-db-repository", w.config.JavaDBRepository)
}

if w.config.DebugMode {
args = append(args, "--debug")
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/trivy/wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ func TestWrapper_Scan(t *testing.T) {
IgnorePolicy: "/home/scanner/opa/policy.rego",
SkipDBUpdate: true,
SkipJavaDBUpdate: true,
DBRepository: "ghcr.io/aquasecurity/trivy-db",
JavaDBRepository: "ghcr.io/aquasecurity/trivy-java-db",
GitHubToken: "<github_token>",
Insecure: true,
Timeout: 5 * time.Minute,
Expand Down Expand Up @@ -153,6 +155,10 @@ func TestWrapper_Scan(t *testing.T) {
"--ignore-unfixed",
"--skip-db-update",
"--skip-java-db-update",
"--db-repository",
"ghcr.io/aquasecurity/trivy-db",
"--java-db-repository",
"ghcr.io/aquasecurity/trivy-java-db",
"--ignore-policy",
"/home/scanner/opa/policy.rego",
"--debug",
Expand Down