Repository navigation
Make tool:call imply tool:read for tool listing - #6903
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
jhrozek
left a comment
There was a problem hiding this comment.
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).
a60a7c1 to
0e44ae5
Compare
aponcedeleonch
left a comment
There was a problem hiding this comment.
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 addedstampTraceContext(r.Context(), event)at the end ofaddMetadata. Put the discovery-marker block before that call. Keeping both naively lands it insidestampTraceContext, whereris out of scope.pkg/audit/mcp_events.go: keep both the newtrace_id/span_idkeys 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_filteredandTestAuthorizeListAndServe_WithholdsAcceptEncoding. Switching them tonewTestFilteringWriter, or wrapping withauthorizers.WithToolCallImpliesRead, should fix them.
The vMCP FilterTools change also covers #6925, so please add Closes #6925 to the description. A few smaller things inline.
0e44ae5 to
1fbb4c6
Compare
|
@aponcedeleonch thanks for the reviews. I've worked through every point:
One thing I want to be upfront about: with 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. |
|
@jhrozek Thanks. I've ported the new fakes (opsAuthorizer, nativeOpsAuthorizer, callOnlyAuthorizer) to a new generated mock in 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
left a comment
There was a problem hiding this comment.
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 #6925is still missing. The vMCPFilterToolschange covers it.- The first sentence says
tools/listwasn'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.
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.
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.
98dd137 to
f46fcd8
Compare
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.
902ec9e to
f9116b1
Compare
aponcedeleonch
left a comment
There was a problem hiding this comment.
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!
Closes #6925.
Summary
This PR makes
tools/listask atool:readcheck, and atool:callgrant also passes that check, so anyone who can call a tool can see it. Withpdp.forward_tool_read, the PDP owns that rule instead. The rule only goes one way: atool:readgrant 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
call_toolpolicies still decide what is listed.mcp:tool:call, once per tool. A call-only forbid still hides its tool.pdp.forward_tool_read: true: the PDP is askedmcp:tool:readonce per tool, with no call fallback. A read error hides the tool.A
tool:readerror does not fall back totool:call.Does this introduce a user-facing change?
Yes. There is a new option,
pdp.forward_tool_read(defaultfalse). Leave it off to keep current HTTP PDP visibility. Turn it on only if your PDP answersmcp:tool:read.Test plan
main(not yet done for this description)tool_read_fallback_authz_test.goandtool_read_forward_authz_test.go: need a cluster, so this waits on CIgolangci-linton the rebased branch (not run locally)Related
tools/listfiltering) was fixed separately in Filter SSE list answers on the event stream #6949. This PR does not change the SSE path.🤖 Generated with Claude Code