@@ -28,6 +28,8 @@ import (
2828const (
2929 CustomAuthorizationHeader = "kubernetes-authorization"
3030 OAuthAuthorizationHeader = "Authorization"
31+
32+ CustomUserAgent = "kubernetes-mcp-server/bearer-token-auth"
3133)
3234
3335type CloseWatchKubeConfig func () error
@@ -140,15 +142,24 @@ func (m *Manager) Derived(ctx context.Context) *Kubernetes {
140142 return & Kubernetes {manager : m }
141143 }
142144 klog .V (5 ).Infof ("%s header found (Bearer), using provided bearer token" , OAuthAuthorizationHeader )
143- derivedCfg := rest .CopyConfig (m .cfg )
144- derivedCfg .BearerToken = strings .TrimPrefix (authorization , "Bearer " )
145- derivedCfg .BearerTokenFile = ""
146- derivedCfg .Username = ""
147- derivedCfg .Password = ""
148- derivedCfg .AuthProvider = nil
149- derivedCfg .AuthConfigPersister = nil
150- derivedCfg .ExecProvider = nil
151- derivedCfg .Impersonate = rest.ImpersonationConfig {}
145+ derivedCfg := & rest.Config {
146+ Host : m .cfg .Host ,
147+ APIPath : m .cfg .APIPath ,
148+ // Copy only server verification TLS settings (CA bundle and server name)
149+ TLSClientConfig : rest.TLSClientConfig {
150+ Insecure : m .cfg .TLSClientConfig .Insecure ,
151+ ServerName : m .cfg .TLSClientConfig .ServerName ,
152+ CAFile : m .cfg .TLSClientConfig .CAFile ,
153+ CAData : m .cfg .TLSClientConfig .CAData ,
154+ },
155+ BearerToken : strings .TrimPrefix (authorization , "Bearer " ),
156+ // pass custom UserAgent to identify the client
157+ UserAgent : CustomUserAgent ,
158+ QPS : m .cfg .QPS ,
159+ Burst : m .cfg .Burst ,
160+ Timeout : m .cfg .Timeout ,
161+ Impersonate : rest.ImpersonationConfig {},
162+ }
152163 clientCmdApiConfig , err := m .clientCmdConfig .RawConfig ()
153164 if err != nil {
154165 return & Kubernetes {manager : m }
0 commit comments