Skip to content

Commit

Permalink
feat: ssl-cert dir support on init containers and built-in server (#1903
Browse files Browse the repository at this point in the history
)

Signed-off-by: chenk <hen.keinan@gmail.com>
  • Loading branch information
chen-keinan committed Mar 12, 2024
1 parent 5600921 commit 50b60fd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 52 deletions.
10 changes: 10 additions & 0 deletions deploy/helm/templates/trivy-server/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ spec:
- mountPath: /home/scanner/.cache
name: data
readOnly: false
{{- with .Values.trivy.sslCertDir | quote }}
- mountPath: {{ . }}
name: ssl-cert-dir
readOnly: true
{{- end }}
{{- with .Values.trivy.server.resources }}
resources: {{- toYaml . | nindent 12 }}
{{- end }}
Expand All @@ -125,6 +130,11 @@ spec:
- name: data
emptyDir: {}
{{- end }}
{{- with .Values.trivy.sslCertDir | quote }}
- name: ssl-cert-dir
hostPath:
path: {{ . }}
{{- end }}
{{- with .Values.tolerations }}
tolerations: {{- toYaml . | nindent 8 }}
{{- end }}
Expand Down
46 changes: 22 additions & 24 deletions pkg/plugins/trivy/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,28 @@ func GetPodSpecForStandaloneFSMode(ctx trivyoperator.PluginContext, config Confi
ReadOnly: false,
},
}

volumes := []corev1.Volume{
{
Name: FsSharedVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
Medium: corev1.StorageMediumDefault,
},
},
},
{
Name: tmpVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
Medium: corev1.StorageMediumDefault,
},
},
},
}
if volume, volumeMount := config.GenerateSslCertDirVolumeIfAvailable(trivyConfigName); volume != nil && volumeMount != nil {
volumes = append(volumes, *volume)
volumeMounts = append(volumeMounts, *volumeMount)
}
initContainerCopyBinary := corev1.Container{
Name: p.idGenerator.GenerateID(),
Image: trivyImageRef,
Expand Down Expand Up @@ -122,25 +143,6 @@ func GetPodSpecForStandaloneFSMode(ctx trivyoperator.PluginContext, config Confi

var containers []corev1.Container

volumes := []corev1.Volume{
{
Name: FsSharedVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
Medium: corev1.StorageMediumDefault,
},
},
},
{
Name: tmpVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
Medium: corev1.StorageMediumDefault,
},
},
},
}

volumeMounts = append(volumeMounts, getScanResultVolumeMount())
volumes = append(volumes, getScanResultVolume())

Expand All @@ -152,10 +154,6 @@ func GetPodSpecForStandaloneFSMode(ctx trivyoperator.PluginContext, config Confi
volumes = append(volumes, *volume)
volumeMounts = append(volumeMounts, *volumeMount)
}
if volume, volumeMount := config.GenerateSslCertDirVolumeIfAvailable(trivyConfigName); volume != nil && volumeMount != nil {
volumes = append(volumes, *volume)
volumeMounts = append(volumeMounts, *volumeMount)
}

for _, c := range getContainers(spec) {
env := []corev1.EnvVar{
Expand Down
51 changes: 23 additions & 28 deletions pkg/plugins/trivy/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@ func GetPodSpecForStandaloneMode(ctx trivyoperator.PluginContext,

cacheDir := config.GetImageScanCacheDir()

volumeMounts := []corev1.VolumeMount{
{
Name: tmpVolumeName,
ReadOnly: false,
MountPath: "/tmp",
},
}
volumes := []corev1.Volume{
{
Name: tmpVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
Medium: corev1.StorageMediumDefault,
},
},
},
}

if volume, volumeMount := config.GenerateSslCertDirVolumeIfAvailable(trivyConfigName); volume != nil && volumeMount != nil {
volumes = append(volumes, *volume)
volumeMounts = append(volumeMounts, *volumeMount)
}
initContainer := corev1.Container{
Name: p.idGenerator.GenerateID(),
Image: trivyImageRef,
Expand All @@ -117,34 +139,11 @@ func GetPodSpecForStandaloneMode(ctx trivyoperator.PluginContext,
},
Resources: requirements,
SecurityContext: securityContext,
VolumeMounts: []corev1.VolumeMount{
{
Name: tmpVolumeName,
MountPath: "/tmp",
ReadOnly: false,
},
},
VolumeMounts: volumeMounts,
}

var containers []corev1.Container

volumeMounts := []corev1.VolumeMount{
{
Name: tmpVolumeName,
ReadOnly: false,
MountPath: "/tmp",
},
}
volumes := []corev1.Volume{
{
Name: tmpVolumeName,
VolumeSource: corev1.VolumeSource{
EmptyDir: &corev1.EmptyDirVolumeSource{
Medium: corev1.StorageMediumDefault,
},
},
},
}
volumeMounts = append(volumeMounts, getScanResultVolumeMount())
volumes = append(volumes, getScanResultVolume())

Expand All @@ -156,10 +155,6 @@ func GetPodSpecForStandaloneMode(ctx trivyoperator.PluginContext,
volumes = append(volumes, *volume)
volumeMounts = append(volumeMounts, *volumeMount)
}
if volume, volumeMount := config.GenerateSslCertDirVolumeIfAvailable(trivyConfigName); volume != nil && volumeMount != nil {
volumes = append(volumes, *volume)
volumeMounts = append(volumeMounts, *volumeMount)
}

for _, c := range containersSpec {
env := []corev1.EnvVar{
Expand Down

0 comments on commit 50b60fd

Please sign in to comment.