Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* [BUGFIX] Compactor: Avoid race condition which allow a grouper to not compact all partitions. #7082
* [BUGFIX] Fix bug where validating metric names uses the wrong validation logic. #7086
* [BUGFIX] Ring: Change DynamoDB KV to retry indefinetly for WatchKey. #7088
* [BUGFIX] Add alertmanager receiver validation for discord and email. #7097

## 1.20.0 in progress

Expand Down
28 changes: 28 additions & 0 deletions pkg/alertmanager/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ var (
errMSTeamsV2WebhookUrlFileNotAllowed = errors.New("setting MSTeamsV2 webhook_url_file is not allowed")
errRocketChatTokenIdFileNotAllowed = errors.New("setting RocketChat token_id_file is not allowed")
errRocketChatTokenFileNotAllowed = errors.New("setting RocketChat token_file is not allowed")
errDiscordWebhookUrlFileNotAllowed = errors.New("setting Discord webhook_url_file is not allowed")
errEmailAuthPasswordFileNotAllowed = errors.New("setting Email auth_password_file is not allowed")
)

// UserConfig is used to communicate a users alertmanager configs
Expand Down Expand Up @@ -399,6 +401,14 @@ func validateAlertmanagerConfig(cfg any) error {
if err := validateRocketChatConfig(v.Interface().(config.RocketchatConfig)); err != nil {
return err
}
case reflect.TypeOf(config.DiscordConfig{}):
if err := validateDiscordConfig(v.Interface().(config.DiscordConfig)); err != nil {
return err
}
case reflect.TypeOf(config.EmailConfig{}):
if err := validateEmailConfig(v.Interface().(config.EmailConfig)); err != nil {
return err
}
}

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

return nil
}

// validateDiscordConfig validates the Discord Config and returns an error if it contains
// settings not allowed by Cortex.
func validateDiscordConfig(cfg config.DiscordConfig) error {
if cfg.WebhookURLFile != "" {
return errDiscordWebhookUrlFileNotAllowed
}
return nil
}

// validateEmailConfig validates the Email Config and returns an error if it contains
// settings not allowed by Cortex.
func validateEmailConfig(cfg config.EmailConfig) error {
if cfg.AuthPasswordFile != "" {
return errEmailAuthPasswordFileNotAllowed
}
return nil
}
29 changes: 29 additions & 0 deletions pkg/alertmanager/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,35 @@ alertmanager_config: |
`,
err: errors.Wrap(errRocketChatTokenFileNotAllowed, "error validating Alertmanager config"),
},
{
name: "Should return error if Discord webhook_url_file is set",
cfg: `
alertmanager_config: |
receivers:
- name: default-receiver
discord_configs:
- webhook_url_file: /tokenFile
route:
receiver: 'default-receiver'
`,
err: errors.Wrap(errDiscordWebhookUrlFileNotAllowed, "error validating Alertmanager config"),
},
{
name: "Should return error if Email auth_password_file is set",
cfg: `
alertmanager_config: |
receivers:
- name: default-receiver
email_configs:
- to: [email protected]
from: [email protected]
smarthost: example.com:25
auth_password_file: /passwordFile
route:
receiver: 'default-receiver'
`,
err: errors.Wrap(errEmailAuthPasswordFileNotAllowed, "error validating Alertmanager config"),
},
}

limits := &mockAlertManagerLimits{}
Expand Down
Loading