Skip to content

KNOX-3594: Populate role members on the LDAP all-groups search - #1529

Merged
lmccay merged 2 commits into
apache:masterfrom
handavid:KNOX-3594-role-members
Nov 21, 2026
Merged

lmccay merged 2 commits into
apache:masterfrom
handavid:KNOX-3594-role-members

Conversation

@handavid

Copy link
Copy Markdown
Contributor

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

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.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Test Results

  5 files    5 suites   1m 21s ⏱️
231 tests 230 ✅ 1 💤 0 ❌
275 runs  274 ✅ 1 💤 0 ❌

Results for commit 2d1adb7.

♻️ This comment has been updated with latest results.

Review follow-ups to the role-member population work:

- Seed the nested-group cycle guards with the group's own DN so a nested group
  that references it back does not make the group a member of itself.
- Merge nested members into whichever membership attribute the entry already
  uses (member or uniqueMember) instead of always member, so a
  groupOfUniqueNames keeps a single uniqueMember list.
- Memoize DN normalization per request in the roles interceptor so each member
  DN is rebuilt through the schema only once across resolveUsers and
  retainUserMembers.
- Clarify in the docs that a role listing returning all user attributes (no
  attribute list, or *) also populates member, not only an explicit request.
- Strengthen the cycle test and add a uniqueMember expansion test (isolated
  containers so existing member counts are unaffected); both fail without the
  backend fix.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@lmccay lmccay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks @handavid !

@lmccay
lmccay merged commit 163547b into apache:master Nov 21, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants