|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// *mcp_gateway_config/mcp-gateway-revoke-tool-access.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="proc-mcp-gateway-filter-revoked-tools-display_{context}"] |
| 7 | += Filtering revoked tools from tools/list display |
| 8 | + |
| 9 | +[role="_abstract"] |
| 10 | +After you revoke a tool by using your identity provider, `tools/call` requests are blocked. However, the revoked tool is still displayed in `tools/list` responses. To filter revoked tools from the displayed list, you must give the MCP broker component a signed header that carries the user's authorized tools. |
| 11 | + |
| 12 | +You can remove blocked tools from responses by configuring the Authorino Operator to generate the header by using a wristband JWT signed with an ECDSA key pair. |
| 13 | + |
| 14 | +.Prerequisites |
| 15 | + |
| 16 | +* You installed {mcpg}. |
| 17 | +* You configured a `Gateway` object with both `mcp` and `mcps` listeners. |
| 18 | +* You are logged into a running {ocp} cluster with an `admin` role. |
| 19 | +* You configured an `HTTPRoute` object for the gateway. |
| 20 | +* You registered an MCP server. |
| 21 | +* You configured authentication with an `AuthPolicy` CR on the `mcp` listener. |
| 22 | +* You configured authorization with a tool-level `AuthPolicy` CR on the `mcps` listener. |
| 23 | +
|
| 24 | +.Procedure |
| 25 | + |
| 26 | +. Generate an ECDSA key pair by running the following commands: |
| 27 | + |
| 28 | +.. Generate the private key and save it to a file by running the following command: |
| 29 | ++ |
| 30 | +[source,terminal] |
| 31 | +---- |
| 32 | +$ openssl ecparam -name prime256v1 -genkey -noout -out private-key.pem |
| 33 | +---- |
| 34 | + |
| 35 | +.. Generate the public key and save it to a file by running the following command: |
| 36 | ++ |
| 37 | +[source,terminal] |
| 38 | +---- |
| 39 | +$ openssl ec -in private-key.pem -pubout -out public-key.pem |
| 40 | +---- |
| 41 | + |
| 42 | +. Create a Kubernetes `Secret` object in the Authorino Operator namespace by adding the private key with the following command: |
| 43 | ++ |
| 44 | +[source,terminal,subs="+quotes"] |
| 45 | +---- |
| 46 | +$ oc create secret generic trusted-headers-private-key \ |
| 47 | + --from-file=key.pem=private-key.pem \ |
| 48 | + -n _<kuadrant_system>_ \ |
| 49 | + --dry-run=client -o yaml | oc apply -f - |
| 50 | +---- |
| 51 | ++ |
| 52 | +Replace `_<kuadrant_system>_` with the namespace where {prodname} is installed. |
| 53 | + |
| 54 | +. Create a Kubernetes `Secret` object in the MCP broker component namespace by adding the public key with the following command: |
| 55 | ++ |
| 56 | +[source,terminal,subs="+quotes"] |
| 57 | +---- |
| 58 | +$ oc create secret generic trusted-headers-public-key \ |
| 59 | + --from-file=key=public-key.pem \ |
| 60 | + -n _<mcp_system>_ \ |
| 61 | + --dry-run=client -o yaml | oc apply -f - |
| 62 | +---- |
| 63 | ++ |
| 64 | +Replace `_<mcp_system>_` with the namespace where {mcpg} is installed. |
| 65 | + |
| 66 | +. Delete only the existing `AuthPolicy` CR on the `mcp` listener by running the following command: |
| 67 | ++ |
| 68 | +[source,terminal,subs="+quotes"] |
| 69 | +---- |
| 70 | +$ oc delete authpolicy _<mcp_authn_policy>_ -n _<authn_namespace>_ --ignore-not-found |
| 71 | +---- |
| 72 | ++ |
| 73 | +* Replace `_<mcp_authn_policy>_` with the name of your `AuthPolicy` CR. |
| 74 | +* Replace `_<authn_namespace>_` with the namespace where your `AuthPolicy` CR is applied. |
| 75 | ++ |
| 76 | +[IMPORTANT] |
| 77 | +==== |
| 78 | +You must delete the `AuthPolicy` CR and create a new one. Using `$ oc apply` merges both the new and old policies. |
| 79 | +==== |
| 80 | +
|
| 81 | +. Generate a new `x-authorized-tools` header by creating and applying a new `AuthPolicy` CR. Use the following example: |
| 82 | ++ |
| 83 | +.Example AuthPolicy CR |
| 84 | +[source,yaml] |
| 85 | +---- |
| 86 | +$ oc create -f - <<EOF |
| 87 | +apiVersion: kuadrant.io/v1 |
| 88 | +kind: AuthPolicy |
| 89 | +metadata: |
| 90 | + name: _<mcp_auth_policy>_ |
| 91 | + namespace: _<authn_namespace>_ |
| 92 | +spec: |
| 93 | + targetRef: |
| 94 | + group: gateway.networking.k8s.io |
| 95 | + kind: Gateway |
| 96 | + name: _<mcp_gateway>_ |
| 97 | + sectionName: mcp |
| 98 | + when: |
| 99 | + - predicate: "!request.path.contains('/.well-known')" |
| 100 | + rules: |
| 101 | + authentication: |
| 102 | + 'keycloak': |
| 103 | + jwt: |
| 104 | + issuerUrl: https://keycloak.example.com:port/realms/mcp |
| 105 | + authorization: |
| 106 | + 'allow-mcp-method': |
| 107 | + patternMatching: |
| 108 | + patterns: |
| 109 | + - predicate: | |
| 110 | + !request.headers.exists(h, h == 'x-mcp-method') || (request.headers['x-mcp-method'] in ["tools/list","initialize","notifications/initialized"]) |
| 111 | + 'authorized-tools': |
| 112 | + opa: |
| 113 | + rego: | |
| 114 | + allow = true |
| 115 | + tools = { server: roles | server := object.keys(input.auth.identity.resource_access)[_]; roles := object.get(input.auth.identity.resource_access, server, {}).roles } |
| 116 | + allValues: true |
| 117 | + response: |
| 118 | + success: |
| 119 | + headers: |
| 120 | + x-authorized-tools: |
| 121 | + wristband: |
| 122 | + issuer: 'authorino' |
| 123 | + customClaims: |
| 124 | + 'allowed-tools': |
| 125 | + selector: auth.authorization.authorized-tools.tools.@tostr |
| 126 | + tokenDuration: 300 |
| 127 | + signingKeyRefs: |
| 128 | + - name: trusted-headers-private-key |
| 129 | + algorithm: ES256 |
| 130 | + unauthenticated: |
| 131 | + headers: |
| 132 | + 'WWW-Authenticate': |
| 133 | + value: Bearer resource_metadata=https://mcp.example.com:port/.well-known/oauth-protected-resource |
| 134 | + body: |
| 135 | + value: | |
| 136 | + { |
| 137 | + "error": "Unauthorized", |
| 138 | + "message": "Access denied: Authentication required." |
| 139 | + } |
| 140 | + unauthorized: |
| 141 | + code: 401 |
| 142 | + headers: |
| 143 | + 'WWW-Authenticate': |
| 144 | + value: Bearer resource_metadata=https://mcp.example.com:port/.well-known/oauth-protected-resource |
| 145 | + body: |
| 146 | + value: | |
| 147 | + { |
| 148 | + "error": "Forbidden", |
| 149 | + "message": "Access denied: Unsupported method. New authentication required (401)." |
| 150 | + } |
| 151 | +EOF |
| 152 | +---- |
| 153 | ++ |
| 154 | +* Replace `_<mcp_auth_policy>_` with the name of your new `AuthPolicy` CR. |
| 155 | +* Replace `_<authn_namespace>_` with the namespace where you removed the `AuthPolicy CR` that was on the `mcp` listener. |
| 156 | +* Replace `_<mcp_gateway>_` with the name of your {mcpg} deployment. |
| 157 | +
|
| 158 | +. Configure the MCP broker component to validate the signed header by running the following command: |
| 159 | ++ |
| 160 | +[source,terminal,subs="+quotes"] |
| 161 | +---- |
| 162 | +$ oc patch mcpgatewayextension _<mcp_gateway_extension>_ -n _<mcp_system>_ --type='merge' \ |
| 163 | + -p='{"spec":{"trustedHeadersKey":{"secretName":"trusted-headers-public-key"}}}' |
| 164 | +---- |
| 165 | ++ |
| 166 | +* Replace `_<mcp_gateway_extension>_` with the name of your `MCPGatewayExtension` CR. |
| 167 | +* Replace `_<mcp_system>_` with the namespace where {mcpg} is installed. |
| 168 | +
|
| 169 | +. Wait for the automatic MCP broker component redeployment to load the public key from the `Secret` CR created in the earlier step by running the following command: |
| 170 | ++ |
| 171 | +[source,terminal,subs="+quotes"] |
| 172 | +---- |
| 173 | +$ oc rollout status deployment/_<mcp_gateway>_ -n _<mcp_system>_ --timeout=60s |
| 174 | +---- |
| 175 | ++ |
| 176 | +* Replace `_<mcp_gateway>_` with the name of your {mcpg} deployment. |
| 177 | +* Replace `_<mcp_system>_` with the namespace where your {mcpg} deployment is applied. |
| 178 | +
|
| 179 | +. If the redeployment does not start, force it by running the following command: |
| 180 | ++ |
| 181 | +[source,terminal,subs="+quotes"] |
| 182 | +---- |
| 183 | +$ oc rollout restart deployment/_<mcp_gateway>_ -n _<mcp_system>_ |
| 184 | +---- |
| 185 | ++ |
| 186 | +* Replace `_<mcp_gateway>_` with the name of your {mcpg} deployment. |
| 187 | +* Replace `_<mcp_system>_` with the namespace where your {mcpg} deployment is applied. |
| 188 | +
|
| 189 | +.Verification |
| 190 | + |
| 191 | +. Verify that the new `AuthPolicy` CR is enforced by running the following command: |
| 192 | ++ |
| 193 | +[source,terminal,subs="+quotes"] |
| 194 | +---- |
| 195 | +$ oc get authpolicy _<mcp_auth_policy>_ -n _<authn_namespace>_ -o jsonpath='{.status.conditions[?(@.type=="Enforced")].status}' |
| 196 | +---- |
| 197 | ++ |
| 198 | +* Replace `_<mcp_auth_policy>_` with the name of your new `AuthPolicy` CR. |
| 199 | +* Replace `_<authn_namespace>_` with the namespace where your `AuthPolicy` CR is applied. |
| 200 | ++ |
| 201 | +.Example output |
| 202 | +[source,text] |
| 203 | +---- |
| 204 | +True |
| 205 | +---- |
| 206 | +
|
| 207 | +. Log out and log back in with the user credentials that you changed access for to get a fresh token. |
| 208 | + |
| 209 | +. Request all available tools from your MCP servers for the user or group whose access you revoked. The expected response is a list of all tools that the user or group can access from all registered MCP servers. |
0 commit comments