[
https://issues.apache.org/jira/browse/KNOX-3600?focusedWorklogId=1056057&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1056057
]
ASF GitHub Bot logged work on KNOX-3600:
----------------------------------------
Author: ASF GitHub Bot
Created on: 19/Nov/26 23:48
Start Date: 19/Nov/26 23:48
Worklog Time Spent: 10m
Work Description: smolnar82 commented on code in PR #1531:
URL: https://github.com/apache/knox/pull/1531#discussion_r4636640059
##########
gateway-service-knoxidf/src/main/java/org/apache/knox/gateway/service/knoxidf/RegistrationResource.java:
##########
@@ -212,6 +224,33 @@ private boolean isAnonymousCaller() {
return
ANONYMOUS_PRINCIPAL.equalsIgnoreCase(SubjectUtils.getCurrentEffectivePrincipalName());
}
+ /**
+ * @return {@code true} when the request must be rejected because the
caller is itself a registered
+ * client (its subject is the id of a CLIENT_ID token) while client
callers have not been explicitly
+ * allowed. Such a client would own the clients it registers, each with
its own per-user token limit.
+ */
+ boolean clientCallerDenied() {
+ return clientCallersDenied && isClientCaller();
+ }
+
+ private boolean isClientCaller() {
+ // The primary principal is the subject as authenticated. The
effective principal is the result of
+ // identity-assertion mapping (e.g. lowercase), which can turn a
client id into an unknown name.
+ final Subject subject = SubjectUtils.getCurrentSubject();
+ final String subjectName = subject == null ? null :
SubjectUtils.getPrimaryPrincipalName(subject);
+ // Without token state there is no client id to look up.
Review Comment:
Fixed.
Issue Time Tracking
-------------------
Worklog Id: (was: 1056057)
Time Spent: 40m (was: 0.5h)
> Prevent CLIENT_ID tokens from registering other clients
> -------------------------------------------------------
>
> Key: KNOX-3600
> URL: https://issues.apache.org/jira/browse/KNOX-3600
> Project: Apache Knox
> Issue Type: Improvement
> Components: KnoxIDF
> Reporter: Sandor Molnar
> Assignee: Sandor Molnar
> Priority: Critical
> Fix For: 3.1.0
>
> Time Spent: 40m
> Remaining Estimate: 0h
>
> *Problem*
> A registered client (a CLIENT_ID token with {{{}thirdPartyApp=true{}}})
> authenticates with its own client id as subject. Such a token can reach
> {{/knoxidf/api/v1/client/register}} this way: {{client_credentials}} at a
> server-managed topology, then a same-subject token exchange at a topology the
> registration topology trusts. The client then registers a new client owned by
> itself. That client gets its own {{knox.token.limit.per.user}} and can do the
> same, so the limit bounds nothing. Revoking the first client leaves all the
> clients it created working.
> *Fix*
> In {{{}RegistrationResource.registerClient{}}}, right after
> {{{}anonymousRegistrationDenied(){}}}: if the caller's subject is the id of a
> CLIENT_ID token, reject with {{access_denied}} and audit
> {{{}reason=client_caller_denied{}}}.
> * New KNOXIDF service param
> {{{}knoxidf.client.registration.client.callers.denied{}}}, default
> {{{}true{}}}. Setting {{false}} restores today's behaviour.
> * Check the raw subject ({{{}SubjectUtils.getPrimaryPrincipalName{}}}), not
> the effective principal. Identity-assertion mapping such as {{lowercase}}
> would hide a mixed-case user-supplied client id.
> * {{{}tokenStateService.getTokenMetadata(subject){}}}: reject if
> {{{}isClientId(){}}}. Unknown id: not a client.
> *Known limit*
> A deleted client's already-exchanged token passes until it expires, because
> its metadata is gone and it looks like a user.
> *Tests*
> * CLIENT_ID subject: rejected and audited. With the param set to
> {{{}false{}}}: registered.
> * User subject: registered.
> * Mixed-case client id under {{lowercase}} mapping: rejected.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)