Add authServerRef CRD types, controller logic, and unit tests#4644
Add authServerRef CRD types, controller logic, and unit tests#4644tgrunnagle wants to merge 9 commits intomainfrom
Conversation
Implements changes for issue #4640 (Phase 1 of RFC-0050): - Add AuthServerRef (TypedLocalObjectReference) to MCPServerSpec and MCPRemoteProxySpec - Add AuthServerConfigHash to MCPServerStatus and MCPRemoteProxyStatus - Add AddAuthServerRefOptions and ValidateAndAddAuthServerRefOptions utility functions - Wire conflict validation (authServerRef + externalAuthConfigRef both embedded = error) - Extend watch handlers to reconcile on authServerRef config changes - Extend MCPExternalAuthConfig controller to find resources via authServerRef - Add handleAuthServerRef config hash tracking in both reconcile loops - Add authServerRef volume/env generation for deployments - Regenerate CRD YAML and deepcopy functions - Add unit tests for AddAuthServerRefOptions and authServerRef referencing logic
Fixed issues from code review: - HIGH: Return non-NotFound errors in conflict validation instead of silently ignoring - HIGH: Add table-driven tests for ValidateAndAddAuthServerRefOptions - HIGH: Add table-driven tests for GenerateAuthServerConfigFromRef - MEDIUM: Return error for unsupported Kind in GenerateAuthServerConfigFromRef - MEDIUM: Add comments explaining reconcile-time validation in deployment builders - MEDIUM: Remove redundant name-matching in refExtractor closures Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The findReferencingMCPServers and findReferencingWorkloads closures used an early-return pattern that only returned the externalAuthConfigRef name, causing authServerRef changes to be missed when both fields were set on the same server pointing to different MCPExternalAuthConfig resources. Split each closure into two separate FindReferencingMCPServers calls (one per ref field) and merge with deduplication. Also rewire findReferencingWorkloads to delegate to findReferencingMCPServers to avoid duplicating merge logic. Add test cases covering: - Server with both refs pointing to different configs (both trigger reconciliation) - Server with both refs pointing to the same config (deduplicated to one entry) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
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.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4644 +/- ##
==========================================
- Coverage 68.88% 68.86% -0.03%
==========================================
Files 505 509 +4
Lines 52437 53007 +570
==========================================
+ Hits 36121 36501 +380
- Misses 13525 13686 +161
- Partials 2791 2820 +29 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ce887cc to
30def11
Compare
30def11 to
0234528
Compare
0234528 to
5c69e4e
Compare
…rces The MCPExternalAuthConfig controller only tracked MCPServer references, missing MCPRemoteProxy resources that also have externalAuthConfigRef and authServerRef fields. This adds: - FindReferencingMCPRemoteProxies utility in controllerutil/config.go - findReferencingMCPRemoteProxies and mapMCPRemoteProxyToExternalAuthConfig in the MCPExternalAuthConfig controller - MCPRemoteProxy listing in findReferencingWorkloads - Watches() registration for MCPRemoteProxy in SetupWithManager - Kind check on AuthServerRef before treating it as MCPExternalAuthConfig - Extracted mapMCPServerToExternalAuthConfig from anonymous closure - Consolidated GenerateAuthServerConfig/FromRef into GenerateAuthServerConfigByName - EmbeddedAuthServerConfigName helper for single auth config selection - Fixed data race in parallel tests by using factory functions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
5c69e4e to
9f7ba26
Compare
jhrozek
left a comment
There was a problem hiding this comment.
Nice work on the consolidation in the last commit — the EmbeddedAuthServerConfigName + GenerateAuthServerConfigByName approach is much cleaner than the two separate code paths. A few thoughts inline.
…rRef
TypedLocalObjectReference is deprecated upstream and exposes apiGroup/kind
with no admission-time validation. Replace it with a local AuthServerRef
struct that uses kubebuilder markers for enum validation on Kind and
MinLength on Name, consistent with ExternalAuthConfigRef and other refs
in the codebase. Users can now write just {name: my-auth} and get schema
validation that Kind is MCPExternalAuthConfig.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The handleExternalAuthConfig methods set detailed conditions (NotFound, FetchError, Valid, MultiUpstream) visible in kubectl describe, but handleAuthServerRef only returned errors that surfaced as generic Phase=Failed. Add an AuthServerRefValidated condition with the same level of detail: InvalidKind, NotFound, FetchError, InvalidType, MultiUpstream, and Valid reasons for both MCPServer and MCPRemoteProxy. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cover all condition reasons in both MCPServer and MCPRemoteProxy handleAuthServerRef: nil ref (condition removed), InvalidKind, NotFound, InvalidType, MultiUpstream, and Valid. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Large PR justification has been provided. Thank you!
|
✅ Large PR justification has been provided. The size review has been dismissed and this PR can now proceed with normal review. |
…d types The previous commit made this function error on non-embedded types for defensiveness, but it broke the externalAuthConfigRef fallback path where non-embedded types (headerInjection, tokenExchange) are valid and simply don't need auth server volumes. Type validation for authServerRef is already handled by handleAuthServerRef which sets an InvalidType condition. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
e1e57dd to
cc091b1
Compare
Summary
The embedded auth server currently competes with outgoing auth types (like AWS STS) for the single
externalAuthConfigRefslot on MCPServer and MCPRemoteProxy CRDs. BecauseMCPExternalAuthConfigenforces mutually exclusive types, users cannot configure both an embedded auth server for incoming client authentication and an outgoing token exchange on the same resource. This PR adds a dedicatedauthServerReffield to both CRDs, separating the embedded auth server fromexternalAuthConfigRefso both can coexist. This is Phase 1 of RFC-0050.Closes #4640
Type of change
Test plan
task test)task lint-fix)Changes
api/v1alpha1/mcpserver_types.goAuthServerReffield toMCPServerSpecandAuthServerConfigHashtoMCPServerStatusapi/v1alpha1/mcpremoteproxy_types.goAuthServerReffield toMCPRemoteProxySpecandAuthServerConfigHashtoMCPRemoteProxyStatusapi/v1alpha1/zz_generated.deepcopy.gopkg/controllerutil/authserver.goAddAuthServerRefOptions,ValidateAndAddAuthServerRefOptions, andGenerateAuthServerConfigFromRefutility functionscontrollers/mcpserver_runconfig.gocontrollers/mcpremoteproxy_runconfig.gocontrollers/mcpserver_controller.gohandleAuthServerReffor config hash tracking, extend watch handler and deployment builder for authServerRefcontrollers/mcpremoteproxy_controller.gohandleAuthServerReffor config hash tracking, extend watch handler for authServerRefcontrollers/mcpremoteproxy_deployment.gocontrollers/mcpexternalauthconfig_controller.gofindReferencingMCPServersandfindReferencingWorkloadsto check authServerRef with deduplication; add reverse watch for authServerRef inSetupWithManagerpkg/controllerutil/authserver_test.goAddAuthServerRefOptionsandValidateAndAddAuthServerRefOptionscovering nil ref, invalid kind, wrong type, valid ref, conflict detection, and combined auth pathscontrollers/mcpexternalauthconfig_controller_test.goDoes this introduce a user-facing change?
Yes. MCPServer and MCPRemoteProxy resources now accept an optional
authServerReffield that references anMCPExternalAuthConfigof typeembeddedAuthServer. This allows configuring the embedded auth server independently fromexternalAuthConfigRef, enabling use cases like embedded auth server + AWS STS token exchange on the same resource.Special notes for reviewers
authServerReffield usescorev1.TypedLocalObjectReference(not the existingExternalAuthConfigReftype) to future-proof for a dedicated auth server CRD.authServerRefandexternalAuthConfigRefcannot point to anembeddedAuthServertype simultaneously.Generated with Claude Code
Large PR Justification