Add warning message if metrics are exposed without protection

This commit is contained in:
Till Faelligen 2019-10-11 10:07:07 +02:00
parent e2cca682be
commit 0b1dd5cf35

View file

@ -13,6 +13,7 @@ import (
"github.com/opentracing/opentracing-go/ext" "github.com/opentracing/opentracing-go/ext"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
) )
// BasicAuth is used for authorization on /metrics handlers // BasicAuth is used for authorization on /metrics handlers
@ -125,6 +126,9 @@ func SetupHTTPAPI(servMux *http.ServeMux, apiMux http.Handler, cfg *config.Dendr
// WrapHandlerInBasicAuth adds basic auth to a handler. Only used for /metrics // WrapHandlerInBasicAuth adds basic auth to a handler. Only used for /metrics
func WrapHandlerInBasicAuth(h http.Handler, b BasicAuth) http.HandlerFunc { func WrapHandlerInBasicAuth(h http.Handler, b BasicAuth) http.HandlerFunc {
if b.Username == "" || b.Password == "" {
logrus.Info("Metrics are exposed without protection. Make sure you set up protection at proxy level.")
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Serve without authorization if either Username or Password is unset // Serve without authorization if either Username or Password is unset
if b.Username == "" || b.Password == "" { if b.Username == "" || b.Password == "" {