[
https://issues.apache.org/jira/browse/KNOX-3600?focusedWorklogId=1056040&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1056040
]
ASF GitHub Bot logged work on KNOX-3600:
----------------------------------------
Author: ASF GitHub Bot
Created on: 19/Nov/26 23:07
Start Date: 19/Nov/26 23:07
Worklog Time Spent: 10m
Work Description: smolnar82 opened a new pull request, #1531:
URL: https://github.com/apache/knox/pull/1531
[KNOX-3600](https://issues.apache.org/jira/browse/KNOX-3600) - Prevent
CLIENT_ID tokens from registering other clients
## What changes were proposed in this pull request?
A registered client (`thirdPartyApp=true`) authenticates with its own client
id as subject. If its token reaches `/knoxidf/api/v1/client/register`, it
registers clients owned by itself, each with its own
`knoxidf.knox.token.limit.per.user`, so the limit bounds nothing. Revoking the
first client leaves the clients it registered working.
- `RegistrationResource.registerClient` rejects a caller whose subject is
the id of a CLIENT_ID token with `access_denied`, audited as
`reason=client_caller_denied`. The check runs right after the anonymous check.
- The lookup uses the primary principal (the subject as authenticated), not
the effective one, so identity-assertion mapping such as `lowercase` cannot
hide a mixed-case client id. An unknown id is treated as a user.
- New KNOXIDF service param
`knoxidf.client.registration.client.callers.denied`, default `true`; `false`
restores the previous behaviour.
- Docs: `configuration.md` and `security.md` (dynamic client registration),
including the known limit: a deleted client's earlier tokens pass until they
expire.
## How was this patch tested?
Unit tests: new `RegistrationResourceClientCallerGuardTest` (7 tests) covers
a client caller rejected by default and allowed with the opt-out, user callers,
non-client token ids, the mixed-case client id after `lowercase` mapping, and
no subject or token state. All 282 `gateway-service-knoxidf` tests pass.
Manual test on a local gateway. The `knoxidf-auth-clientregistration`
topology (`JWTProvider` trusting `KNOXSSO`, `knoxidf.thirdPartyApp=true`)
issues the clients; `tokenexchange` (`KNOXTOKEN` + `CLIENTID`, server-managed)
exchanges a client's credentials for a JWT. Steps:
1. Get guest's KNOXSSO token: `{"iss":"KNOXSSO","sub":"guest"}`.
2. guest registers client 1 at
`/knoxidf-auth-clientregistration/knoxidf/api/v1/client/register`: `HTTP 200`.
3. Client 1 gets its own token at `/tokenexchange/oauth/v1/token`
(`client_credentials`): `{"iss":"KNOXSSO","sub":"<client 1 id>"}`.
4. Client 1 registers client 2 with that token.
Results of step 4:
- Default (param unset) and explicit `true`: `HTTP 403`,
`{"error":"access_denied","error_description":"A registered client cannot
register another client."}`; the audit log has `principal=<client 1
id>|failure|event=client_registration reason=client_caller_denied`.
- `knoxidf.client.registration.client.callers.denied=false`: `HTTP 200`,
client 2 registered.
**Default** (`knoxidf.client.registration.client.callers.denied` unset):
client 1 cannot register client 2.
```
1. guest's KNOXSSO token
{"iss":"KNOXSSO","sub":"guest"}
2. guest registers client 1 (expect 200)
{"client_secret":"…","redirect_uris":"https://app.example.com/cb","client_id":"382739db-e5f7-462e-b739-49f1e9bdb51c","allowed_scopes":"openid,profile,email,offline_access"}
HTTP 200
3. client 1 gets its own token at tokenexchange (client_credentials)
{"iss":"KNOXSSO","sub":"382739db-e5f7-462e-b739-49f1e9bdb51c"}
4. client 1 registers client 2 (expect 403 access_denied when sub is the
client id)
{
"error_description" : "A registered client cannot register another
client.",
"error" : "access_denied"
}
HTTP 403
```
**Opt-out** (`knoxidf.client.registration.client.callers.denied=false`):
client 1 registers client 2.
```
1. guest's KNOXSSO token
{"iss":"KNOXSSO","sub":"guest"}
2. guest registers client 1 (expect 200)
{"client_secret":"…","redirect_uris":"https://app.example.com/cb","client_id":"44efa306-0b0c-4ccd-9e06-7642193b4933","allowed_scopes":"openid,profile,email,offline_access"}
HTTP 200
3. client 1 gets its own token at tokenexchange (client_credentials)
{"iss":"KNOXSSO","sub":"44efa306-0b0c-4ccd-9e06-7642193b4933"}
4. client 1 registers client 2 (expect 403 access_denied when sub is the
client id)
{"client_secret":"…","redirect_uris":"https://app.example.com/cb","client_id":"51a331c5-96ef-4471-9587-b9b533453776","allowed_scopes":"openid,profile,email,offline_access"}
HTTP 200
```
```
Issue Time Tracking
-------------------
Worklog Id: (was: 1056040)
Remaining Estimate: 0h
Time Spent: 10m
> 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: 10m
> 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)