hello-stephen commented on code in PR #71396:
URL: https://github.com/apache/doris/pull/71396#discussion_r4795652735


##########
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:
   [P3] Recognize the mounted Kerberos config in the regression runner
   
   The external pipeline’s FE and BE configs use `/keytabs/krb5.conf`, and 
`run-regression-test.sh` launches the runner separately. If the fixture config 
and keytabs are mounted at `/keytabs` and the runner has no explicit override, 
this fallback uses `/etc/krb5.conf`. The suite can then fail HDFS preflight 
before any SQL despite having both fixture credentials available. Try a 
readable `/keytabs/krb5.conf` before the system fallback while preserving the 
explicit overrides. [FE 
configuration](https://github.com/apache/doris/blob/2b0413617115d1ade1030e7ddb161f65d58bb38b/regression-test/pipeline/external/conf/fe.conf#L106)
 · [Runner 
invocation](https://github.com/apache/doris/blob/2b0413617115d1ade1030e7ddb161f65d58bb38b/run-regression-test.sh#L280-L288)



##########
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:
   [P3] Enable the SDK manifest byte cache in the HMS fixture
   
   Without an explicit `io-impl`, Iceberg 1.11’s `HiveCatalog` constructs stock 
`HadoopFileIO` without calling `initialize` with the catalog properties. The 
SDK byte cache defaults off, so the row checks cannot warm the cache that the 
following catalog refreshes are meant to clear. Set 
`io-impl=org.apache.iceberg.hadoop.HadoopFileIO` and 
`io.manifest.cache-enabled=true` to exercise that scenario while keeping the 
exact FileIO class the adapter accepts. [Catalog 
initialization](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/hive-metastore/src/main/java/org/apache/iceberg/hive/HiveCatalog.java#L115-L121)
 · [FileIO 
initialization](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/core/src/main/java/org/apache/iceberg/CatalogUtil.java#L390-L396)
 · [Cache 
default](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/core/src/main/java/org/apache/iceberg/CatalogProperties.java#L71-L72)



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