Skip to content

Commit

Permalink
feat: add dbRepositoryUsername and dbRepositoryPassword for dbReposit… (
Browse files Browse the repository at this point in the history
#1657)

* feat: add dbRepositoryUsername and dbRepositoryPassword for dbRepository authentication

* fix lint issue

* refactor documentation

* test: condition for repo-db credentials

Signed-off-by: chenk <hen.keinan@gmail.com>

---------

Signed-off-by: chenk <hen.keinan@gmail.com>
Co-authored-by: chenk <hen.keinan@gmail.com>
  • Loading branch information
juergen-fast and chen-keinan committed Dec 27, 2023
1 parent e717828 commit 1ecf6a0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions deploy/helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ Keeps security report resources updated
| trivy.dbRegistry | string | `"ghcr.io"` | |
| trivy.dbRepository | string | `"aquasecurity/trivy-db"` | |
| trivy.dbRepositoryInsecure | string | `"false"` | The Flag to enable insecure connection for downloading trivy-db via proxy (air-gaped env) |
| trivy.dbRepositoryPassword | string | `nil` | The password for dbRepository authentication |
| trivy.dbRepositoryUsername | string | `nil` | The username for dbRepository authentication |
| trivy.debug | bool | `false` | debug One of `true` or `false`. Enables debug mode. |
| trivy.filesystemScanCacheDir | string | `"/var/trivyoperator/trivy-db"` | filesystemScanCacheDir the flag to set custom path for trivy filesystem scan `cache-dir` parameter. Only applicable in filesystem scan mode. |
| trivy.githubToken | string | `nil` | githubToken is the GitHub access token used by Trivy to download the vulnerabilities database from GitHub. Only applicable in Standalone mode. |
Expand Down
6 changes: 6 additions & 0 deletions deploy/helm/templates/secrets/trivy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ data:
{{- with .Values.trivy.githubToken }}
trivy.githubToken: {{ . | b64enc | quote }}
{{- end }}
{{- with .Values.trivy.dbRepositoryUsername }}
trivy.dbRepositoryUsername: {{ . | b64enc | quote }}
{{- end }}
{{- with .Values.trivy.dbRepositoryPassword }}
trivy.dbRepositoryPassword: {{ . | b64enc | quote }}
{{- end }}
{{- if or (eq .Values.trivy.mode "ClientServer") .Values.operator.builtInTrivyServer }}
{{- with .Values.trivy.serverToken }}
trivy.serverToken: {{ . | b64enc | quote }}
Expand Down
8 changes: 8 additions & 0 deletions deploy/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,14 @@ trivy:
dbRegistry: "ghcr.io"
dbRepository: "aquasecurity/trivy-db"

# -- The username for dbRepository authentication
#
dbRepositoryUsername: ~

# -- The password for dbRepository authentication
#
dbRepositoryPassword: ~

# -- javaDbRegistry is the registry for the Java vulnerability database.
javaDbRegistry: "ghcr.io"
javaDbRepository: "aquasecurity/trivy-java-db"
Expand Down
8 changes: 8 additions & 0 deletions pkg/plugins/trivy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ const (
keyTrivySkipFiles = "trivy.skipFiles"
keyTrivySkipDirs = "trivy.skipDirs"
keyTrivyDBRepository = "trivy.dbRepository"
keyTrivyDBRepositoryUsername = "trivy.dbRepositoryUsername"
keyTrivyDBRepositoryPassword = "trivy.dbRepositoryPassword" // #nosec G101
keyTrivyJavaDBRepository = "trivy.javaDbRepository"
keyTrivyDBRepositoryInsecure = "trivy.dbRepositoryInsecure"

Expand Down Expand Up @@ -221,6 +223,12 @@ func (c Config) GetSkipJavaDBUpdate() bool {
return boolVal
}

func (c Config) TrivyDBRepositoryCredentialsSet() bool {
_, userOk := c.Data[keyTrivyDBRepositoryUsername]
_, passOk := c.Data[keyTrivyDBRepositoryPassword]
return userOk && passOk
}

func (c Config) GetImageScanCacheDir() string {
val, ok := c.Data[keyTrivyImageScanCacheDir]
if !ok || val == "" {
Expand Down
6 changes: 6 additions & 0 deletions pkg/plugins/trivy/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,12 @@ func initContainerFSEnvVar(trivyConfigName string, config Config) []corev1.EnvVa
constructEnvVarSourceFromConfigMap("NO_PROXY", trivyConfigName, keyTrivyNoProxy),
constructEnvVarSourceFromSecret("GITHUB_TOKEN", trivyConfigName, keyTrivyGitHubToken),
}
if config.TrivyDBRepositoryCredentialsSet() {
envs = append(envs, []corev1.EnvVar{
constructEnvVarSourceFromSecret("TRIVY_USERNAME", trivyConfigName, keyTrivyDBRepositoryUsername),
constructEnvVarSourceFromSecret("TRIVY_PASSWORD", trivyConfigName, keyTrivyDBRepositoryPassword),
}...)
}
if config.GetDBRepositoryInsecure() {
envs = append(envs, corev1.EnvVar{
Name: "TRIVY_INSECURE",
Expand Down
6 changes: 6 additions & 0 deletions pkg/plugins/trivy/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,12 @@ func initContainerEnvVar(trivyConfigName string, config Config) []corev1.EnvVar
constructEnvVarSourceFromConfigMap("NO_PROXY", trivyConfigName, keyTrivyNoProxy),
constructEnvVarSourceFromSecret("GITHUB_TOKEN", trivyConfigName, keyTrivyGitHubToken),
}
if config.TrivyDBRepositoryCredentialsSet() {
envs = append(envs, []corev1.EnvVar{
constructEnvVarSourceFromSecret("TRIVY_USERNAME", trivyConfigName, keyTrivyDBRepositoryUsername),
constructEnvVarSourceFromSecret("TRIVY_PASSWORD", trivyConfigName, keyTrivyDBRepositoryPassword),
}...)
}

if config.GetDBRepositoryInsecure() {
envs = append(envs, corev1.EnvVar{
Expand Down

0 comments on commit 1ecf6a0

Please sign in to comment.