@@ -28,6 +28,8 @@ import (
28
28
const (
29
29
CustomAuthorizationHeader = "kubernetes-authorization"
30
30
OAuthAuthorizationHeader = "Authorization"
31
+
32
+ CustomUserAgent = "kubernetes-mcp-server/bearer-token-auth"
31
33
)
32
34
33
35
type CloseWatchKubeConfig func () error
@@ -140,15 +142,24 @@ func (m *Manager) Derived(ctx context.Context) *Kubernetes {
140
142
return & Kubernetes {manager : m }
141
143
}
142
144
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
+ }
152
163
clientCmdApiConfig , err := m .clientCmdConfig .RawConfig ()
153
164
if err != nil {
154
165
return & Kubernetes {manager : m }
0 commit comments