[
https://issues.apache.org/jira/browse/KNOX-3578?focusedWorklogId=1055145&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1055145
]
ASF GitHub Bot logged work on KNOX-3578:
----------------------------------------
Author: ASF GitHub Bot
Created on: 16/Nov/26 23:50
Start Date: 16/Nov/26 23:50
Worklog Time Spent: 10m
Work Description: github-actions[bot] commented on PR #1515:
URL: https://github.com/apache/knox/pull/1515#issuecomment-6932974275
## Test Results
5 files 5 suites 1m 40s ⏱️
227 tests 226 ✅ 1 💤 0 ❌
271 runs 270 ✅ 1 💤 0 ❌
Results for commit 75340c04.
[test-results]:data:application/gzip;base64,H4sIAMiW+2oC/02MwQ6DIBAFf8Vw7mGhIG1/xuDCJqQqDcLJ9N+LxKLHmZc3GyM/uZW9OnXr2Jp9amBzNMmHpSAHKKJMaR+F0H8a1oxYVX+qt//snybI+KmIlhhcjCEeJualNjU/oCU1NHMWK1+Cla89DPPsUwGm1V0CgnTacEvG0ohKErgeAR5mFE+Omkhy9v0BVbeB9gUBAAA=
Issue Time Tracking
-------------------
Worklog Id: (was: 1055145)
Time Spent: 0.5h (was: 20m)
> 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
> Priority: Major
> Fix For: 3.1.0
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> 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.
> A check in the KnoxIDF service alone would come too late. By the time
> {{TokenResource}} runs, {{JWTFederationFilter}} has already validated the
> grant's credentials: the {{client_secret}} or {{client_assertion}}, the
> refresh token, or the {{subject_token}} (possibly fetching a JWKS). A grant
> the topology doesn't serve should be refused before any of that work.
> h3. Proposal
> Add a new JWTProvider param, {{jwt.allowed.grant.types}} (comma-separated):
> * *Unset or empty:* behaviour stays as today. Every grant is allowed,
> including requests with no {{grant_type}}.
> * *Set, in {{JWTFederationFilter}}:* a request whose {{grant_type}} (body or
> query) is present but not on the list gets {{400}} with {{"error":
> "unsupported_grant_type"}} (RFC 6749 section 5.2). This happens before any
> credential is validated, so nothing is verified, looked up or consumed. The
> filter reads {{grant_type}} even when an {{Authorization}} header is present.
> Requests with no {{grant_type}} pass through unchanged, because the filter
> can't tell a token request from a userinfo, registration or proxied request.
> * *Set, in KnoxIDF:* the filter passes the parsed list to the service as a
> request attribute, also on {{jwt.unauthenticated.path.list}} paths. KnoxIDF
> uses that list and has no setting of its own:
> ** {{TokenResource}} ({{doPost}} and {{doGet}}) returns {{400
> unsupported_grant_type}} when {{grant_type}} is missing or not on the list.
> This closes the bearer re-mint.
> ** {{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}}.
> * When set, the filter parses the form body of requests on that topology to
> read {{grant_type}}. The param is meant for topologies that serve the token
> endpoint, not for ones that proxy form posts to backends.
> * KnoxIDF behind a different federation provider gets no list and behaves as
> today. That includes a discovery document served from an SSOCookieProvider
> topology.
> Example for a topology that serves only token exchange:
> {code:xml}
> <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>
> </param>
> <param>
> <name>jwt.unauthenticated.path.list</name>
>
> <value>/knoxidf/api/v1/.well-known/openid-configuration,/knoxidf/api/v1/jwks</value>
> </param>
> </provider>
> {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}}
> (client secret in the body or over HTTP Basic, or {{client_assertion}})
> return {{400 unsupported_grant_type}} from the filter. No credential is
> validated and the code or refresh token is not consumed;
> ** the same holds when a bearer {{Authorization}} header is also present;
> ** requests with no {{grant_type}} pass the filter, and the KnoxIDF token
> endpoint rejects them ({{POST}} and {{GET /token}}) with {{400
> unsupported_grant_type}};
> ** the discovery documents, served on unauthenticated paths, list only
> token-exchange and leave out the authorization, registration and userinfo
> endpoints.
> * KnoxIDF without the request attribute (behind another provider) behaves as
> today.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)