[
https://issues.apache.org/jira/browse/KNOX-3461?focusedWorklogId=1042248&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1042248
]
ASF GitHub Bot logged work on KNOX-3461:
----------------------------------------
Author: ASF GitHub Bot
Created on: 17/Sep/26 07:19
Start Date: 17/Sep/26 07:19
Worklog Time Spent: 10m
Work Description: smolnar82 commented on code in PR #1405:
URL: https://github.com/apache/knox/pull/1405#discussion_r4034186229
##########
gateway-provider-security-jwt/src/test/java/org/apache/knox/gateway/provider/federation/jwt/filter/TokenExchangeHandlerTest.java:
##########
@@ -571,6 +560,74 @@ public void
testNoResourceOrAudienceLeavesRequestAttributeUnset() throws Excepti
assertFalse(requestedAudiencesAttr.hasCaptured());
}
+ @Test
+ public void testSameSubjectRequestedAudienceIgnoredWhenFlagDisabled() throws
Exception {
+ // Fail-safe default: for a same-subject exchange the requested audience
is dropped entirely
+ // (not conveyed downstream), so a passthrough audience validator cannot
mint an
+ // arbitrarily-audienced token without authorization. The exchange still
succeeds.
+ filter.valid.put("subtok", jwtWithAudiences("alice", "KNOXSSO",
"service-a"));
+ handler.handle(exchangeRequest("subtok", null, new String[]
{"service-a"}), response, chain);
+
+ assertTrue(filter.continued);
+ assertFalse(requestedAudiencesAttr.hasCaptured());
+ }
+
+ @Test
+ public void
testSameSubjectRequestedAudienceAuthorizedWhenSubsetOfSubjectTokenAudience()
throws Exception {
+ // Honoring on: a requested audience the subject token already carries is
authorized and
+ // conveyed, even when the subject token carries additional audiences.
+ filter.delegationSameSubjectRequestedAudienceEnabled = true;
+ filter.valid.put("subtok", jwtWithAudiences("alice", "KNOXSSO",
"service-a", "service-b", "service-c"));
+ handler.handle(exchangeRequest("subtok", null, new String[]
{"service-a"}), response, chain);
+
+ assertTrue(filter.continued);
+ assertEquals(Arrays.asList("service-a"),
requestedAudiencesAttr.getValue());
+ }
+
+ @Test
+ public void
testSameSubjectRequestedAudienceRejectedWhenNotInSubjectTokenAudience() throws
Exception {
+ // Honoring on but the requested audience is not among the subject token's
own aud claim:
+ // rejected as invalid_target and never conveyed.
+ filter.delegationSameSubjectRequestedAudienceEnabled = true;
+ filter.valid.put("subtok", jwtWithAudiences("alice", "KNOXSSO",
"service-a"));
+ handler.handle(exchangeRequest("subtok", null, new String[]
{"service-b"}), response, chain);
+
+ assertFalse(filter.continued);
+ assertEquals(HttpServletResponse.SC_BAD_REQUEST, filter.errorStatus);
+ assertEquals("invalid_target", filter.error);
+ assertFalse(requestedAudiencesAttr.hasCaptured());
+ }
+
+ @Test
+ public void
testSameSubjectRequestedAudienceRejectedWhenSubjectTokenHasNoAudience() throws
Exception {
+ // Honoring on and a requested audience present, but the subject token
carries no aud claim:
+ // there is nothing to authorize against, so the request is rejected.
+ filter.delegationSameSubjectRequestedAudienceEnabled = true;
+ filter.valid.put("subtok", jwt("alice", "KNOXSSO"));
+ handler.handle(exchangeRequest("subtok", null, new String[]
{"service-a"}), response, chain);
+
+ assertFalse(filter.continued);
+ assertEquals(HttpServletResponse.SC_BAD_REQUEST, filter.errorStatus);
+ assertEquals("invalid_target", filter.error);
+ assertFalse(requestedAudiencesAttr.hasCaptured());
+ }
Review Comment:
Will add a boundary test where some requested audiences are in the subject
token's `aud` and some aren't, asserting it's rejected, which confirms all
values are checked, not just one.
Issue Time Tracking
-------------------
Worklog Id: (was: 1042248)
Time Spent: 1h 20m (was: 1h 10m)
> Same subject validation for requested audience
> ----------------------------------------------
>
> Key: KNOX-3461
> URL: https://issues.apache.org/jira/browse/KNOX-3461
> Project: Apache Knox
> Issue Type: Sub-task
> Components: JWT
> Reporter: Harrison Sheinblatt
> Assignee: Sandor Molnar
> Priority: Major
> Time Spent: 1h 20m
> Remaining Estimate: 0h
>
> When delegation is enabled, we'll want to set the knoxidf audience strategy
> to passthrough so we rely on the delegation policy to authorize a requested
> audience instead of the hardcoded list. But once that's set, then the
> same-subject requested audience is unauthorized at all. So we either need to
> not allow requested audiences just for same-subject exchanges with a setting,
> or add enforcement, or both.
> The simplest thing is to add a setting to skip reading the requested audience
> only for same-subject token exchanges.
> The natural authz is to validate the original subject token has the audience
> requested to allow the requested audience. So if the flag to allow reading
> the audience for same-subject exchange is on, we'd authorize on the subject
> token. If this proves a problem, we can turn it off or figure out a way to
> add more audiences to the user tokens knox issues.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)