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

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

                Author: ASF GitHub Bot
            Created on: 29/Nov/26 09:10
            Start Date: 29/Nov/26 09:10
    Worklog Time Spent: 10m 
      Work Description: 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 

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

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

> KnoxIDF: allow the LDAP user params lookup to use the Knox LDAP service
> -----------------------------------------------------------------------
>
>                 Key: KNOX-3622
>                 URL: https://issues.apache.org/jira/browse/KNOX-3622
>             Project: Apache Knox
>          Issue Type: Improvement
>          Components: KnoxIDF, LDAP
>            Reporter: Sandor Molnar
>            Assignee: Sandor Molnar
>            Priority: Major
>             Fix For: 3.1.0
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> Today the KnoxIDF LDAP user params provider ({{LdapUserParamsProvider}}) 
> always opens its own JNDI connection. It needs separate configuration: 
> {{user.params.provider.ldap.url}}, {{systemUser}}, {{systemPasswordAlias}}, 
> {{userSearchBase}}, {{groupSearchBase}}, and so on. In production this 
> usually points back at Knox's own embedded LDAP server. The same backend is 
> then configured twice, and every lookup does a network bind and search 
> against our own process.
> {{HadoopGroupProvider}} already avoids this with {{use.ldap.service=true}}, 
> which resolves groups in-process through {{KnoxLDAPService}}. KnoxIDF should 
> offer the same option.
> *Proposed changes*
> * Add a {{lookupUser(username, attributes...)}} method to {{KnoxLDAPService}} 
> / {{KnoxLDAPServerManager}}, next to {{lookupUserGroups}}. It returns the 
> requested attributes and the user's groups. The search runs through the 
> embedded server's admin session, so it uses the full interceptor chain: the 
> proxy backend, attribute mapping and the roles lookup interceptor. 
> {{lookupUserGroups}} is reimplemented on top of it.
> * Escape the username in the {{(uid=...)}} search filter. It is currently 
> concatenated unescaped, so a username such as {{*}} matches some other user. 
> The fix also covers the existing {{lookupUserGroups}} callers (the Hadoop 
> group provider and the delegation policy).
> * Add {{KnoxLdapServiceUserParamsProvider}}. It maps cn/sn/givenName/mail to 
> name/family_name/given_name/email, plus sub, email_verified and roles. Both 
> providers share the claim mapping, so their output can't drift apart.
> * Add the topology parameter {{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 ({{url}} gives the JNDI provider; otherwise no user 
> params). {{knoxidf.token.user.params.enabled}} still applies.
> * Roles semantics: 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 enabled, both return the same roles.
> * Document the new parameter in {{knox-site/docs/knoxidf/configuration.md}}.
> *Testing*
> * Unit tests for {{lookupUser}} (attributes, groups, user not found, filter 
> escaping), for the new provider, and for the provider factory's selection and 
> fallback logic.
> * E2E:
> ** A new {{knoxidf-token-ldap-service}} topology, which is {{knoxidf-token}} 
> with only the new flag in place of the LDAP connection settings.
> ** A new {{test_user_params_claims}} test checks the profile and email claims 
> in both the access token and /userinfo.
> ** The KnoxIDF suite is re-run through the new provider for guest and sam, 
> with a parity check against the JNDI provider.
> ** REST roles lookup variants are added.
> ** The KnoxIDF E2E tests now revoke the tokens and auth codes they obtain, so 
> they no longer use up the gateway-wide {{knox.token.limit.per.user}} that 
> other suites share.



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

Reply via email to