From fc1fef92913c071573d4f4b4e785c20e7c953447 Mon Sep 17 00:00:00 2001 From: Yan Bondarenko <202671653+yankawai@users.noreply.github.com> Date: Mon, 26 Oct 2026 18:49:28 +0300 Subject: [PATCH] fix(monitoring): reject a non-text email template before the default alerta.alerts.email.template went through default "" before its type was checked, so false, 0 or an empty list or map turned into an empty string and the chart rendered without a template instead of failing. The type is now checked on the value as written, and anything other than text or an absent key fails the render. Assisted-by: LLM Signed-off-by: Yan Bondarenko <202671653+yankawai@users.noreply.github.com> --- packages/system/monitoring/templates/alerta/alerta.yaml | 9 +++++---- .../tests/alertmanager_email_validation_test.yaml | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/system/monitoring/templates/alerta/alerta.yaml b/packages/system/monitoring/templates/alerta/alerta.yaml index 33c8c5b77..0938f7e0b 100644 --- a/packages/system/monitoring/templates/alerta/alerta.yaml +++ b/packages/system/monitoring/templates/alerta/alerta.yaml @@ -11,7 +11,11 @@ {{- $emailSeverities := $email.severities | default (list "critical" "major") }} {{- $emailPasswordSecret := "alertmanager-email-password" }} {{- $emailTemplateConfigMap := "alertmanager-email-template" }} -{{- $emailTemplate := $email.template | default "" }} +{{- $emailTemplateRaw := index $email "template" }} +{{- if not (or (kindIs "string" $emailTemplateRaw) (kindIs "invalid" $emailTemplateRaw)) }} +{{- fail (printf "alerta.alerts.email.template must be the text of an Alertmanager template file, got a %s" (kindOf $emailTemplateRaw)) }} +{{- end }} +{{- $emailTemplate := $emailTemplateRaw | default "" }} {{- $emailSet := list }} {{- range $field := list "to" "from" "smarthost" "authUsername" "repeatInterval" "alertnames" "severities" "template" }} {{- if index $email $field }}{{ $emailSet = append $emailSet $field }}{{ end }} @@ -104,9 +108,6 @@ {{- end }} {{- end }} {{- if $emailTemplate }} -{{- if not (kindIs "string" $emailTemplate) }} -{{- fail (printf "alerta.alerts.email.template must be the text of an Alertmanager template file, got a %s" (kindOf $emailTemplate)) }} -{{- end }} {{- if not (regexMatch "\\{\\{-?\\s*define\\s" $emailTemplate) }} {{- fail "alerta.alerts.email.template must define named templates, such as email.default.subject and email.default.html, because Alertmanager only uses the file through the names it defines" }} {{- end }} diff --git a/packages/system/monitoring/tests/alertmanager_email_validation_test.yaml b/packages/system/monitoring/tests/alertmanager_email_validation_test.yaml index 5c2271155..5edc54242 100644 --- a/packages/system/monitoring/tests/alertmanager_email_validation_test.yaml +++ b/packages/system/monitoring/tests/alertmanager_email_validation_test.yaml @@ -251,3 +251,10 @@ tests: asserts: - failedTemplate: errorMessage: "alerta.alerts.email to, from and smarthost must all be set to enable email alerts. To turn email off, clear every field under alerta.alerts.email. Fields still set are template" + + - it: rejects a template given as a boolean instead of being dropped by the default + set: + alerta.alerts.email.template: false + asserts: + - failedTemplate: + errorMessage: "alerta.alerts.email.template must be the text of an Alertmanager template file, got a bool"