apoorvmittal10 commented on PR #20912:
URL: https://github.com/apache/kafka/pull/20912#issuecomment-6802907606

   Thanks @ekuvardin. I found a correctness regression in hasHead and verified 
it by running a test against this PR’s head.
   
   `hasHead` only checks headMap(allowStr).lastKey(), the greatest smaller key, 
so it misses a shorter deny prefix when a larger sibling key sorts in between.
   
   Example: deny PREFIXED "a" and "abb", allow LITERAL "abc". lastKey is "abb", 
which isn’t a prefix of "abc", so the deny on "a" is missed. 
authorizeByResourceType returns ALLOWED. It returned DENIED before this change. 
That means a deny ACL is bypassed.
   
   ```
   @Test
   public void 
testAuthorizeByResourceTypeShorterPrefixDenyWithLargerSiblingPrefix() throws 
Exception {
       KafkaPrincipal user1 = new KafkaPrincipal(KafkaPrincipal.USER_TYPE, 
"user1");
       InetAddress host1 = InetAddress.getByName("192.168.1.1");
       RequestContext ctx = newRequestContext(user1, host1);
       AccessControlEntry allowAce = new AccessControlEntry(user1.toString(), 
host1.getHostAddress(), READ, ALLOW);
       AccessControlEntry denyAce = new AccessControlEntry(user1.toString(), 
host1.getHostAddress(), READ, DENY);
   
       addAcls(authorizer, Set.of(denyAce), new ResourcePattern(GROUP, "a", 
PREFIXED));
       addAcls(authorizer, Set.of(denyAce), new ResourcePattern(GROUP, "abb", 
PREFIXED));
       addAcls(authorizer, Set.of(allowAce), new ResourcePattern(GROUP, "abc", 
LITERAL));
   
       assertFalse(authorizeByResourceType(authorizer, ctx, READ, 
ResourceType.GROUP));
   }
   ```
   
   This fails on the PR and passes on trunk. Please include it and fix the 
lookup.
   
   Also more importantly, there’s no baseline benchmark against the old code, 
so the gain isn’t demonstrated. Prefixes are short and the old path was O(L) 
hash lookups. **Please add them and evaluate if really we require this change**.
   
   **This adds commons-collections4 to the clients module for one method, which 
needs wider agreement.**
   
   If the benchmark results prove the performance is really great then we can 
evaluate the PR further.
   


-- 
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]

Reply via email to