[ 
https://issues.apache.org/jira/browse/KNOX-3414?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18104536#comment-18104536
 ] 

ASF subversion and git services commented on KNOX-3414:
-------------------------------------------------------

Commit 9a1d04a2b54ba17644dad2001a0b59e32ea75bb2 in knox's branch 
refs/heads/knox_idf from Sandor Molnar
[ https://gitbox.apache.org/repos/asf?p=knox.git;h=9a1d04a2b ]

KNOX-3414: add opt-in Keycloak federation E2E test and activate 
federated-identity persistence

Adds an opt-in end-to-end test that stands up a real Keycloak as the external
OpenID Provider and drives the full broker flow through Knox (register client,
/authorize -> SSOCookie redirect -> Keycloak login -> callback -> token 
exchange).
It is layered in via docker-compose.knoxidf-federation.yml and is NOT part of 
the
default test run (the base compose ignores test_knoxidf_federation.py).

Surfacing that path exposed a production bug baked into the OIDC-provider 
squash:
federated-identity persistence never activated. The service factories decided
whether to use the JDBC-backed store by calling TopologyService.getTopologies()
at gateway-service-init time, but topologies are not loaded yet at that point, 
so
the no-op EmptyFederatedIdentityService was chosen in every deployment and the
token exchange failed with "Federated identity not found".

Fixes:
- Move isKnoxIdfEnabledInAnyTopology into AbstractServiceFactory and add a
  topology-directory disk-scan fallback for when getTopologies() is still empty 
at
  init time; match both KNOXIDF and KNOXIDF_ADMIN roles. 
TrustedOidcIssuerServiceFactory
  now delegates to the shared helper.
- Add a self-provisioning DerbyDBFederatedIdentityService (mirrors
  DerbyDBTokenStateService) and 3-way backend auto-selection: explicit impl 
wins;
  otherwise an operator-configured external DB -> JDBC, else the embedded Derby
  default so federation works out of the box with no extra infrastructure.
- SQL DDL: the create-table runner executes a single statement per file, so fold
  the federated-identity UNIQUE constraint inline and drop trailing semicolons.
- Validate federated OP id_tokens with a JWS type verifier that accepts typ=JWT
  and an absent typ (Keycloak and most OPs set typ=JWT; the shared token 
authority
  rejects any typ'd token when no verifier is supplied).
- getPrefix() now returns "knoxidf." (trailing dot) so knoxidf.knox.token.* 
topology
  params map onto the base KNOXTOKEN params; add the same override to 
AuthorizeResource
  so its callback-minted tokens honor the per-user limit/ttl configured on the 
topology.

Covered by FederatedIdentityServiceFactoryTest, 
DerbyDBFederatedIdentityServiceTest,
and the 3 federation E2E tests (all green); default KnoxIDF E2E and the knoxidf/
knoxtoken JUnit suites remain green.

Co-Authored-By: Claude Opus 4.8 <[email protected]>


> KnoxIDF (OIDC Provider): security hardening, correctness fixes, and 
> documentation
> ---------------------------------------------------------------------------------
>
>                 Key: KNOX-3414
>                 URL: https://issues.apache.org/jira/browse/KNOX-3414
>             Project: Apache Knox
>          Issue Type: Improvement
>          Components: KnoxIDF
>            Reporter: Sandor Molnar
>            Assignee: Sandor Molnar
>            Priority: Critical
>             Fix For: 3.1.0
>
>
> Follow-up work on the KnoxIDF OAuth2/OIDC Authorization Server. Items to fix:
> Client authentication & flow security
> - Authenticate the client on the refresh_token grant.
> - Authenticate the client on the authorization_code grant (PKCE S256 or 
> constant-time client_secret).
> - Reject PKCE plain; accept only S256, and advertise only S256 in discovery.
> - Require and validate state/nonce; bind the federated id_token to the 
> request via nonce.
> - Atomically consume authorization codes and refresh tokens before issuance 
> (close replay windows).
> Federation
> - Fully validate the federated OP id_token (signature/JWKS, issuer, audience, 
> exp/nbf, sub) before trusting any claim.
> - Reject a federated id_token missing sub with a 4xx, not a 500.
> - Fail closed when a federated-OP client-secret alias is unresolvable.
> - Stop persisting federated OP access tokens at rest; store only 
> ID-token-derived identity data.
> - Activate federated-identity persistence (was silently disabled) with 
> self-provisioning embedded Derby default.
> Redirect-URI / registration
> - Normalize redirect_uri path before wildcard matching; match on parsed URI 
> components (fix open redirect).
> - Build a well-formed success redirect when redirect_uri already carries a 
> query.
> - Require HTTPS for registered redirect URIs (loopback HTTP excepted, RFC 
> 8252).
> - Make anonymous dynamic client registration an explicit, secure-by-default 
> opt-in.
> Correctness / robustness
> - Fix SCOPE_ATTRIBUTE always resolving to null (double getClaim).
> - Fix iat=1970 regression on non-KnoxIDF tokens (default issue time to now).
> - /userinfo returns 401 invalid_token, not 500, for a bad bearer token.
> - Fix broken double-checked locking in service init paths.
> - Escape LDAP username input; remove hardcoded LDAP system-password fallback 
> (fail fast).
> - Per-request claim map (fix cross-user claim leakage in the shared 
> singleton).
> Persistence
> - Fix TOCTOU on federated-identity insert (unique constraint as arbiter).
> - Write identity + attributes in a single transaction.
> - Align Derby schema (NOT NULL / unique index) with other dialects.
> Key management & auditing
> - Publish multiple JWKs and select the verification key by kid (enables 
> zero-downtime signing-key rotation).
> - Emit structured audit records across the OAuth2/OIDC endpoints.
> OIDC discovery / docs
> - Complete OIDC discovery metadata for OAuth/MCP client integration.
> - Add opt-in Keycloak federation E2E test; extend existing E2E suite to cover 
> the fixes above.
> - Add the Identity Federation (OIDC Provider) documentation book.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to