Skip to content

Make tool:call imply tool:read for tool listing - #6903

Merged
aponcedeleonch merged 20 commits into
stacklok:mainfrom
rkb32:fix/4048-tool-call-implies-tool-read
Nov 27, 2026
Merged

aponcedeleonch merged 20 commits into
stacklok:mainfrom
rkb32:fix/4048-tool-call-implies-tool-read

Conversation

@rkb32

@rkb32 rkb32 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Closes #6925.

Summary

This PR makes tools/list ask a tool:read check, and a tool:call grant also passes that check, so anyone who can call a tool can see it. With pdp.forward_tool_read, the PDP owns that rule instead. The rule only goes one way: a tool:read grant never allows a call. A decorator (pkg/authz/authorizers/tool_read.go) applies this rule in the proxy middleware and in vMCP admission.

Behaviour by authorizer

  • Cedar: unchanged. Cedar has no read action, so call_tool policies still decide what is listed.
  • HTTP PDP (default): unchanged. The PDP is asked only mcp:tool:call, once per tool. A call-only forbid still hides its tool.
  • HTTP PDP with pdp.forward_tool_read: true: the PDP is asked mcp:tool:read once per tool, with no call fallback. A read error hides the tool.
  • All: one 30s deadline covers the whole list. Tools checked after it are hidden, with a WARN.
    A tool:read error does not fall back to tool:call.

Does this introduce a user-facing change?

Yes. There is a new option, pdp.forward_tool_read (default false). Leave it off to keep current HTTP PDP visibility. Turn it on only if your PDP answers mcp:tool:read.

Test plan

  • Re-run after the rebase onto current main (not yet done for this description)
  • e2e tool_read_fallback_authz_test.go and tool_read_forward_authz_test.go: need a cluster, so this waits on CI
  • golangci-lint on the rebased branch (not run locally)

Related

🤖 Generated with Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-21T22:50:43.127016Z
We couldn’t complete this review. Comment @codex review to try again.
370d03f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment thread docs/authz.md Resolved
@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.28571% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.56%. Comparing base (fc81f63) to head (f9116b1).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
pkg/authz/tool_filter.go 76.92% 3 Missing ⚠️
pkg/vmcp/core/admission.go 81.25% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6903      +/-   ##
==========================================
+ Coverage   82.46%   82.56%   +0.09%     
==========================================
  Files         937      941       +4     
  Lines       95869    96689     +820     
==========================================
+ Hits        79060    79828     +768     
- Misses      16804    16856      +52     
  Partials        5        5              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for picking this up. The shape matches what we agreed on in #4048, and I checked that nothing that leads to a tools/call now goes through a read check, so the security story holds. Most of my comments are about making it smaller and putting the decorator where it belongs.

One thing I want to call out because it isn't obvious from the code. With Cedar, the tool:read check errors with "unsupported feature/operation combination" and the decorator drops that error, so visibility is decided by call_tool. That turns out to be the right answer, but only by accident. I wrote a quick test against the real Cedar authorizer with this policy set:

permit(principal, action, resource);
forbid(principal, action == Action::"call_tool", resource == Tool::"t");

On main, t is hidden from tools/list. With this PR it's still hidden. If Cedar evaluated a real Action::"read_tool", t would show up, because the broad permit matches and the call-only forbid doesn't. That's what #6924 proposes, so I've left a comment there. It needs a design for this case before it goes ahead. What I'd ask for here instead is that the Cedar authorizer returns false, nil for tool/read before it resolves claims. Today every tool on every tools/list goes through the full claim and upstream-token processing twice, and the first pass only exists to produce an error we throw away. With a plain deny, combineToolReadDecision and the "ignore the read error" logic can go away too.

The same combination affects the HTTP PDP (see the inline comment on docs/authz.md).

Comment thread pkg/authz/authorizers/tool_read.go Resolved
Comment thread pkg/authz/tool_filter.go Resolved
Comment thread pkg/authz/authorizers/tool_read.go Resolved
Comment thread docs/authz.md Resolved
Comment thread docs/authz.md Resolved
Comment thread docs/authz.md Resolved
Comment thread pkg/authz/tool_filter_fallback_test.go Resolved
Comment thread pkg/authz/authorizers/tool_read_test.go Resolved
@rkb32
rkb32 requested a review from jerm-dro as a code owner October 23, 2026 14:54
@rkb32
rkb32 force-pushed the fix/4048-tool-call-implies-tool-read branch from a60a7c1 to 0e44ae5 Compare October 23, 2026 15:59
@rkb32
rkb32 requested review from JAORMX and jhrozek October 23, 2026 16:06

