-
Notifications
You must be signed in to change notification settings - Fork 149
Implement ExternalAuthConfig discovery for VirtualMCPServer backends #2726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2726 +/- ##
==========================================
- Coverage 56.29% 56.19% -0.10%
==========================================
Files 319 319
Lines 30753 30956 +203
==========================================
+ Hits 17312 17396 +84
- Misses 11953 12062 +109
- Partials 1488 1498 +10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
implements #2704 |
- Merge latest main branch into PR branch - Refactor convertExternalAuthConfigToStrategy to use converter registry instead of manual conversion, enabling support for all auth types (token exchange, header injection, etc.) - Remove all references to pass_through strategy (removed in main) - Update tests to use external_auth_config_ref instead of pass_through - Add header injection test case - All tests pass and linting is clean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Large PR Detected
This PR exceeds 1000 lines of changes and requires justification before it can be reviewed.
How to unblock this PR:
Add a section to your PR description with the following format:
## Large PR Justification
[Explain why this PR must be large, such as:]
- Generated code that cannot be split
- Large refactoring that must be atomic
- Multiple related changes that would break if separated
- Migration or data transformationAlternative:
Consider splitting this PR into smaller, focused changes (< 1000 lines each) for easier review and reduced risk.
See our Contributing Guidelines for more details.
This review will be automatically dismissed once you add the justification section.
The 'discovered' type is not a valid vmcp strategy type - it's only used at the CRD level to indicate that discovery should happen. When used in inline mode (as a BackendAuthConfig type), it should be rejected with an error since it cannot be converted to a valid vmcp strategy. This fixes e2e test failures where VirtualMCPServer was not becoming ready due to invalid auth configuration being written to the ConfigMap. - Add validation to reject 'discovered' type in convertBackendAuthConfigToVMCP - Update test to expect error for 'discovered' type - All unit tests pass
Summary
This PR implements automatic discovery and resolution of
MCPExternalAuthConfigresources for backend MCPServers in the VirtualMCPServer controller. The feature enables VirtualMCPServer to automatically discover and apply external authentication configurations (e.g., OAuth2 Token Exchange) from referenced MCPServer resources without requiring manual configuration.Changes
Core Implementation
buildOutgoingAuthConfig: New function that buildsOutgoingAuthConfigby discoveringExternalAuthConfigfrom MCPServer resources when using "discovered" or "mixed" source modesconvertExternalAuthConfigToStrategy: ConvertsMCPExternalAuthConfigCRD resources to internalBackendAuthStrategyformat, handling token exchange configuration including client secrets, scopes, and token typesconvertBackendAuthConfigToVMCP: Converts inlineBackendAuthConfigfrom CRD spec toBackendAuthStrategy, supporting both direct references andExternalAuthConfigRefreferencesdiscoverBackends: Now uses the resolvedOutgoingAuthConfig(including discovered external auth configs) when creating theUnifiedBackendDiscovererensureVmcpConfigConfigMap: Ensures that fully resolvedOutgoingAuthConfig(including discovered external auths) is written to the ConfigMap consumed by VirtualMCPServer podsFeatures
Three source modes supported:
discovered: Automatically discover auth configs from all referenced MCPServersmixed: Discover from MCPServers but allow inline overrides per backendinline: Use only explicitly specified auth configs (existing behavior)Token Exchange support: Full support for OAuth2 Token Exchange (RFC 8693) including:
Testing
Unit tests: Comprehensive test coverage in
virtualmcpserver_externalauth_test.go:TestConvertExternalAuthConfigToStrategy: Tests conversion logic with various configurationsTestBuildOutgoingAuthConfig: Tests buildingOutgoingAuthConfigin all three modesTestConvertBackendAuthConfigToVMCP: Tests inline config conversionTestDiscoverBackendsWithExternalAuthConfigIntegration: Integration test for end-to-end discovery flowManual testing: Added complete manual testing setup:
manual-test-external-auth-discovery.yaml,manual-test-mixed-mode.yaml,manual-test-inline-mode.yaml)verify-external-auth.sh) to validate ConfigMap content and deployment configurationQUICK_START.md,MANUAL_TESTING_GUIDE.md) with step-by-step instructionsHow It Works
ExternalAuthConfigRef, the controller:MCPExternalAuthConfigresourceBackendAuthStrategywith appropriate metadataOutgoingAuthConfigfor that backendExample Usage
l
MCPExternalAuthConfig defines token exchange configuration
apiVersion: toolhive.stacklok.dev/v1alpha1
kind: MCPExternalAuthConfig
metadata:
name: backend-1-auth-config
spec:
type: tokenExchange
tokenExchange:
tokenUrl: https://oauth.example.com/token
clientId: my-client-id
clientSecretRef:
name: oauth-secret
key: client-secret
audience: backend-service
scopes: [read, write]
MCPServer references the ExternalAuthConfig
apiVersion: toolhive.stacklok.dev/v1alpha1
kind: MCPServer
metadata:
name: backend-1
spec:
externalAuthConfigRef:
name: backend-1-auth-config
... other spec fields
VirtualMCPServer automatically discovers and applies the auth config
apiVersion: toolhive.stacklok.dev/v1alpha1
kind: VirtualMCPServer
metadata:
name: my-vmcp
spec:
groups:
- name: my-group
outgoingAuth:
source: discovered # Automatically discover from MCPServers## Notes
MCPExternalAuthConfigresources by logging and skipping affected backendsRelated Issues
Fixes the issue where
ExternalAuthConfigwas not being resolved and used by the VirtualMCPServer controller to populate backend authentication configurations.Testing