diff --git a/proxy.go b/proxy.go index 2aca36a90..4d3b43173 100644 --- a/proxy.go +++ b/proxy.go @@ -31,6 +31,13 @@ func NewAlertmanagerProxy(alertmanager *alertmanager.Alertmanager) (*httputil.Re Director: func(req *http.Request) { req.URL.Scheme = upstreamURL.Scheme req.URL.Host = upstreamURL.Host + + if upstreamURL.User.Username() != "" { + username := upstreamURL.User.Username() + password, _ := upstreamURL.User.Password() + req.SetBasicAuth(username, password) + } + // drop Accept-Encoding header so we always get uncompressed reponses from // upstream, there's a gzip middleware that's global so we don't want it // to gzip twice diff --git a/proxy_test.go b/proxy_test.go index 0d099413e..813140e3e 100644 --- a/proxy_test.go +++ b/proxy_test.go @@ -162,6 +162,16 @@ var proxyHeaderTests = []proxyHeaderTest{ authUser: "foo", authPass: "bar", }, + { + method: "POST", + localPath: "/proxy/alertmanager/dummy/api/v1/silences", + upstreamURI: "http://alertmanager.example.com/api/v1/silences", + code: 200, + alertmanagerURI: "http://foo@alertmanager.example.com", + alertmanagerHost: "alertmanager.example.com", + authUser: "foo", + authPass: "", + }, } func TestProxyHeaders(t *testing.T) {