moresandeep commented on code in PR #1553:
URL: https://github.com/apache/knox/pull/1553#discussion_r4741044260


##########
gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/AbstractJWTFilter.java:
##########
@@ -595,7 +599,7 @@ protected Subject createSubjectFromTokenData(final String 
principal,
                                                final String 
expectedPrincipalClaimValue,
                                                final String tokenId,
                                                final List<Map<String, Object>> 
actorChain) {
-    return createSubjectFromTokenData(principal, expectedPrincipalClaimValue, 
tokenId, actorChain, null);
+    return createSubjectFromTokenData(principal, expectedPrincipalClaimValue, 
tokenId, actorChain, null, null);

Review Comment:
   Loks like `createSubjectFromTokenIdentifier` does not add 
TokenProvenancePrincipal, and TokenResource.persistTokenDetails doesn't save 
provenance in the token metadata. 
   
   A laundered token's passcode can register a client at a provenance denied 
topology. So can an API key or a re-mint made from that passcode. This 
contradicts the claim in security.md that "neither a second exchange nor a 
re-mint can launder the origin away".



##########
gateway-service-knoxidf/src/main/java/org/apache/knox/gateway/service/knoxidf/RegistrationResource.java:
##########
@@ -334,6 +359,19 @@ boolean delegatedCallerDenied() {
         return delegatedCallersDenied && 
SubjectUtils.getActorChainPrincipal(SubjectUtils.getCurrentSubject()) != null;
     }
 
+    /**
+     * @return {@code true} when the caller's token carries a 
knox_token_provenance claim (its exchange
+     * origin issuer) in the configured denied list -- blocking a login token 
laundered through a
+     * same-subject exchange into a registration-capable credential.
+     */
+    boolean provenanceDenied() {
+        if (deniedProvenanceIssuers.isEmpty()) {
+            return false;
+        }
+        final String provenance = 
SubjectUtils.getTokenProvenance(SubjectUtils.getCurrentSubject());
+        return provenance != null && 
deniedProvenanceIssuers.contains(provenance);

Review Comment:
   A raw token issued by the denied issuer still registers. So, the deny list 
skips tokens that have no provenance.



##########
gateway-provider-security-jwt/src/main/java/org/apache/knox/gateway/provider/federation/jwt/filter/TokenExchangeHandler.java:
##########
@@ -176,6 +189,23 @@ void handle(HttpServletRequest request, 
HttpServletResponse response, FilterChai
         actorToken = outcome.actorToken;
         conveyRequestedAudiences = outcome.conveyRequestedAudiences;
       } else {
+        // A same-subject exchange normalizes the issuer and audience of the 
output to this topology's own
+        // values. For issuers configured as delegation-required, refuse it 
here so such a token can only be
+        // exchanged on-behalf-of (carrying an act claim a downstream resource 
can reject); see
+        // JWTFederationFilter.TOKEN_EXCHANGE_DELEGATION_REQUIRED_ISSUERS. The 
inherited provenance is
+        // checked too, so a token already laundered once (iss normalized 
away) is still recognized.
+        if (filter.isDelegationRequiredForIssuer(subjectToken.getIssuer())

Review Comment:
   Option 1 assumes OBO always produces an act claim. `act` is only built when 
knox.token.enable.delegated.auth=true, which is off by default. Even with it 
on, no act is built when the actor and subject are the same user. The docs 
claim this case can't happen.



##########
gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/TokenResource.java:
##########
@@ -1351,6 +1351,18 @@ private JWT getJWT(UserContext userContext, long 
issueTime, long expires, String
       customAttributes.putAll(userContext.userParams);
     }
 
+    // KNOX-3623: the knox_token_provenance claim (CommonTokenConstants) is 
reserved -- never taken from
+    // claim mappings or user params. An exchange mint uses the value the 
exchange path resolved; any other
+    // mint carries forward the provenance of the caller's own authenticated 
token, so re-minting a
+    // laundered token outside an exchange does not drop it. A plain mint 
never stamps a new value.
+    
customAttributes.remove(CommonTokenConstants.TOKEN_EXCHANGE_PROVENANCE_CLAIM);
+    final String provenanceIssuer = 
Boolean.TRUE.equals(request.getAttribute(CommonTokenConstants.TOKEN_EXCHANGE_REQUEST_ATTR))
+        ? (String) 
request.getAttribute(CommonTokenConstants.TOKEN_EXCHANGE_PROVENANCE_REQUEST_ATTR)
+        : SubjectUtils.getTokenProvenance(subject);

Review Comment:
   A plain KNOXTOKEN mint launders the token too. A mint made with a login 
bearer JWT never records the caller token's iss as provenance. Stamping the 
caller's iss as provenance when the caller token has none might help??



##########
gateway-service-knoxidf/src/main/java/org/apache/knox/gateway/service/knoxidf/RegistrationResource.java:
##########
@@ -180,6 +201,10 @@ public Response registerClient(@FormParam("redirect_uris") 
String redirectUris,
                 detail = "reason=delegated_caller_denied";
                 return error("access_denied", "A delegated token cannot 
register a client.");
             }
+            if (provenanceDenied()) {

Review Comment:
   Nit: denylist is checked only on /register



-- 
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]

Reply via email to