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


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