etzel-mes opened a new pull request, #30317:
URL: https://github.com/apache/camel/pull/30317

   # Description
   
   https://issues.apache.org/jira/browse/CAMEL-27144
   
   Since CAMEL-25405 the MCP server puts the authenticated caller's roles on 
the tool exchange (`CamelMcpSecurityPrincipalRoles`). To use them, a route 
author writes an `AuthorizationPolicy` class or an OPA rule. This adds the 
declarative form for the plain case, a role for each tool:
   
   - `allowedRoles`: comma-separated role names; the caller needs one of them. 
Name, type and levels as camel-undertow's `allowedRoles`.
   - `allRolesRequired` (default `false`): the caller needs all of them.
   
   Both are endpoint options; set on the component they are the default of 
every tool route.
   
   How it works:
   
   - The check is a processor in front of the tool route, at the seam 
`authorizationPolicy` uses in `AiToolConsumer`, in place before the tool is 
registered. With both set, the roles are checked first.
   - Roles are read only from the exchange property, never from a header or a 
tool argument. A call without the property is refused: over stdio, on a server 
without authentication, and on a runtime whose MCP engine does not set it.
   - A refusal is the existing one: `CamelAuthorizationException`, 
`AiToolResult.AuthorizationDenied`, the WARN and 
`AiToolAuthorizationDeniedEvent` (`getPolicyId()` is `allowedRoles`).
   - An `allowedRoles` that is set but names no role (an empty placeholder, for 
example) refuses every call, as the security model asks of a check with nothing 
to check. The route still starts and a WARN at start names the tool, as 
camel-undertow does for roles nothing can check. If you prefer the route to 
fail at start, I change it.
   - Not set means no check. No existing route changes behaviour.
   
   Not in this PR:
   
   - `AiEvent.ToolCallDeniedEvent` in camel-api still says "denied by the 
route's `authorizationPolicy`". I left the core module out of this diff; say if 
you want that line updated here.
   - A switch that closes every tool nobody guarded, scopes for each tool, and 
filtering `tools/list`: separate issues.
   
   Tests: unit tests in camel-ai-tool and camel-mcp-server (Camel Main with JWT 
and with the OAuth profile). Also run against a real Keycloak 26.8 on Camel 
Main: realm roles, client roles and groups through mappers, role-less and 
unauthenticated callers, every blank form of the option, attempts to pass a 
role in arguments, headers, `_meta` and the query string, and parallel calls.
   
   Tried on the other runtimes too (JVM mode): on Spring Boot the option works 
over the Streamable transport, where the engine sets the roles from Spring 
Security authorities (CAMEL-26360); on Quarkus the engine does not set them yet 
(camel-quarkus PR 9509), so such a tool refuses every MCP call there. The 
camel-ai-tool starter needs its usual regeneration: until then Spring Boot 
ignores `camel.component.ai-tool.allowed-roles` silently, while the endpoint 
option works. The "Only the Vert.x streamable HTTP server ... populates these 
today" sentence on the ai-tool page is upstream text and is out of date for 
Spring Boot; I left it for a separate docs fix.
   
   cc @davsclaus @oscerd
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [ ] I have run `mvn clean install -DskipTests` locally from root folder 
and I have committed all auto-generated changes.
   
   Not from the root folder: I built the three changed modules, regenerated the 
catalog and both DSL modules, ran `-Psourcecheck`, and committed every 
generated file that changed.
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   _Claude Code on behalf of etzel-mes_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to