[ 
https://issues.apache.org/jira/browse/KNOX-3623?focusedWorklogId=1057566&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1057566
 ]

ASF GitHub Bot logged work on KNOX-3623:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 30/Nov/26 09:47
            Start Date: 30/Nov/26 09:47
    Worklog Time Spent: 10m 
      Work Description: smolnar82 opened a new pull request, #1553:
URL: https://github.com/apache/knox/pull/1553

   [KNOX-3623](https://issues.apache.org/jira/browse/KNOX-3623) - Refuse 
laundered login tokens via delegation-required issuers and token provenance
   
   ## What changes were proposed in this pull request?
   
   A user login token (issued by an SSO/login issuer) run through a plain 
**same-subject** RFC 8693 exchange comes out with its issuer and audience 
normalized to the exchange topology's own values and carries no `act` claim. 
The result is indistinguishable from a token a service legitimately obtained 
for itself, and can be presented to the KnoxIDF `/client` registration endpoint 
to register arbitrary OAuth clients.
   
   This PR adds two cooperating, independently-usable defenses, both **off by 
default** so no existing behavior changes unless explicitly configured.
   
   **Option 1 — delegation-required issuers** 
(`token.exchange.delegation.required.issuers` on the token-exchange 
`JWTProvider`). A same-subject exchange of a token whose issuer is in the list 
is refused with `400 invalid_request`, so such a token can only be exchanged 
**on-behalf-of**, which carries an `act` claim the existing delegated-callers 
check at registration already rejects. Empty (the default) restricts no issuer.
   
   **Option 2 — token provenance** (defense in depth). Mint side: 
`token.exchange.provenance.claim.enabled=true` makes every exchange stamp the 
subject's **origin issuer** into the minted token as the sticky, single-valued 
`knox_token_provenance` claim, carried forward verbatim across further 
exchanges so a second exchange cannot launder the origin away. Enforcement 
side: `knoxidf.client.registration.denied.provenance.issuers` makes `/client` 
registration refuse (`403 access_denied`) a caller whose token carries a listed 
provenance. A natively-issued service token carries no provenance claim and is 
unaffected.
   
   Identity-assertion reassertion rebuilds the Subject and selectively copies 
principals forward; it previously preserved the actor chain, token id, and 
token-exchange principals but not the new `TokenProvenancePrincipal`, dropping 
the provenance before registration ran. `AbstractIdentityAssertionFilter` now 
preserves it too, mirroring the existing `ActorChainPrincipal` handling, so 
enforcement reaches the registration sink.
   
   Docs updated: `knoxidf/security.md`, `knoxidf/token_exchange.md`, 
`knoxidf/configuration.md` (both controls and their parameter tables).
   
   ## How was this patch tested?
   
   Automated unit tests, all green: `JWTFederationFilterTest` and 
`TokenExchangeHandlerTest` (delegation-required refusal and provenance 
stamping/carry-forward), `TokenServiceResourceTest` (mint stamps the claim only 
when enabled), `RegistrationResourceProvenanceGuardTest` (registration 
deny-list), and `AbstractIdentityAssertionFilterTokenExchangeTest` (new 
regression test: the provenance principal survives reassertion).
   
   ## Integration Tests
   
   Added `.github/workflows/tests/test_token_exchange_laundering.py` (8 tests) 
driving a running gateway: each defense is proven both to bite and — via a 
matched control — to leave pre-existing behavior untouched (delegation refusal 
vs. a non-matching issuer; provenance stamped vs. the plain-exchange control; 
registration denied vs. allowed where no deny-list is set and vs. a token with 
no provenance). Four CI-only topologies back these tests. Full Docker Compose 
suite green: **185 passed**, pylint 10.00/10. No opt-in label suites 
(`test-federation`, `test-ha`) are needed for this change.
   ```
   tests-1  | Waiting for knox...
   tests-1  | ============================= test session starts 
==============================
   tests-1  | platform linux 

Issue Time Tracking
-------------------

            Worklog Id:     (was: 1057566)
    Remaining Estimate: 0h
            Time Spent: 10m

> KnoxIDF token exchange: prevent a same-subject exchange from laundering an 
> input token into a client-registration credential
> ----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: KNOX-3623
>                 URL: https://issues.apache.org/jira/browse/KNOX-3623
>             Project: Apache Knox
>          Issue Type: Task
>          Components: KnoxIDF
>            Reporter: Sandor Molnar
>            Assignee: Sandor Molnar
>            Priority: Major
>             Fix For: 3.1.0
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> h3. Background
> The KnoxIDF token endpoint supports RFC 8693 token exchange. A topology can 
> enable a same-subject exchange 
> ({{token.exchange.same.subject.requested.audience.enabled}}): the caller 
> presents a {{subject_token}} and receives a new token for the same subject, 
> stamped with the exchange topology's own issuer 
> ({{knoxidf.knox.token.issuer}}) and default audience 
> ({{knoxidf.knox.token.audiences}}), with no {{act}} claim added.
> KNOX-3600 lets the dynamic client-registration endpoint 
> ({{/client/register}}) refuse a caller whose subject is a registered client 
> (a CLIENT_ID token) or whose token carries an {{act}} claim. A deployment can 
> configure registration to trust the token-exchange topology's issuer so that 
> service identities can register clients.
> h3. Problem
> A same-subject exchange normalizes *both* the issuer and the audience of the 
> output token to the exchange topology's own values. If a deployment also lets 
> the token-exchange topology trust a user-facing login / auth-code issuer (so 
> OBO flows can exchange a user's token), a holder of a user's login token can:
> # present it to the token endpoint as a plain same-subject exchange (no 
> {{actor_token}}, no {{requested_subject}});
> # receive a token stamped with the exchange issuer and default audience, 
> carrying no {{act}} claim;
> # present that token to {{/client/register}}, which cannot distinguish it 
> from a legitimate service token and registers clients as the user.
> The KNOX-3600 guards do not catch this: the subject is a user (not a 
> CLIENT_ID) and there is no {{act}} claim. An audience check at registration 
> cannot help either, because the exchange has already overwritten the audience 
> with its own default. The only property that distinguishes a laundered token 
> from a legitimate one -- the original input issuer -- is lost during the 
> exchange.
> Today the only mitigation is deployment-side issuer-list segregation (a 
> dedicated exchange topology whose output issuer no registration endpoint 
> trusts). It works but is fragile: it relies on every future topology edit 
> preserving the segregation.
> h3. Proposed enhancement
> Give the token-exchange provider a way to stop an input issuer's tokens from 
> becoming registration-capable credentials, so the invariant is enforced by 
> Knox rather than by deployment wiring. Either, or both, of:
> # *Per-issuer exchange policy:* a provider parameter listing input issuers 
> for which a same-subject exchange is refused -- tokens from those issuers may 
> only be exchanged as a delegation (with an {{actor_token}}), so the output 
> always carries an {{act}} claim that RegistrationResource already refuses.
> # *Input-issuer provenance:* stamp the original {{subject_token}} issuer into 
> a claim on the exchanged token that survives further exchanges, and let 
> RegistrationResource (and other resources) refuse tokens whose provenance 
> chain originates from a configured set of issuers.
> h3. Related
> KNOX-3600 -- prevent CLIENT_ID and delegated tokens from registering other 
> clients.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to