feat(auth): Authorize user from custom SSE header #96
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.
PoC to show how we can propagate an Authorization Bearer token from the MCP client up to the Kubernetes API by passing a custom header (
kubernetes-authorization-bearer-token
).A new Derived client is necessary for each request due to the incompleteness of some of the client-go clients.
This might add some overhead for each prompt.
Ideally, the issue with the discoveryclient and others should be fixed to allow reading the authorization header from the request context.
To use the feature, the MCP Server still needs to be started with a basic configuration (either provided InCluster by a service account or locally by a
.kube/config
file) so that it's able to infer the server settings.Demo
kubernetes-mcp-server-auth-header.mp4
The demo shows how a JavaScript client adds a
Kubernetes-Authorization-Bearer-Token
HTTP header to each request.There are 3 scenarios shown:
❌ The request fails because the loaded
.kube/config
doesn't contain user auth.The token is sent as an HTTP header with the SSE request.
✅ The request is successful and the pods are listed.
❌ Request fails with Kubernetes API server requesting credentials.
Roundtripper wrapper issue
Using a wrap function for the roundtripper, and reading the context from the derived roundtripper should be the ideal solution.
However, some of the clients in use don't leverage the provided context, so it's impossible to propagate the SSE request header to the Kube API request.