[
https://issues.apache.org/jira/browse/KNOX-3603?focusedWorklogId=1056245&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1056245
]
ASF GitHub Bot logged work on KNOX-3603:
----------------------------------------
Author: ASF GitHub Bot
Created on: 20/Nov/26 15:20
Start Date: 20/Nov/26 15:20
Worklog Time Spent: 10m
Work Description: smolnar82 opened a new pull request, #1533:
URL: https://github.com/apache/knox/pull/1533
[KNOX-3603](https://issues.apache.org/jira/browse/KNOX-3603) - KnoxIDF:
Refuse delegated tokens at client revocation and enable/disable
## What changes were proposed in this pull request?
KNOX-3600 refuses a delegated token (RFC 8693 `act` claim, an
`ActorChainPrincipal` on the subject) at `/knoxidf/api/v1/client/register`. The
other `/client` endpoints `RegistrationResource` inherits from `TokenResource`
had no such check. They authorize the caller's effective principal, which for a
delegated token is the user it acts for, and accept a bare token id. So whoever
holds a user's delegated token could list that user's tokens and revoke,
disable or re-enable any of them whose id it knows.
- `RegistrationResource` overrides `getUserTokens`, `revoke`,
`revokeTokens`, `enable`, `enableTokens`, `disable` and `disableTokens`. A
delegated caller gets `403` `access_denied` ("A delegated token cannot
list/revoke/enable/disable tokens.") before the parent runs, audited as
`authorization|…|failure|event=client_<token_listing|revocation|enablement|disablement>
reason=delegated_caller_denied`. Other callers reach the inherited
implementation unchanged.
- The existing `knoxidf.client.registration.delegated.callers.denied`
(default `true`) now controls these endpoints too, so one switch decides
whether delegated tokens may manage clients. `false` restores the previous
behaviour.
- Only the actor chain is checked, as in KNOX-3600: Shiro/LDAP callers,
passcodes and non-delegated JWTs are unaffected.
- Docs: `configuration.md` and `security.md`.
## How was this patch tested?
Unit tests: new `RegistrationResourceDelegatedTokenAccessGuardTest` (13
tests). A delegated caller is refused with `access_denied` at all 7 endpoints,
and a strict `TokenStateService` mock verifies the token state is untouched.
With the param set to `false`, and for a non-delegated caller, `revoke`,
`disable` and `getUserTokens` reach the parent and return `200`. All 299
`gateway-service-knoxidf` tests pass, and `mvn verify` (checkstyle, PMD) is
clean.
Manual test on a local gateway, on two delegated-token paths. In both, the
test first registers two clients C1 and C2 owned by the user, then calls
`getUserTokens`, `disable`/`enable` C1, `disableTokens`/`enableTokens` C2,
`revoke` C1 and `revokeTokens` C2, first with the delegated token, then with a
non-delegated token of the same user. The `knoxidf-auth-clientregistration`
topology (`JWTProvider`, `lowercase` principal mapping, `thirdPartyApp=true`,
`knoxidf.client.registration.delegated.callers.denied=true`) serves `/client`.
A test-only PathAcls rule opens `/knoxidf/api/v1/client/*` there, so the
requests reach `RegistrationResource` instead of being stopped by the existing
`register`-only ACL.
**RFC 8693 on-behalf-of token.** `knoxidf-tokenexchange`
(`delegation.server.enabled=true`,
`knoxidf.knox.token.enable.delegated.auth=true`, `passthrough` audience
validator) exchanges admin's KNOXSSO token with guest's as the actor, under a
delegation policy (guest may act for admin at audience `knoxidf`) set at
`knoxidf-admin`. The registration topology trusts that issuer. The same-subject
exchange of admin's token is the non-delegated control.
```
1. delegation policy: guest may act for admin at audience knoxidf (upsert at
knoxidf-admin)
HTTP 201
2. KNOXSSO tokens for admin (subject) and guest (actor)
3. admin's same-subject exchange at knoxidf-tokenexchange (no act)
{"iss":"http://knox.knox.svc.cluster.local:8443/gateway/knox-knoxidf-tokenexchange","sub":"admin","aud":null,"act":null}
4. OBO exchange at knoxidf-tokenexchange: subject admin, actor guest
{"iss":"http://knox.knox.svc.cluster.local:8443/gateway/knox-knoxidf-tokenexchange","sub":"admin","aud":"knoxidf","act":{"sub":"guest"}}
5. the OBO token registers a client (expect 403 access_denied)
{
"error_description" : "A delegated token cannot register a client.",
"error" : "access_denied"
}
HTTP 403
6. the same-subject token registers clients C1 and C2 (expect 200)
C1=e2e35d79-46a4-4b48-a890-dc5beff80a1c
C2=adabc6da-7fa3-4b2b-ae53-6fbaff80b2aa
7. the OBO token on admin's clients (expect 403 access_denied for each)
getUserTokens
HTTP 403 { "error_description" : "A delegated token cannot list
tokens.", "error" : "access_denied"}
disable C1
HTTP 403 { "error_description" : "A delegated token cannot disable
tokens.", "error" : "access_denied"}
enable C1
HTTP 403 { "error_description" : "A delegated token cannot enable
tokens.", "error" : "access_denied"}
disableTokens
HTTP 403 { "error_description" : "A delegated token cannot disable
tokens.", "error" : "access_denied"}
enableTokens
HTTP 403 { "error_description" : "A delegated token cannot enable
tokens.", "error" : "access_denied"}
revoke C1
HTTP 403 { "error_description" : "A delegated token cannot revoke
tokens.", "error" : "access_denied"}
revokeTokens
HTTP 403 { "error_description" : "A delegated token cannot revoke
tokens.", "error" : "access_denied"}
8. the same-subject token on the same clients (expect 200 for each)
getUserTokens
HTTP 200
{"tokens":[{"tokenId":"21ae695d-db93-4882-a597-53f44a4357bf","issueTime":"2026-11-20T00:40:49.678+0100","expiration":"Never","maxLifetime":"
disable C1
HTTP 200 { "setEnabledFlag": "true", "isEnabled": "false"}
enable C1
HTTP 200 { "setEnabledFlag": "true", "isEnabled": "true"}
disableTokens
HTTP 200 { "setEnabledFlag": "true", "isEnabled": "false"}
enableTokens
HTTP 200 { "setEnabledFlag": "true", "isEnabled": "true"}
revoke C1
HTTP 200 { "revoked": "true"}
revokeTokens
HTTP 200 { "revoked": "true"}
```
**Impersonation token with `act`.** The test-only `delegation` topology from
KNOX-3600 (`doAs` impersonation for guest, `KNOXTOKEN` with
`knox.token.enable.delegated.auth=true`) mints a KNOXSSO token for admin with
`act.sub=guest`. Steps 1–5 are the KNOX-3600 registration checks; admin's
KNOXSSO token registers C1 and C2 and is the control.
```
4. guest gets a token for admin at delegation (doAs=admin, act.sub=guest)
{"iss":"KNOXSSO","sub":"admin","act":{"sub":"guest"}}
5. the delegated token registers a client (expect 403 access_denied unless
delegated callers are allowed)
{
"error_description" : "A delegated token cannot register a client.",
"error" : "access_denied"
}
HTTP 403
6. admin's KNOXSSO token registers clients C1 and C2, admin's own tokens
(expect 200)
C1=d8d6a6e6-3e15-4e77-b5ee-d885b8514313
C2=f4730bd0-db23-41c6-9f7b-88a1b43538c0
7. the delegated token (sub=admin) on admin's clients (expect 403
access_denied for each)
getUserTokens
HTTP 403 { "error_description" : "A delegated token cannot list
tokens.", "error" : "access_denied"}
disable C1
HTTP 403 { "error_description" : "A delegated token cannot disable
tokens.", "error" : "access_denied"}
enable C1
HTTP 403 { "error_description" : "A delegated token cannot enable
tokens.", "error" : "access_denied"}
disableTokens
HTTP 403 { "error_description" : "A delegated token cannot disable
tokens.", "error" : "access_denied"}
enableTokens
HTTP 403 { "error_description" : "A delegated token cannot enable
tokens.", "error" : "access_denied"}
revoke C1
HTTP 403 { "error_description" : "A delegated token cannot revoke
tokens.", "error" : "access_denied"}
revokeTokens
HTTP 403 { "error_description" : "A delegated token cannot revoke
tokens.", "error" : "access_denied"}
8. admin's own token on the same clients (expect 200 for each: the refusals
above changed nothing)
getUserTokens
HTTP 200
{"tokens":[{"tokenId":"21ae695d-db93-4882-a597-53f44a4357bf","issueTime":"2026-11-20T00:40:49.678+0100","expiration":"Never","maxLifetime":"
disable C1
HTTP 200 { "setEnabledFlag": "true", "isEnabled": "false"}
enable C1
HTTP 200 { "setEnabledFlag": "true", "isEnabled": "true"}
disableTokens
HTTP 200 { "setEnabledFlag": "true", "isEnabled": "false"}
enableTokens
HTTP 200 { "setEnabledFlag": "true", "isEnabled": "true"}
revoke C1
HTTP 200 { "revoked": "true"}
revokeTokens
HTTP 200 { "revoked": "true"}
```
Each refusal is in the audit log, e.g.:
```
|KNOXIDF|admin|||authorization|principal|admin|failure|event=client_enablement
reason=delegated_caller_denied
|KNOXIDF|admin|||authorization|principal|admin|failure|event=client_revocation
reason=delegated_caller_denied
```
The KNOX-3600 client-caller check is unaffected: with
`knoxidf.client.registration.client.callers.denied` unset, a registered
client's own token still gets `403` "A registered client cannot register
another client.".
## Integration Tests
Two new tests in `test_delegation.py`, which already sets up delegation
policies and RFC 8693 exchanges. Both use a token delegated to recursiveUser
acting for tom (`sub=tom`, `act.sub=recursiveUser`) from
`knoxidf-token-delegation-policy`.
- `test_delegated_token_refused_at_client_endpoints`, on
`knoxidf-token-delegation-policy` (default, delegated callers refused): tom's
own token registers two clients. The delegated token gets `403` `access_denied`
at `register` and at all 7 token endpoints, each with its verb in the message.
Each refusal leaves one `authorization` failure audit record with the right
`event` and `reason=delegated_caller_denied`, matched by an `audit_marker`
query parameter as in the KNOX-3568 tests. tom's own token then gets `200` at
all 7, so the 403s come from the delegated check.
- `test_delegated_token_reaches_client_endpoints_when_allowed`, on the new
`knoxidf-client-delegated-allowed` topology (`JWTProvider`, server-managed,
`KNOXIDF` with `knoxidf.client.registration.delegated.callers.denied=false`):
the same delegated token registers two clients and gets `200` at all 7
endpoints.
```
tests-1 | Your code has been rated at 10.00/10
tests-1 |
tests-1 | Waiting for knox...
tests-1 | ============================= test session starts
==============================
tests-1 | platform linux
Issue Time Tracking
-------------------
Worklog Id: (was: 1056245)
Remaining Estimate: 0h
Time Spent: 10m
> KnoxIDF: Refuse delegated tokens at client revocation and enable/disable
> ------------------------------------------------------------------------
>
> Key: KNOX-3603
> URL: https://issues.apache.org/jira/browse/KNOX-3603
> Project: Apache Knox
> Issue Type: Improvement
> Components: KnoxIDF
> Reporter: Sandor Molnar
> Assignee: Sandor Molnar
> Priority: Major
> Fix For: 3.1.0
>
> Time Spent: 10m
> Remaining Estimate: 0h
>
> *Problem*
> KNOX-3600 refuses a delegated token (an {{ActorChainPrincipal}} on the
> subject, from an {{act}} claim) at {{{}/knoxidf/api/v1/client/register{}}}.
> The other client endpoints {{RegistrationResource}} inherits from
> {{TokenResource}} have no such check: {{{}revoke{}}}, {{{}revokeTokens{}}},
> {{{}enable{}}}, {{{}enableTokens{}}}, {{disable,}} {{{}disableTokens and
> getUserTokens{}}}. They act when the caller's effective principal is the
> token's user or creator, and accept a bare token id. So whoever holds a
> user's delegated token ({{{}sub{}}} = user, {{act}} = itself) can revoke or
> disable any of that user's tokens whose ids it knows, on any topology that
> serves these paths and trusts the issuer of the delegated token.
> *Fix*
> In {{{}RegistrationResource{}}}, override those six methods: if
> {{{}delegatedCallerDenied(){}}}, reject with {{access_denied}} and audit
> {{{}reason=delegated_caller_denied{}}}, as {{registerClient}} does.
> * Reuse {{knoxidf.client.registration.delegated.callers.denied}} (default
> {{{}true{}}}): one switch decides whether delegated tokens may manage clients.
> * Only the actor chain is checked, as in KNOX-3600. Callers without one
> (Shiro/LDAP, passcodes, non-delegated JWTs) are unaffected.
> *Tests*
> * Delegated subject: each of the six methods is rejected and audited, and
> the token's state is unchanged.
> * With the param set to {{{}false{}}}: a delegated subject can revoke and
> disable.
> * Non-delegated subject: revokes and disables its own token.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)