Skip to content

Commit 5fc9f7c

Browse files
friedrichgalanprot
authored andcommitted
Fix opsgenie validation (#5045)
* Validate OpsGenie alertmanager configuration Signed-off-by: Friedrich Gonzalez <friedrichg@gmail.com> * Update changelog Signed-off-by: Friedrich Gonzalez <friedrichg@gmail.com> * Validate global config too Signed-off-by: Friedrich Gonzalez <friedrichg@gmail.com> * fix pr number in changelog Signed-off-by: Friedrich Gonzalez <friedrichg@gmail.com> Signed-off-by: Friedrich Gonzalez <friedrichg@gmail.com> Signed-off-by: Alan Protasio <approtas@amazon.com>
1 parent de2ef5e commit 5fc9f7c

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
# Changelog
22

3+
## 1.13.2 2022-12-18
4+
5+
* [CHANGE] Alertmanager: Local file disclosure vulnerability in OpsGenie configuration has been fixed. #5045
6+
37
## 1.13.1 2022-10-03
4-
[BUGFIX] AlertManager: fixed issue introduced by #4495 where templates files were being deleted when using alertmanager local store. #4890
8+
* [BUGFIX] AlertManager: fixed issue introduced by #4495 where templates files were being deleted when using alertmanager local store. #4890
59

610
## 1.13.0 2022-07-14
711
* [CHANGE] Changed default for `-ingester.min-ready-duration` from 1 minute to 15 seconds. #4539

pkg/alertmanager/api.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var (
4646
errTLSFileNotAllowed = errors.New("setting TLS ca_file, cert_file and key_file is not allowed")
4747
errSlackAPIURLFileNotAllowed = errors.New("setting Slack api_url_file and global slack_api_url_file is not allowed")
4848
errVictorOpsAPIKeyFileNotAllowed = errors.New("setting VictorOps api_key_file is not allowed")
49+
errOpsGenieAPIKeyFileNotAllowed = errors.New("setting OpsGenie api_key_file is not allowed")
4950
)
5051

5152
// UserConfig is used to communicate a users alertmanager configs
@@ -337,6 +338,11 @@ func validateAlertmanagerConfig(cfg interface{}) error {
337338
return err
338339
}
339340

341+
case reflect.TypeOf(config.OpsGenieConfig{}):
342+
if err := validateOpsGenieConfig(v.Interface().(config.OpsGenieConfig)); err != nil {
343+
return err
344+
}
345+
340346
case reflect.TypeOf(commoncfg.TLSConfig{}):
341347
if err := validateReceiverTLSConfig(v.Interface().(commoncfg.TLSConfig)); err != nil {
342348
return err
@@ -427,12 +433,24 @@ func validateReceiverTLSConfig(cfg commoncfg.TLSConfig) error {
427433
// validateGlobalConfig validates the Global config and returns an error if it contains
428434
// settings now allowed by Cortex.
429435
func validateGlobalConfig(cfg config.GlobalConfig) error {
436+
if cfg.OpsGenieAPIKeyFile != "" {
437+
return errOpsGenieAPIKeyFileNotAllowed
438+
}
430439
if cfg.SlackAPIURLFile != "" {
431440
return errSlackAPIURLFileNotAllowed
432441
}
433442
return nil
434443
}
435444

445+
// validateOpsGenieConfig validates the OpsGenie config and returns an error if it contains
446+
// settings now allowed by Cortex.
447+
func validateOpsGenieConfig(cfg config.OpsGenieConfig) error {
448+
if cfg.APIKeyFile != "" {
449+
return errOpsGenieAPIKeyFileNotAllowed
450+
}
451+
return nil
452+
}
453+
436454
// validateSlackConfig validates the Slack config and returns an error if it contains
437455
// settings now allowed by Cortex.
438456
func validateSlackConfig(cfg config.SlackConfig) error {

pkg/alertmanager/api_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,23 @@ alertmanager_config: |
371371
`,
372372
err: errors.Wrap(errOAuth2SecretFileNotAllowed, "error validating Alertmanager config"),
373373
},
374+
{
375+
name: "Should return error if global opsgenie_api_key_file is set",
376+
cfg: `
377+
alertmanager_config: |
378+
global:
379+
opsgenie_api_key_file: /secrets
380+
381+
receivers:
382+
- name: default-receiver
383+
webhook_configs:
384+
- url: http://localhost
385+
386+
route:
387+
receiver: 'default-receiver'
388+
`,
389+
err: errors.Wrap(errOpsGenieAPIKeyFileNotAllowed, "error validating Alertmanager config"),
390+
},
374391
{
375392
name: "Should return error if global slack_api_url_file is set",
376393
cfg: `
@@ -402,6 +419,20 @@ alertmanager_config: |
402419
`,
403420
err: errors.Wrap(errSlackAPIURLFileNotAllowed, "error validating Alertmanager config"),
404421
},
422+
{
423+
name: "Should return error if OpsGenie api_key_file is set",
424+
cfg: `
425+
alertmanager_config: |
426+
receivers:
427+
- name: default-receiver
428+
opsgenie_configs:
429+
- api_key_file: /secrets
430+
431+
route:
432+
receiver: 'default-receiver'
433+
`,
434+
err: errors.Wrap(errOpsGenieAPIKeyFileNotAllowed, "error validating Alertmanager config"),
435+
},
405436
{
406437
name: "Should return error if VictorOps api_key_file is set",
407438
cfg: `

0 commit comments

Comments
 (0)