Skip to content

Commit

Permalink
feat: Add TRIVY_INSECURE flag to skip verifying registry certificates
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Pacak <pacak.daniel@gmail.com>
  • Loading branch information
danielpacak committed Apr 15, 2020
1 parent 49a85f0 commit a58e260
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ Configuration of the adapter is done via environment variables at startup.
| `SCANNER_TRIVY_IGNORE_UNFIXED` | `false` | The flag to display only fixed vulnerabilities |
| `SCANNER_TRIVY_SKIP_UPDATE` | `false` | The flag to enable or disable [Trivy DB][trivy-db] downloads from GitHub |
| `SCANNER_TRIVY_GITHUB_TOKEN` | N/A | The GitHub access token to download [Trivy DB][trivy-db] (see [GitHub rate limiting][gh-rate-limit]) |
| `SCANNER_TRIVY_INSECURE` | `false` | The flag to skip verifying registry certificate |
| `SCANNER_STORE_REDIS_URL` | `redis://harbor-harbor-redis:6379` | Redis server URI for a redis store |
| `SCANNER_STORE_REDIS_NAMESPACE` | `harbor.scanner.trivy:store` | A namespace for keys in a redis store |
| `SCANNER_STORE_REDIS_POOL_MAX_ACTIVE` | `5` | The max number of connections allocated by the pool for a redis store |
Expand Down
1 change: 1 addition & 0 deletions helm/harbor-scanner-trivy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ The following table lists the configurable parameters of the scanner adapter cha
| `scanner.trivy.ignoreUnfixed` | The flag to display only fixed vulnerabilities | `false` |
| `scanner.trivy.skipUpdate` | The flag to enable or disable Trivy DB downloads from GitHub | `false` |
| `scanner.trivy.gitHubToken` | The GitHub access token to download Trivy DB | |
| `scanner.trivy.insecure` | The flag to skip verifying registry certificate | `false` |
| `scanner.store.redisURL` | Redis server URI for a redis store | `redis://harbor-harbor-redis:6379` |
| `scanner.store.redisNamespace` | A namespace for keys in a redis store | `harbor.scanner.trivy:store` |
| `scanner.store.redisMaxActive` | The max number of connections allocated by the pool for a redis store | `5` |
Expand Down
2 changes: 2 additions & 0 deletions helm/harbor-scanner-trivy/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ spec:
secretKeyRef:
name: {{ include "harbor-scanner-trivy.fullname" . }}
key: gitHubToken
- name: "SCANNER_TRIVY_INSECURE"
value: {{ .Values.scanner.trivy.insecure | default false | quote }}
- name: "SCANNER_STORE_REDIS_URL"
value: {{ .Values.scanner.store.redisURL | quote }}
- name: "SCANNER_STORE_REDIS_NAMESPACE"
Expand Down
2 changes: 2 additions & 0 deletions helm/harbor-scanner-trivy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ scanner:
# You can create a GitHub token by following the instructions in
# https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line
gitHubToken: ""
# insecure the flag to skip verifying registry certificate
insecure: false
store:
redisURL: "redis://harbor-harbor-redis:6379"
redisNamespace: "harbor.scanner.trivy:store"
Expand Down
1 change: 1 addition & 0 deletions pkg/etc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Trivy struct {
IgnoreUnfixed bool `env:"SCANNER_TRIVY_IGNORE_UNFIXED" envDefault:"false"`
SkipUpdate bool `env:"SCANNER_TRIVY_SKIP_UPDATE" envDefault:"false"`
GitHubToken string `env:"SCANNER_TRIVY_GITHUB_TOKEN"`
Insecure bool `env:"SCANNER_TRIVY_INSECURE" envDefault:"false"`
}

type API struct {
Expand Down
3 changes: 3 additions & 0 deletions pkg/etc/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func TestGetConfig(t *testing.T) {
ReportsDir: "/home/scanner/.cache/reports",
VulnType: "os,library",
Severity: "UNKNOWN,LOW,MEDIUM,HIGH,CRITICAL",
Insecure: false,
GitHubToken: "",
},
RedisStore: RedisStore{
Expand Down Expand Up @@ -105,6 +106,7 @@ func TestGetConfig(t *testing.T) {
"SCANNER_TRIVY_VULN_TYPE": "os,library",
"SCANNER_TRIVY_SEVERITY": "CRITICAL",
"SCANNER_TRIVY_IGNORE_UNFIXED": "true",
"SCANNER_TRIVY_INSECURE": "true",
"SCANNER_TRIVY_SKIP_UPDATE": "true",
"SCANNER_TRIVY_GITHUB_TOKEN": "<GITHUB_TOKEN>",

Expand All @@ -131,6 +133,7 @@ func TestGetConfig(t *testing.T) {
Severity: "CRITICAL",
IgnoreUnfixed: true,
SkipUpdate: true,
Insecure: true,
GitHubToken: "<GITHUB_TOKEN>",
},
RedisStore: RedisStore{
Expand Down
5 changes: 5 additions & 0 deletions pkg/trivy/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ func (w *wrapper) prepareScanCmd(imageRef ImageRef, outputFile string) (*exec.Cm
if strings.TrimSpace(w.config.GitHubToken) != "" {
cmd.Env = append(cmd.Env, fmt.Sprintf("GITHUB_TOKEN=%s", w.config.GitHubToken))
}

if w.config.Insecure {
cmd.Env = append(cmd.Env, "TRIVY_INSECURE=true")
}

return cmd, nil
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/trivy/wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func TestWrapper_Scan(t *testing.T) {
IgnoreUnfixed: true,
SkipUpdate: true,
GitHubToken: "<github_token>",
Insecure: true,
}

imageRef := ImageRef{
Expand Down Expand Up @@ -99,6 +100,7 @@ func TestWrapper_Scan(t *testing.T) {
"TRIVY_PASSWORD=s3cret",
"TRIVY_NON_SSL=true",
"GITHUB_TOKEN=<github_token>",
"TRIVY_INSECURE=true",
}

ambassador.On("TempFile", "/home/scanner/.cache/reports", "scan_report_*.json").
Expand Down

0 comments on commit a58e260

Please sign in to comment.