mimaison commented on code in PR #22501:
URL: https://github.com/apache/kafka/pull/22501#discussion_r3466570809


##########
checkstyle/import-control-metadata.xml:
##########
@@ -91,6 +91,7 @@
         <allow pkg="org.apache.kafka.snapshot" />
         <allow pkg="org.apache.kafka.test" />
         <allow pkg="org.apache.kafka.timeline" />
+        <allow pkg="org.apache.commons.net.util" />

Review Comment:
   Is this needed? 



##########
metadata/src/main/java/org/apache/kafka/metadata/authorizer/CidrUtils.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.metadata.authorizer;
+
+import org.apache.commons.net.util.SubnetUtils;
+import org.apache.commons.net.util.SubnetUtils6;
+
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public final class CidrUtils {
+
+    private CidrUtils() {}
+
+    private static InetAddress parseCidrAddress(String cidrPattern) {
+        String ipPart = cidrPattern.contains("/")
+            ? cidrPattern.substring(0, cidrPattern.indexOf('/'))
+            : cidrPattern;
+        try {
+            return InetAddress.getByName(ipPart);

Review Comment:
   `ipPart` is user controlled and this may trigger a DNS resolution, if a user 
tries to create an ACL with `example.com/24` (or even just `example.com/path`) 
as the host name for example. I wonder if we could just rely on the pattern 
containing a `:` to determine which SubnetUtils to use. This internally will 
ensure the string is a valid IP. 



##########
metadata/src/main/java/org/apache/kafka/metadata/authorizer/CidrUtils.java:
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.metadata.authorizer;
+
+import org.apache.commons.net.util.SubnetUtils;
+import org.apache.commons.net.util.SubnetUtils6;
+
+import java.net.Inet6Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public final class CidrUtils {
+
+    private CidrUtils() {}
+
+    private static InetAddress parseCidrAddress(String cidrPattern) {
+        String ipPart = cidrPattern.contains("/")
+            ? cidrPattern.substring(0, cidrPattern.indexOf('/'))
+            : cidrPattern;

Review Comment:
   It seems all code paths leading to this method have already checked that the 
string contains a slash, so maybe we can simplify this bit.



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