Implement bearer token controller logic and environment variable management#3487
Implement bearer token controller logic and environment variable management#3487
Conversation
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 #3487 +/- ##
==========================================
- Coverage 65.71% 65.68% -0.04%
==========================================
Files 410 410
Lines 40624 40704 +80
==========================================
+ Hits 26697 26736 +39
- Misses 11846 11886 +40
- Partials 2081 2082 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
PR size has been reduced below the XL threshold. Thank you for splitting this up!
|
✅ PR size has been reduced below the XL threshold. The size review has been dismissed and this PR can now proceed with normal review. Thank you for splitting this up! |
cmd/thv-operator/controllers/mcpexternalauthconfig_controller.go
Outdated
Show resolved
Hide resolved
f146eb7 to
a47eb6f
Compare
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