Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose pprof without auth when enabled for httpd #1520

Merged
merged 1 commit into from
Aug 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion services/httpd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,15 @@ type Route struct {
HandlerFunc interface{}
NoGzip bool
NoJSON bool
BypassAuth bool
}

// Handler represents an HTTP handler for the Kapacitor API server.
type Handler struct {
methodMux map[string]*ServeMux

requireAuthentication bool
exposePprof bool
sharedSecret string

allowGzip bool
Expand Down Expand Up @@ -101,6 +103,7 @@ type Handler struct {
// NewHandler returns a new instance of handler with routes.
func NewHandler(
requireAuthentication,
pprofEnabled,
loggingEnabled,
writeTrace,
allowGzip bool,
Expand All @@ -112,6 +115,7 @@ func NewHandler(
h := &Handler{
methodMux: make(map[string]*ServeMux),
requireAuthentication: requireAuthentication,
exposePprof: pprofEnabled,
sharedSecret: sharedSecret,
allowGzip: allowGzip,
logger: l,
Expand Down Expand Up @@ -203,35 +207,41 @@ func NewHandler(
Pattern: BasePath + "/debug/pprof/",
HandlerFunc: servePprof,
NoJSON: true,
BypassAuth: true,
},
{
Method: "GET",
Pattern: BasePath + "/debug/pprof/cmdline",
HandlerFunc: pprof.Cmdline,
NoJSON: true,
BypassAuth: true,
},
{
Method: "GET",
Pattern: BasePath + "/debug/pprof/profile",
HandlerFunc: pprof.Profile,
NoJSON: true,
BypassAuth: true,
},
{
Method: "GET",
Pattern: BasePath + "/debug/pprof/symbol",
HandlerFunc: pprof.Symbol,
NoJSON: true,
BypassAuth: true,
},
{
Method: "GET",
Pattern: BasePath + "/debug/pprof/trace",
HandlerFunc: pprof.Trace,
NoJSON: true,
BypassAuth: true,
},
{
Method: "GET",
Pattern: BasePath + "/debug/vars",
HandlerFunc: serveExpvar,
BypassAuth: true,
},
})

Expand Down Expand Up @@ -294,7 +304,11 @@ func (h *Handler) addRawRoute(r Route) error {

// This is a normal handler signature so perform standard authentication/authorization.
if hf, ok := r.HandlerFunc.(func(http.ResponseWriter, *http.Request)); ok {
handler = authenticate(authorize(hf), h, h.requireAuthentication)
requireAuth := h.requireAuthentication
if r.BypassAuth && h.exposePprof {
requireAuth = false
}
handler = authenticate(authorize(hf), h, requireAuth)
}
if handler == nil {
return errors.New("route does not have valid handler function")
Expand Down
1 change: 1 addition & 0 deletions services/httpd/httpdtest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func NewServer(verbose bool) *Server {
ls := loggingtest.New()
s := &Server{
Handler: httpd.NewHandler(
false,
false,
verbose,
verbose,
Expand Down
1 change: 1 addition & 0 deletions services/httpd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func NewService(c Config, hostname string, l *log.Logger, li logging.Interface)
shutdownTimeout: time.Duration(c.ShutdownTimeout),
Handler: NewHandler(
c.AuthEnabled,
c.PprofEnabled,
c.LogEnabled,
c.WriteTracing,
c.GZIP,
Expand Down