Repository navigation
Skip group DNs without an entry when resolving nested LDAP roles - #6697
DarshitChanpura merged 6 commits into
Conversation
- LdapHelper.lookup now returns null when the server answers NO_SUCH_OBJECT or INVALID_DN_SYNTAX for the DN, which matches its existing null result for a search that does not return one entry. - resolveNestedRoles in both LDAP backends logs a warning with the DN and skips the attribute walk when the lookup returns null, so the other groups and the role search still resolve. Before, the user got no backend roles: a missing DN failed with NO_SUCH_OBJECT and a referral to a missing DN failed with a NullPointerException. - Both backends skip a null role name. getRoleFromEntry returns null for such a DN, and User.withRoles failed on it. - Tests: a user and a nested group that point to missing DNs, a DN with an escaped newline, and a referral to a missing DN, for the ldap and ldap2 backends with old-style and new-style settings. The tests fail without the main-code change and pass with it. All LDAP test classes and spotlessCheck pass. Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
PR Reviewer Guide 🔍(Review updated until commit cec045f)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to cec045f Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 0b95cb5
Suggestions up to commit eab4f89
Suggestions up to commit 95bcdb7
Suggestions up to commit e7a55d2
Suggestions up to commit 94a1e1d
|
- getRoleFromEntry now logs a warning when no entry exists for the role DN. Both the nested and the flat role paths call it for each role DN, so a missing DN logs one warning in either mode. Before, the flat path logged nothing at the default level. - The nested-role walk logs the same case at debug, so a missing DN is not reported twice. - All LDAP test classes pass (309 tests), and the warning appears in the output of the new missing-entry tests. Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
|
Persistent review updated to latest commit e7a55d2 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #6697 +/- ##
==========================================
+ Coverage 77.23% 77.34% +0.11%
==========================================
Files 487 487
Lines 32277 32311 +34
Branches 4874 4883 +9
==========================================
+ Hits 24928 24990 +62
+ Misses 5124 5093 -31
- Partials 2225 2228 +3
🚀 New features to boost your workflow:
|
- The two new tests in each LDAP test class built the same settings and backend. A private helper now builds them, and each test only names the user and the expected roles. - No change to what the tests assert. All LDAP test classes and spotlessCheck pass. Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
|
Persistent review updated to latest commit 95bcdb7 |
|
Persistent review updated to latest commit eab4f89 |
- escapeDn now escapes control characters as \XX. Rdn does not escape them, so a DN with \0A in a value reached the server with a raw newline, and Active Directory rejected the DN of a group that exists. - LdapHelper.lookup maps only NO_SUCH_OBJECT to null. A DN that the server rejects is not a missing entry. resolveNestedRoles skips such a DN with its own warning and continues with the other groups. - resolveNestedRoles returns no roles for a DN without an entry. A role search with that DN can only match stale references, so a user no longer gets the parent roles of a deleted group. - Tests: escapeDn keeps \0A escaped; a group with a stale uniqueMember reference adds no role; a DN that the server rejects is skipped (a mocked connection, because the embedded server answers NO_SUCH_OBJECT for these DNs). Each test fails with its fix reverted. All LDAP test classes (314 tests) and spotlessCheck pass. Signed-off-by: Darshit Chanpura <dchanp@amazon.com>
|
Persistent review updated to latest commit 0b95cb5 |
|
Persistent review updated to latest commit cec045f |
Description
Nested LDAP role resolution now skips a group DN that has no entry or that the LDAP server rejects, and the other groups still resolve. DNs that contain an escaped control character such as
\0Anow reach the server escaped.NO_SUCH_OBJECT, and a referral to a DN with no entry failed with aNullPointerExceptioninresolveNestedRoles. Either failure removed every backend role of the user.escapeDnescapes control characters as\XX.Rdndoes not escape them, so a DN such asCN=SCA-LDAP\0ACNF:...(an Active Directory conflict object) reached the server with a raw newline, and the server rejected the DN of a group that exists.LdapHelper.lookupreturns null forNO_SUCH_OBJECT, the same result it already gives when the search does not return one entry. Every caller oflookupalready handles null. Other errors, includingINVALID_DN_SYNTAX, are thrown as before.resolveNestedRolesin both backends returns no roles for a DN without an entry. It does not run the role search for that DN, because a match on it can only be a stale reference, for example a group whoseuniqueMemberstill names a deleted group.resolveNestedRolesskips a DN that the server rejects withINVALID_DN_SYNTAX, with its own warning, and continues with the other groups.getRoleFromEntrylogs one warning per missing DN, in both the nested and the flat role path. Both backends skip a null role name, whichUser.withRolesrejected.Issues Resolved
Resolves #6060
Testing
LdapBackendTest(ldap backend) and inLdapBackendTestOldStyleConfig2andLdapBackendTestNewStyleConfig2(ldap2 backend), with newbase.ldiffixtures: a group that points to a missing DN, a nested group that points to a missing DN, a referral to a missing DN, and a group with a staleuniqueMemberreference to a missing DN. Each test asserts the exact role set, so the stale group must not appear.LdapHelperTestchecks thatescapeDnkeeps\0Aescaped.testResolveNestedRolesSkipsDnRejectedByServeruses a mocked connection that answersINVALID_DN_SYNTAX, because the embedded server answersNO_SUCH_OBJECTfor every DN tried.staleparent) when the role search still runs, and the rejected-DN test without the skip. With all changes, the LDAP test classes pass (314 tests, 0 failures).spotlessCheckpasses.Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.