@aponcedeleonch aponcedeleonch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working through both rounds so thoroughly, @rkb32, and sorry it took a while to get back to this. I checked each point from the October 22 reviews against the current head and they're addressed. The decorator is wrapped once and every list path picks it up, tools/call still only asks tool:call, and the Cedar plain deny keeps Cedar's behavior identical to main. Failing closed on a tool:read error is fine with us.

The main thing left is a rebase, since main has moved under a few files:

  • pkg/audit/auditor.go: #7102 added stampTraceContext(r.Context(), event) at the end of addMetadata. Put the discovery-marker block before that call. Keeping both naively lands it inside stampTraceContext, where r is out of scope.
  • pkg/audit/mcp_events.go: keep both the new trace_id/span_id keys and yours.
  • pkg/authz/authorizers/cedar/core_test.go: an append-at-the-end conflict, keep both.
  • After the rebase, two tests from main fail because they build the filter with a raw Cedar authorizer, which now denies tool:read: TestResponseFilteringWriter_ContentEncodedListFailsClosed/explicit_identity_is_filtered and TestAuthorizeListAndServe_WithholdsAcceptEncoding. Switching them to newTestFilteringWriter, or wrapping with authorizers.WithToolCallImpliesRead, should fix them.

The vMCP FilterTools change also covers #6925, so please add Closes #6925 to the description. A few smaller things inline.

Comment thread pkg/vmcp/core/admission.go Resolved
Comment thread pkg/audit/auditor.go Resolved
Comment thread pkg/authz/tool_filter.go Resolved
@rkb32
rkb32 force-pushed the fix/4048-tool-call-implies-tool-read branch from 0e44ae5 to 1fbb4c6 Compare November 13, 2026 15:23
@rkb32

rkb32 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor Author

@aponcedeleonch thanks for the reviews. I've worked through every point:

  • The vMCP docs now explain the read check and the call check separately.
  • The audit count is documented, including the other vMCP events where it can show up.
  • The release note is in the PR description.
  • The two 30s budget constants are now one shared constant.
  • The e2e tests cover both modes: the default, and forward_tool_read on.

One thing I want to be upfront about: with forward_tool_read on, the HTTP PDP is only asked tool:read, so the "read before call" order doesn't happen for HTTP anymore. The unit tests cover that order, and I've explained this on the e2e thread.

Could you approve the fork workflow run when you get a chance? The e2e tests need a cluster, so CI is the only place they can run.

@rkb32
rkb32 requested a review from aponcedeleonch November 14, 2026 16:49
@rkb32

rkb32 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

@jhrozek Thanks. I've ported the new fakes (opsAuthorizer, nativeOpsAuthorizer, callOnlyAuthorizer) to a new generated mock in pkg/authz/authorizers/mocks. The error-path cases you asked for (read error, read timeout, call error) are covered in TestToolCallImpliesRead_ErrorPaths. opFilterAuthorizer is gone.

You also asked about mockAuthorizer. It predates this PR, though this PR extends it, and it's used in 65 lines across 8 test files. Porting it here would bury the authz change in the diff. Do you want that as a follow-up PR, or here in this one?

@aponcedeleonch aponcedeleonch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the quick turnaround, @rkb32. I went through every point from my review and jhrozek's against the current head, and almost all of them are addressed. The Cedar plain deny, the single wrap, the shared deadline and the vMCP read check all look right. The race tests also pass locally for pkg/authz, pkg/audit and pkg/vmcp/core.

Two things on the description:

  • Closes #6925 is still missing. The vMCP FilterTools change covers it.
  • The first sentence says tools/list wasn't filtered on SSE (#6926). This PR doesn't touch the SSE path and #6926 is still open, so it reads like this PR fixes it. I'd drop that sentence or move #6926 to the Related section.

The main thing left is the audit count, see inline. The rest are small.

Comment thread pkg/authz/authorizers/tool_read.go Resolved
Comment thread docs/authz.md Resolved
Comment thread docs/authz.md Resolved
Comment thread pkg/authz/authorizers/http/config.go Resolved
Comment thread pkg/vmcp/core/admission.go Resolved
Comment thread pkg/authz/authorizers/tool_read_test.go Resolved
tools/list filtered tools by tool:call. It now filters by tool:read, and a
tool:call grant also satisfies the read check through a decorator around the
Authorizer (pkg/authz/authorizers/tool_read.go). The implication is one way:
tool:read never grants tool:call, and there is no new ingress verb.

The decorator is applied once, where the authorization middleware is built
(Middleware) and in the vMCP admission. vMCP FilterTools now checks tool:read;
AllowToolCall still checks tool:call. Cedar denies tool:read without
evaluating claims, so call_tool policies decide visibility, as before.

tools/list runs under one shared deadline. A tool:read error, including a
timeout, is returned without a tool:call check, so a slow PDP cannot double
the wait. A tools/list entry listed only through the tool:call fallback is
counted in the audit event as discovery_fallback_count.

HTTP PDP rules that allow mcp:tool:read now list a tool even when the matching
mcp:tool:call rule denies it. This is documented in docs/authz.md.

Closes stacklok#4048

Signed-off-by: rkb32 <[email protected]>
Clarify the vMCP and audit docs that described list and call as one
decision, fix the admission log message that said "context ended" when a
deadline expired, note that the discovery fallback count is taken before the
--tools allowlist, make the e2e test assert the listed tool and the
tool:read-before-call order instead of only a non-zero read count, and wrap
the authorizers in the content-encoding tests the same way production does.
Stop the deadline loop before the next check once the shared context is done,
so Cedar, which ignores the context, cannot keep checking tools after the
deadline. Return false on a tool:read error instead of the inner value, restore
the em dashes and arrows that an earlier commit garbled in comments, and drop
a trailing blank line in the Cedar test file.
The HTTP PDP is now asked only mcp:tool:call for tools/list visibility by
default, so a call-only forbid keeps hiding its tool and existing deployments
see no change. Setting pdp.forward_tool_read to true asks mcp:tool:read once per
tool instead, and the PDP owns the rule that call implies read. The
tool:read decorator picks one path per authorizer through an optional
ToolReadNative interface, so each tool costs exactly one PDP decision in
both modes. Cedar is unchanged.
rkb32 and others added 10 commits November 26, 2026 11:41
Cover the default and the opt-in paths through the same decorator the filters
use: default sends only mcp:tool:call, a call-only forbid still hides the tool,
forward_tool_read sends only mcp:tool:read with no call fallback, and the flag
parses and defaults to false.
The doc said list and call enforce the same decision. List now asks tool:read and
call asks tool:call, so the doc says that and that a listed tool can still be
refused when called.
The fallback count is taken before the --tools allowlist, and vMCP runs the filter
under initialize, server/discover and ListBackends too, so the key can appear on
events that do not list tools to the client. Say so in the audit section.
The default now asks the PDP only tool:call, so the e2e test checks that the PDP
never sees tool:read and that only the allowed tool is listed. The CallTool and
LookupTool docs now say that a visible tool can still be refused when called.
The vMCP filter kept its own 30s budget copy. Export the authz constant and use it
in both places. Add an e2e case with forward_tool_read on: the PDP is asked
mcp:tool:read once for the listed tool and never mcp:tool:call.
The flag-on e2e file was copied from the default one, so its comments still
described the fallback. Reword them, rename its server prefix, and check that no
request ever carries mcp:tool:call, not only the allowed tool's. Drop the vMCP
claim that PDP costs apply there.
The filter asks tool:read once per tool, so the total was 3, not 1.
Count only the reads for query_vulnerability.
Generate pkg/authz/authorizers/mocks from the Authorizer interface and
port opsAuthorizer, nativeOpsAuthorizer and callOnlyAuthorizer to it.
tool_read_test moves to the external test package so it can import the mock.
@rkb32
rkb32 force-pushed the fix/4048-tool-call-implies-tool-read branch from 98dd137 to f46fcd8 Compare November 26, 2026 18:10
The count is either the visible-tool count or always zero under the
current defaults, so it does not separate a read grant from a call
grant. Remove the marker, its audit key, and its test; it can return
with the read_tool work.
Document forward_tool_read in the PDP options and the CRD comment,
state that the PDP must allow read wherever it allows call, drop the
changelog-style upgrade and audit bullets, say that the deadline also
covers cancelled requests, and reuse getRequests in the e2e tests.
The three tests differed only in the authorizer's answersRead flag,
the allowed operations and the expected calls, so they are rows in one
table now.
The httpv1 field list in the MCPAuthzConfig CRD comment names
forward_tool_read, so the generated reference includes it too.
The forward_tool_read entry made the httpv1 line 154 characters, over
the 130 limit. Move it to its own list line and regenerate the CRD docs.
Add the forward_tool_read entry to the httpv1 description in the CRD
manifests, matching the comment in the Go type. The operator CI
Generate CRDs check compares these files.
@rkb32
rkb32 force-pushed the fix/4048-tool-call-implies-tool-read branch from 902ec9e to f9116b1 Compare November 27, 2026 06:49

@aponcedeleonch aponcedeleonch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot for sticking with this one, @rkb32. I went through every thread from both rounds against the current head and they're all addressed. The decorator is wired once, the Cedar plain deny keeps its behavior identical to main, forward_tool_read is documented end to end, and CI is green including the new e2e tests. Great work, and thanks for the contribution!

@aponcedeleonch
aponcedeleonch merged commit df5aed7 into stacklok:main Nov 27, 2026
46 checks passed
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.

Filter vMCP tools/list with tool:read, as the single-server path does

4 participants