showuon commented on code in PR #24340:
URL: https://github.com/apache/kafka/pull/24340#discussion_r4719227790


##########
clients/src/main/java/org/apache/kafka/common/requests/RequestUtils.java:
##########
@@ -23,22 +23,39 @@
 import org.apache.kafka.common.errors.UnsupportedEndpointTypeException;
 import org.apache.kafka.common.errors.UnsupportedForMessageFormatException;
 import org.apache.kafka.common.errors.UnsupportedVersionException;
+import org.apache.kafka.common.internals.UnsupportedProtocolFieldException;
 import org.apache.kafka.common.message.ProduceRequestData;
+import org.apache.kafka.common.protocol.ApiKeys;
 import org.apache.kafka.common.protocol.ByteBufferAccessor;
 import org.apache.kafka.common.protocol.Message;
 import org.apache.kafka.common.protocol.ObjectSerializationCache;
 import org.apache.kafka.common.record.internal.RecordBatch;
 import org.apache.kafka.common.record.internal.Records;
+import org.apache.kafka.common.resource.ResourceType;
 
 import java.nio.ByteBuffer;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.Optional;
 import java.util.function.Predicate;
 
 public final class RequestUtils {
 
     private RequestUtils() {}
 
+    // Resource types that need a newer CreateAcls, DescribeAcls and 
DeleteAcls version than the baseline.
+    static final Map<Byte, Short> MIN_ACLS_VERSIONS = 
Map.of(ResourceType.CLUSTER_MIRROR.code(), (short) 4);

Review Comment:
   Because we only have one entry now, maybe we can just create a 
`MIN_CLUSTER_MIRROR_ACLS_VERSION = 4` variable directly.



##########
clients/src/test/java/org/apache/kafka/common/requests/RequestUtilsTest.java:
##########
@@ -45,4 +58,19 @@ public void testIsFatalException() {
         // retriable exceptions
         assertFalse(RequestUtils.isFatalException(new 
DisconnectException("")));
     }
+
+    // Catches a new ResourceType added without deciding which CreateAcls, 
DescribeAcls and DeleteAcls version
+    // supports it, which would otherwise be sent to brokers that do not 
understand it.
+    @ParameterizedTest
+    @EnumSource(ResourceType.class)
+    public void 
testEveryResourceTypeIsBaselineOrHasMinAclsVersion(ResourceType resourceType) {
+        Short minVersion = 
RequestUtils.MIN_ACLS_VERSIONS.get(resourceType.code());
+        assertTrue(BASELINE_ACLS_RESOURCE_TYPES.contains(resourceType) || 
minVersion != null,
+            resourceType + " is neither a baseline ACL resource type nor in 
RequestUtils.MIN_ACLS_VERSIONS");

Review Comment:
   This check is hard to understand. Translate it into plain English is, we 
expect the resource type is baseline acl or has `minVersion`. I can't see any 
relation between baseline acl and minVersion. As suggested above, you need to 
think how to make it readable.



##########
clients/src/test/java/org/apache/kafka/common/requests/RequestUtilsTest.java:
##########
@@ -25,13 +25,26 @@
 import org.apache.kafka.common.errors.UnsupportedEndpointTypeException;
 import org.apache.kafka.common.errors.UnsupportedForMessageFormatException;
 import org.apache.kafka.common.errors.UnsupportedVersionException;
+import org.apache.kafka.common.protocol.ApiKeys;
+import org.apache.kafka.common.resource.ResourceType;
 
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+
+import java.util.EnumSet;
+import java.util.Set;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 public class RequestUtilsTest {
+    // Resource types supported by every CreateAcls, DescribeAcls and 
DeleteAcls version. USER was added in version 3
+    // (KIP-373) but has never been validated.
+    private static final Set<ResourceType> BASELINE_ACLS_RESOURCE_TYPES = 
EnumSet.of(ResourceType.UNKNOWN, ResourceType.ANY,
+        ResourceType.TOPIC, ResourceType.GROUP, ResourceType.CLUSTER, 
ResourceType.TRANSACTIONAL_ID, ResourceType.DELEGATION_TOKEN,
+        ResourceType.USER);
+

Review Comment:
   From the name: `BASELINE_ACLS_RESOURCE_TYPES`, I really don't know what it 
contains, and why the `CLUSTER_MIRROR` is not part of it. Please rename it.



##########
server/src/test/java/org/apache/kafka/security/authorizer/AclEntryTest.java:
##########
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.kafka.security.authorizer;
+
+import org.apache.kafka.common.protocol.Errors;
+import org.apache.kafka.common.resource.ResourceType;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+
+import java.util.Set;
+
+import static org.apache.kafka.common.acl.AclOperation.ALTER;
+import static org.apache.kafka.common.acl.AclOperation.ALTER_CONFIGS;
+import static org.apache.kafka.common.acl.AclOperation.CREATE;
+import static org.apache.kafka.common.acl.AclOperation.DELETE;
+import static org.apache.kafka.common.acl.AclOperation.DESCRIBE;
+import static org.apache.kafka.common.acl.AclOperation.DESCRIBE_CONFIGS;
+import static org.apache.kafka.common.acl.AclOperation.READ;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+
+public class AclEntryTest {
+
+    // Catches a new ResourceType added without a supportedOperations case, 
which would otherwise only fail at runtime
+    // (e.g. in AuthHelper or AclCommand). authorizationError is not checked 
here since USER has no authorization error.

Review Comment:
   This comment is hard to understand. Could you please refine it or maybe 
remove it because the test is self-explanatory?



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