@@ -49,9 +49,21 @@ func getK8sClientsForRequest(c *gin.Context) (*kubernetes.Clientset, dynamic.Int
4949 token = rawFwd
5050 }
5151
52+ // Debug: basic auth header state (do not log token)
53+ hasAuthHeader := strings .TrimSpace (rawAuth ) != ""
54+ hasFwdToken := strings .TrimSpace (rawFwd ) != ""
55+ xfUser := c .GetHeader ("X-Forwarded-User" )
56+ xfPref := c .GetHeader ("X-Forwarded-Preferred-Username" )
57+ log .Printf ("auth debug: path=%s method=%s tokenSource=%s tokenLen=%d hasAuthHeader=%t hasFwdToken=%t user=%q preferred=%q" ,
58+ c .FullPath (), c .Request .Method , tokenSource , len (token ), hasAuthHeader , hasFwdToken , xfUser , xfPref )
59+
5260 if token != "" && baseKubeConfig != nil {
5361 cfg := * baseKubeConfig
5462 cfg .BearerToken = token
63+ // Ensure we do NOT fall back to the in-cluster SA token or other auth providers
64+ cfg .BearerTokenFile = ""
65+ cfg .AuthProvider = nil
66+ cfg .ExecProvider = nil
5567 cfg .Username = ""
5668 cfg .Password = ""
5769
@@ -62,14 +74,15 @@ func getK8sClientsForRequest(c *gin.Context) (*kubernetes.Clientset, dynamic.Int
6274
6375 // Best-effort update last-used for service account tokens
6476 updateAccessKeyLastUsedAnnotation (c )
77+ log .Printf ("auth debug: built user-scoped clients ok (source=%s) for %s" , tokenSource , c .FullPath ())
6578 return kc , dc
6679 }
6780 // Token provided but client build failed – treat as invalid token
68- log .Printf ("Failed to build user-scoped k8s clients (source=%s) typedErr=%v dynamicErr=%v for %s" , tokenSource , err1 , err2 , c .FullPath ())
81+ log .Printf ("Failed to build user-scoped k8s clients (source=%s tokenLen=%d ) typedErr=%v dynamicErr=%v for %s" , tokenSource , len ( token ) , err1 , err2 , c .FullPath ())
6982 return nil , nil
7083 } else {
7184 // No token provided
72- log .Printf ("No user token found for %s" , c .FullPath ())
85+ log .Printf ("No user token found for %s (hasAuthHeader=%t hasFwdToken=%t) " , c .FullPath (), hasAuthHeader , hasFwdToken )
7386 return nil , nil
7487 }
7588 // Unreachable
0 commit comments