@@ -5,10 +5,8 @@ import (
55 "fmt"
66 "strings"
77
8- corev1 "k8s.io/api/core/v1"
98 "k8s.io/apimachinery/pkg/api/errors"
109 "k8s.io/apimachinery/pkg/runtime"
11- "k8s.io/apimachinery/pkg/types"
1210 clientgoscheme "k8s.io/client-go/kubernetes/scheme"
1311 "sigs.k8s.io/controller-runtime/pkg/client"
1412
@@ -200,12 +198,6 @@ func (d *k8sDiscoverer) mcpServerToBackend(ctx context.Context, mcpServer *mcpv1
200198 return nil
201199 }
202200
203- // Discover and populate incoming OIDC configuration from MCPServer
204- if err := d .discoverIncomingOIDCConfig (ctx , mcpServer , backend ); err != nil {
205- logger .Errorf ("Failed to discover incoming OIDC config for MCPServer %s: %v" , mcpServer .Name , err )
206- return nil
207- }
208-
209201 return backend
210202}
211203
@@ -242,97 +234,6 @@ func (d *k8sDiscoverer) discoverAuthConfig(ctx context.Context, mcpServer *mcpv1
242234 return nil
243235}
244236
245- // discoverIncomingOIDCConfig discovers and stores the backend's OIDC authentication requirements.
246- //
247- // When a backend MCPServer has OIDCConfig configured, it means clients (including vMCP) must present
248- // OIDC tokens to access that backend. This method discovers the backend's OIDC configuration and
249- // stores it in backend.IncomingOIDCConfig.
250- //
251- // Authentication Flow:
252- // - When vMCP's outgoing auth mode is "discovered", vMCP will use the authentication configuration
253- // defined in the backend MCPServer (via ExternalAuthConfigRef for token exchange/header injection,
254- // or via OIDCConfig for OIDC-protected backends)
255- // - The discovered OIDC config is stored in Backend.IncomingOIDCConfig (see pkg/vmcp/types.go)
256- // - This config is used by vMCP to authenticate to backends that require OIDC tokens
257- //
258- // Return behavior:
259- // - Returns nil error if OIDCConfig is nil (no OIDC required) - this is expected behavior
260- // - Returns nil error if OIDC config is discovered and successfully populated into backend
261- // - Returns error if OIDC config exists but discovery/resolution fails (e.g., secret not found)
262- func (d * k8sDiscoverer ) discoverIncomingOIDCConfig (
263- ctx context.Context , mcpServer * mcpv1alpha1.MCPServer , backend * vmcp.Backend ,
264- ) error {
265- // If no OIDC config, nothing to discover
266- if mcpServer .Spec .OIDCConfig == nil {
267- logger .Debugf ("MCPServer %s has no OIDCConfig, no incoming auth required" , mcpServer .Name )
268- return nil
269- }
270-
271- oidcConfig := mcpServer .Spec .OIDCConfig
272-
273- // Convert OIDC config to map for storage in backend
274- config := make (map [string ]interface {})
275-
276- // Handle inline OIDC configuration
277- if oidcConfig .Type == "inline" && oidcConfig .Inline != nil {
278- inline := oidcConfig .Inline
279- config ["issuer" ] = inline .Issuer
280-
281- if inline .Audience != "" {
282- config ["audience" ] = inline .Audience
283- }
284-
285- if inline .ClientID != "" {
286- config ["client_id" ] = inline .ClientID
287- }
288-
289- // Resolve client secret from secret reference if present
290- if inline .ClientSecretRef != nil {
291- secret := & corev1.Secret {}
292- secretKey := types.NamespacedName {
293- Name : inline .ClientSecretRef .Name ,
294- Namespace : mcpServer .Namespace ,
295- }
296-
297- if err := d .k8sClient .Get (ctx , secretKey , secret ); err != nil {
298- return fmt .Errorf ("failed to get secret %s/%s: %w" ,
299- mcpServer .Namespace , inline .ClientSecretRef .Name , err )
300- }
301-
302- secretValue , ok := secret .Data [inline .ClientSecretRef .Key ]
303- if ! ok {
304- return fmt .Errorf ("secret %s/%s does not contain key %s" ,
305- mcpServer .Namespace , inline .ClientSecretRef .Name , inline .ClientSecretRef .Key )
306- }
307-
308- config ["client_secret" ] = string (secretValue )
309- } else if inline .ClientSecret != "" {
310- // Use direct client secret if provided (not recommended but supported)
311- config ["client_secret" ] = inline .ClientSecret
312- }
313-
314- if inline .JWKSURL != "" {
315- config ["jwks_url" ] = inline .JWKSURL
316- }
317-
318- if inline .IntrospectionURL != "" {
319- config ["introspection_url" ] = inline .IntrospectionURL
320- }
321-
322- // Add security flags
323- config ["insecure_allow_http" ] = inline .InsecureAllowHTTP
324- config ["jwks_allow_private_ip" ] = inline .JWKSAllowPrivateIP
325- config ["protected_resource_allow_private_ip" ] = inline .ProtectedResourceAllowPrivateIP
326- }
327-
328- // Store the discovered OIDC config
329- backend .IncomingOIDCConfig = config
330-
331- logger .Infof ("✓ Discovered incoming OIDC config for MCPServer %s: issuer=%s, client_id=%s" ,
332- mcpServer .Name , config ["issuer" ], config ["client_id" ])
333- return nil
334- }
335-
336237// mapK8SWorkloadPhaseToHealth converts a MCPServerPhase to a backend health status.
337238func mapK8SWorkloadPhaseToHealth (phase mcpv1alpha1.MCPServerPhase ) vmcp.BackendHealthStatus {
338239 switch phase {
0 commit comments