From c1d9e793be4ed4f064916fe97187ea846d078d1d Mon Sep 17 00:00:00 2001 From: Nihal <38865967+wasim-nihal@users.noreply.github.com> Date: Thu, 11 Jul 2024 18:25:48 +0530 Subject: [PATCH] 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 * added change log for the change fixing the issue https://github.com/grafana/grafana/issues/86902 Signed-off-by: Syed Nihal * Update CHANGELOG.md --------- Signed-off-by: Syed Nihal --- pkg/api/http_server.go | 1 + 1 file changed, 1 insertion(+) diff --git a/pkg/api/http_server.go b/pkg/api/http_server.go index f5ba1e92354..63d60710029 100644 --- a/pkg/api/http_server.go +++ b/pkg/api/http_server.go @@ -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 }