Gabriel39 commented on code in PR #71396:
URL: https://github.com/apache/doris/pull/71396#discussion_r4796638391


##########
regression-test/suites/external_table_p0/kerberos/test_iceberg_hms_manifest_kerberos.groovy:
##########
@@ -0,0 +1,259 @@
+// 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.
+
+suite("test_iceberg_hms_manifest_kerberos", 
"p0,external,kerberos,external_docker,external_docker_kerberos") {
+    if 
(!"true".equalsIgnoreCase(context.config.otherConfigs.get("enableKerberosTest")))
 {
+        return
+    }
+    String externalEnvIp = context.config.otherConfigs.get("externalEnvIp")
+    String suffix = UUID.randomUUID().toString().replace("-", "").substring(0, 
12)
+    String database = "manifest_auth_${suffix}"
+    def fixtures = [
+        [catalog: "iceberg_manifest_a_${suffix}", realm: "LABS.TERADATA.COM", 
host: "hadoop-master",
+         hmsPort: 9583, hdfsPort: 8520, keytab: "hive-presto-master.keytab"],
+        [catalog: "iceberg_manifest_b_${suffix}", realm: "OTHERREALM.COM", 
host: "hadoop-master-2",
+         hmsPort: 9683, hdfsPort: 8620, keytab: 
"other-hive-presto-master.keytab"]
+    ]
+    String rules = 'RULE:[2:$1@$0](.*@LABS.TERADATA.COM)s/@.*//\n' +
+            'RULE:[2:$1@$0](.*@OTHERREALM.COM)s/@.*//\nDEFAULT'
+    // The regression runner also needs the fixture credentials to verify HDFS 
cleanup after SDK purge errors.
+    String clientConfig = 
context.config.otherConfigs.get("kerberosClientConfig") ?:
+            System.getProperty("java.security.krb5.conf") ?: 
System.getenv("KRB5_CONFIG") ?: "/etc/krb5.conf"

Review Comment:
   Fixed in 30b299b315b8. The runner keeps explicit suite settings, the Java 
property and KRB5_CONFIG authoritative. When none is set it selects a readable 
regular /keytabs/krb5.conf before /etc/krb5.conf. Invalid explicit overrides 
still fail before any SQL. The actual fixture prefix passed 18 isolated 
layout/preflight controls; the mounted-default selection case fails against the 
previous prefix and passes after this change. These controls test 
selection/preflight, not Kerberos authentication.



##########
regression-test/suites/external_table_p0/kerberos/test_iceberg_hms_manifest_kerberos.groovy:
##########
@@ -0,0 +1,259 @@
+// 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.
+
+suite("test_iceberg_hms_manifest_kerberos", 
"p0,external,kerberos,external_docker,external_docker_kerberos") {
+    if 
(!"true".equalsIgnoreCase(context.config.otherConfigs.get("enableKerberosTest")))
 {
+        return
+    }
+    String externalEnvIp = context.config.otherConfigs.get("externalEnvIp")
+    String suffix = UUID.randomUUID().toString().replace("-", "").substring(0, 
12)
+    String database = "manifest_auth_${suffix}"
+    def fixtures = [
+        [catalog: "iceberg_manifest_a_${suffix}", realm: "LABS.TERADATA.COM", 
host: "hadoop-master",
+         hmsPort: 9583, hdfsPort: 8520, keytab: "hive-presto-master.keytab"],
+        [catalog: "iceberg_manifest_b_${suffix}", realm: "OTHERREALM.COM", 
host: "hadoop-master-2",
+         hmsPort: 9683, hdfsPort: 8620, keytab: 
"other-hive-presto-master.keytab"]
+    ]
+    String rules = 'RULE:[2:$1@$0](.*@LABS.TERADATA.COM)s/@.*//\n' +
+            'RULE:[2:$1@$0](.*@OTHERREALM.COM)s/@.*//\nDEFAULT'
+    // The regression runner also needs the fixture credentials to verify HDFS 
cleanup after SDK purge errors.
+    String clientConfig = 
context.config.otherConfigs.get("kerberosClientConfig") ?:
+            System.getProperty("java.security.krb5.conf") ?: 
System.getenv("KRB5_CONFIG") ?: "/etc/krb5.conf"
+    File configFile = new File(clientConfig).absoluteFile
+    assert configFile.isFile() && configFile.canRead():
+            "Configure kerberosClientConfig with a readable fixture krb5.conf"
+    String clientKeytabDir = 
context.config.otherConfigs.get("kerberosClientKeytabDir")
+    if (!clientKeytabDir) {
+        // Rootless hosts keep generated credentials together; older fixtures 
still provision /keytabs.
+        File configDirectory = configFile.parentFile
+        boolean adjacentKeytabs = fixtures.every { fixture ->
+            File keytab = new File(configDirectory, fixture.keytab)
+            keytab.isFile() && keytab.canRead()
+        }
+        clientKeytabDir = adjacentKeytabs ? configDirectory.path : "/keytabs"
+    }
+    fixtures.each { fixture ->
+        fixture.warehouse = 
"hdfs://${externalEnvIp}:${fixture.hdfsPort}/tmp/iceberg/${database}"
+        assert new File(clientKeytabDir, fixture.keytab).canRead():
+                "Configure kerberosClientKeytabDir with both fixture keytabs"
+    }
+    // Hadoop 2.x uses global UGI state for SASL; isolate each realm from the 
parallel regression JVM.
+    String fileSystemScript = '''
+        import org.apache.hadoop.conf.Configuration
+        import org.apache.hadoop.fs.FileSystem
+        import org.apache.hadoop.fs.Path
+        import org.apache.hadoop.security.SecurityUtil
+        import org.apache.hadoop.security.UserGroupInformation
+        import java.security.PrivilegedExceptionAction
+
+        def (principal, keytab, warehouse, namenode, rules, phase, database) = 
args
+        URI root = new URI(warehouse)
+        assert database ==~ /manifest_auth_[0-9a-f]{12}/
+        assert root.scheme == "hdfs" && root.authority && root.query == null 
&& root.fragment == null
+        assert root.path == "/tmp/iceberg/${database}"
+        Configuration conf = new Configuration(false)
+        conf.set("hadoop.security.authentication", "kerberos")
+        conf.set("hadoop.security.auth_to_local", rules)
+        conf.set("dfs.namenode.kerberos.principal", namenode)
+        conf.set("fs.hdfs.impl", 
"org.apache.hadoop.hdfs.DistributedFileSystem")
+        conf.setBoolean("dfs.client.use.datanode.hostname", true)
+        conf.set("dfs.data.transfer.protection", "authentication")
+        SecurityUtil.setTokenServiceUseIp(false)
+        UserGroupInformation.setConfiguration(conf)
+        def identity = 
UserGroupInformation.loginUserFromKeytabAndReturnUGI(principal, keytab)
+        identity.doAs({
+            FileSystem fs = FileSystem.newInstance(root, conf)
+            try {
+                Path path = new Path(root)
+                if (phase == "cleanup" && fs.exists(path)) {
+                    assert fs.delete(path, true)
+                }
+                assert !fs.exists(path)
+            } finally {
+                fs.close()
+            }
+            return null
+        } as PrivilegedExceptionAction)
+    '''
+    def checkFileSystem = { fixture, phase ->
+        List<String> command = [new File(System.getProperty("java.home"), 
"bin/java").path,
+                "-Xmx256m", "-Djava.security.krb5.conf=${clientConfig}", "-cp",
+                System.getProperty("java.class.path"), "groovy.ui.GroovyMain", 
"-e", fileSystemScript, "--",
+                "hive/presto-master.docker.cluster@${fixture.realm}",
+                new File(clientKeytabDir, fixture.keytab).path, 
fixture.warehouse,
+                "hdfs/${fixture.host}@${fixture.realm}", rules.replace('\\n', 
'\n'), phase, database]
+                .collect { it.toString() }
+        String javaVersion = System.getProperty("java.specification.version")
+        int javaMajor = (javaVersion.startsWith("1.") ? 
javaVersion.substring(2) : javaVersion).tokenize(".")[0] as int
+        if (javaMajor >= 9) {
+            // Hadoop 2.x uses JDK-internal DNS and Kerberos helpers during 
authenticated IPC setup.
+            command.add(1, "--add-exports=java.base/sun.net.dns=ALL-UNNAMED")
+            command.add(1, "--add-exports=java.base/sun.net.util=ALL-UNNAMED")
+            command.add(1, 
"--add-exports=java.security.jgss/sun.security.krb5=ALL-UNNAMED")
+            command.add(1, 
"--add-exports=java.security.jgss/sun.security.jgss=ALL-UNNAMED")
+        }
+        File output = File.createTempFile("iceberg-manifest-filesystem-", 
".log")
+        Process process = null
+        Throwable processFailure = null
+        try {
+            process = new 
ProcessBuilder(command).redirectErrorStream(true).redirectOutput(output).start()
+            assert process.waitFor(60, java.util.concurrent.TimeUnit.SECONDS):
+                    "Timed out verifying the fixture HDFS directory"
+            assert process.exitValue() == 0: "Fixture HDFS verification 
failed: ${output.text}"
+        } catch (Throwable error) {
+            processFailure = error
+            throw error
+        } finally {
+            List<Throwable> errors = []
+            try {
+                if (process != null && process.isAlive()) {
+                    process.destroyForcibly()
+                    assert process.waitFor(10, 
java.util.concurrent.TimeUnit.SECONDS):
+                            "The fixture filesystem process did not terminate"
+                }
+            } catch (Throwable error) {
+                errors.add(error)
+            }
+            try {
+                java.nio.file.Files.deleteIfExists(output.toPath())
+            } catch (Throwable error) {
+                errors.add(error)
+            }
+            if (!errors.isEmpty()) {
+                if (processFailure != null) {
+                    errors.each { processFailure.addSuppressed(it) }
+                } else {
+                    errors.tail().each { errors[0].addSuppressed(it) }
+                    throw errors[0]
+                }
+            }
+        }
+    }
+    // Check both identities before creating SQL resources; a missing runner 
keytab must fail without leaking data.
+    fixtures.each { checkFileSystem(it, "prepare") }
+    def overwriteModeRows = sql "SHOW VARIABLES LIKE 
'iceberg_partition_overwrite_mode'"
+    String previousOverwriteMode = overwriteModeRows.isEmpty() ? null : 
overwriteModeRows[0][1].toString()
+    Throwable failure = null
+    try {
+        if (previousOverwriteMode != null) {
+            sql "SET iceberg_partition_overwrite_mode = 'dynamic'"
+        }
+        fixtures.each { fixture ->
+            // Keep the SDK HadoopFileIO: DelegateFileIO would mask a 
manifest-worker authentication regression.
+            sql """
+                CREATE CATALOG `${fixture.catalog}` PROPERTIES (
+                    "type" = "iceberg",
+                    "iceberg.catalog.type" = "hms",
+                    "warehouse" = "${fixture.warehouse}",
+                    "hive.metastore.uris" = 
"thrift://${externalEnvIp}:${fixture.hmsPort}",
+                    "hive.metastore.sasl.enabled" = "true",
+                    "hive.metastore.kerberos.principal" = 
"hive/${fixture.host}@${fixture.realm}",
+                    "fs.defaultFS" = 
"hdfs://${externalEnvIp}:${fixture.hdfsPort}",
+                    "hadoop.security.authentication" = "kerberos",
+                    "hadoop.kerberos.principal" = 
"hive/presto-master.docker.cluster@${fixture.realm}",
+                    "hadoop.kerberos.keytab" = "/keytabs/${fixture.keytab}",
+                    "hadoop.security.auth_to_local" = "${rules}",
+                    "dfs.namenode.kerberos.principal" = 
"hdfs/${fixture.host}@${fixture.realm}",
+                    "dfs.client.use.datanode.hostname" = "true",
+                    "hadoop.security.token.service.use_ip" = "false",
+                    "dfs.data.transfer.protection" = "authentication",
+                    "meta.cache.iceberg.manifest.enable" = "true"

Review Comment:
   Fixed in 30b299b315b8. The HMS fixture now explicitly selects 
org.apache.iceberg.hadoop.HadoopFileIO and sets io.manifest.cache-enabled=true. 
Actual HiveCatalog initialization and physical Avro manifest reads on both 
public target runtimes confirm the configured IO receives these properties: the 
warm read reuses cached bytes and cache eviction forces a physical reopen. 
Implicit construction with the cache property alone and explicit disabled 
caching are negative controls. The full Groovy suite compiles, its four 
cold-overwrite boundaries are unchanged, and 10 focused FE cache/manager tests 
passed on this target. Full deployed SQL/HMS regression execution remains for 
CI.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to