@@ -40,10 +40,12 @@ import (
40
40
"github.com/prometheus/alertmanager/ui"
41
41
"github.com/prometheus/client_golang/prometheus"
42
42
"github.com/prometheus/client_golang/prometheus/promauto"
43
+ commoncfg "github.com/prometheus/common/config"
43
44
"github.com/prometheus/common/model"
44
45
"github.com/prometheus/common/route"
45
46
46
47
"github.com/cortexproject/cortex/pkg/alertmanager/alertstore"
48
+ util_net "github.com/cortexproject/cortex/pkg/util/net"
47
49
"github.com/cortexproject/cortex/pkg/util/services"
48
50
)
49
51
@@ -95,6 +97,7 @@ type Alertmanager struct {
95
97
wg sync.WaitGroup
96
98
mux * http.ServeMux
97
99
registry * prometheus.Registry
100
+ firewallDialer * util_net.FirewallDialer
98
101
99
102
// The Dispatcher is the only component we need to recreate when we call ApplyConfig.
100
103
// Given its metrics don't have any variable labels we need to re-use the same metrics.
@@ -148,6 +151,10 @@ func New(cfg *Config, reg *prometheus.Registry) (*Alertmanager, error) {
148
151
cfg : cfg ,
149
152
logger : log .With (cfg .Logger , "user" , cfg .UserID ),
150
153
stop : make (chan struct {}),
154
+ firewallDialer : util_net .NewFirewallDialer (util_net.FirewallDialerConfig {
155
+ BlockCIDRNetworks : cfg .ReceiversFirewall .Block .CIDRNetworks ,
156
+ BlockPrivateAddresses : cfg .ReceiversFirewall .Block .PrivateAddresses ,
157
+ }),
151
158
configHashMetric : promauto .With (reg ).NewGauge (prometheus.GaugeOpts {
152
159
Name : "alertmanager_config_hash" ,
153
160
Help : "Hash of the currently loaded alertmanager configuration." ,
@@ -280,8 +287,6 @@ func clusterWait(position func() int, timeout time.Duration) func() time.Duratio
280
287
281
288
// ApplyConfig applies a new configuration to an Alertmanager.
282
289
func (am * Alertmanager ) ApplyConfig (userID string , conf * config.Config , rawCfg string ) error {
283
- conf = injectFirewallToAlertmanagerConfig (conf , am .cfg .ReceiversFirewall )
284
-
285
290
templateFiles := make ([]string , len (conf .Templates ))
286
291
if len (conf .Templates ) > 0 {
287
292
for i , t := range conf .Templates {
@@ -318,7 +323,7 @@ func (am *Alertmanager) ApplyConfig(userID string, conf *config.Config, rawCfg s
318
323
return d + waitFunc ()
319
324
}
320
325
321
- integrationsMap , err := buildIntegrationsMap (conf .Receivers , tmpl , am .logger )
326
+ integrationsMap , err := buildIntegrationsMap (conf .Receivers , tmpl , am .firewallDialer , am . logger )
322
327
if err != nil {
323
328
return nil
324
329
}
@@ -410,10 +415,10 @@ func (am *Alertmanager) getFullState() (*clusterpb.FullState, error) {
410
415
411
416
// buildIntegrationsMap builds a map of name to the list of integration notifiers off of a
412
417
// list of receiver config.
413
- func buildIntegrationsMap (nc []* config.Receiver , tmpl * template.Template , logger log.Logger ) (map [string ][]notify.Integration , error ) {
418
+ func buildIntegrationsMap (nc []* config.Receiver , tmpl * template.Template , firewallDialer * util_net. FirewallDialer , logger log.Logger ) (map [string ][]notify.Integration , error ) {
414
419
integrationsMap := make (map [string ][]notify.Integration , len (nc ))
415
420
for _ , rcv := range nc {
416
- integrations , err := buildReceiverIntegrations (rcv , tmpl , logger )
421
+ integrations , err := buildReceiverIntegrations (rcv , tmpl , firewallDialer , logger )
417
422
if err != nil {
418
423
return nil , err
419
424
}
@@ -425,7 +430,7 @@ func buildIntegrationsMap(nc []*config.Receiver, tmpl *template.Template, logger
425
430
// buildReceiverIntegrations builds a list of integration notifiers off of a
426
431
// receiver config.
427
432
// Taken from https://github.com/prometheus/alertmanager/blob/94d875f1227b29abece661db1a68c001122d1da5/cmd/alertmanager/main.go#L112-L159.
428
- func buildReceiverIntegrations (nc * config.Receiver , tmpl * template.Template , logger log.Logger ) ([]notify.Integration , error ) {
433
+ func buildReceiverIntegrations (nc * config.Receiver , tmpl * template.Template , firewallDialer * util_net. FirewallDialer , logger log.Logger ) ([]notify.Integration , error ) {
429
434
var (
430
435
errs types.MultiError
431
436
integrations []notify.Integration
@@ -439,29 +444,34 @@ func buildReceiverIntegrations(nc *config.Receiver, tmpl *template.Template, log
439
444
}
440
445
)
441
446
447
+ // Inject the firewall to any receiver integration supporting it.
448
+ httpOps := []commoncfg.HTTPClientOption {
449
+ commoncfg .WithDialContextFunc (firewallDialer .DialContext ),
450
+ }
451
+
442
452
for i , c := range nc .WebhookConfigs {
443
- add ("webhook" , i , c , func (l log.Logger ) (notify.Notifier , error ) { return webhook .New (c , tmpl , l ) })
453
+ add ("webhook" , i , c , func (l log.Logger ) (notify.Notifier , error ) { return webhook .New (c , tmpl , l , httpOps ... ) })
444
454
}
445
455
for i , c := range nc .EmailConfigs {
446
456
add ("email" , i , c , func (l log.Logger ) (notify.Notifier , error ) { return email .New (c , tmpl , l ), nil })
447
457
}
448
458
for i , c := range nc .PagerdutyConfigs {
449
- add ("pagerduty" , i , c , func (l log.Logger ) (notify.Notifier , error ) { return pagerduty .New (c , tmpl , l ) })
459
+ add ("pagerduty" , i , c , func (l log.Logger ) (notify.Notifier , error ) { return pagerduty .New (c , tmpl , l , httpOps ... ) })
450
460
}
451
461
for i , c := range nc .OpsGenieConfigs {
452
- add ("opsgenie" , i , c , func (l log.Logger ) (notify.Notifier , error ) { return opsgenie .New (c , tmpl , l ) })
462
+ add ("opsgenie" , i , c , func (l log.Logger ) (notify.Notifier , error ) { return opsgenie .New (c , tmpl , l , httpOps ... ) })
453
463
}
454
464
for i , c := range nc .WechatConfigs {
455
- add ("wechat" , i , c , func (l log.Logger ) (notify.Notifier , error ) { return wechat .New (c , tmpl , l ) })
465
+ add ("wechat" , i , c , func (l log.Logger ) (notify.Notifier , error ) { return wechat .New (c , tmpl , l , httpOps ... ) })
456
466
}
457
467
for i , c := range nc .SlackConfigs {
458
- add ("slack" , i , c , func (l log.Logger ) (notify.Notifier , error ) { return slack .New (c , tmpl , l ) })
468
+ add ("slack" , i , c , func (l log.Logger ) (notify.Notifier , error ) { return slack .New (c , tmpl , l , httpOps ... ) })
459
469
}
460
470
for i , c := range nc .VictorOpsConfigs {
461
- add ("victorops" , i , c , func (l log.Logger ) (notify.Notifier , error ) { return victorops .New (c , tmpl , l ) })
471
+ add ("victorops" , i , c , func (l log.Logger ) (notify.Notifier , error ) { return victorops .New (c , tmpl , l , httpOps ... ) })
462
472
}
463
473
for i , c := range nc .PushoverConfigs {
464
- add ("pushover" , i , c , func (l log.Logger ) (notify.Notifier , error ) { return pushover .New (c , tmpl , l ) })
474
+ add ("pushover" , i , c , func (l log.Logger ) (notify.Notifier , error ) { return pushover .New (c , tmpl , l , httpOps ... ) })
465
475
}
466
476
if errs .Len () > 0 {
467
477
return nil , & errs
0 commit comments