KNOX-3374: Skip redundant roles lookup in PreAuth/ExtAuthz when the identity-assertion layer already resolved roles#1306
Open
smolnar82 wants to merge 2 commits into
Open
KNOX-3374: Skip redundant roles lookup in PreAuth/ExtAuthz when the identity-assertion layer already resolved roles#1306smolnar82 wants to merge 2 commits into
smolnar82 wants to merge 2 commits into
Conversation
…dentity-assertion layer already resolved roles
Contributor
Author
|
Cc. @handavid |
Test Results36 tests 36 ✅ 4s ⏱️ Results for commit 0916590. ♻️ This comment has been updated with latest results. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
KNOX-3374 - Avoid duplicate LDAP roles lookup between the identity-assertion layer and the PreAuth/ExtAuthz auth services
What changes were proposed in this pull request?
During roles-lookup testing it turned out that Knox performed the remote roles lookup twice for a single request, and the second lookup could return the wrong roles:
HadoopGroupProviderFilterresolves groups against Knox's embedded LDAP server (theLDAPRolesLookupInterceptordoes the lookup as part of the group search), andPreAuth/ExtAuthzauth services (AbstractAuthResource#lookupRoles).Because the interceptor already looked roles up on the authentication layer, the second call in the auth resource is redundant. This PR makes the auth-service-level roles lookup conditional: it now happens only if
We deliberately keep the auth-service lookup for the case where the topology's Shiro config points to an external LDAP server (not Knox's embedded one) but roles are still wanted: a valid Apache scenario. The case where the interceptor is not configured but the roles-lookup service is present is not supported: those deployments must configure the
LDAPRolesLookupInterceptor.How it works
AbstractIdentityAssertionBase.ROLES_LOOKUP_EXECUTEDis introduced to flag, per request, that roles were already resolved on the authentication layer.HadoopGroupProviderFiltersets this attribute when it resolves groups viaKnoxLDAPServiceand the embedded LDAP server has the roles-lookup interceptor active. To support this,KnoxLDAPService/KnoxLDAPServerManagernow exposehasRolesLookupInterceptor(), computed once at startup from the configured interceptor chain.KnoxLDAPServerManager#getUserGroupsno longer attaches theRolesLookupBypassControlto the group search request (reverted changes from KNOX-3374: Fix inherited roles missing from auth headers when LDAP ro… #1300).AbstractAuthResourcereads the attribute (via a new abstractgetRequest()implemented by PreAuthResource and ExtAuthzResource) and skips its own lookupRoles call - and emits a single roles header - when roles were already resolved upstream.mapGroupPrincipals(...)SPI method gains aServletRequestparameter so implementations can decorate the request with the flag. All identity-assertion filters (common, concat, hadoop-groups, no-doas, pseudo, regex, switchcase) are updated for the new signature.How was this patch tested?
Ran the affected module unit tests (
gateway-provider-identity-assertion-*, gateway-service-auth, gateway-server).Added / updated unit tests:
HadoopGroupProviderFilterTest#testLdapServiceIntegrationWithRolesLookupInterceptor- verifies theROLES_LOOKUP_EXECUTEDattribute is set on the request when the interceptor is active.PreAuthResourceTest#testRolesAreNotPopulatedTwice- verifies the auth resource does not call lookupRoles again (strict mock) and emits the roles header only once when the flag is set.ExtAuthzResourceTest / PreAuthResourceTestupdated to inject theHttpServletRequestand stub theROLES_LOOKUP_EXECUTEDattribute.mapGroupPrincipals(...)call sites in existing filter tests updated for the new signature.KnoxLDAPServerManagerTest#testGetUserGroupsReturnsRawGroupsEvenWhenRolesInterceptorRewritesMemberOf, which asserted the now-removed bypass-control behavior on the group search.Manually tested against the sandbox topology, covering both roles-lookup paths:
Integration Tests
N/A
UI changes
N/A