Skip to content

Commit 67716f9

Browse files
committed
Add receiver validation (discord and email) (#7097)
1 parent 8d0f0df commit 67716f9

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
* [BUGFIX] Scheduler: Avoid all queriers reserved for prioritized requests. #7057
112112
* [BUGFIX] Fix bug where validating metric names uses the wrong validation logic. #7086
113113
* [BUGFIX] Compactor: Avoid race condition which allow a grouper to not compact all partitions. #7082
114+
* [BUGFIX] Add alertmanager receiver validation for discord and email. #7097
114115

115116
## 1.19.1 2025-09-20
116117

pkg/alertmanager/api.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ var (
5656
errMSTeamsV2WebhookUrlFileNotAllowed = errors.New("setting MSTeamsV2 webhook_url_file is not allowed")
5757
errRocketChatTokenIdFileNotAllowed = errors.New("setting RocketChat token_id_file is not allowed")
5858
errRocketChatTokenFileNotAllowed = errors.New("setting RocketChat token_file is not allowed")
59+
errDiscordWebhookUrlFileNotAllowed = errors.New("setting Discord webhook_url_file is not allowed")
60+
errEmailAuthPasswordFileNotAllowed = errors.New("setting Email auth_password_file is not allowed")
5961
)
6062

6163
// UserConfig is used to communicate a users alertmanager configs
@@ -399,6 +401,14 @@ func validateAlertmanagerConfig(cfg any) error {
399401
if err := validateRocketChatConfig(v.Interface().(config.RocketchatConfig)); err != nil {
400402
return err
401403
}
404+
case reflect.TypeOf(config.DiscordConfig{}):
405+
if err := validateDiscordConfig(v.Interface().(config.DiscordConfig)); err != nil {
406+
return err
407+
}
408+
case reflect.TypeOf(config.EmailConfig{}):
409+
if err := validateEmailConfig(v.Interface().(config.EmailConfig)); err != nil {
410+
return err
411+
}
402412
}
403413

404414
// If the input config is a struct, recursively iterate on all fields.
@@ -588,3 +598,21 @@ func validateRocketChatConfig(cfg config.RocketchatConfig) error {
588598

589599
return nil
590600
}
601+
602+
// validateDiscordConfig validates the Discord Config and returns an error if it contains
603+
// settings not allowed by Cortex.
604+
func validateDiscordConfig(cfg config.DiscordConfig) error {
605+
if cfg.WebhookURLFile != "" {
606+
return errDiscordWebhookUrlFileNotAllowed
607+
}
608+
return nil
609+
}
610+
611+
// validateEmailConfig validates the Email Config and returns an error if it contains
612+
// settings not allowed by Cortex.
613+
func validateEmailConfig(cfg config.EmailConfig) error {
614+
if cfg.AuthPasswordFile != "" {
615+
return errEmailAuthPasswordFileNotAllowed
616+
}
617+
return nil
618+
}

pkg/alertmanager/api_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,35 @@ alertmanager_config: |
703703
`,
704704
err: errors.Wrap(errRocketChatTokenFileNotAllowed, "error validating Alertmanager config"),
705705
},
706+
{
707+
name: "Should return error if Discord webhook_url_file is set",
708+
cfg: `
709+
alertmanager_config: |
710+
receivers:
711+
- name: default-receiver
712+
discord_configs:
713+
- webhook_url_file: /urlFile
714+
route:
715+
receiver: 'default-receiver'
716+
`,
717+
err: errors.Wrap(errDiscordWebhookUrlFileNotAllowed, "error validating Alertmanager config"),
718+
},
719+
{
720+
name: "Should return error if Email auth_password_file is set",
721+
cfg: `
722+
alertmanager_config: |
723+
receivers:
724+
- name: default-receiver
725+
email_configs:
726+
- to: user@example.com
727+
from: admin@example.com
728+
smarthost: example.com:25
729+
auth_password_file: /passwordFile
730+
route:
731+
receiver: 'default-receiver'
732+
`,
733+
err: errors.Wrap(errEmailAuthPasswordFileNotAllowed, "error validating Alertmanager config"),
734+
},
706735
}
707736

708737
limits := &mockAlertManagerLimits{}

0 commit comments

Comments
 (0)