Skip to content

Commit

Permalink
warn about costly scan scheduling in Helm output (#256)
Browse files Browse the repository at this point in the history
* helm-chart: warn about costly scan scheduling in Helm output

* fix typo

* fix: check API version before calling lookup function

* fix costly schedules check
  • Loading branch information
matheusfm committed Mar 26, 2024
1 parent 66d8fe5 commit 8828c73
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
13 changes: 13 additions & 0 deletions charts/zora/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@ Visit our documentation for in-depth information: https://zora-docs.undistro.io
{{ if .Values.saas.workspaceID -}}
Visit Zora Dashboard to explore your clusters and issues: {{ .Values.saas.server }}
{{- end }}

{{- $warnMisconfig := and .Values.scan.misconfiguration.schedule (include "zora.IsMisconfigScheduleMoreOftenThanHourly" .) }}
{{- if eq $warnMisconfig "true" }}
WARNING: The misconfiguration scan appears to be scheduled to run more frequently than hourly, you should be aware this
may lead to higher resource utilization and network traffic.
{{- end }}

{{- $warVuln := and .Values.scan.vulnerability.schedule (include "zora.IsVulnScheduleMoreOftenThanDaily" .) }}
{{- if eq $warVuln "true" }}
WARNING: The vulnerability scan appears to be scheduled to run more frequently than daily, potentially leading to
significant increases in networking costs and resource utilization. This is particularly relevant for
vulnerability scans, which involve downloading a vulnerability database and pulling images.
{{ end }}
19 changes: 19 additions & 0 deletions charts/zora/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,22 @@ Truncate a name to a specific length
{{- .name }}
{{- end }}
{{- end }}

{{/* Returns true if the explicitly set misconfiguration schedule is more frequently than hourly */}}
{{- define "zora.IsMisconfigScheduleMoreOftenThanHourly" -}}
{{- $cron_fields := split " " .Values.scan.misconfiguration.schedule -}}
{{- $minute := $cron_fields._0 -}}
{{/* minute must be in range [0-59] */}}
{{- not (mustRegexMatch "^(?:\\d|[0-5]\\d)$" $minute) -}}
{{- end -}}

{{/* Returns true if the explicitly set vulnerability schedule is more frequently than daily */}}
{{- define "zora.IsVulnScheduleMoreOftenThanDaily" -}}
{{- $cron_fields := split " " .Values.scan.vulnerability.schedule -}}
{{- $minute := $cron_fields._0 -}}
{{- $hour := $cron_fields._1 -}}
{{/* minute and hour must be in range [0-59] */}}
{{- $isMinuteBad := not (mustRegexMatch "^(?:\\d|[0-5]\\d)$" $minute) -}}
{{- $isHourBad := not (mustRegexMatch "^(?:\\d|[0-5]\\d)$" $hour) -}}
{{- or $isMinuteBad $isHourBad -}}
{{- end -}}
4 changes: 2 additions & 2 deletions charts/zora/templates/clusterscan/clusterscan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ metadata:
spec:
clusterRef:
name: {{ include "zora.clusterName" . }}
{{- $currentMisconfigScan := (lookup "zora.undistro.io/v1alpha1" "ClusterScan" .Release.Namespace $misconfigScanName) }}
{{- $currentMisconfigScan := and (.Capabilities.APIVersions.Has "zora.undistro.io/v1alpha1") (lookup "zora.undistro.io/v1alpha1" "ClusterScan" .Release.Namespace $misconfigScanName) }}
{{- if and $currentMisconfigScan (not .Values.scan.misconfiguration.schedule) }}
schedule: {{ $currentMisconfigScan.spec.schedule | quote }}
{{- else }}
Expand All @@ -62,7 +62,7 @@ metadata:
spec:
clusterRef:
name: {{ include "zora.clusterName" . }}
{{- $currentVulnScan := (lookup "zora.undistro.io/v1alpha1" "ClusterScan" .Release.Namespace $vulnScanName) }}
{{- $currentVulnScan := and (.Capabilities.APIVersions.Has "zora.undistro.io/v1alpha1") (lookup "zora.undistro.io/v1alpha1" "ClusterScan" .Release.Namespace $vulnScanName) }}
{{- if and $currentVulnScan (not .Values.scan.vulnerability.schedule) }}
schedule: {{ $currentVulnScan.spec.schedule | quote }}
{{- else }}
Expand Down

0 comments on commit 8828c73

Please sign in to comment.