Skip to content

feat(auth): Authorize user from custom SSE header #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 29, 2025

Conversation

manusa
Copy link
Owner

@manusa manusa commented May 28, 2025

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:

  1. No headers are added to the SSE request.
    ❌ The request fails because the loaded .kube/config doesn't contain user auth.
  2. A valid token is loaded by the JavaScript MCP Client from the system environment.
    The token is sent as an HTTP header with the SSE request.
    ✅ The request is successful and the pods are listed.
  3. An invalid hardcoded token is sent by the JavaScript MCP Client with the SSE request.
    ❌ 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.

@manusa manusa force-pushed the feat/kubernetes-authorization-impersonation branch from 33f1342 to 40074b8 Compare May 28, 2025 10:31
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.
@manusa manusa marked this pull request as ready for review May 29, 2025 14:32
@manusa manusa added this to the 0.1.0 milestone May 29, 2025 — with automated-tasks
@manusa manusa merged commit f80d8df into main May 29, 2025
5 checks passed
@manusa manusa deleted the feat/kubernetes-authorization-impersonation branch May 29, 2025 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant