-
Notifications
You must be signed in to change notification settings - Fork 1.9k
OSDOCS-17719: adds authorization to MCP gateway docs #109794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ShaunaDiaz
merged 1 commit into
openshift:mcp-gateway-docs-tp
from
ShaunaDiaz:OSDOCS-17719
Apr 20, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| :_mod-docs-content-type: ASSEMBLY | ||
| include::_attributes/attributes.adoc[] | ||
| [id="mcp-gateway-authorization"] | ||
| = Using authorization with {mcpg} | ||
| :context: mcp-gateway-authorization | ||
|
|
||
|
ShaunaDiaz marked this conversation as resolved.
|
||
| [role="_abstract"] | ||
| You can configure authorization for the {mcpg} by using an additional `AuthPolicy` custom resource (CR) that adds access control for servers, data, and tools. | ||
|
|
||
| include::modules/con-understanding-mcp-gateway-authorization.adoc[leveloffset=+1] | ||
|
|
||
| include::modules/proc-mcp-gateway-authorization.adoc[leveloffset=+1] | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // Module included in the following assemblies: | ||
| // | ||
| // *mcp_gateway_config/mcp-gateway-authorization.adoc | ||
|
|
||
| :_mod-docs-content-type: CONCEPT | ||
| [id="con-understanding-mcp-gateway-authorization_{context}"] | ||
| = Understanding authorization in {mcpg} | ||
|
|
||
| [role="_abstract"] | ||
| By setting up authorization in the MCP gateway, you can control which authenticated users can access specific MCP server tools. The MCP gateway supports authorization approaches including other policy engines and Gateway API policy extensions. | ||
|
|
||
| The following steps represent what happens during an authorization evaluation: | ||
|
|
||
| * Authentication: A user authenticates and receives a JSON Web Token (JWT) with permissions. | ||
| * Tool request: The client makes an MCP tool call, such as `tools/call`. | ||
| * Request identity check: An `AuthPolicy` object verifies the JWT and extracts authorization claims. | ||
| * Authorization check: A Common Expression Language (CEL) expression evaluates the requested tool against the user's permissions that were extracted from the JWT. | ||
| * Access decision: `Allow` or `deny` based on the authorization check result. | ||
|
|
||
| To create an authorization evaluation, you must set up authentication, define permissions, and specify access control roles. For example, take the following steps if using {keycloak}: | ||
|
|
||
| * Define your permissions and user claims. If you are using {keycloak}, you can add groups or attributes to the default JWT. | ||
| * Provide tool-level authorization to control access to individual MCP tools. | ||
| * Define role-based access by using {keycloak} client roles and group bindings for permission decisions. | ||
| * Configure your identity provider to include Access Control List (ACL) claims in the tokens it issues. | ||
| * Define complex authorization logic using Common Expression Language expressions that evaluate the claims and decide whether to let them through. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
|
|
||
| // Module included in the following assemblies: | ||
| // | ||
| // *mcp_gateway_config/mcp-gateway-authorization.adoc | ||
|
|
||
| :_mod-docs-content-type: PROCEDURE | ||
| [id="proc-mcp-gateway-authorization_{context}"] | ||
| = Configuring {mcpg} authorization with an AuthPolicy | ||
|
|
||
| [role="_abstract"] | ||
| The following example demonstrates using a Kuadrant `AuthPolicy` custom resource (CR) with Common Expression Language (CEL) to implement role-based access control. You can use this procedure as a general pattern for applying the authorization specific to your use case. The {mcpg} supports Istio or Gateway API compatible authorization mechanisms. | ||
|
|
||
| .Prerequisites | ||
|
|
||
| * You installed {mcpg}. | ||
| * You installed {prodname}. | ||
| * You configured a `Gateway` object. | ||
| * You completed authentication procedures. | ||
| * You configured your identity provider to include `group` and `role` claims in JSON Web Tokens (JWT). | ||
|
|
||
| .Procedure | ||
|
|
||
| . Ensure that your identity provider includes the required `group` and `role` claims in the issued JWTs. In the following example, {keycloak} is used: | ||
| + | ||
| .Example issued OAuth token claims: | ||
| [source,json] | ||
| ---- | ||
| { | ||
| "resource_access": { | ||
| "mcp-ns/arithmetic-mcp-server": { | ||
| "roles": ["add", "sum", "multiply", "divide"] | ||
| }, | ||
| "mcp-ns/geometry-mcp-server": { | ||
| "roles": ["area", "distance", "volume"] | ||
| } | ||
| } | ||
| } | ||
| ---- | ||
| + | ||
| * The `"mcp-ns/arithmetic-mcp-server"` specification must match the namespaced name of the `MCPServerRegistration` CR. | ||
| * The `"roles": ["add", "sum", "multiply", "divide"]` parameter and values specify the roles representing the allowed tools. | ||
|
|
||
| . Configure tool-level authorization by creating an `AuthPolicy` CR that enforces tool-level access control, as shown in the following example: | ||
| + | ||
| .Example tool-level access control AuthPolicy | ||
| [source,yaml,subs="+quotes"] | ||
| ---- | ||
| apiVersion: kuadrant.io/v1 | ||
| kind: AuthPolicy | ||
| metadata: | ||
| name: _<mcp_tool_auth_policy>_ | ||
| namespace: _<gateway_system>_ | ||
| spec: | ||
| targetRef: | ||
| group: gateway.networking.k8s.io | ||
| kind: Gateway | ||
| name: _<mcp_gateway>_ | ||
| sectionName: _<mcps>_ | ||
| rules: | ||
| authentication: | ||
| 'sso-server': | ||
| jwt: | ||
| issuerUrl: http://keycloak.example.com:8002/realms/mcp | ||
| authorization: | ||
| 'tool-access-check': | ||
| patternMatching: | ||
| patterns: | ||
| - predicate: | | ||
| request.headers['x-mcp-toolname'] in (has(auth.identity.resource_access) && auth.identity.resource_access.exists(p, p == request.headers['x-mcp-servername']) ? auth.identity.resource_access[request.headers['x-mcp-servername']].roles : []) | ||
| response: | ||
| unauthenticated: | ||
| headers: | ||
| 'WWW-Authenticate': | ||
| value: Bearer resource_metadata=http://mcp.example.com:8001/.well-known/oauth-protected-resource/mcp | ||
| body: | ||
| value: | | ||
| { | ||
| "error": "Unauthorized", | ||
| "message": "MCP Tool Access denied: Authentication required." | ||
| } | ||
| unauthorized: | ||
| body: | ||
| value: | | ||
| { | ||
| "error": "Forbidden", | ||
| "message": "MCP Tool Access denied: Insufficient permissions for this tool." | ||
| } | ||
| ---- | ||
| + | ||
| * Replace `metadata.name:` with the name of the `AuthPolicy`. | ||
| * Replace `metadata.namespace:` with the namespace where the `AuthPolicy` CR is applied. | ||
| * Replace `spec.targetRef.name:` with the name of the `Gateway` CR. | ||
| * The `spec.targetRef.sectionName:` value targets the MCP server listener. | ||
| * Authentication: Validates the JWT token using the configured issuer URL | ||
| * Authorization Logic: CEL expression checks if user's roles allow access to the requested tool | ||
| * CEL Breakdown: | ||
| ** `request.headers['x-mcp-toolname']`: The name of the requested MCP tool, stripped from prefix. | ||
| ** `request.headers['x-mcp-servername']`: The namespaced name of the MCP server matching the `MCPServerRegistration` CR. | ||
| ** `auth.identity.resource_access`: The JWT claim containing all roles representing each allowed tool the user can access, grouped by MCP server. | ||
| * Response handling: Custom `401` and `403` responses for unauthenticated and unauthorized access attempts. | ||
|
|
||
| . Apply the AuthPolicy CR by running the following command: | ||
| + | ||
| [source,terminal,subs="+quotes"] | ||
| ---- | ||
| $ oc apply -f _<mcp_tool_auth_policy.yaml>_ | ||
| ---- | ||
| * Replace `_<mcp_tool_auth_policy.yaml>_` with the name of the `AuthPolicy` YAML filename. | ||
|
|
||
| .Verification | ||
|
|
||
| . Monitor authorization decisions by checking the `AuthPolicy` CR `status` with the following command: | ||
| + | ||
| [source,terminal] | ||
| ---- | ||
| $ oc get authpolicy -A | ||
| ---- | ||
| + | ||
| .Example output | ||
| [source,text] | ||
| ---- | ||
| NAMESPACE NAME STATUS | ||
| gateway-system mcp-tool-auth-policy Enforced | ||
| ---- | ||
|
|
||
| . Check the authorization logs by running the following command: | ||
| + | ||
| [source,terminal] | ||
| ---- | ||
| $ oc logs -n mcp-system -l app.kubernetes.io/name=mcp-gateway | ||
| ---- |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.