lmccay commented on code in PR #1515: URL: https://github.com/apache/knox/pull/1515#discussion_r4593818341
########## knox-site/docs/config_jwt_allowed_grant_types.md: ########## @@ -0,0 +1,43 @@ +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + https://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +### JWT Provider Allowed Grant Types ### + +By default the `JWTProvider` federation provider passes every OAuth 2.0 grant through to the token endpoint behind it, such as the [KnoxIDF](knoxidf/endpoints.md#token-endpoint) token endpoint. Setting `jwt.allowed.grant.types` restricts a topology's token endpoint to the listed grants: + + <provider> + <role>federation</role> + <name>JWTProvider</name> + <enabled>true</enabled> + <param> + <name>jwt.allowed.grant.types</name> + <value>urn:ietf:params:oauth:grant-type:token-exchange</value> Review Comment: Is there a reason to require the full urn value here rather than a endsWith(:token-exchange) sort of approach? This current way is probably more correct but easily misconfigured, I think. ########## gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTFederationFilter.java: ########## @@ -318,7 +343,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha // RFC 8693 token exchange: getWireToken flags this via TokenType.TokenExchange when the // grant_type is in the request body. The subject_token/actor_token are read from the unwrapped // request by the handler. Reading the body only happens on this (header-less) grant-flow path, - // so a proxied backend's body is never consumed by the header-authenticated path. + // so a proxied backend's body is never consumed by the header-authenticated path (unless + // ALLOWED_GRANT_TYPES is set). if (wireToken != null && TokenType.TokenExchange.equals(wireToken.getType())) { Review Comment: That could be an argument for adding this and enabling it at the service level rather than the provider level. Maybe that should be a later refactor and optimization? ########## gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/JWTFederationFilter.java: ########## @@ -318,7 +343,8 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha // RFC 8693 token exchange: getWireToken flags this via TokenType.TokenExchange when the // grant_type is in the request body. The subject_token/actor_token are read from the unwrapped // request by the handler. Reading the body only happens on this (header-less) grant-flow path, - // so a proxied backend's body is never consumed by the header-authenticated path. + // so a proxied backend's body is never consumed by the header-authenticated path (unless + // ALLOWED_GRANT_TYPES is set). if (wireToken != null && TokenType.TokenExchange.equals(wireToken.getType())) { Review Comment: So this means that any use of allowed grant types setting restricts the entire topology to only Knox's own APIs. If you try to proxy access to another service, it will have the body consumed already and fail. Right? Would this be sufficiently clear to an admin? -- 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]
