Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions pkg/http/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"k8s.io/utils/strings/slices"

"github.com/containers/kubernetes-mcp-server/pkg/config"
"github.com/containers/kubernetes-mcp-server/pkg/mcp"
)

// write401 sends a 401/Unauthorized response with WWW-Authenticate header.
Expand Down Expand Up @@ -88,12 +87,6 @@ func AuthorizationMiddleware(staticConfig *config.StaticConfig, oidcProvider *oi
if err == nil {
err = claims.ValidateWithProvider(r.Context(), staticConfig.OAuthAudience, oidcProvider)
}
// Scopes propagation, they are likely to be used for authorization.
if err == nil {
scopes := claims.GetScopes()
klog.V(2).Infof("JWT token validated - Scopes: %v", scopes)
r = r.WithContext(context.WithValue(r.Context(), mcp.TokenScopesContextKey, scopes))
}
if err != nil {
klog.V(1).Infof("Authentication failed - JWT validation error: %s %s from %s, error: %v", r.Method, r.URL.Path, r.RemoteAddr, err)
write401(w, wwwAuthenticateHeader, "invalid_token", "Unauthorized: Invalid token")
Expand Down
7 changes: 0 additions & 7 deletions pkg/mcp/mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import (
"github.com/containers/kubernetes-mcp-server/pkg/version"
)

type ContextKey string

const TokenScopesContextKey = ContextKey("TokenScopesContextKey")

type Configuration struct {
*config.StaticConfig
listOutput output.Output
Expand Down Expand Up @@ -97,9 +93,6 @@ func NewServer(configuration Configuration, oidcProvider *oidc.Provider, httpCli

s.server.AddReceivingMiddleware(authHeaderPropagationMiddleware)
s.server.AddReceivingMiddleware(toolCallLoggingMiddleware)
if configuration.RequireOAuth && false { // TODO: Disabled scope auth validation for now
s.server.AddReceivingMiddleware(toolScopedAuthorizationMiddleware)
}

var err error
s.p, err = internalk8s.NewProvider(s.configuration.StaticConfig)
Expand Down
15 changes: 0 additions & 15 deletions pkg/mcp/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package mcp
import (
"bytes"
"context"
"fmt"
"slices"

internalk8s "github.com/containers/kubernetes-mcp-server/pkg/kubernetes"
"github.com/modelcontextprotocol/go-sdk/mcp"
Expand Down Expand Up @@ -46,16 +44,3 @@ func toolCallLoggingMiddleware(next mcp.MethodHandler) mcp.MethodHandler {
return next(ctx, method, req)
}
}

func toolScopedAuthorizationMiddleware(next mcp.MethodHandler) mcp.MethodHandler {
return func(ctx context.Context, method string, req mcp.Request) (mcp.Result, error) {
scopes, ok := ctx.Value(TokenScopesContextKey).([]string)
if !ok {
return NewTextResult("", fmt.Errorf("authorization failed: Access denied: Tool '%s' requires scope 'mcp:%s' but no scope is available", method, method)), nil
}
if !slices.Contains(scopes, "mcp:"+method) && !slices.Contains(scopes, method) {
return NewTextResult("", fmt.Errorf("authorization failed: Access denied: Tool '%s' requires scope 'mcp:%s' but only scopes %s are available", method, method, scopes)), nil
}
return next(ctx, method, req)
}
}