Metrics: Fix internal metrics endpoint not accessible from browser if basic auth is enabled (#86904)

* add WWW-Authenticate header in the http response of /metrics endpoint in case of wrong basic auth credentials

Signed-off-by: Syed Nihal <syed.nihal@nokia.com>

* added change log for the change fixing the issue https://github.com/grafana/grafana/issues/86902

Signed-off-by: Syed Nihal <syed.nihal@nokia.com>

* Update CHANGELOG.md

---------

Signed-off-by: Syed Nihal <syed.nihal@nokia.com>
This commit is contained in:
Nihal
2024-07-11 14:55:48 +02:00
committed by GitHub
parent 420ff1d07b
commit c1d9e793be
+1
View File
@@ -656,6 +656,7 @@ func (hs *HTTPServer) metricsEndpoint(ctx *web.Context) {
}
if hs.metricsEndpointBasicAuthEnabled() && !BasicAuthenticatedRequest(ctx.Req, hs.Cfg.MetricsEndpointBasicAuthUsername, hs.Cfg.MetricsEndpointBasicAuthPassword) {
ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Grafana"`)
ctx.Resp.WriteHeader(http.StatusUnauthorized)
return
}