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

fix: helm param gcr service account auth #2108

Merged
merged 3 commits into from
Jun 26, 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
1 change: 1 addition & 0 deletions deploy/helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ Keeps security report resources updated
| trivyOperator.scanJobTolerations | list | `[]` | scanJobTolerations tolerations to be applied to the scanner pods so that they can run on nodes with matching taints |
| trivyOperator.skipInitContainers | bool | `false` | skipInitContainers when this flag is set to true, the initContainers will be skipped for the scanner and node collector pods |
| trivyOperator.skipResourceByLabels | string | `""` | skipResourceByLabels comma-separated labels keys which trivy-operator will skip scanning on resources with matching labels |
| trivyOperator.useGCRServiceAccount | bool | `true` | useGCRServiceAccount the flag to enable the usage of GCR service account for scanning images in GCR |
| trivyOperator.vulnerabilityReportsPlugin | string | `"Trivy"` | vulnerabilityReportsPlugin the name of the plugin that generates vulnerability reports `Trivy` |
| volumeMounts[0].mountPath | string | `"/tmp"` | |
| volumeMounts[0].name | string | `"cache-policies"` | |
Expand Down
1 change: 1 addition & 0 deletions deploy/helm/templates/configmaps/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ data:
{{- with .Values.trivyOperator.scanJobAutomountServiceAccountToken }}
scanJob.automountServiceAccountToken: {{ . | quote }}
{{- end }}
scanJob.useGCRServiceAccount: {{ .Values.trivyOperator.useGCRServiceAccount | quote }}
{{- with .Values.trivyOperator.skipInitContainers }}
scanJob.skipInitContainers: {{ . | quote }}
{{- end }}
Expand Down
3 changes: 2 additions & 1 deletion deploy/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ trivyOperator:
# hostPath:
# path: /var/lib/etcd


# -- useGCRServiceAccount the flag to enable the usage of GCR service account for scanning images in GCR
useGCRServiceAccount: true
# -- scanJobAutomountServiceAccountToken the flag to enable automount for service account token on scan job
scanJobAutomountServiceAccountToken: false

Expand Down
1 change: 1 addition & 0 deletions deploy/static/trivy-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2936,6 +2936,7 @@ metadata:
data:
nodeCollector.volumes: "[{\"hostPath\":{\"path\":\"/var/lib/etcd\"},\"name\":\"var-lib-etcd\"},{\"hostPath\":{\"path\":\"/var/lib/kubelet\"},\"name\":\"var-lib-kubelet\"},{\"hostPath\":{\"path\":\"/var/lib/kube-scheduler\"},\"name\":\"var-lib-kube-scheduler\"},{\"hostPath\":{\"path\":\"/var/lib/kube-controller-manager\"},\"name\":\"var-lib-kube-controller-manager\"},{\"hostPath\":{\"path\":\"/etc/systemd\"},\"name\":\"etc-systemd\"},{\"hostPath\":{\"path\":\"/lib/systemd\"},\"name\":\"lib-systemd\"},{\"hostPath\":{\"path\":\"/etc/kubernetes\"},\"name\":\"etc-kubernetes\"},{\"hostPath\":{\"path\":\"/etc/cni/net.d/\"},\"name\":\"etc-cni-netd\"}]"
nodeCollector.volumeMounts: "[{\"mountPath\":\"/var/lib/etcd\",\"name\":\"var-lib-etcd\",\"readOnly\":true},{\"mountPath\":\"/var/lib/kubelet\",\"name\":\"var-lib-kubelet\",\"readOnly\":true},{\"mountPath\":\"/var/lib/kube-scheduler\",\"name\":\"var-lib-kube-scheduler\",\"readOnly\":true},{\"mountPath\":\"/var/lib/kube-controller-manager\",\"name\":\"var-lib-kube-controller-manager\",\"readOnly\":true},{\"mountPath\":\"/etc/systemd\",\"name\":\"etc-systemd\",\"readOnly\":true},{\"mountPath\":\"/lib/systemd/\",\"name\":\"lib-systemd\",\"readOnly\":true},{\"mountPath\":\"/etc/kubernetes\",\"name\":\"etc-kubernetes\",\"readOnly\":true},{\"mountPath\":\"/etc/cni/net.d/\",\"name\":\"etc-cni-netd\",\"readOnly\":true}]"
scanJob.useGCRServiceAccount: "true"
scanJob.podTemplateContainerSecurityContext: "{\"allowPrivilegeEscalation\":false,\"capabilities\":{\"drop\":[\"ALL\"]},\"privileged\":false,\"readOnlyRootFilesystem\":true}"
scanJob.compressLogs: "true"
vulnerabilityReports.scanner: "Trivy"
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugins/trivy/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ func GetPodSpecForStandaloneMode(ctx trivyoperator.PluginContext,
Value: "true",
})
}
gcrImage := CheckGcpCrOrPrivateRegistry(c.Image)
if _, ok := containersCredentials[c.Name]; ok && secret != nil {
registryUsernameKey := fmt.Sprintf("%s.username", c.Name)
registryPasswordKey := fmt.Sprintf("%s.password", c.Name)
secretName := secret.Name
if gcrImage {
if CheckGcpCrOrPrivateRegistry(c.Image) &&
trivyoperator.GetDefaultConfig().GetScanJobUseGCRServiceAccount() {
createEnvandVolumeForGcr(&env, &volumeMounts, &volumes, &registryPasswordKey, &secretName)
} else {
env = append(env, corev1.EnvVar{
Expand Down
9 changes: 9 additions & 0 deletions pkg/trivyoperator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const (
KeyNodeCollectorVolumeMounts = "nodeCollector.volumeMounts"
KeyScanJobCustomVolumesMount = "scanJob.customVolumesMount"
KeyScanJobCustomVolumes = "scanJob.customVolumes"
KeyScanJobUseGCRServiceAccount = "scanJob.UseGCRServiceAccount"

keyScanJobNodeSelector = "scanJob.nodeSelector"
keyScanJobAnnotations = "scanJob.annotations"
Expand Down Expand Up @@ -319,6 +320,14 @@ func (c ConfigData) GetScanJobAutomountServiceAccountToken() bool {
return c.getBoolKey(keyscanJobAutomountServiceAccountToken)
}

func (c ConfigData) GetScanJobUseGCRServiceAccount() bool {
val, ok := c[KeyScanJobUseGCRServiceAccount]
if !ok {
return true
}
return val == "true"
}

func (c ConfigData) GetSkipInitContainers() bool {
return c.getBoolKey(keySkipInitContainers)
}
Expand Down
Loading