Sandor Molnar created KNOX-3578:
-----------------------------------

             Summary: KnoxIDF: allow restricting the grant types accepted by 
the token endpoint
                 Key: KNOX-3578
                 URL: https://issues.apache.org/jira/browse/KNOX-3578
             Project: Apache Knox
          Issue Type: Improvement
            Reporter: Sandor Molnar
            Assignee: Sandor Molnar
             Fix For: 3.1.0


h3. Problem

The KnoxIDF {{TokenResource}} accepts every grant type on every topology that 
serves the KNOXIDF service:
 * {{authorization_code}} and {{refresh_token}} are handled by KnoxIDF itself.
 * Every other request goes to the KNOXTOKEN mint ({{{}super.doPost(){}}} / 
{{{}doGet(){}}}). That includes {{{}client_credentials{}}}, 
{{{}urn:ietf:params:oauth:grant-type:token-exchange{}}}, and requests with no 
{{grant_type}} at all (a bearer {{{}POST /token{}}}, or {{{}GET /token{}}}).

Auth codes, refresh tokens and registered clients are kept in the gateway-wide 
token state service. {{PasscodeTokenResourceBase#setupTokenStateService}} 
always enables server-managed state for KnoxIDF. As a result, a code issued by 
{{/authorize}} on one topology can be redeemed on any other topology that 
serves KNOXIDF. The tokens it gets back use that topology's issuer and audience 
policy.

This becomes a problem when a deployment splits KnoxIDF across topologies, for 
example one topology for the authorization code flow and another only for RFC 
8693 token exchange with 
{{{}knoxidf.knox.token.audience.validator=passthrough{}}}. On the token 
exchange topology:
 * An auth code obtained on the authorization topology can be redeemed. The 
resulting tokens carry the token exchange topology's issuer, and any requested 
{{resource}} becomes the {{{}aud{}}}.
 * Any accepted JWT presented as a bearer with no {{grant_type}} is re-minted 
with any requested audience. The incoming {{act}} chain is kept, so a delegated 
token can be re-targeted without the requested-audience authorization that 
{{TokenExchangeHandler}} enforces.
 * Discovery advertises all four grant types, because 
{{AuthorizationServerMetadata}} hardcodes {{{}grant_types_supported{}}}. It 
also advertises the authorization, registration and userinfo endpoints, even 
though this topology isn't meant to serve them.

h3. Proposal

Add a new KNOXIDF service param, {{knoxidf.allowed.grant.types}} 
(comma-separated):
 * *Unset or empty:* behaviour stays as today. Every grant is allowed, 
including requests with no {{{}grant_type{}}}.
 * *Set:* {{TokenResource}} ({{{}doPost{}}} and {{{}doGet{}}}) returns {{400}} 
with {{"error": "unsupported_grant_type"}} (RFC 6749 section 5.2) for any 
request whose {{grant_type}} is missing or not on the list. The check runs 
before any grant handling, so a rejected request never consumes an auth code or 
a refresh token.
 * *Discovery:* {{AuthorizationServerMetadata}} advertises only the allowed 
grants in {{{}grant_types_supported{}}}. When {{authorization_code}} isn't 
allowed, it also leaves out {{{}authorization_endpoint{}}}, 
{{registration_endpoint}} and {{{}userinfo_endpoint{}}}.

Example for a topology that serves only token exchange:
{code:xml}
<service>
  <role>KNOXIDF</role>
  <param>
    <name>knoxidf.allowed.grant.types</name>
    <value>urn:ietf:params:oauth:grant-type:token-exchange</value>
  </param>
</service>
{code}
h3. Tests
 * Param unset: behaviour is unchanged for every grant type.
 * Param set to token-exchange:
 ** token exchange still succeeds;
 ** {{{}authorization_code{}}}, {{refresh_token}} and {{client_credentials}} 
return {{{}400 unsupported_grant_type{}}}, and the code or refresh token is not 
consumed;
 ** requests with no {{grant_type}} ({{{}POST{}}} and {{{}GET /token{}}}) 
return {{{}400 unsupported_grant_type{}}};
 ** the discovery documents list only token-exchange and leave out the 
authorization, registration and userinfo endpoints.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to