Set Basic Auth on proxied requests if user:pass is set in the Alertmanager URI

This commit is contained in:
Łukasz Mierzwa
2018-04-17 21:52:50 -07:00
parent ae2a4f7109
commit 8a65496787
2 changed files with 17 additions and 0 deletions

View File

@@ -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

View File

@@ -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) {