smolnar82 opened a new pull request, #1552: URL: https://github.com/apache/knox/pull/1552
[KNOX-3622](https://issues.apache.org/jira/browse/KNOX-3622) - Allow the KnoxIDF LDAP user params lookup to use the Knox LDAP service ## What changes were proposed in this pull request? `LdapUserParamsProvider` always opens its own JNDI connection and needs its own `user.params.provider.ldap.*` settings (URL, bind user, password alias, search bases). In production these usually point back at Knox's embedded LDAP server. This PR adds an option, like HadoopGroupProvider's `use.ldap.service`, to read the user params straight from the Knox LDAP service. - **`KnoxLDAPService.lookupUser(username, attributes...)`**: new method returning a `UserLookupResult` (whether the user was found, the requested attributes, the groups, and whether roles lookup applied). - The search runs in-process through the embedded server's admin session, so the proxy backend, attribute mapping and roles-lookup interceptor all apply. - `lookupUserGroups` is now built on top of it. - **Filter escaping fix**: the username in the `(uid=...)` search filter is now escaped with `FilterEncoder.encodeFilterValue`. Before, a username such as `*` matched some other user. This also protects the existing `lookupUserGroups` callers (the Hadoop group provider and the delegation policy). - **`KnoxLdapServiceUserParamsProvider`**: new provider. It maps cn/sn/givenName/mail to name/family_name/given_name/email, plus sub, email_verified and roles, filtered by the requested scopes. The claim mapping moved into `UserParamsClaims`, which both providers share so their output can't drift apart. - **`user.params.provider.ldap.use.ldap.service`** (default `false`): - When it is `true` and `gateway.ldap.enabled` is on, the new provider is used. It takes precedence over `user.params.provider.ldap.url`, and no URL, bind user or password alias is needed. - If the embedded LDAP is disabled, a warning is logged and the existing behavior applies. - `knoxidf.token.user.params.enabled` still applies. - **Roles**: the new provider returns every group the LDAP service resolves, the same set HadoopGroupProvider sees. The JNDI provider keeps only the groups directly under `groupSearchBase`. With the roles-lookup interceptor both return the same roles. This is documented. - **Dependency**: `gateway-service-knoxidf` now has a compile dependency on `gateway-server`, as `gateway-provider-identity-assertion-hadoop-groups` already does. - **Docs**: `knox-site/docs/knoxidf/configuration.md` documents the new parameter. ## How was this patch tested? - `mvn -pl gateway-server,gateway-service-knoxidf verify` passes, including checkstyle, PMD, spotbugs, forbiddenapis, RAT and dependency analysis. - New unit tests: - `KnoxLDAPServerManagerTest`: `lookupUser` attributes, groups, user not found, and a filter-escaping regression test (`*` and `)(` match nothing). - `KnoxLdapServiceUserParamsProviderTest`: claim mapping per scope, missing attributes, user not found, anonymous, lookup failure. - `UserParamsProviderFactoryTest`: provider selection, precedence over `url`, fallback when the embedded LDAP is disabled, and the token switch. - Existing `LdapUserParamsProviderTest`, `TokenResourceUserParamsTest` and `UserInfoResourceUserParamsTest` still pass. - Docker Compose E2E, run locally on this branch: - base suite: 196 passed; - REST roles-lookup pass: 82 passed, 1 skipped (an existing skip). ## Integration Tests - New topology `knoxidf-token-ldap-service.xml`: `knoxidf-token` with the LDAP connection settings replaced by `user.params.provider.ldap.use.ldap.service=true` alone. - `test_knoxidf.py`: - New `test_user_params_claims` checks the profile and email claims (`sub`, `name`, `family_name`, `given_name`, `email`, `email_verified`) and the roles in both the access token and `/userinfo`. E2E previously checked only `roles`. - The token topology is now a class attribute, so subclasses can redeem codes at another KnoxIDF token topology. - The tests now revoke the tokens and auth codes they get, the same way `test_knoxtoken_jwt.py` does. Without this, the extra suites pushed guest over the gateway-wide `knox.token.limit.per.user` (default 10), and `test_knoxtoken_jwt` failed with "token limit exceeded". - New `test_knoxidf_ldap_service.py`: reruns the whole KnoxIDF suite through the new provider for guest and sam, and checks that its claims and `/userinfo` match the JNDI provider's. - `test_knoxidf_with_rest_role_lookup.py`: new LDAP service variants for the guest and sam roles when the REST roles lookup replaces the LDAP groups. ``` tests-1 | ------------------------------------ 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 -- 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 196 items tests-1 | tests-1 | test_clientid_credentials.py ........... [ 5%] tests-1 | test_delegation.py .............. [ 12%] tests-1 | test_gateway_identity_cert.py ...... [ 15%] tests-1 | test_health.py ..... [ 18%] tests-1 | test_k8s_delegation.py ........ [ 22%] tests-1 | test_k8s_jwks_ca.py ........... [ 28%] tests-1 | test_k8s_serviceaccount_validation.py ...... [ 31%] tests-1 | test_knox_admin_path_traversal.py ... [ 32%] tests-1 | test_knox_auth_service_and_ldap.py ... [ 34%] tests-1 | test_knox_configs.py . [ 34%] tests-1 | test_knox_ldap_backend_password_alias_retry.py .. [ 35%] tests-1 | test_knox_ldap_cache.py ... [ 37%] tests-1 | test_knox_ldap_injection.py ....... [ 40%] tests-1 | test_knox_ldap_proxy_search.py ............... [ 48%] tests-1 | test_knoxauth_preauth_and_paths.py ...... [ 51%] tests-1 | test_knoxauth_token_forwarding.py ........... [ 57%] tests-1 | test_knoxidf.py ........ [ 61%] tests-1 | test_knoxidf_ldap_service.py .................. [ 70%] tests-1 | test_knoxsso_redirect.py . [ 70%] tests-1 | test_knoxtoken_jwt.py .................... [ 81%] tests-1 | test_pathacls_encoded_path.py ...... [ 84%] tests-1 | test_pathacls_rule_order.py ... [ 85%] tests-1 | test_remote_auth.py ... [ 87%] tests-1 | test_remoteauth_extauthz_additional_path.py .... [ 89%] tests-1 | test_token_exchange.py ................. [ 97%] tests-1 | test_token_limit_by_type.py .... [100%] tests-1 | tests-1 | =============================== warnings summary =============================== ... tests-1 | ----------------- generated xml file: /tests/test-results.xml ------------------ tests-1 | ================= 196 passed, 174 warnings in 70.85s (0:01:10) ================= 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 ``` No opt-in label is needed; the new tests run in the default suites. ## Performance implications None unless the new flag is set; it defaults to `false` and existing topologies behave exactly as before. With the flag on, each token issuance (and each `/userinfo` call) does one in-process search through the embedded LDAP server instead of a network connection, bind and two searches (user and groups) against it. That is cheaper, and no LDAP connection settings are needed. The embedded server still forwards to its configured backend (proxy backend, and the roles-lookup REST service if enabled), so those calls are unchanged. There is no new caching or shared state. In HA deployments each gateway uses its own embedded LDAP service, as HadoopGroupProvider's `use.ldap.service` does. -- 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]
