Skip to content

Conversation

@ardaguclu
Copy link
Member

This PR is derivation of this #217. However, #217 contains some hacky code to make agentic flow working such as intentional fall back to in-cluster config, etc.

This PR introduces scoped based authorization for tool calls. If it detects the tool name is not included in the token scopes, mcp server fails with 403 forbidden error.

Currently this PR uses tool names as scoped names. But in the future, we may want to create a mapping to customize scope names.

klog.Warningf("authorization-url is using http://, this is not recommended production use")
}
}
if m.StaticConfig.ServerURL != "" {
Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, server url field is used for arbitrary audience rather than a structured URL format. I'm removing this validation (and its test). But if we decide to force URL format in the future, we'll need to revert this change (and its test).


func toolScopedAuthorizationMiddleware(next server.ToolHandlerFunc) server.ToolHandlerFunc {
return func(ctx context.Context, ctr mcp.CallToolRequest) (*mcp.CallToolResult, error) {
scopes, ok := ctx.Value(TokenScopesContextKey).([]string)
Copy link
Member Author

Choose a reason for hiding this comment

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

@manusa although we agreed that we'll add this scoped based validation in authorization.go rather than here, mcp clients all failed to handle the flow. I think, apart from here all the rest is a clear indication of model context protocol violation.

After adding the scope based check in tool call middleware, it simply works.

@ardaguclu
Copy link
Member Author

I have no idea what are these verification errors in here https://github.com/containers/kubernetes-mcp-server/pull/224/checks?check_run_id=47091334553. So I'll have to ignore them.

@manusa would you please have a look at this PR, when you have a moment?. Thanks.

@manusa
Copy link
Member

manusa commented Jul 31, 2025

I have no idea what are these verification errors in here https://github.com/containers/kubernetes-mcp-server/pull/224/checks?check_run_id=47091334553. So I'll have to ignore them.

No idea either. We need to migrate to our own pipelines.

@manusa would you please have a look at this PR, when you have a moment?. Thanks.

👍

Copy link
Member

@manusa manusa left a comment

Choose a reason for hiding this comment

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

LGTM, thx!

@manusa manusa changed the title Introduce scoped based authorization feat(auth): introduce scoped based authorization Jul 31, 2025
@manusa manusa added this to the 0.1.0 milestone Jul 31, 2025
@manusa manusa merged commit be80db1 into containers:main Jul 31, 2025
7 of 8 checks passed
@ardaguclu ardaguclu deleted the scoped-based-authorization branch July 31, 2025 09:10
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.

2 participants