diff --git a/config/config.go b/config/config.go index 7f7595dcd..7824780c3 100644 --- a/config/config.go +++ b/config/config.go @@ -819,6 +819,7 @@ type AlertmanagerConfig struct { ServiceDiscoveryConfigs discovery.Configs `yaml:"-"` HTTPClientConfig config.HTTPClientConfig `yaml:",inline"` + SigV4Config *sigv4.SigV4Config `yaml:"sigv4,omitempty"` // The URL scheme to use when talking to Alertmanagers. Scheme string `yaml:"scheme,omitempty"` @@ -854,6 +855,13 @@ func (c *AlertmanagerConfig) UnmarshalYAML(unmarshal func(interface{}) error) er return err } + httpClientConfigAuthEnabled := c.HTTPClientConfig.BasicAuth != nil || + c.HTTPClientConfig.Authorization != nil || c.HTTPClientConfig.OAuth2 != nil + + if httpClientConfigAuthEnabled && c.SigV4Config != nil { + return fmt.Errorf("at most one of basic_auth, authorization, oauth2, & sigv4 must be configured") + } + // Check for users putting URLs in target groups. if len(c.RelabelConfigs) == 0 { if err := checkStaticTargets(c.ServiceDiscoveryConfigs); err != nil { diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index b9373498a..c9e941549 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -3287,6 +3287,25 @@ authorization: # It is mutually exclusive with `credentials`. [ credentials_file: ] +# Optionally configures AWS's Signature Verification 4 signing process to +# sign requests. Cannot be set at the same time as basic_auth, authorization, or oauth2. +# To use the default credentials from the AWS SDK, use `sigv4: {}`. +sigv4: + # The AWS region. If blank, the region from the default credentials chain + # is used. + [ region: ] + + # The AWS API keys. If blank, the environment variables `AWS_ACCESS_KEY_ID` + # and `AWS_SECRET_ACCESS_KEY` are used. + [ access_key: ] + [ secret_key: ] + + # Named AWS profile used to authenticate. + [ profile: ] + + # AWS Role ARN, an alternative to using AWS API keys. + [ role_arn: ] + # Optional OAuth 2.0 configuration. # Cannot be used at the same time as basic_auth or authorization. oauth2: diff --git a/notifier/notifier.go b/notifier/notifier.go index 891372c43..a516c8f05 100644 --- a/notifier/notifier.go +++ b/notifier/notifier.go @@ -31,6 +31,7 @@ import ( "github.com/prometheus/alertmanager/api/v2/models" "github.com/prometheus/client_golang/prometheus" config_util "github.com/prometheus/common/config" + "github.com/prometheus/common/sigv4" "github.com/prometheus/common/model" "github.com/prometheus/common/version" "go.uber.org/atomic" @@ -640,6 +641,17 @@ func newAlertmanagerSet(cfg *config.AlertmanagerConfig, logger log.Logger, metri if err != nil { return nil, err } + t := client.Transport + + if cfg.SigV4Config != nil { + t, err = sigv4.NewSigV4RoundTripper(cfg.SigV4Config, client.Transport) + if err != nil { + return nil, err + } + } + + client.Transport = t + s := &alertmanagerSet{ client: client, cfg: cfg,