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

feat(registry-scanner): check cronjob frequency to avoid misuse #1983

Merged
merged 4 commits into from
Oct 18, 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
2 changes: 1 addition & 1 deletion charts/registry-scanner/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description: Sysdig Registry Scanner
type: application
home: https://www.sysdig.com/
icon: https://avatars.githubusercontent.com/u/5068817?s=200&v=4
version: 1.4.0
version: 1.4.1
appVersion: 0.5.0
maintainers:
- name: sysdiglabs
2 changes: 1 addition & 1 deletion charts/registry-scanner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Use the following command to deploy:
helm upgrade --install registry-scanner \
--namespace sysdig-agent \
--create-namespace \
--version=1.4.0 \
--version=1.4.1 \
--set config.secureBaseURL=<SYSDIG_SECURE_URL> \
--set config.secureAPIToken=<SYSDIG_SECURE_API_TOKEN> \
--set config.secureSkipTLS=true \
Expand Down
21 changes: 21 additions & 0 deletions charts/registry-scanner/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,24 @@ Fail if cronjob.timeZone is set for Kubernetes < 1.24
{{ fail "cronjob.timeZone was specified but kubernetes version is smaller than 1.24." }}
{{- end }}
{{- end }}
{{/*
Check cronjob value
*/}}
{{- define "registry-scanner.checkCronSchedule" -}}
{{- $schedule := .Values.cronjob.schedule}}
{{- $parts := splitList " " $schedule -}}

{{- if eq (len $parts) 5 -}}
{{- $minute := index $parts 0 -}}
{{- $hour := index $parts 1 -}}
{{- $dayOfMonth := index $parts 2 -}}
{{- $month := index $parts 3 -}}
{{- $dayOfWeek := index $parts 4 -}}

{{- if and (eq $dayOfMonth "*" ) (eq $dayOfWeek "*") (eq $month "*") -}}}
{{- printf "WARNING: You have configured the registry scanner to run on a schedule of '%s'. Running the scanner more often than every 24 hours can increase the load on your registry. The recommended configuration is to perform a scan weekly." $schedule | fail}}
{{- end -}}
{{- else -}}
{{- print "Error: Wrong cronjob format." | quote }}
{{- end -}}
{{- end -}}
1 change: 1 addition & 0 deletions charts/registry-scanner/templates/cronjob.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- include "registry-scanner.checkCronSchedule" . }}
{{- include "registry-scanner.validateTimeZone" . }}
{{- if (include "registry-scanner.kubeVersionLessThan" (dict "root" . "major" 1 "minor" 21)) }}
apiVersion: batch/v1beta1
Expand Down
17 changes: 17 additions & 0 deletions charts/registry-scanner/tests/cronjob_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,20 @@ tests:
- failedTemplate:
# errorMessage: spec.timeZone
errorMessage: "cronjob.timeZone was specified but kubernetes version is smaller than 1.24."

- it: sets cronjob schedule more often than 24h
set:
cronjob.schedule: "0 0 * * *"
asserts:
- failedTemplate:
errorMessage: "WARNING: You have configured the registry scanner to run on a schedule of '0 0 * * *'. \
Running the scanner more often than every 24 hours can increase the load on your registry. \
The recommended configuration is to perform a scan weekly."

- it: sets cronjob schedule less often than 24h
set:
cronjob.schedule: "0 0 1 * *"
asserts:
- equal:
path: spec.schedule
value: "0 0 1 * *"
Loading