stacklok / stacklok/toolhive

Scope pods/attach Role rule to stdio transport only

Open Beginner friendly
#6,230 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good-tenth-issue kubernetes
Dominant language
Go
Stars
2.2k
Forks
300
Avg merge
1d 15h
Merged PRs (30d)
184

Description

Summary

The per-MCP Role created by the operator (-proxy-runner) unconditionally includes pods/attach (create, get) regardless of the transport type configured on the MCPServer. For streamable-http and sse transports, the proxy runner communicates over HTTP and never needs to attach to the MCP pod's stdio — so this permission is granted but never used.

Current behavior

In cmd/thv-operator/controllers/mcpserver_controller.go, defaultRBACRules is applied to every MCPServer regardless of transport:

{APIGroups: []string{""}, Resources: []string{"pods/attach"}, Verbs: []string{"create", "get"}},

This means every MCP running streamable-http or sse transport gets a Role with pods/attach that it has no functional need for.

Expected behavior

The pods/attach rule should only be included in the Role when spec.transport is stdio. For streamable-http and sse, the rule should be omitted entirely.

Why it matters

Security auditing tools (e.g. Polaris) flag pods/attach as an elevated permission equivalent to pod exec. Clusters with strict audit policies will surface this as a violation on every MCPServer deployment, even when the permission is architecturally unnecessary for the configured transport.

Suggested fix

Gate the rule on transport type in ensureRBACResources (or wherever defaultRBACRules is applied):

rules := defaultRBACRules
if mcpServer.Spec.Transport == transportStdio {
rules = append(rules, podAttachRule)
}

Environment

  • ToolHive operator version: v0.33.0
  • Transport in use: streamable-http
  • Audit tool flagging this: Polaris

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in cmd/thv-operator/controllers/mcpserver_controller.go, focusing on defaultRBACRules and ensureRBACResources. Trace how the MCPServer transport is read, then verify that pods/attach appears only for stdio and is omitted for streamable-http and sse. Done means the generated Roles have the expected rules for each transport.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
infrastructure, security
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.