Skip to content

Commit f8a1f81

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>
1 parent 1b292d3 commit f8a1f81

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## master / unreleased
44
## 1.14.1 2022-12-18
5+
* [CHANGE] Alertmanager: Local file disclosure vulnerability in OpsGenie configuration has been fixed. #5045
56
* [BUGFIX] Fix panic when otel and xray tracing is enabled. #5044
67

78
## 1.14.0 2022-12-02

pkg/alertmanager/api.go

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

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

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

444+
// validateOpsGenieConfig validates the OpsGenie config and returns an error if it contains
445+
// settings now allowed by Cortex.
446+
func validateOpsGenieConfig(cfg config.OpsGenieConfig) error {
447+
if cfg.APIKeyFile != "" {
448+
return errOpsGenieAPIKeyFileNotAllowed
449+
}
450+
return nil
451+
}
452+
435453
// validateSlackConfig validates the Slack config and returns an error if it contains
436454
// settings now allowed by Cortex.
437455
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)