Skip to content

Commit 4c2a5f1

Browse files
author
Tyler Reid
committed
Add sigv4 as a global config option
Signed-off-by: Tyler Reid <[email protected]>
1 parent 7ecb6bc commit 4c2a5f1

File tree

3 files changed

+77
-28
lines changed

3 files changed

+77
-28
lines changed

config/config.go

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/pkg/errors"
2929
commoncfg "github.com/prometheus/common/config"
3030
"github.com/prometheus/common/model"
31+
"github.com/prometheus/common/sigv4"
3132
"gopkg.in/yaml.v2"
3233

3334
"github.com/prometheus/alertmanager/pkg/labels"
@@ -454,6 +455,7 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
454455
if sns.HTTPConfig == nil {
455456
sns.HTTPConfig = c.Global.HTTPConfig
456457
}
458+
sns.Sigv4 = mergeSigV4Configs(sns.Sigv4, c.Global.Sigv4)
457459
}
458460
names[rcv.Name] = struct{}{}
459461
}
@@ -522,6 +524,49 @@ func checkTimeInterval(r *Route, timeIntervals map[string]struct{}) error {
522524
return nil
523525
}
524526

527+
func mergeSigV4Configs(snsSigV4Config sigv4.SigV4Config, globalSigV4Config sigv4.SigV4Config) sigv4.SigV4Config {
528+
var (
529+
accessKey string
530+
secretKey commoncfg.Secret
531+
region string
532+
profile string
533+
roleARN string
534+
)
535+
536+
if snsSigV4Config.AccessKey == "" {
537+
accessKey = globalSigV4Config.AccessKey
538+
} else {
539+
accessKey = snsSigV4Config.AccessKey
540+
}
541+
if snsSigV4Config.SecretKey == "" {
542+
secretKey = globalSigV4Config.SecretKey
543+
} else {
544+
secretKey = snsSigV4Config.SecretKey
545+
}
546+
if snsSigV4Config.Region == "" {
547+
region = globalSigV4Config.Region
548+
} else {
549+
region = snsSigV4Config.Region
550+
}
551+
if snsSigV4Config.Profile == "" {
552+
profile = globalSigV4Config.Profile
553+
} else {
554+
profile = snsSigV4Config.Profile
555+
}
556+
if snsSigV4Config.RoleARN == "" {
557+
roleARN = globalSigV4Config.RoleARN
558+
} else {
559+
roleARN = snsSigV4Config.RoleARN
560+
}
561+
return sigv4.SigV4Config{
562+
Region: region,
563+
AccessKey: accessKey,
564+
SecretKey: secretKey,
565+
Profile: profile,
566+
RoleARN: roleARN,
567+
}
568+
}
569+
525570
// DefaultGlobalConfig returns GlobalConfig with default values.
526571
func DefaultGlobalConfig() GlobalConfig {
527572
var defaultHTTPConfig = commoncfg.DefaultHTTPClientConfig
@@ -636,24 +681,25 @@ type GlobalConfig struct {
636681

637682
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`
638683

639-
SMTPFrom string `yaml:"smtp_from,omitempty" json:"smtp_from,omitempty"`
640-
SMTPHello string `yaml:"smtp_hello,omitempty" json:"smtp_hello,omitempty"`
641-
SMTPSmarthost HostPort `yaml:"smtp_smarthost,omitempty" json:"smtp_smarthost,omitempty"`
642-
SMTPAuthUsername string `yaml:"smtp_auth_username,omitempty" json:"smtp_auth_username,omitempty"`
643-
SMTPAuthPassword Secret `yaml:"smtp_auth_password,omitempty" json:"smtp_auth_password,omitempty"`
644-
SMTPAuthSecret Secret `yaml:"smtp_auth_secret,omitempty" json:"smtp_auth_secret,omitempty"`
645-
SMTPAuthIdentity string `yaml:"smtp_auth_identity,omitempty" json:"smtp_auth_identity,omitempty"`
646-
SMTPRequireTLS bool `yaml:"smtp_require_tls" json:"smtp_require_tls,omitempty"`
647-
SlackAPIURL *SecretURL `yaml:"slack_api_url,omitempty" json:"slack_api_url,omitempty"`
648-
SlackAPIURLFile string `yaml:"slack_api_url_file,omitempty" json:"slack_api_url_file,omitempty"`
649-
PagerdutyURL *URL `yaml:"pagerduty_url,omitempty" json:"pagerduty_url,omitempty"`
650-
OpsGenieAPIURL *URL `yaml:"opsgenie_api_url,omitempty" json:"opsgenie_api_url,omitempty"`
651-
OpsGenieAPIKey Secret `yaml:"opsgenie_api_key,omitempty" json:"opsgenie_api_key,omitempty"`
652-
WeChatAPIURL *URL `yaml:"wechat_api_url,omitempty" json:"wechat_api_url,omitempty"`
653-
WeChatAPISecret Secret `yaml:"wechat_api_secret,omitempty" json:"wechat_api_secret,omitempty"`
654-
WeChatAPICorpID string `yaml:"wechat_api_corp_id,omitempty" json:"wechat_api_corp_id,omitempty"`
655-
VictorOpsAPIURL *URL `yaml:"victorops_api_url,omitempty" json:"victorops_api_url,omitempty"`
656-
VictorOpsAPIKey Secret `yaml:"victorops_api_key,omitempty" json:"victorops_api_key,omitempty"`
684+
SMTPFrom string `yaml:"smtp_from,omitempty" json:"smtp_from,omitempty"`
685+
SMTPHello string `yaml:"smtp_hello,omitempty" json:"smtp_hello,omitempty"`
686+
SMTPSmarthost HostPort `yaml:"smtp_smarthost,omitempty" json:"smtp_smarthost,omitempty"`
687+
SMTPAuthUsername string `yaml:"smtp_auth_username,omitempty" json:"smtp_auth_username,omitempty"`
688+
SMTPAuthPassword Secret `yaml:"smtp_auth_password,omitempty" json:"smtp_auth_password,omitempty"`
689+
SMTPAuthSecret Secret `yaml:"smtp_auth_secret,omitempty" json:"smtp_auth_secret,omitempty"`
690+
SMTPAuthIdentity string `yaml:"smtp_auth_identity,omitempty" json:"smtp_auth_identity,omitempty"`
691+
SMTPRequireTLS bool `yaml:"smtp_require_tls" json:"smtp_require_tls,omitempty"`
692+
SlackAPIURL *SecretURL `yaml:"slack_api_url,omitempty" json:"slack_api_url,omitempty"`
693+
SlackAPIURLFile string `yaml:"slack_api_url_file,omitempty" json:"slack_api_url_file,omitempty"`
694+
PagerdutyURL *URL `yaml:"pagerduty_url,omitempty" json:"pagerduty_url,omitempty"`
695+
OpsGenieAPIURL *URL `yaml:"opsgenie_api_url,omitempty" json:"opsgenie_api_url,omitempty"`
696+
OpsGenieAPIKey Secret `yaml:"opsgenie_api_key,omitempty" json:"opsgenie_api_key,omitempty"`
697+
WeChatAPIURL *URL `yaml:"wechat_api_url,omitempty" json:"wechat_api_url,omitempty"`
698+
WeChatAPISecret Secret `yaml:"wechat_api_secret,omitempty" json:"wechat_api_secret,omitempty"`
699+
WeChatAPICorpID string `yaml:"wechat_api_corp_id,omitempty" json:"wechat_api_corp_id,omitempty"`
700+
VictorOpsAPIURL *URL `yaml:"victorops_api_url,omitempty" json:"victorops_api_url,omitempty"`
701+
VictorOpsAPIKey Secret `yaml:"victorops_api_key,omitempty" json:"victorops_api_key,omitempty"`
702+
Sigv4 sigv4.SigV4Config `yaml:"sigv4,omitempty" json:"sigv4,omitempty"`
657703
}
658704

659705
// UnmarshalYAML implements the yaml.Unmarshaler interface for GlobalConfig.
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
route:
22
receiver: 'sns-api-notifications'
33
group_by: [alertname]
4-
4+
global:
5+
sigv4:
6+
region: us-east-2
7+
access_key: access_key
8+
secret_key: secret_ket
59
receivers:
610
- name: 'sns-api-notifications'
711
sns_configs:
812
- api_url: https://sns.us-east-2.amazonaws.com
913
topic_arn: arn:aws:sns:us-east-2:123456789012:My-Topic
10-
sigv4:
11-
region: us-east-2
12-
access_key: access_key
13-
secret_key: secret_ket
1414
attributes:
1515
severity: Sev2

docs/configuration.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ global:
9090
[ wechat_api_url: <string> | default = "https://qyapi.weixin.qq.com/cgi-bin/" ]
9191
[ wechat_api_secret: <secret> ]
9292
[ wechat_api_corp_id: <string> ]
93+
# Configures AWS's Signature Verification 4 signing process to sign requests.
94+
sigv4:
95+
[ <sigv4_config> ]
9396

9497
# The default HTTP client configuration
9598
[ http_config: <http_config> ]
@@ -737,18 +740,18 @@ attributes:
737740
###`<sigv4_config>`
738741
```yaml
739742
# The AWS region. If blank, the region from the default credentials chain is used.
740-
[ region: <string> ]
743+
[ region: <string> | default = global.sigv4.region ]
741744
742745
# The AWS API keys. Both access_key and secret_key must be supplied or both must be blank.
743746
# If blank the environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` are used.
744-
[ access_key: <string> ]
745-
[ secret_key: <secret> ]
747+
[ access_key: <string> | default = global.sigv4.access_key ]
748+
[ secret_key: <secret> | default = global.sigv4.secret_key ]
746749

747750
# Named AWS profile used to authenticate.
748-
[ profile: <string> ]
751+
[ profile: <string> | default = global.sigv4.profile ]
749752

750753
# AWS Role ARN, an alternative to using AWS API keys.
751-
[ role_arn: <string> ]
754+
[ role_arn: <string> | default = global.sigv4.role_arn ]
752755
```
753756
754757
## `<matcher>`

0 commit comments

Comments
 (0)