Implement bearer token controller logic and environment variable management #3487
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implements the controller logic and runtime integration for bearer token authentication in Kubernetes, building on the foundation laid in PR #3224. This completes the bearer token authentication flow by adding reconciliation, RunConfig generation, environment variable management, and secret watching capabilities.
Context
This PR builds on PR #3224 which added:
BearerTokenConfigCRD type inMCPExternalAuthConfigExternalAuthTypeBearerTokenenum valueThis PR implements the operational logic to make bearer tokens work end-to-end.
Changes
Controller Implementation
MCPExternalAuthConfig Controller:
bearerTokentype inmcpexternalauthconfig_controller.gofindMCPExternalAuthConfigsReferencingSecret()- finds configs referencing a secretconfigReferencesSecret()- checks if a config references a specific secretMCPRemoteProxy Controller:
mcpremoteproxy_runconfig.go)"secret-name,target=bearer_token")Environment Variable Management
GenerateBearerTokenEnvVar(): CreatesTOOLHIVE_SECRET_{secret-name}env vars from Secret referencesEnsureRequiredEnvVars(): Auto-detectsTOOLHIVE_SECRET_*env vars and setsTOOLHIVE_SECRETS_PROVIDER=environmentTOOLHIVE_SECRET_*prefixSecret Resolution Flow
MCPExternalAuthConfigwithbearerTokentype referencing a Kubernetes SecretTOOLHIVE_SECRET_{secret-name}env var in pod specEnsureRequiredEnvVarsdetects secret env vars and setsTOOLHIVE_SECRETS_PROVIDER=environment"secret-name,target=bearer_token"EnvironmentProviderresolves secret fromTOOLHIVE_SECRET_*env varTesting
mcpremoteproxy_runconfig_test.go)EnsureRequiredEnvVarswith 13 test cases covering:mcpexternalauthconfig_controller_test.go)Examples & Documentation
mcpremoteproxy_with_bearer_token.yamlexample demonstrating bearer token configurationSecurity
Technical Details
Secret Watch Implementation
MCPExternalAuthConfigresources that reference themWatches(&corev1.Secret{}, secretHandler)inSetupWithManagerConfig Hash with Secret Content
calculateConfigHash()now includes SHA256 hash (truncated to 16 hex chars) of referenced secret valuesMCPServerandMCPRemoteProxyresourcesRelated