handavid opened a new pull request, #1529: URL: https://github.com/apache/knox/pull/1529
[KNOX-3594](https://issues.apache.org/jira/browse/KNOX-3594) - A short description of the change ## What changes were proposed in this pull request? Answer an all-groups (role listing) search that requests the member attribute with each role's members: the users directly assigned to the role plus the user members of the groups assigned to it. A listing that does not request member still short-circuits to the bare role list and issues no further searches. Member resolution runs as sub-searches carrying the RolesLookupBypassControl so the backend groups and users are returned as-is rather than remapped to roles, and it leaves the caller's search context untouched. Directly-assigned users and the group members are resolved to directory user entries in a single user-base search, and only members that resolve to a user entry (objectClass inetOrgPerson) become role members, so group DNs never leak into a role's member list. The LDAP proxy backend flattens nested groups into their transitive members so the interceptor sees a group's full user membership. Nested members are classified authoritatively by object class rather than by DN location: each recursion level issues one batched search that matches the level's candidate DNs and restricts to the group object classes, so the server returns only the candidates that are actually groups. This stays correct when users and groups share a container (a group DN under the user search base would otherwise be mistaken for a user and not expanded) while fetching only the groups. Member and user DNs are normalized through the schema before comparison, since a user entry returned by the proxy backend may carry a DN that is not schema-normalized the way a member DN built via the schema is; without this the forms never match and every group-derived member is dropped. Two further guards cover DNs whose RDN attribute the schema does not know: the user filter is not issued with an empty OR, and DN normalization falls back to a schema-less structural normalization before a raw lowercase string. ## How was this patch tested? Added Unit tests, Integration tests. Performed manual tests against Active Directory with File-based roles lookup configured. The roles assignments were arbitrarily generated using the users and groups from AD. submitted search requests w/o `member` attribute: ``` time ldapsearch -v -x -H ldap://localhost:3890 -D 'uid=bind2,ou=people,dc=proxy,dc=com' -w bind-password -E pr=250/noprompt -b 'ou=groups,DC=proxy,DC=com' -s sub '(objectClass=groupOfNames)' 'dn' objectClass cn ``` The results come back very quickly since the data is from the roles service only. ``` ... # platform:viewer, groups, proxy.com dn: cn=platform:viewer,ou=groups,dc=proxy,dc=com objectClass: groupOfNames cn: platform:viewer ... # search result search: 2 result: 0 Success control: 1.2.840.113556.1.4.319 false MAUCAQAEAA== pagedresults: cookie= # numResponses: 61 # numEntries: 60 ldapsearch -v -x -H ldap://localhost:3890 -D -w bind-password -E -b -s sub 0.01s user 0.01s system 54% cpu 0.038 total ``` Also searched with `member` requested ``` time ldapsearch -v -x -H ldap://localhost:3890 -D 'uid=bind2,ou=people,dc=proxy,dc=com' -w bind-password -E pr=250/noprompt -b 'ou=groups,DC=proxy,DC=com' -s sub '(objectClass=groupOfNames)' '*' '+' ``` This takes longer because LDAP searches are submitted to retrieve the user members of each group assigned to a role. Recursive groups are configured in the backend that flattens nested groups to depth 3. ``` ... # platform:viewer, groups, proxy.com dn: cn=platform:viewer,ou=groups,dc=proxy,dc=com cn: platform:viewer objectClass: groupOfNames member: CN=T24MAR$,ou=people,dc=proxy,dc=com member: CN=zookeeper,ou=people,dc=proxy,dc=com member: CN=viewuser,ou=people,dc=proxy,dc=com member: CN=T73130MA$,ou=people,dc=proxy,dc=com member: CN=cstm-ams,ou=people,dc=proxy,dc=com member: CN=testuser47,ou=people,dc=proxy,dc=com member: CN=cstm-livy2,ou=people,dc=proxy,dc=com member: CN=PC26OCT7$,ou=people,dc=proxy,dc=com member: CN=repadmin,ou=people,dc=proxy,dc=com member: CN=PCAD32JU$,ou=people,dc=proxy,dc=com member: CN=bosch_user6,ou=people,dc=proxy,dc=com member: CN=guy2,ou=people,dc=proxy,dc=com member: CN=hbasefoo0,ou=people,dc=proxy,dc=com member: CN=T73119MA$,ou=people,dc=proxy,dc=com member: CN=testuser93,ou=people,dc=proxy,dc=com member: CN=s3gfoo0,ou=people,dc=proxy,dc=com member: CN=PCCDPD10$,ou=people,dc=proxy,dc=com member: CN=mapred,ou=people,dc=proxy,dc=com member: CN=hive,ou=people,dc=proxy,dc=com member: CN=dwxdevuser,ou=people,dc=proxy,dc=com ... # search result search: 2 result: 0 Success control: 1.2.840.113556.1.4.319 false MAUCAQAEAA== pagedresults: cookie= # numResponses: 61 # numEntries: 60 ldapsearch -v -x -H ldap://localhost:3890 -D -w bind-password -E -b -s sub 0.01s user 0.01s system 0% cpu 4.564 total ``` ## Integration Tests Integration tests were added to the `test_knox_ldap_proxy_search_with_role_lookup.py` file, which run during the `docker-compose.role-lookup.yml` and `docker-compose.role-lookup-rest.yml` ## UI changes No UI changes -- 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]
