You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@knox.apache.org by "smolnar82 (via GitHub)" <gi...@apache.org> on 2026/09/02 09:52:55 UTC

[PR] KNOX-3424: Complete RFC 8707/8693 dynamic resource/audience handling in KNOXTOKEN and token exchange [knox]

smolnar82 opened a new pull request, #1373:
URL: https://github.com/apache/knox/pull/1373

   [KNOX-3424](https://issues.apache.org/jira/browse/KNOX-3424) - Complete RFC 8707/8693 dynamic `resource`/`audience` handling in KNOXTOKEN and token exchange
   
   ## What changes were proposed in this pull request?
   
   Follow-up to #1356, finishing the dynamic-audience work so Knox implements both RFC 8707 (Resource Indicators) and RFC 8693 (Token Exchange) end to end. Three self-contained commits:
   
   1. **Replace the `audience` query param with a URL-validated `resource` param.**
   The KNOXTOKEN service now reads the per-request target via `resource` instead of `audience`. Each value must be an absolute URI without a fragment (RFC 8707 §2 / RFC 3986 §4.3); a value that is not a valid absolute URI, or that carries a fragment, is rejected with `400 Bad Request` / `INVALID_RESOURCE`. Repeated and comma-separated values are supported; whitespace is trimmed. The pluggable audience validators (`static` / `whitelist` / `passthrough`) are unchanged in behavior.
   
   2. **Wire the RFC 8693 `resource`/`audience` body parameters into token exchange.**
   The JWTProvider's `TokenExchangeHandler` now parses the optional `resource`/`audience` body params from the exchange request and conveys them to the downstream KNOXTOKEN service via a new shared request attribute (`CommonTokenConstants.REQUESTED_AUDIENCES_REQUEST_ATTR`), so they land in the minted token's `aud` claim. `resource` values are URI-validated (malformed → `invalid_target`); `audience` values are logical service names taken verbatim. When present, the body values take precedence over the `resource` query parameter.
   
   2. **JSON-escape the caller-supplied `resource` value in the token error body.** 
   The token-issuance error echoed the caller-supplied value back in a hand-concatenated JSON body, so a value containing a `"` could break out of the JSON string. The `{"error": ..., "code": ...}` body is now rendered through `JsonUtils` (the same escaping the KNOX-3423/#1354 filter-layer error path uses), keeping the existing `{error, code}` / `ErrorCode` shape.
   
   Documentation in `knox-site/docs/config_knox_token.md` is updated to describe the `resource` parameter, the absolute-URI requirement, and the RFC 8707 mapping into the `aud` claim.
   
   ## How was this patch tested?
   
   Automated unit tests (all green, offline Maven build):
   
   - `TokenExchangeHandlerTest` — 21 tests, including 8 new ones covering `resource`/`audience` body-param parsing, comma-splitting, invalid-URI and fragment rejection as `invalid_target`, empty-value rejection, and the no-param case leaving the request attribute unset.
   - `TokenServiceResourceTest` — 101 tests, including new coverage for the `resource` query param, invalid-URI/fragment rejection, exchange-attribute precedence over the query param, and a regression test asserting a `resource` value containing double quotes yields a well-formed, parseable JSON error body with the value round-tripped intact.
   - `JWTFederationFilterTokenExchangeTest` — 56 tests, re-run to confirm no regression on the broader exchange path.
   
   Checkstyle passes with 0 violations across `gateway-spi`, `gateway-provider-security-jwt`, and `gateway-service-knoxtoken`.
   
   ## Integration Tests
   
   No new integration test was added: the change is an extension of the existing token-exchange / dynamic-audience paths, which are covered comprehensively at the unit level, and the KnoxIDF federation broker flow (`test_knoxidf.py` / `test_knoxidf_federation.py`) already exercises the token-exchange handler this PR modifies. Because commit 2 touches the JWTProvider federation broker path, adding the **`test-federation`** label here before pushing, so the Keycloak-backed E2E federation suite runs against these changes.


-- 
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: dev-unsubscribe@knox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KNOX-3424: Complete RFC 8707/8693 dynamic resource/audience handling in KNOXTOKEN and token exchange [knox]

Posted by "smolnar82 (via GitHub)" <gi...@apache.org>.
smolnar82 merged PR #1373:
URL: https://github.com/apache/knox/pull/1373


-- 
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: dev-unsubscribe@knox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KNOX-3424: Complete RFC 8707/8693 dynamic resource/audience handling in KNOXTOKEN and token exchange [knox]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #1373:
URL: https://github.com/apache/knox/pull/1373#issuecomment-5508148458

   ## Test Results
     5 files    5 suites   18s ⏱️
    87 tests  87 ✅ 0 💤 0 ❌
   105 runs  105 ✅ 0 💤 0 ❌
   
   Results for commit cfa00242.
   
   [test-results]:data:application/gzip;base64,H4sIAGX6l2oC/13MSw6DIBSF4a0Yxh3wUrGbaQAhualKc4FR070XjVrs8PtPct7Ew+QiuTftrSExQzoxZtQJwlLIVHFZ0rqp/sAjZmv/yhNepdAzeA3TJTjEgHvBvKyPjLY7jse6/B43V4eb6z8b5hlSAbFeU8olHxgzkhmhjfS9o50Rg+LWj05ILpwS5PMFQW1C/QIBAAA=
   


-- 
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: dev-unsubscribe@knox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KNOX-3424: Complete RFC 8707/8693 dynamic resource/audience handling in KNOXTOKEN and token exchange [knox]

Posted by "lmccay (via GitHub)" <gi...@apache.org>.
lmccay commented on code in PR #1373:
URL: https://github.com/apache/knox/pull/1373#discussion_r3916619548


##########
gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/TokenResource.java:
##########
@@ -1163,26 +1168,65 @@ public ResponseMap(String accessToken, String tokenId, Map<String, Object> map,
     }
   }
 
-  private List<String> parseRequestedAudiences() {
+  private List<String> parseRequestedResources() throws RequestedAudienceValidationException {
+    // An RFC 8693 token-exchange request carries the requested resource/audience in the form body,
+    // which the JWTProvider's TokenExchangeHandler has already parsed and validated and stashed as a
+    // request attribute. When present, those body-supplied values take precedence over the resource
+    // query parameter.
+    @SuppressWarnings("unchecked")
+    final List<String> fromExchange =
+        (List<String>) request.getAttribute(CommonTokenConstants.REQUESTED_AUDIENCES_REQUEST_ATTR);
+    if (fromExchange != null) {
+      return fromExchange;
+    }

Review Comment:
   I'm not sure that I like how this is being done. We are leaking exchange specifics into the API service which should only be about issuing tokens. Perhaps this is happening already elsewhere but I want to be careful not to do this.



-- 
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: dev-unsubscribe@knox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KNOX-3424: Complete RFC 8707/8693 dynamic resource/audience handling in KNOXTOKEN and token exchange [knox]

Posted by "smolnar82 (via GitHub)" <gi...@apache.org>.
smolnar82 commented on code in PR #1373:
URL: https://github.com/apache/knox/pull/1373#discussion_r3926064402


##########
gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/TokenResource.java:
##########
@@ -1163,26 +1168,65 @@ public ResponseMap(String accessToken, String tokenId, Map<String, Object> map,
     }
   }
 
-  private List<String> parseRequestedAudiences() {
+  private List<String> parseRequestedResources() throws RequestedAudienceValidationException {
+    // An RFC 8693 token-exchange request carries the requested resource/audience in the form body,
+    // which the JWTProvider's TokenExchangeHandler has already parsed and validated and stashed as a
+    // request attribute. When present, those body-supplied values take precedence over the resource
+    // query parameter.
+    @SuppressWarnings("unchecked")
+    final List<String> fromExchange =
+        (List<String>) request.getAttribute(CommonTokenConstants.REQUESTED_AUDIENCES_REQUEST_ATTR);
+    if (fromExchange != null) {
+      return fromExchange;
+    }

Review Comment:
   Filed [KNOX-3437](https://issues.apache.org/jira/browse/KNOX-3437) to not to forget about this.



-- 
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: dev-unsubscribe@knox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KNOX-3424: Complete RFC 8707/8693 dynamic resource/audience handling in KNOXTOKEN and token exchange [knox]

Posted by "smolnar82 (via GitHub)" <gi...@apache.org>.
smolnar82 commented on PR #1373:
URL: https://github.com/apache/knox/pull/1373#issuecomment-5507729923

   Cc. @hsheinblatt 


-- 
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: dev-unsubscribe@knox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KNOX-3424: Complete RFC 8707/8693 dynamic resource/audience handling in KNOXTOKEN and token exchange [knox]

Posted by "lmccay (via GitHub)" <gi...@apache.org>.
lmccay commented on code in PR #1373:
URL: https://github.com/apache/knox/pull/1373#discussion_r3924900021


##########
gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/TokenResource.java:
##########
@@ -1163,26 +1168,65 @@ public ResponseMap(String accessToken, String tokenId, Map<String, Object> map,
     }
   }
 
-  private List<String> parseRequestedAudiences() {
+  private List<String> parseRequestedResources() throws RequestedAudienceValidationException {
+    // An RFC 8693 token-exchange request carries the requested resource/audience in the form body,
+    // which the JWTProvider's TokenExchangeHandler has already parsed and validated and stashed as a
+    // request attribute. When present, those body-supplied values take precedence over the resource
+    // query parameter.
+    @SuppressWarnings("unchecked")
+    final List<String> fromExchange =
+        (List<String>) request.getAttribute(CommonTokenConstants.REQUESTED_AUDIENCES_REQUEST_ATTR);
+    if (fromExchange != null) {
+      return fromExchange;
+    }

Review Comment:
   Okay. Let's move forward here but I think we need to do some careful testing. Having no way to ensure that the form body param is chosen over the query param without using the JWTProvider may be problematic.



-- 
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: dev-unsubscribe@knox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KNOX-3424: Complete RFC 8707/8693 dynamic resource/audience handling in KNOXTOKEN and token exchange [knox]

Posted by "smolnar82 (via GitHub)" <gi...@apache.org>.
smolnar82 commented on code in PR #1373:
URL: https://github.com/apache/knox/pull/1373#discussion_r3921217352


##########
gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/TokenResource.java:
##########
@@ -1163,26 +1168,65 @@ public ResponseMap(String accessToken, String tokenId, Map<String, Object> map,
     }
   }
 
-  private List<String> parseRequestedAudiences() {
+  private List<String> parseRequestedResources() throws RequestedAudienceValidationException {
+    // An RFC 8693 token-exchange request carries the requested resource/audience in the form body,
+    // which the JWTProvider's TokenExchangeHandler has already parsed and validated and stashed as a
+    // request attribute. When present, those body-supplied values take precedence over the resource
+    // query parameter.
+    @SuppressWarnings("unchecked")
+    final List<String> fromExchange =
+        (List<String>) request.getAttribute(CommonTokenConstants.REQUESTED_AUDIENCES_REQUEST_ATTR);
+    if (fromExchange != null) {
+      return fromExchange;
+    }

Review Comment:
   The leak is really the _naming_, not the _mechanism_. I'll rename the attribute to a generic `knox.token.requested.audiences` and reword the docs/comment so TokenResource only knows "an upstream filter may have pre-resolved the requested audiences; use them over the query param" — no RFC 8693 / exchange references. The exchange specifics stay entirely in TokenExchangeHandler.
   What do you think?



-- 
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: dev-unsubscribe@knox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] KNOX-3424: Complete RFC 8707/8693 dynamic resource/audience handling in KNOXTOKEN and token exchange [knox]

Posted by "smolnar82 (via GitHub)" <gi...@apache.org>.
smolnar82 commented on code in PR #1373:
URL: https://github.com/apache/knox/pull/1373#discussion_r3921217352


##########
gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/TokenResource.java:
##########
@@ -1163,26 +1168,65 @@ public ResponseMap(String accessToken, String tokenId, Map<String, Object> map,
     }
   }
 
-  private List<String> parseRequestedAudiences() {
+  private List<String> parseRequestedResources() throws RequestedAudienceValidationException {
+    // An RFC 8693 token-exchange request carries the requested resource/audience in the form body,
+    // which the JWTProvider's TokenExchangeHandler has already parsed and validated and stashed as a
+    // request attribute. When present, those body-supplied values take precedence over the resource
+    // query parameter.
+    @SuppressWarnings("unchecked")
+    final List<String> fromExchange =
+        (List<String>) request.getAttribute(CommonTokenConstants.REQUESTED_AUDIENCES_REQUEST_ATTR);
+    if (fromExchange != null) {
+      return fromExchange;
+    }

Review Comment:
   The leak is really the _naming_, not the _mechanism_. I'll rename the attribute to a generic `knox.token.requested.audiences` and reword the docs/comment so TokenResource only knows "an upstream filter may have pre-resolved the requested audiences; use them over the query param" — no RFC 8693 / exchange references. The exchange specifics stay entirely in TokenExchangeHandler.
   Pushing that shortly.



-- 
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: dev-unsubscribe@knox.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org