|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// *mcp_gateway_config/mcp-gateway-troubleshooting.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: PROCEDURE |
| 6 | +[id="proc-mcp-gateway-ts-auth-issues_{context}"] |
| 7 | += Troubleshooting {mcpg} authentication issues |
| 8 | + |
| 9 | +[role="_abstract"] |
| 10 | +Authentication errors can happen in a variety of ways, including silent failures, broken sessions, and tool-access denials, depending on your backend MCP server setup. You can troubleshoot common problems by checking your connections and custom resource (CR) configurations. |
| 11 | + |
| 12 | +.Prerequisites |
| 13 | + |
| 14 | +* You installed {mcpg}. |
| 15 | +* You installed {prodname}. |
| 16 | +* You installed the {oc-first}. |
| 17 | +* You configured a `Gateway` object. |
| 18 | +* You configured an `HTTPRoute` object for the gateway. |
| 19 | +* You registered an MCP server. |
| 20 | +* You created a `Secret` CR for authentication. |
| 21 | +
|
| 22 | +.Procedure |
| 23 | + |
| 24 | +. When your clients cannot discover OAuth configuration, discovery is not working. Use the following steps to troubleshoot this situation: |
| 25 | + |
| 26 | +.. Retrieve the JSON object that lists the security requirements for your backend MCP server by running the following command: |
| 27 | ++ |
| 28 | +[source,terminal,subs="+quotes"] |
| 29 | +---- |
| 30 | +$ curl http://_<mcp_hostname>_/_<.well-known/oauth-protected-resource>_ |
| 31 | +---- |
| 32 | ++ |
| 33 | +* Replace `_<mcp_hostname>_` with the name of the host for your MCP server. |
| 34 | +* Replace `_<.well-known/oauth-protected-resource>_` with the reserved path and JSON file that describes the OAuth 2.0 security requirements for the MCP server. |
| 35 | ++ |
| 36 | +.Example output |
| 37 | +[source,text] |
| 38 | +---- |
| 39 | +{ |
| 40 | + "resource": "https://mcp.example.com", |
| 41 | + "authorization_servers": [ |
| 42 | + "https://auth.provider.com/oauth2/default" |
| 43 | + ], |
| 44 | + "scopes_supported": ["mcp:tools", "mcp:resources"], |
| 45 | + "bearer_methods_supported": ["header"], |
| 46 | + "resource_documentation": "https://docs.example.com/mcp-help" |
| 47 | +} |
| 48 | +---- |
| 49 | +
|
| 50 | +.. Check that your associated `HTTPRoute` CR includes a path for your `/.well-known/oauth-protected-resource` by running the following command: |
| 51 | ++ |
| 52 | +[source,terminal,subs="+quotes"] |
| 53 | +---- |
| 54 | +$ oc get httproute _<route_name>_ -o jsonpath='{.spec.rules[*].matches[*].path.value}' |
| 55 | +---- |
| 56 | ++ |
| 57 | +Replace `_<route_name>_` with the associated `HTTPRoute` CR. |
| 58 | + |
| 59 | +.. Check the specific `AuthPolicy` CR configuration by running the following command: |
| 60 | ++ |
| 61 | +[source,terminal,subs="+quotes"] |
| 62 | +---- |
| 63 | +$ oc describe authpolicy _<policy_name>_ -n _<namespace>_ |
| 64 | +---- |
| 65 | + |
| 66 | +.. Check that you excluded all `/.well-known` paths from your `AuthPolicy` CR by trying to reach the endpoint without any credentials by using the following command: |
| 67 | ++ |
| 68 | +[source,terminal,subs="+quotes"] |
| 69 | +---- |
| 70 | +$ curl -o /dev/null -s -w "%{http_code}\n" http://_<mcp_hostname>_/_<.well-known/oauth-protected-resource>_ |
| 71 | +---- |
| 72 | ++ |
| 73 | +* Replace `_<mcp_hostname>_` with the name of the host for your MCP server. |
| 74 | +* Replace `_<.well-known/oauth-protected-resource>_` with the reserved path and JSON file that describes the OAuth 2.0 security requirements for the MCP server. |
| 75 | ++ |
| 76 | +[NOTE] |
| 77 | +==== |
| 78 | +The following codes are examples of possible outputs: |
| 79 | +
|
| 80 | +* `200`: Means that the exclusion exists and matches. |
| 81 | +* `401`: Means that your `AuthPolicy` CR is still demanding a token for this path. The exclusion is either not present or not working. |
| 82 | +* `404`: The exclusion might be present and working, but the `HTTPRoute` CR does not point to that path to a valid backend. |
| 83 | +==== |
| 84 | +
|
| 85 | +.. Optional. Check all MCP broker component environment variables by running the following command: |
| 86 | ++ |
| 87 | +[source,terminal,subs="+quotes"] |
| 88 | +---- |
| 89 | +$ oc get deployment _<mcp_gateway>_ -n _<mcp_system>_ -o yaml | grep -A 10 env |
| 90 | +---- |
| 91 | +* Replace `_<mcp_gateway>_` with the name of your {mcpg} deployment. |
| 92 | +* Replace `_<mcp_system>_` with the namespace where your {mcpg} deployment is applied. |
| 93 | +//Q: do we actually make Deployment or DeploymentConfig objects for MCP gateway? If yes, when? |
| 94 | +
|
| 95 | +.. Check that the `OAUTH_*` environment variables are set on your MCP broker component. |
| 96 | ++ |
| 97 | +[source,terminal,subs="+quotes"] |
| 98 | +---- |
| 99 | +$ oc set env deployment/_<mcp_gateway>_ --list |
| 100 | +---- |
| 101 | ++ |
| 102 | +Replace `_<mcp_gateway>_` with the name of your {mcpg} deployment. |
| 103 | + |
| 104 | +.. Verify that the MCP broker component pod restarted after any environment variable changes. |
| 105 | + |
| 106 | +. If your valid tokens are being rejected with `401` errors, your JWT token validation is failing. Use the following steps to troubleshoot this situation: |
| 107 | + |
| 108 | +.. List the `AuthPolicy` CRs by running the following command: |
| 109 | ++ |
| 110 | +[source,terminal] |
| 111 | +---- |
| 112 | +$ oc get authpolicy -A |
| 113 | +---- |
| 114 | + |
| 115 | +.. Check the specific `AuthPolicy` CR configuration by running the following command: |
| 116 | ++ |
| 117 | +[source,terminal,subs="+quotes"] |
| 118 | +---- |
| 119 | +$ oc describe authpolicy _<policy_name>_ -n _<namespace>_ |
| 120 | +---- |
| 121 | + |
| 122 | +.. Verify that the `issuerUrl` in the `AuthPolicy` CR matches your identity provider's `realm`. |
| 123 | + |
| 124 | +.. Check the Authorino Operator logs by running the following command: |
| 125 | ++ |
| 126 | +[source,terminal,subs="+quotes"] |
| 127 | +---- |
| 128 | +$ oc logs -n kuadrant-system -l authorino-resource=authorino |
| 129 | +---- |
| 130 | + |
| 131 | +.. Decode JWT to verify claims by running the following command: |
| 132 | ++ |
| 133 | +[source,terminal,subs="+quotes"] |
| 134 | +---- |
| 135 | +$ echo "_<example_token>_" | cut -d. -f2 | base64 -d | jq |
| 136 | +---- |
| 137 | ++ |
| 138 | +Replace `_<example_token>_` with your token. |
| 139 | + |
| 140 | +.. Ensure that your issuer URL is reachable from the cluster by using the `cluster-local` service name. |
| 141 | + |
| 142 | +.. Check the token expiration time by examining the `exp` claim. |
| 143 | + |
| 144 | +.. Verify the audience, if required, by using an `aud` claim. |
| 145 | + |
| 146 | +.. Ensure that the token includes all required claims such as `groups`, `email`, and so on. |
| 147 | + |
| 148 | +. If your `401 Unauthorized` responses do not include OAuth discovery information, the `WWW-Authenticate` header is missing. This usually means that your `AuthPolicy` CR is not properly configured. Use the following steps to troubleshoot this situation: |
| 149 | + |
| 150 | +.. Isolate the failure point by using verbose output which lists the TLS handshake, the HTTP headers, and the server response code by running the following command: |
| 151 | ++ |
| 152 | +[source,terminal,subs="+quotes"] |
| 153 | +---- |
| 154 | +$ curl -v http://_<mcp_hostname>_/mcp \ |
| 155 | + -H "Content-Type: application/json" \ |
| 156 | + -d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}' |
| 157 | +---- |
| 158 | ++ |
| 159 | +Replace `_<mcp_hostname>_` with the hostname for your backend MCP server. |
| 160 | + |
| 161 | +.. Verify that your `AuthPolicy` CR `spec.response.unauthenticated.headers:` list includes `response.unauthenticated.headers.WWW-Authenticate`. |
| 162 | + |
| 163 | +.. Check that your `AuthPolicy` CR `response.unauthenticated.headers.WWW-Authenticate.value` includes the correct `metadata`. |
| 164 | + |
| 165 | +.. Ensure that your `AuthPolicy` CR is applied to the correct `Gateway` object and listener. |
0 commit comments