mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-12 23:54:01 +09:00
fix(observability-proxy): accept the bearer scheme in any case
The authorization scheme is case-insensitive, and kube-apiserver accepts "bearer" as well as "Bearer", so a client that works against the API server got 401 from the proxy with the same header. Assisted-by: LLM Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
1 parent
95ed8134e4
commit
650a99ff27
2 files changed
+20
-2
No files matched your search
@@ -300,8 +300,8 @@ func (s *Server) readForm(w http.ResponseWriter, r *http.Request) *HTTPError {
|
||||
}
|
||||
|
||||
func (s *Server) authorize(r *http.Request, route Route) (string, *HTTPError) {
|
||||
token, ok := strings.CutPrefix(r.Header.Get("Authorization"), "Bearer ")
|
||||
if !ok {
|
||||
scheme, token, _ := strings.Cut(r.Header.Get("Authorization"), " ")
|
||||
if !strings.EqualFold(scheme, "Bearer") {
|
||||
return "", errorf(http.StatusUnauthorized, "missing bearer token")
|
||||
}
|
||||
user, err := s.auth.Authenticate(r.Context(), strings.TrimSpace(token))
|
||||
|
||||
@@ -452,3 +452,21 @@ func TestServerTailLongLine(t *testing.T) {
|
||||
t.Fatalf("long line not streamed intact: got %d bytes", len(body))
|
||||
}
|
||||
}
|
||||
|
||||
// The auth scheme is case-insensitive (RFC 9110, section 11.1), as
|
||||
// kube-apiserver reads it.
|
||||
func TestServerBearerSchemeCase(t *testing.T) {
|
||||
h := newHarness(t, Config{}, nil)
|
||||
for _, auth := range []string{"Bearer good", "bearer good", "BEARER good"} {
|
||||
resp := h.do(http.MethodGet, logsRoot+"query", "", nil, map[string]string{"Authorization": auth})
|
||||
_ = resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Errorf("Authorization %q answered %d, want 200", auth, resp.StatusCode)
|
||||
}
|
||||
}
|
||||
resp := h.do(http.MethodGet, logsRoot+"query", "", nil, map[string]string{"Authorization": "Basic good"})
|
||||
_ = resp.Body.Close()
|
||||
if resp.StatusCode != http.StatusUnauthorized {
|
||||
t.Errorf("Basic scheme answered %d, want 401", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user