hello-stephen commented on code in PR #71396: URL: https://github.com/apache/doris/pull/71396#discussion_r4796899066
########## regression-test/suites/external_table_p0/kerberos/test_iceberg_hms_manifest_kerberos.groovy: ########## @@ -0,0 +1,267 @@ +// 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") + if (!clientConfig) { + // The runner does not inherit FE/BE JVM options, but shares the fixture's mounted credentials. + File mountedConfig = new File("/keytabs/krb5.conf") + clientConfig = mountedConfig.isFile() && mountedConfig.canRead() ? mountedConfig.path : "/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. + // HiveCatalog only initializes FileIO properties when an explicit implementation is selected. + 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}", Review Comment: [P3] Make the server keytab directory configurable On a same-host rootless run, the fixture launcher writes the keytabs beside the generated `krb5.conf` and leaves `/keytabs` untouched. The runner can pass preflight with the adjacent keytabs, then the first catalog operation fails when the FE logs in using the literal path in this property. Add a server-side keytab directory override, keeping `/keytabs` as the default for deployments that mount credentials there. [Rootless fixture layout](https://github.com/apache/doris/blob/30b299b315b8616bafc90c072e82a195f6a5cdd5/docker/thirdparties/README.md#L60-L63) · [FE authentication setup](https://github.com/apache/doris/blob/30b299b315b8616bafc90c072e82a195f6a5cdd5/fe/fe-core/src/main/java/org/apache/doris/datasource/property/metastore/HMSBaseProperties.java#L174-L180) ########## regression-test/suites/external_table_p0/kerberos/test_iceberg_hms_manifest_kerberos.groovy: ########## @@ -0,0 +1,267 @@ +// 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") + if (!clientConfig) { + // The runner does not inherit FE/BE JVM options, but shares the fixture's mounted credentials. + File mountedConfig = new File("/keytabs/krb5.conf") + clientConfig = mountedConfig.isFile() && mountedConfig.canRead() ? mountedConfig.path : "/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. + // HiveCatalog only initializes FileIO properties when an explicit implementation is selected. + 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", + "io-impl" = "org.apache.iceberg.hadoop.HadoopFileIO", + "io.manifest.cache-enabled" = "true" + ) + """ + sql """CREATE DATABASE `${fixture.catalog}`.`${database}` + PROPERTIES ("location" = "${fixture.warehouse}/database")""" + sql """ + CREATE TABLE `${fixture.catalog}`.`${database}`.events (id INT, payload STRING) + ENGINE = iceberg PROPERTIES ("write-format" = "parquet") + """ + sql """ + CREATE TABLE `${fixture.catalog}`.`${database}`.empty_source (id INT, payload STRING) + ENGINE = iceberg PROPERTIES ("write-format" = "parquet") + """ + } + def tableName = { fixture -> "`${fixture.catalog}`.`${database}`.events" } + def checkRows = { fixture, expected -> + sql "REFRESH TABLE ${tableName(fixture)}" + def rows = sql "SELECT id, payload FROM ${tableName(fixture)} ORDER BY id" + assertEquals(expected, rows.collect { row -> row.collect { value -> value.toString() } }) + } + // Alternate realms on the same FE so a shared SDK worker must not retain the previous catalog's identity. Review Comment: [P3] Ensure the Kerberos regression reuses SDK workers On a fresh JDK 17 FE with a large Iceberg worker pool, these writes can each get a newly created worker. The worker can inherit the submitting catalog’s subject, so secured manifest opens can succeed even when the FileIO adapter is bypassed. The catalog refreshes clear cached bytes but do not affect worker creation. Prestart the regression FE’s SDK workers outside either catalog identity, as the FE unit test does, or configure the test FE to force worker reuse before the assertions. [Iceberg worker pool](https://github.com/apache/iceberg/blob/apache-iceberg-1.11.0/core/src/main/java/org/apache/iceberg/util/ThreadPools.java#L140-L146) · [JDK 17 thread context](https://github.com/openjdk/jdk17u/blob/master/src/java.base/share/classes/java/lang/Thread.java#L427-L428) -- 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]
