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 -- Python 3.10.20, pytest-9.0.3, pluggy-1.7.0 tests-1 | rootdir: /tests tests-1 | plugins: platformdirs-4.12.4 tests-1 | collected 185 items tests-1 | tests-1 | test_clientid_credentials.py ........... [ 5%] tests-1 | test_delegation.py .............. [ 13%] tests-1 | test_gateway_identity_cert.py ...... [ 16%] tests-1 | test_health.py ..... [ 19%] tests-1 | test_k8s_delegation.py ........ [ 23%] tests-1 | test_k8s_jwks_ca.py ........... [ 29%] tests-1 | test_k8s_serviceaccount_validation.py ...... [ 32%] tests-1 | test_knox_admin_path_traversal.py ... [ 34%] tests-1 | test_knox_auth_service_and_ldap.py ... [ 36%] tests-1 | test_knox_configs.py . [ 36%] tests-1 | test_knox_ldap_backend_password_alias_retry.py .. [ 37%] tests-1 | test_knox_ldap_cache.py ... [ 39%] tests-1 | test_knox_ldap_injection.py ....... [ 43%] tests-1 | test_knox_ldap_proxy_search.py ............... [ 51%] tests-1 | test_knoxauth_preauth_and_paths.py ...... [ 54%] tests-1 | test_knoxauth_token_forwarding.py ........... [ 60%] tests-1 | test_knoxidf.py ....... [ 64%] tests-1 | test_knoxsso_redirect.py . [ 64%] tests-1 | test_knoxtoken_jwt.py .................... [ 75%] tests-1 | test_pathacls_encoded_path.py ...... [ 78%] tests-1 | test_pathacls_rule_order.py ... [ 80%] tests-1 | test_remote_auth.py ... [ 82%] tests-1 | test_remoteauth_extauthz_additional_path.py .... [ 84%] tests-1 | test_token_exchange.py ................. [ 93%] tests-1 | test_token_exchange_laundering.py ........ [ 97%] tests-1 | test_token_limit_by_type.py .... [100%] tests-1 | tests-1 | =============================== warnings summary =============================== ... tests-1 | -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html tests-1 | ----------------- generated xml file: /tests/test-results.xml ------------------ tests-1 | ================= 185 passed, 163 warnings in 67.17s (0:01:07) ================= tests-1 exited with code 0 Aborting on container exit... Container compose-tests-1 Stopping Container compose-tests-1 Stopped Config w Enable Watch d Detach ``` ## Performance implications None. The new work runs only on the token-exchange and client-registration paths, is gated on configuration that is empty/off by default, and amounts to a constant-time issuer-list check and one extra claim/principal. No new remote or DB calls, no caching or locking changes, and no HA/multi-instance behavior change. -- 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]
