Skip to content

add bearerToken type to MCPExternalAuthConfig CRD#3224

Merged
amirejaz merged 15 commits intomainfrom
operator-bearer-token-crd-types
Jan 22, 2026
Merged

add bearerToken type to MCPExternalAuthConfig CRD#3224
amirejaz merged 15 commits intomainfrom
operator-bearer-token-crd-types

Conversation

@amirejaz
Copy link
Contributor

@amirejaz amirejaz commented Jan 8, 2026

Summary

This PR adds bearer token authentication support to the MCPExternalAuthConfig CRD, allowing users to configure bearer token authentication for remote MCP servers via Kubernetes Secrets.

NOTE: Controller Implementation will be done in next PR

Changes

CRD Types (cmd/thv-operator/api/v1alpha1/mcpexternalauthconfig_types.go)

  • Added ExternalAuthTypeBearerToken constant
  • Added BearerTokenConfig struct with TokenSecretRef *SecretKeyRef field
  • Updated MCPExternalAuthConfigSpec to include BearerToken *BearerTokenConfig field
  • Updated validation enum to include bearerToken type

Webhook Validation (cmd/thv-operator/api/v1alpha1/mcpexternalauthconfig_webhook.go)

  • Added validation for bearerToken type:
    • BearerToken config must be provided when type is bearerToken
    • TokenExchange and HeaderInjection must not be set when type is bearerToken
    • BearerToken must not be set when type is not bearerToken
  • Updated validation for other types to reject BearerToken field

Tests (cmd/thv-operator/api/v1alpha1/mcpexternalauthconfig_webhook_test.go)

  • Added comprehensive test cases:
    • Valid bearer token configuration
    • Invalid: bearerToken without config
    • Invalid: bearerToken with tokenExchange
    • Invalid: bearerToken with headerInjection
    • Invalid: unauthenticated with bearerToken
    • Invalid: tokenExchange with bearerToken
    • Invalid: headerInjection with bearerToken

Code Generation

  • Regenerated deepcopy code (includes BearerTokenConfig)

Example Usage

apiVersion: v1
kind: Secret
metadata:
  name: posthog-bearer-token
  namespace: default
type: Opaque
stringData:
  token: "your-bearer-token-here"
---
apiVersion: toolhive.stacklok.dev/v1alpha1
kind: MCPExternalAuthConfig
metadata:
  name: posthog-bearer-auth
  namespace: default
spec:
  type: bearerToken
  bearerToken:
    tokenSecretRef:
      name: posthog-bearer-token
      key: token

Security Considerations

No Plain Text: Only Kubernetes Secret references are supported
Namespace Scoped: Secrets must be in the same namespace as the MCPExternalAuthConfig
Consistent with OAuth: Follows the same security model as ClientSecretRef in token exchange

Testing

✅ All existing tests pass
✅ New bearer token validation tests pass
✅ CRD validation correctly rejects invalid configurations
✅ Deepcopy code generated successfully

Related

Part of Phase 3: Kubernetes Operator Implementation
PR 1 of 2: CRD Types and Validation (this PR)
PR 2: Controller Implementation (next)

@github-actions github-actions bot added the size/S Small PR: 100-299 lines changed label Jan 8, 2026
@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

❌ Patch coverage is 90.00000% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.79%. Comparing base (9ff9ec2) to head (73f7834).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...perator/controllers/virtualmcpserver_deployment.go 0.00% 2 Missing ⚠️
...d/thv-operator/pkg/controllerutil/tokenexchange.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3224      +/-   ##
==========================================
+ Coverage   64.76%   64.79%   +0.02%     
==========================================
  Files         381      381              
  Lines       37121    37149      +28     
==========================================
+ Hits        24043    24069      +26     
+ Misses      11194    11193       -1     
- Partials     1884     1887       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

jhrozek
jhrozek previously approved these changes Jan 8, 2026
Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine adding a new type as a user shortcut, but it would be nice to, at least thinking about vmCP, reuse code when converting this to a vMCP auth strategy

@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/S Small PR: 100-299 lines changed labels Jan 8, 2026
@amirejaz amirejaz requested a review from jhrozek January 8, 2026 15:43
@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Jan 9, 2026
@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Jan 9, 2026
@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Jan 9, 2026
@amirejaz amirejaz requested a review from dmjb January 9, 2026 16:05
@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Jan 9, 2026
@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Jan 12, 2026
@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Jan 12, 2026
@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Jan 19, 2026
@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Jan 20, 2026
@amirejaz
Copy link
Contributor Author

@jhrozek would appreciate another look

@jhrozek
Copy link
Contributor

jhrozek commented Jan 20, 2026

LGTM, but needs rebase (sorry for the late review!)

@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Jan 21, 2026
@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Jan 22, 2026
@jhrozek
Copy link
Contributor

jhrozek commented Jan 22, 2026

LGTM again, I'm sorry but the version needs to be bumped again. Let me know when you've bumped the version on Slack so we can merge the patch ASAP.

@github-actions github-actions bot added size/M Medium PR: 300-599 lines changed and removed size/M Medium PR: 300-599 lines changed labels Jan 22, 2026
Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and you've got version 100 :-)

@amirejaz amirejaz merged commit a7962a6 into main Jan 22, 2026
38 checks passed
@amirejaz amirejaz deleted the operator-bearer-token-crd-types branch January 22, 2026 22:41
@amirejaz
Copy link
Contributor Author

and you've got version 100 :-)

Honestly, I didn’t wait for it to reach 100 😄

therealnb pushed a commit that referenced this pull request Jan 23, 2026
* add bearerToken type to MCPExternalAuthConfig CRD

* refactor to fix linting

* bumped version

* bumped crd version

* bumped version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Medium PR: 300-599 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants