Skip to content

Commit c9a5204

Browse files
committed
OCPBUGS-52835: Fix incorrect auth token cookie for metrics requests
1 parent cb0532c commit c9a5204

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pkg/metrics/handler.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package metrics
22

3-
import "net/http"
3+
import (
4+
"net/http"
5+
"strings"
6+
)
47

58
func AddHeaderAsCookieMiddleware(next http.Handler) http.Handler {
69
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
710
// Requests from prometheus-k8s have the access token in headers instead of cookies.
811
// This allows metric requests with proper tokens in either headers or cookies.
912
if r.URL.Path == "/metrics" {
1013
openshiftSessionCookieName := "openshift-session-token"
11-
openshiftSessionCookieValue := r.Header.Get("Authorization") // FIXME: in OIDC setup, this actually ends up checking the token "Bearer <jwt>" to the underlying auth layer - instead of `<jwt>`.
14+
openshiftSessionCookieValue := r.Header.Get("Authorization")
15+
openshiftSessionCookieValue = strings.TrimPrefix(openshiftSessionCookieValue, "Bearer ")
1216
r.AddCookie(&http.Cookie{Name: openshiftSessionCookieName, Value: openshiftSessionCookieValue})
1317
}
1418
next.ServeHTTP(w, r)

0 commit comments

Comments
 (0)