Skip to content

Commit 1b8478f

Browse files
authored
Add authServerRef CRD types, controller logic, and unit tests (#4644)
The embedded auth server currently competes with outgoing auth types (like AWS STS) for the single `externalAuthConfigRef` slot on MCPServer and MCPRemoteProxy CRDs. Because `MCPExternalAuthConfig` enforces 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 dedicated `authServerRef` field to both CRDs, separating the embedded auth server from `externalAuthConfigRef` so both can coexist.
1 parent a4e4c1c commit 1b8478f

20 files changed

Lines changed: 2004 additions & 120 deletions

cmd/thv-operator/api/v1alpha1/mcpremoteproxy_types.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ type MCPRemoteProxySpec struct {
7676
// +optional
7777
ExternalAuthConfigRef *ExternalAuthConfigRef `json:"externalAuthConfigRef,omitempty"`
7878

79+
// AuthServerRef optionally references a resource that configures an embedded
80+
// OAuth 2.0/OIDC authorization server to authenticate MCP clients.
81+
// Currently the only supported kind is MCPExternalAuthConfig (type: embeddedAuthServer).
82+
// +optional
83+
AuthServerRef *AuthServerRef `json:"authServerRef,omitempty"`
84+
7985
// HeaderForward configures headers to inject into requests to the remote MCP server.
8086
// Use this to add custom headers like X-Tenant-ID or correlation IDs.
8187
// +optional
@@ -172,6 +178,11 @@ type MCPRemoteProxyStatus struct {
172178
// +optional
173179
ExternalAuthConfigHash string `json:"externalAuthConfigHash,omitempty"`
174180

181+
// AuthServerConfigHash is the hash of the referenced authServerRef spec,
182+
// used to detect configuration changes and trigger reconciliation.
183+
// +optional
184+
AuthServerConfigHash string `json:"authServerConfigHash,omitempty"`
185+
175186
// OIDCConfigHash is the hash of the referenced MCPOIDCConfig spec for change detection
176187
// +optional
177188
OIDCConfigHash string `json:"oidcConfigHash,omitempty"`
@@ -219,6 +230,9 @@ const (
219230
// ConditionTypeMCPRemoteProxyExternalAuthConfigValidated indicates whether the ExternalAuthConfigRef is valid
220231
ConditionTypeMCPRemoteProxyExternalAuthConfigValidated = "ExternalAuthConfigValidated"
221232

233+
// ConditionTypeMCPRemoteProxyAuthServerRefValidated indicates whether the AuthServerRef is valid
234+
ConditionTypeMCPRemoteProxyAuthServerRefValidated = "AuthServerRefValidated"
235+
222236
// ConditionTypeConfigurationValid indicates whether the proxy spec has passed all pre-deployment validation checks
223237
ConditionTypeConfigurationValid = "ConfigurationValid"
224238
)
@@ -277,6 +291,24 @@ const (
277291
// for MCPRemoteProxy (use VirtualMCPServer for multi-upstream).
278292
ConditionReasonMCPRemoteProxyExternalAuthConfigMultiUpstream = "MultiUpstreamNotSupported"
279293

294+
// ConditionReasonMCPRemoteProxyAuthServerRefValid indicates the AuthServerRef is valid
295+
ConditionReasonMCPRemoteProxyAuthServerRefValid = "AuthServerRefValid"
296+
297+
// ConditionReasonMCPRemoteProxyAuthServerRefNotFound indicates the referenced auth server config was not found
298+
ConditionReasonMCPRemoteProxyAuthServerRefNotFound = "AuthServerRefNotFound"
299+
300+
// ConditionReasonMCPRemoteProxyAuthServerRefFetchError indicates an error occurred fetching the auth server config
301+
ConditionReasonMCPRemoteProxyAuthServerRefFetchError = "AuthServerRefFetchError"
302+
303+
// ConditionReasonMCPRemoteProxyAuthServerRefInvalidKind indicates the authServerRef kind is not supported
304+
ConditionReasonMCPRemoteProxyAuthServerRefInvalidKind = "AuthServerRefInvalidKind"
305+
306+
// ConditionReasonMCPRemoteProxyAuthServerRefInvalidType indicates the referenced config is not an embeddedAuthServer
307+
ConditionReasonMCPRemoteProxyAuthServerRefInvalidType = "AuthServerRefInvalidType"
308+
309+
// ConditionReasonMCPRemoteProxyAuthServerRefMultiUpstream indicates multi-upstream is not supported
310+
ConditionReasonMCPRemoteProxyAuthServerRefMultiUpstream = "MultiUpstreamNotSupported"
311+
280312
// ConditionReasonConfigurationValid indicates all configuration validations passed
281313
ConditionReasonConfigurationValid = "ConfigurationValid"
282314

cmd/thv-operator/api/v1alpha1/mcpserver_types.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,31 @@ const (
108108
ConditionReasonExternalAuthConfigMultiUpstream = "MultiUpstreamNotSupported"
109109
)
110110

111+
const (
112+
// ConditionTypeAuthServerRefValidated indicates whether the AuthServerRef is valid
113+
ConditionTypeAuthServerRefValidated = "AuthServerRefValidated"
114+
)
115+
116+
const (
117+
// ConditionReasonAuthServerRefValid indicates the referenced auth server config is valid
118+
ConditionReasonAuthServerRefValid = "AuthServerRefValid"
119+
120+
// ConditionReasonAuthServerRefNotFound indicates the referenced auth server config was not found
121+
ConditionReasonAuthServerRefNotFound = "AuthServerRefNotFound"
122+
123+
// ConditionReasonAuthServerRefFetchError indicates an error occurred fetching the auth server config
124+
ConditionReasonAuthServerRefFetchError = "AuthServerRefFetchError"
125+
126+
// ConditionReasonAuthServerRefInvalidKind indicates the authServerRef kind is not supported
127+
ConditionReasonAuthServerRefInvalidKind = "AuthServerRefInvalidKind"
128+
129+
// ConditionReasonAuthServerRefInvalidType indicates the referenced config is not an embeddedAuthServer
130+
ConditionReasonAuthServerRefInvalidType = "AuthServerRefInvalidType"
131+
132+
// ConditionReasonAuthServerRefMultiUpstream indicates multi-upstream is not supported
133+
ConditionReasonAuthServerRefMultiUpstream = "MultiUpstreamNotSupported"
134+
)
135+
111136
// ConditionTelemetryConfigRefValidated indicates whether the TelemetryConfigRef is valid
112137
const ConditionTelemetryConfigRefValidated = "TelemetryConfigRefValidated"
113138

@@ -270,6 +295,12 @@ type MCPServerSpec struct {
270295
// +optional
271296
ExternalAuthConfigRef *ExternalAuthConfigRef `json:"externalAuthConfigRef,omitempty"`
272297

298+
// AuthServerRef optionally references a resource that configures an embedded
299+
// OAuth 2.0/OIDC authorization server to authenticate MCP clients.
300+
// Currently the only supported kind is MCPExternalAuthConfig (type: embeddedAuthServer).
301+
// +optional
302+
AuthServerRef *AuthServerRef `json:"authServerRef,omitempty"`
303+
273304
// TelemetryConfigRef references an MCPTelemetryConfig resource for shared telemetry configuration.
274305
// The referenced MCPTelemetryConfig must exist in the same namespace as this MCPServer.
275306
// Cross-namespace references are not supported for security and isolation reasons.
@@ -836,6 +867,21 @@ type ExternalAuthConfigRef struct {
836867
Name string `json:"name"`
837868
}
838869

870+
// AuthServerRef defines a reference to a resource that configures an embedded
871+
// OAuth 2.0/OIDC authorization server. Currently only MCPExternalAuthConfig is supported;
872+
// the enum will be extended when a dedicated auth server CRD is introduced.
873+
type AuthServerRef struct {
874+
// Kind identifies the type of the referenced resource.
875+
// +kubebuilder:validation:Enum=MCPExternalAuthConfig
876+
// +kubebuilder:default=MCPExternalAuthConfig
877+
Kind string `json:"kind"`
878+
879+
// Name is the name of the referenced resource in the same namespace.
880+
// +kubebuilder:validation:Required
881+
// +kubebuilder:validation:MinLength=1
882+
Name string `json:"name"`
883+
}
884+
839885
// ToolConfigRef defines a reference to a MCPToolConfig resource.
840886
// The referenced MCPToolConfig must be in the same namespace as the MCPServer.
841887
type ToolConfigRef struct {
@@ -971,6 +1017,11 @@ type MCPServerStatus struct {
9711017
// +optional
9721018
ExternalAuthConfigHash string `json:"externalAuthConfigHash,omitempty"`
9731019

1020+
// AuthServerConfigHash is the hash of the referenced authServerRef spec,
1021+
// used to detect configuration changes and trigger reconciliation.
1022+
// +optional
1023+
AuthServerConfigHash string `json:"authServerConfigHash,omitempty"`
1024+
9741025
// OIDCConfigHash is the hash of the referenced MCPOIDCConfig spec for change detection
9751026
// +optional
9761027
OIDCConfigHash string `json:"oidcConfigHash,omitempty"`

cmd/thv-operator/api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)