Merge pull request #755 from influxdata/feature/fix-kapacitor-auth

Fix kapacitor auth with basic auth in header
pull/10616/head
Nathan Haugo 2017-01-10 17:16:22 -08:00 committed by GitHub
commit 23b4316853
2 changed files with 10 additions and 3 deletions

View File

@ -1,6 +1,8 @@
## v1.1.0 [unreleased] ## v1.1.0 [unreleased]
### Upcoming Bug Fixes ### Upcoming Bug Fixes
1. [#755](https://github.com/influxdata/chronograf/pull/755): Fix kapacitor basic auth proxying
### Upcoming Features ### Upcoming Features
1. [#660](https://github.com/influxdata/chronograf/issues/660): Add option to accept any certificate from InfluxDB. 1. [#660](https://github.com/influxdata/chronograf/issues/660): Add option to accept any certificate from InfluxDB.
2. [#733](https://github.com/influxdata/chronograf/pull/733): Add optional Github organization membership checks to authentication 2. [#733](https://github.com/influxdata/chronograf/pull/733): Add optional Github organization membership checks to authentication

View File

@ -1,6 +1,7 @@
package server package server
import ( import (
"encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
@ -105,13 +106,17 @@ func (h *Service) KapacitorProxy(w http.ResponseWriter, r *http.Request) {
return return
} }
if srv.Username != "" && srv.Password != "" {
u.User = url.UserPassword(srv.Username, srv.Password)
}
u.Path = path u.Path = path
director := func(req *http.Request) { director := func(req *http.Request) {
req.URL = u req.URL = u
// Because we are acting as a proxy, kapacitor needs to have the basic auth information set as
// a header directly
if srv.Username != "" && srv.Password != "" {
auth := "Basic " + srv.Username + ":" + srv.Password
header := base64.StdEncoding.EncodeToString([]byte(auth))
req.Header.Set("Authorization", header)
}
} }
proxy := &httputil.ReverseProxy{ proxy := &httputil.ReverseProxy{
Director: director, Director: director,