World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#3896] feat(catalog-lakehouse-paimon): Support kerberos auth for Paimon FilesystemCatalog (#4075)
cai can80cc26acd079
diff --git a/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/authentication/AuthenticationConfig.java b/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/authentication/AuthenticationConfig.javaindex 2c26eae9a8..ebf96196d0 100644--- a/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/authentication/AuthenticationConfig.java+++ b/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/authentication/AuthenticationConfig.java@@ -79,7 +79,7 @@ public class AuthenticationConfig extends Config {AUTH_TYPE_KEY,PropertyEntry.stringImmutablePropertyEntry(AUTH_TYPE_KEY,- "The type of authentication for Hadoop catalog, currently we only support Kerberos",+ "The type of authentication for Hadoop catalog, currently we only support simple and Kerberos",false,null,false,diff --git a/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/authentication/kerberos/KerberosClient.java b/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/authentication/kerberos/KerberosClient.javaindex daae9f45b3..b0965729b1 100644--- a/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/authentication/kerberos/KerberosClient.java+++ b/catalogs/catalog-hadoop/src/main/java/org/apache/gravitino/catalog/hadoop/authentication/kerberos/KerberosClient.java@@ -39,7 +39,7 @@ import org.slf4j.LoggerFactory;public class KerberosClient {private static final Logger LOG = LoggerFactory.getLogger(KerberosClient.class);- public static final String GRAVITINO_KEYTAB_FORMAT = "keytabs/gravitino-%s-keytab";+ public static final String GRAVITINO_KEYTAB_FORMAT = "keytabs/gravitino-hadoop-%s-keytab";private final ScheduledThreadPoolExecutor checkTgtExecutor;private final Map<String, String> conf;diff --git a/catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveCatalogOperations.java b/catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveCatalogOperations.javaindex 2036a6b518..572af9fe19 100644--- a/catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveCatalogOperations.java+++ b/catalogs/catalog-hive/src/main/java/org/apache/gravitino/catalog/hive/HiveCatalogOperations.java@@ -106,7 +106,7 @@ import org.slf4j.LoggerFactory;public class HiveCatalogOperations implements CatalogOperations, SupportsSchemas, TableCatalog {public static final Logger LOG = LoggerFactory.getLogger(HiveCatalogOperations.class);- public static final String GRAVITINO_KEYTAB_FORMAT = "keytabs/gravitino-%s-keytab";+ public static final String GRAVITINO_KEYTAB_FORMAT = "keytabs/gravitino-hive-%s-keytab";@VisibleForTesting CachedClientPool clientPool;diff --git a/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/authentication/AuthenticationConfig.java b/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/authentication/AuthenticationConfig.javaindex e0ca926043..d4050c3d17 100644--- a/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/authentication/AuthenticationConfig.java+++ b/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/authentication/AuthenticationConfig.java@@ -93,7 +93,7 @@ public class AuthenticationConfig extends Config {AUTH_TYPE_KEY,PropertyEntry.stringImmutablePropertyEntry(AUTH_TYPE_KEY,- "The type of authentication for Hadoop catalog, currently we support simple Kerberos",+ "The type of authentication for Hadoop catalog, currently we only support simple and Kerberos",false,"simple",false,diff --git a/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/authentication/kerberos/KerberosConfig.java b/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/authentication/kerberos/KerberosConfig.javaindex 22f11119a6..b1a43944e5 100644--- a/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/authentication/kerberos/KerberosConfig.java+++ b/catalogs/catalog-lakehouse-iceberg/src/main/java/org/apache/gravitino/catalog/lakehouse/iceberg/authentication/kerberos/KerberosConfig.java@@ -38,7 +38,8 @@ public class KerberosConfig extends AuthenticationConfig {public static final String FETCH_TIMEOUT_SEC_KEY ="authentication.kerberos.keytab-fetch-timeout-sec";- public static final String GRAVITINO_KEYTAB_FORMAT = "keytabs/gravitino-%s-keytab";+ public static final String GRAVITINO_KEYTAB_FORMAT =+ "keytabs/gravitino-lakehouse-iceberg-%s-keytab";public static final ConfigEntry<String> PRINCIPAL_ENTRY =new ConfigBuilder(PRINCIPAL_KEY)diff --git a/catalogs/catalog-lakehouse-paimon/build.gradle.kts b/catalogs/catalog-lakehouse-paimon/build.gradle.ktsindex 3df919bb39..e7ef41b233 100644--- a/catalogs/catalog-lakehouse-paimon/build.gradle.kts+++ b/catalogs/catalog-lakehouse-paimon/build.gradle.kts@@ -39,6 +39,7 @@ dependencies {}implementation(libs.bundles.log4j)implementation(libs.commons.lang3)+ implementation(libs.caffeine)implementation(libs.guava)implementation(libs.hadoop2.common) {exclude("com.github.spotbugs")@@ -138,6 +139,7 @@ tasks.test {doFirst {environment("GRAVITINO_CI_HIVE_DOCKER_IMAGE", "datastrato/gravitino-ci-hive:0.1.12")+ environment("GRAVITINO_CI_KERBEROS_HIVE_DOCKER_IMAGE", "datastrato/gravitino-ci-kerberos-hive:0.1.3")}val init = project.extra.get("initIntegrationTest") as (Test) -> Unitdiff --git a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonCatalogPropertiesMetadata.java b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonCatalogPropertiesMetadata.javaindex ee0b506fb7..9ea3e43fd8 100644--- a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonCatalogPropertiesMetadata.java+++ b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/PaimonCatalogPropertiesMetadata.java@@ -29,6 +29,8 @@ import com.google.common.collect.Maps;import java.util.HashMap;import java.util.List;import java.util.Map;+import org.apache.gravitino.catalog.lakehouse.paimon.authentication.AuthenticationConfig;+import org.apache.gravitino.catalog.lakehouse.paimon.authentication.kerberos.KerberosConfig;import org.apache.gravitino.connector.BaseCatalogPropertiesMetadata;import org.apache.gravitino.connector.PropertiesMetadata;import org.apache.gravitino.connector.PropertyEntry;@@ -43,9 +45,21 @@ public class PaimonCatalogPropertiesMetadata extends BaseCatalogPropertiesMetada@VisibleForTesting public static final String WAREHOUSE = "warehouse";@VisibleForTesting public static final String URI = "uri";- private static final Map<String, PropertyEntry<?>> PROPERTIES_METADATA;- private static final Map<String, String> GRAVITINO_CONFIG_TO_PAIMON =+ public static final Map<String, String> GRAVITINO_CONFIG_TO_PAIMON =ImmutableMap.of(GRAVITINO_CATALOG_BACKEND, PAIMON_METASTORE, WAREHOUSE, WAREHOUSE, URI, URI);+ private static final Map<String, PropertyEntry<?>> PROPERTIES_METADATA;+ private static final Map<String, String> KERBEROS_CONFIGURATION =+ ImmutableMap.of(+ KerberosConfig.PRINCIPAL_KEY,+ KerberosConfig.PRINCIPAL_KEY,+ KerberosConfig.KEY_TAB_URI_KEY,+ KerberosConfig.KEY_TAB_URI_KEY,+ KerberosConfig.CHECK_INTERVAL_SEC_KEY,+ KerberosConfig.CHECK_INTERVAL_SEC_KEY,+ KerberosConfig.FETCH_TIMEOUT_SEC_KEY,+ KerberosConfig.FETCH_TIMEOUT_SEC_KEY,+ AuthenticationConfig.AUTH_TYPE_KEY,+ AuthenticationConfig.AUTH_TYPE_KEY);static {List<PropertyEntry<?>> propertyEntries =@@ -62,6 +76,8 @@ public class PaimonCatalogPropertiesMetadata extends BaseCatalogPropertiesMetadastringOptionalPropertyEntry(URI, "Paimon catalog uri config", false, null, false));HashMap<String, PropertyEntry<?>> result = Maps.newHashMap(BASIC_CATALOG_PROPERTY_ENTRIES);result.putAll(Maps.uniqueIndex(propertyEntries, PropertyEntry::getName));+ result.putAll(KerberosConfig.KERBEROS_PROPERTY_ENTRIES);+ result.putAll(AuthenticationConfig.AUTHENTICATION_PROPERTY_ENTRIES);PROPERTIES_METADATA = ImmutableMap.copyOf(result);}@@ -77,6 +93,10 @@ public class PaimonCatalogPropertiesMetadata extends BaseCatalogPropertiesMetadaif (GRAVITINO_CONFIG_TO_PAIMON.containsKey(key)) {gravitinoConfig.put(GRAVITINO_CONFIG_TO_PAIMON.get(key), value);}++ if (KERBEROS_CONFIGURATION.containsKey(key)) {+ gravitinoConfig.put(KERBEROS_CONFIGURATION.get(key), value);+ }});return gravitinoConfig;}diff --git a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/authentication/AuthenticationConfig.java b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/authentication/AuthenticationConfig.javanew file mode 100644index 0000000000..7d05a430a5--- /dev/null+++ b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/authentication/AuthenticationConfig.java@@ -0,0 +1,76 @@+/*+ * 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.gravitino.catalog.lakehouse.paimon.authentication;++import com.google.common.collect.ImmutableMap;+import java.util.Map;+import org.apache.gravitino.Config;+import org.apache.gravitino.config.ConfigBuilder;+import org.apache.gravitino.config.ConfigConstants;+import org.apache.gravitino.config.ConfigEntry;+import org.apache.gravitino.connector.PropertyEntry;++public class AuthenticationConfig extends Config {++ // The key for the authentication type, currently we support Kerberos and simple+ public static final String AUTH_TYPE_KEY = "authentication.type";++ enum AuthenticationType {+ SIMPLE,+ KERBEROS+ }++ public AuthenticationConfig(Map<String, String> properties) {+ super(false);+ loadFromMap(properties, k -> true);+ }++ public static final ConfigEntry<String> AUTH_TYPE_ENTRY =+ new ConfigBuilder(AUTH_TYPE_KEY)+ .doc(+ "The type of authentication for Paimon catalog, currently we only support simple and Kerberos")+ .version(ConfigConstants.VERSION_0_6_0)+ .stringConf()+ .createWithDefault("simple");++ public String getAuthType() {+ return get(AUTH_TYPE_ENTRY);+ }++ public boolean isSimpleAuth() {+ return AuthenticationType.SIMPLE.name().equalsIgnoreCase(getAuthType());+ }++ public boolean isKerberosAuth() {+ return AuthenticationType.KERBEROS.name().equalsIgnoreCase(getAuthType());+ }++ public static final Map<String, PropertyEntry<?>> AUTHENTICATION_PROPERTY_ENTRIES =+ new ImmutableMap.Builder<String, PropertyEntry<?>>()+ .put(+ AUTH_TYPE_KEY,+ PropertyEntry.stringImmutablePropertyEntry(+ AUTH_TYPE_KEY,+ "The type of authentication for Paimon catalog, currently we only support simple and Kerberos",+ false,+ null,+ false,+ false))+ .build();+}diff --git a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/authentication/kerberos/FetchFileUtils.java b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/authentication/kerberos/FetchFileUtils.javanew file mode 100644index 0000000000..29cfdc37c5--- /dev/null+++ b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/authentication/kerberos/FetchFileUtils.java@@ -0,0 +1,58 @@+/*+ * 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.gravitino.catalog.lakehouse.paimon.authentication.kerberos;++import java.io.File;+import java.io.IOException;+import java.net.URI;+import java.net.URISyntaxException;+import java.nio.file.Files;+import java.util.Optional;+import org.apache.commons.io.FileUtils;++public class FetchFileUtils {++ private FetchFileUtils() {}++ public static void fetchFileFromUri(String fileUri, File destFile, int timeout)+ throws IOException {+ try {+ URI uri = new URI(fileUri);+ String scheme = Optional.ofNullable(uri.getScheme()).orElse("file");++ switch (scheme) {+ case "http":+ case "https":+ case "ftp":+ FileUtils.copyURLToFile(uri.toURL(), destFile, timeout * 1000, timeout * 1000);+ break;++ case "file":+ Files.createSymbolicLink(destFile.toPath(), new File(uri.getPath()).toPath());+ break;++ default:+ throw new IllegalArgumentException(+ String.format("Doesn't support the scheme %s", scheme));+ }+ } catch (URISyntaxException ue) {+ throw new IllegalArgumentException("The uri of file has the wrong format", ue);+ }+ }+}diff --git a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/authentication/kerberos/KerberosClient.java b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/authentication/kerberos/KerberosClient.javanew file mode 100644index 0000000000..7f1685af90--- /dev/null+++ b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/authentication/kerberos/KerberosClient.java@@ -0,0 +1,120 @@+/*+ * 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.gravitino.catalog.lakehouse.paimon.authentication.kerberos;++import com.google.common.util.concurrent.ThreadFactoryBuilder;+import java.io.Closeable;+import java.io.File;+import java.io.IOException;+import java.util.Map;+import java.util.concurrent.ScheduledThreadPoolExecutor;+import java.util.concurrent.ThreadFactory;+import java.util.concurrent.TimeUnit;+import org.apache.hadoop.conf.Configuration;+import org.apache.hadoop.security.UserGroupInformation;+import org.apache.hadoop.security.authentication.util.KerberosName;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;++public class KerberosClient implements Closeable {+ private static final Logger LOG = LoggerFactory.getLogger(KerberosClient.class);++ public static final String GRAVITINO_KEYTAB_FORMAT =+ "keytabs/gravitino-lakehouse-paimon-%s-keytab";++ private final ScheduledThreadPoolExecutor checkTgtExecutor;+ private final Map<String, String> conf;+ private final Configuration hadoopConf;++ public KerberosClient(Map<String, String> conf, Configuration hadoopConf) {+ this.conf = conf;+ this.hadoopConf = hadoopConf;+ this.checkTgtExecutor = new ScheduledThreadPoolExecutor(1, getThreadFactory("check-tgt"));+ }++ /**+ * performing kerberos authentication based on the keytab file.+ *+ * @param keytabFilePath local keytab file path+ * @throws IOException+ */+ public void login(String keytabFilePath) throws IOException {+ KerberosConfig kerberosConfig = new KerberosConfig(conf);++ // Check the principal and keytab file+ String catalogPrincipal = kerberosConfig.getPrincipalName();++ // Login+ UserGroupInformation.setConfiguration(hadoopConf);+ KerberosName.resetDefaultRealm();+ UserGroupInformation.loginUserFromKeytab(catalogPrincipal, keytabFilePath);+ UserGroupInformation kerberosLoginUgi = UserGroupInformation.getCurrentUser();++ // Refresh the cache if it's out of date.+ int checkInterval = kerberosConfig.getCheckIntervalSec();+ checkTgtExecutor.scheduleAtFixedRate(+ () -> {+ try {+ kerberosLoginUgi.checkTGTAndReloginFromKeytab();+ } catch (Exception e) {+ LOG.error("Fail to refresh ugi token: ", e);+ }+ },+ checkInterval,+ checkInterval,+ TimeUnit.SECONDS);+ }++ public File saveKeyTabFileFromUri(String catalogId) throws IOException {++ KerberosConfig kerberosConfig = new KerberosConfig(conf);++ String keyTabUri = kerberosConfig.getKeytab();++ File keytabsDir = new File("keytabs");+ if (!keytabsDir.exists()) {+ // Ignore the return value, because there exists many Paimon catalog operations making+ // this directory.+ keytabsDir.mkdir();+ }++ File keytabFile = new File(String.format(GRAVITINO_KEYTAB_FORMAT, catalogId));+ keytabFile.deleteOnExit();+ if (keytabFile.exists() && !keytabFile.delete()) {+ throw new IllegalStateException(+ String.format("Fail to delete keytab file %s", keytabFile.getAbsolutePath()));+ }++ int fetchKeytabFileTimeout = kerberosConfig.getFetchTimeoutSec();+ FetchFileUtils.fetchFileFromUri(keyTabUri, keytabFile, fetchKeytabFileTimeout);++ return keytabFile;+ }++ private static ThreadFactory getThreadFactory(String factoryName) {+ return new ThreadFactoryBuilder().setDaemon(true).setNameFormat(factoryName + "-%d").build();+ }++ @Override+ public void close() {+ if (checkTgtExecutor != null) {+ checkTgtExecutor.shutdown();+ }+ }+}diff --git a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/authentication/kerberos/KerberosConfig.java b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/authentication/kerberos/KerberosConfig.javanew file mode 100644index 0000000000..2f03c88412--- /dev/null+++ b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/authentication/kerberos/KerberosConfig.java@@ -0,0 +1,116 @@+/*+ * 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.gravitino.catalog.lakehouse.paimon.authentication.kerberos;++import com.google.common.collect.ImmutableMap;+import java.util.Map;+import org.apache.commons.lang3.StringUtils;+import org.apache.gravitino.catalog.lakehouse.paimon.authentication.AuthenticationConfig;+import org.apache.gravitino.config.ConfigBuilder;+import org.apache.gravitino.config.ConfigConstants;+import org.apache.gravitino.config.ConfigEntry;+import org.apache.gravitino.connector.PropertyEntry;++public class KerberosConfig extends AuthenticationConfig {+ public static final String KEY_TAB_URI_KEY = "authentication.kerberos.keytab-uri";++ public static final String PRINCIPAL_KEY = "authentication.kerberos.principal";++ public static final String CHECK_INTERVAL_SEC_KEY = "authentication.kerberos.check-interval-sec";++ public static final String FETCH_TIMEOUT_SEC_KEY =+ "authentication.kerberos.keytab-fetch-timeout-sec";++ public static final ConfigEntry<String> PRINCIPAL_ENTRY =+ new ConfigBuilder(PRINCIPAL_KEY)+ .doc("The principal of the Kerberos connection")+ .version(ConfigConstants.VERSION_0_6_0)+ .stringConf()+ .checkValue(StringUtils::isNotBlank, ConfigConstants.NOT_BLANK_ERROR_MSG)+ .create();++ public static final ConfigEntry<String> KEYTAB_ENTRY =+ new ConfigBuilder(KEY_TAB_URI_KEY)+ .doc("The keytab of the Kerberos connection")+ .version(ConfigConstants.VERSION_0_6_0)+ .stringConf()+ .checkValue(StringUtils::isNotBlank, ConfigConstants.NOT_BLANK_ERROR_MSG)+ .create();++ public static final ConfigEntry<Integer> CHECK_INTERVAL_SEC_ENTRY =+ new ConfigBuilder(CHECK_INTERVAL_SEC_KEY)+ .doc("The check interval of the Kerberos connection for Paimon catalog")+ .version(ConfigConstants.VERSION_0_6_0)+ .intConf()+ .checkValue(value -> value > 0, ConfigConstants.POSITIVE_NUMBER_ERROR_MSG)+ .createWithDefault(2);++ public static final ConfigEntry<Integer> FETCH_TIMEOUT_SEC_ENTRY =+ new ConfigBuilder(FETCH_TIMEOUT_SEC_KEY)+ .doc("The fetch timeout of the Kerberos connection")+ .version(ConfigConstants.VERSION_0_6_0)+ .intConf()+ .checkValue(value -> value > 0, ConfigConstants.POSITIVE_NUMBER_ERROR_MSG)+ .createWithDefault(2);++ public KerberosConfig(Map<String, String> properties) {+ super(properties);+ loadFromMap(properties, k -> true);+ }++ public String getPrincipalName() {+ return get(PRINCIPAL_ENTRY);+ }++ public String getKeytab() {+ return get(KEYTAB_ENTRY);+ }++ public int getCheckIntervalSec() {+ return get(CHECK_INTERVAL_SEC_ENTRY);+ }++ public int getFetchTimeoutSec() {+ return get(FETCH_TIMEOUT_SEC_ENTRY);+ }++ public static final Map<String, PropertyEntry<?>> KERBEROS_PROPERTY_ENTRIES =+ new ImmutableMap.Builder<String, PropertyEntry<?>>()+ .put(+ KEY_TAB_URI_KEY,+ PropertyEntry.stringImmutablePropertyEntry(+ KEY_TAB_URI_KEY, "The uri of key tab for the catalog", false, null, false, false))+ .put(+ PRINCIPAL_KEY,+ PropertyEntry.stringImmutablePropertyEntry(+ PRINCIPAL_KEY, "The principal for the catalog", false, null, false, false))+ .put(+ CHECK_INTERVAL_SEC_KEY,+ PropertyEntry.integerOptionalPropertyEntry(+ CHECK_INTERVAL_SEC_KEY,+ "The interval to check validness of the principal",+ true,+ 60,+ false))+ .put(+ FETCH_TIMEOUT_SEC_KEY,+ PropertyEntry.integerOptionalPropertyEntry(+ FETCH_TIMEOUT_SEC_KEY, "The timeout to fetch key tab", true, 60, false))+ .build();+}diff --git a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/ops/PaimonBackendCatalogWrapper.java b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/ops/PaimonBackendCatalogWrapper.javanew file mode 100644index 0000000000..dbb6f612ff--- /dev/null+++ b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/ops/PaimonBackendCatalogWrapper.java@@ -0,0 +1,45 @@+/*+ * 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.gravitino.catalog.lakehouse.paimon.ops;++import com.google.common.annotations.VisibleForTesting;+import java.io.Closeable;+import lombok.Getter;+import org.apache.paimon.catalog.Catalog;++@Getter+public class PaimonBackendCatalogWrapper {++ @VisibleForTesting private final Catalog catalog;+ private final Closeable closeableResource;++ public PaimonBackendCatalogWrapper(Catalog catalog, Closeable closeableResource) {+ this.catalog = catalog;+ this.closeableResource = closeableResource;+ }++ public void close() throws Exception {+ if (catalog != null) {+ catalog.close();+ }+ if (closeableResource != null) {+ closeableResource.close();+ }+ }+}diff --git a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/ops/PaimonCatalogOps.java b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/ops/PaimonCatalogOps.javaindex 6694500c99..ed5c2de711 100644--- a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/ops/PaimonCatalogOps.java+++ b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/ops/PaimonCatalogOps.java@@ -20,6 +20,7 @@ package org.apache.gravitino.catalog.lakehouse.paimon.ops;import static org.apache.gravitino.catalog.lakehouse.paimon.utils.CatalogUtils.loadCatalogBackend;+import com.google.common.base.Preconditions;import java.util.List;import java.util.Map;import org.apache.gravitino.catalog.lakehouse.paimon.PaimonConfig;@@ -35,16 +36,21 @@ import org.apache.paimon.table.Table;/** Table operation proxy that handles table operations of an underlying Apache Paimon catalog. */public class PaimonCatalogOps implements AutoCloseable {+ private final PaimonBackendCatalogWrapper paimonBackendCatalogWrapper;protected Catalog catalog;public PaimonCatalogOps(PaimonConfig paimonConfig) {- catalog = loadCatalogBackend(paimonConfig);+ paimonBackendCatalogWrapper = loadCatalogBackend(paimonConfig);+ Preconditions.checkArgument(+ paimonBackendCatalogWrapper.getCatalog() != null,+ "Can not load Paimon backend catalog instance.");+ catalog = paimonBackendCatalogWrapper.getCatalog();}@Overridepublic void close() throws Exception {- if (catalog != null) {- catalog.close();+ if (paimonBackendCatalogWrapper != null) {+ paimonBackendCatalogWrapper.close();}}diff --git a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/CatalogUtils.java b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/CatalogUtils.javaindex 7fe226b03f..fcc4f3088a 100644--- a/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/CatalogUtils.java+++ b/catalogs/catalog-lakehouse-paimon/src/main/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/CatalogUtils.java@@ -21,11 +21,21 @@ package org.apache.gravitino.catalog.lakehouse.paimon.utils;import static org.apache.gravitino.catalog.lakehouse.paimon.PaimonConfig.CATALOG_BACKEND;import static org.apache.gravitino.catalog.lakehouse.paimon.PaimonConfig.CATALOG_URI;import static org.apache.gravitino.catalog.lakehouse.paimon.PaimonConfig.CATALOG_WAREHOUSE;+import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION;+import static org.apache.hadoop.fs.CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION;+import com.google.common.annotations.VisibleForTesting;import com.google.common.base.Preconditions;+import java.io.File;+import java.util.Map;+import java.util.UUID;import org.apache.commons.lang3.StringUtils;import org.apache.gravitino.catalog.lakehouse.paimon.PaimonCatalogBackend;import org.apache.gravitino.catalog.lakehouse.paimon.PaimonConfig;+import org.apache.gravitino.catalog.lakehouse.paimon.authentication.AuthenticationConfig;+import org.apache.gravitino.catalog.lakehouse.paimon.authentication.kerberos.KerberosClient;+import org.apache.gravitino.catalog.lakehouse.paimon.ops.PaimonBackendCatalogWrapper;+import org.apache.hadoop.conf.Configuration;import org.apache.paimon.catalog.Catalog;import org.apache.paimon.catalog.CatalogContext;import org.apache.paimon.catalog.CatalogFactory;@@ -36,27 +46,80 @@ public class CatalogUtils {private CatalogUtils() {}+ @VisibleForTesting+ public static PaimonBackendCatalogWrapper loadCatalogBackend(PaimonConfig paimonConfig) {+ Map<String, String> allConfig = paimonConfig.getAllConfig();+ AuthenticationConfig authenticationConfig = new AuthenticationConfig(allConfig);+ if (authenticationConfig.isSimpleAuth()) {+ return new PaimonBackendCatalogWrapper(loadCatalogBackendWithSimpleAuth(paimonConfig), null);+ } else if (authenticationConfig.isKerberosAuth()) {+ Configuration configuration = new Configuration();+ allConfig.forEach(configuration::set);+ configuration.set(HADOOP_SECURITY_AUTHORIZATION, "true");+ configuration.set(HADOOP_SECURITY_AUTHENTICATION, "kerberos");++ try {+ KerberosClient kerberosClient = new KerberosClient(allConfig, configuration);+ File keytabFile =+ kerberosClient.saveKeyTabFileFromUri(UUID.randomUUID().toString().replace("-", ""));+ kerberosClient.login(keytabFile.getAbsolutePath());+ Catalog catalog = loadCatalogBackendWithKerberosAuth(paimonConfig, configuration);+ return new PaimonBackendCatalogWrapper(catalog, kerberosClient);+ } catch (Exception e) {+ throw new RuntimeException("Failed to login with kerberos", e);+ }+ } else {+ throw new UnsupportedOperationException(+ "Unsupported authentication method: " + authenticationConfig.getAuthType());+ }+ }++ /**+ * Loads {@link Catalog} instance with given {@link PaimonConfig} with kerberos auth.+ *+ * @param paimonConfig The Paimon configuration.+ * @return The {@link Catalog} instance of catalog backend.+ */+ public static Catalog loadCatalogBackendWithKerberosAuth(+ PaimonConfig paimonConfig, Configuration configuration) {+ checkPaimonConfig(paimonConfig);++ // TODO: Now we only support kerberos auth for Filesystem backend, and will support it for Hive+ // backend later.+ Preconditions.checkArgument(+ PaimonCatalogBackend.FILESYSTEM.name().equalsIgnoreCase(paimonConfig.get(CATALOG_BACKEND)));++ CatalogContext catalogContext =+ CatalogContext.create(Options.fromMap(paimonConfig.getAllConfig()), configuration);+ return CatalogFactory.createCatalog(catalogContext);+ }+/**- * Loads {@link Catalog} instance with given {@link PaimonConfig}.+ * Loads {@link Catalog} instance with given {@link PaimonConfig} with simple auth.** @param paimonConfig The Paimon configuration.* @return The {@link Catalog} instance of catalog backend.*/- public static Catalog loadCatalogBackend(PaimonConfig paimonConfig) {+ public static Catalog loadCatalogBackendWithSimpleAuth(PaimonConfig paimonConfig) {+ checkPaimonConfig(paimonConfig);+ CatalogContext catalogContext =+ CatalogContext.create(Options.fromMap(paimonConfig.getAllConfig()));+ return CatalogFactory.createCatalog(catalogContext);+ }++ private static void checkPaimonConfig(PaimonConfig paimonConfig) {String metastore = paimonConfig.get(CATALOG_BACKEND);Preconditions.checkArgument(StringUtils.isNotBlank(metastore), "Paimon Catalog metastore can not be null or empty.");+String warehouse = paimonConfig.get(CATALOG_WAREHOUSE);Preconditions.checkArgument(StringUtils.isNotBlank(warehouse), "Paimon Catalog warehouse can not be null or empty.");+if (!PaimonCatalogBackend.FILESYSTEM.name().equalsIgnoreCase(metastore)) {String uri = paimonConfig.get(CATALOG_URI);Preconditions.checkArgument(- StringUtils.isNotBlank(uri),- String.format("Paimon Catalog uri can not be null or empty for %s.", metastore));+ StringUtils.isNotBlank(uri), "Paimon Catalog uri can not be null or empty.");}- CatalogContext catalogContext =- CatalogContext.create(Options.fromMap(paimonConfig.getAllConfig()));- return CatalogFactory.createCatalog(catalogContext);}}diff --git a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonBaseIT.java b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonBaseIT.javaindex 059b50fa5b..399042ef03 100644--- a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonBaseIT.java+++ b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonBaseIT.java@@ -38,6 +38,7 @@ import org.apache.gravitino.SchemaChange;import org.apache.gravitino.SupportsSchemas;import org.apache.gravitino.catalog.lakehouse.paimon.PaimonCatalogPropertiesMetadata;import org.apache.gravitino.catalog.lakehouse.paimon.PaimonConfig;+import org.apache.gravitino.catalog.lakehouse.paimon.ops.PaimonBackendCatalogWrapper;import org.apache.gravitino.catalog.lakehouse.paimon.utils.CatalogUtils;import org.apache.gravitino.client.GravitinoMetalake;import org.apache.gravitino.dto.util.DTOConverters;@@ -525,7 +526,9 @@ public abstract class CatalogPaimonBaseIT extends AbstractIT {Preconditions.checkArgument(StringUtils.isNotBlank(type), "Paimon Catalog backend type can not be null or empty.");catalogProperties.put(PaimonCatalogPropertiesMetadata.PAIMON_METASTORE, type);- paimonCatalog = CatalogUtils.loadCatalogBackend(new PaimonConfig(catalogProperties));+ PaimonBackendCatalogWrapper paimonBackendCatalogWrapper =+ CatalogUtils.loadCatalogBackend(new PaimonConfig(catalogProperties));+ paimonCatalog = paimonBackendCatalogWrapper.getCatalog();}private void createSchema() {diff --git a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonKerberosFilesystemIT.java b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonKerberosFilesystemIT.javanew file mode 100644index 0000000000..007c902b93--- /dev/null+++ b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/integration/test/CatalogPaimonKerberosFilesystemIT.java@@ -0,0 +1,290 @@+/*+ * 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.gravitino.catalog.lakehouse.paimon.integration.test;++import static org.apache.gravitino.catalog.lakehouse.paimon.authentication.AuthenticationConfig.AUTH_TYPE_KEY;+import static org.apache.gravitino.catalog.lakehouse.paimon.authentication.kerberos.KerberosConfig.KEY_TAB_URI_KEY;+import static org.apache.gravitino.catalog.lakehouse.paimon.authentication.kerberos.KerberosConfig.PRINCIPAL_KEY;++import com.google.common.base.Throwables;+import com.google.common.collect.ImmutableMap;+import com.google.common.collect.Maps;+import java.io.File;+import java.lang.reflect.Method;+import java.nio.charset.StandardCharsets;+import java.nio.file.Files;+import java.util.Map;+import org.apache.commons.io.FileUtils;+import org.apache.gravitino.Catalog;+import org.apache.gravitino.NameIdentifier;+import org.apache.gravitino.catalog.lakehouse.paimon.PaimonCatalogPropertiesMetadata;+import org.apache.gravitino.client.GravitinoAdminClient;+import org.apache.gravitino.client.GravitinoMetalake;+import org.apache.gravitino.client.KerberosTokenProvider;+import org.apache.gravitino.integration.test.container.ContainerSuite;+import org.apache.gravitino.integration.test.container.HiveContainer;+import org.apache.gravitino.integration.test.util.AbstractIT;+import org.apache.gravitino.integration.test.util.GravitinoITUtils;+import org.apache.gravitino.rel.Column;+import org.apache.gravitino.rel.Table;+import org.apache.gravitino.rel.expressions.distributions.Distributions;+import org.apache.gravitino.rel.expressions.sorts.SortOrders;+import org.apache.gravitino.rel.expressions.transforms.Transforms;+import org.apache.gravitino.rel.types.Types;+import org.apache.hadoop.security.UserGroupInformation;+import org.apache.hadoop.security.authentication.util.KerberosName;+import org.apache.hadoop.security.authentication.util.KerberosUtil;+import org.junit.jupiter.api.AfterAll;+import org.junit.jupiter.api.Assertions;+import org.junit.jupiter.api.BeforeAll;+import org.junit.jupiter.api.Tag;+import org.junit.jupiter.api.Test;+import org.junit.jupiter.api.TestInstance;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;++@Tag("gravitino-docker-it")+@TestInstance(TestInstance.Lifecycle.PER_CLASS)+public class CatalogPaimonKerberosFilesystemIT extends AbstractIT {++ private static final Logger LOG =+ LoggerFactory.getLogger(CatalogPaimonKerberosFilesystemIT.class);++ private static final ContainerSuite containerSuite = ContainerSuite.getInstance();++ private static final String SDK_KERBEROS_PRINCIPAL_KEY = "client.kerberos.principal";+ private static final String SDK_KERBEROS_KEYTAB_KEY = "client.kerberos.keytab";++ private static final String GRAVITINO_CLIENT_PRINCIPAL = "gravitino_client@HADOOPKRB";+ private static final String GRAVITINO_CLIENT_KEYTAB = "/gravitino_client.keytab";++ private static final String GRAVITINO_SERVER_PRINCIPAL = "HTTP/localhost@HADOOPKRB";+ private static final String GRAVITINO_SERVER_KEYTAB = "/gravitino_server.keytab";++ private static final String HDFS_CLIENT_PRINCIPAL = "cli@HADOOPKRB";+ private static final String HDFS_CLIENT_KEYTAB = "/client.keytab";++ private static String TMP_DIR;++ private static HiveContainer kerberosHiveContainer;++ private static GravitinoAdminClient adminClient;++ private static final String CATALOG_NAME = GravitinoITUtils.genRandomName("test_catalog");+ private static final String SCHEMA_NAME = GravitinoITUtils.genRandomName("test_schema");+ private static final String TABLE_NAME = GravitinoITUtils.genRandomName("test_table");++ private static String TYPE;+ private static String WAREHOUSE;++ private static final String FILESYSTEM_COL_NAME1 = "col1";+ private static final String FILESYSTEM_COL_NAME2 = "col2";+ private static final String FILESYSTEM_COL_NAME3 = "col3";++ @BeforeAll+ public static void startIntegrationTest() {+ containerSuite.startKerberosHiveContainer();+ kerberosHiveContainer = containerSuite.getKerberosHiveContainer();++ TYPE = "filesystem";+ WAREHOUSE =+ String.format(+ "hdfs://%s:%d/user/hive/paimon_catalog_warehouse/",+ kerberosHiveContainer.getContainerIpAddress(), HiveContainer.HDFS_DEFAULTFS_PORT);++ try {+ File baseDir = new File(System.getProperty("java.io.tmpdir"));+ File file = Files.createTempDirectory(baseDir.toPath(), "test").toFile();+ file.deleteOnExit();+ TMP_DIR = file.getAbsolutePath();++ // Prepare kerberos related-config;+ prepareKerberosConfig();++ // Config kerberos configuration for Gravitino server+ addKerberosConfig();++ // Start Gravitino server+ AbstractIT.startIntegrationTest();+ } catch (Exception e) {+ throw new RuntimeException(e);+ }+ }++ @AfterAll+ public static void stop() {+ // Reset the UGI+ UserGroupInformation.reset();++ LOG.info("krb5 path: {}", System.getProperty("java.security.krb5.conf"));+ // Clean up the kerberos configuration+ System.clearProperty("java.security.krb5.conf");+ System.clearProperty("sun.security.krb5.debug");++ AbstractIT.client = null;+ }++ private static void prepareKerberosConfig() throws Exception {+ // Keytab of the Gravitino SDK client+ kerberosHiveContainer+ .getContainer()+ .copyFileFromContainer("/gravitino_client.keytab", TMP_DIR + GRAVITINO_CLIENT_KEYTAB);++ // Keytab of the Gravitino server+ kerberosHiveContainer+ .getContainer()+ .copyFileFromContainer("/gravitino_server.keytab", TMP_DIR + GRAVITINO_SERVER_KEYTAB);++ // Keytab of Gravitino server to connector to Hive+ kerberosHiveContainer+ .getContainer()+ .copyFileFromContainer("/etc/admin.keytab", TMP_DIR + HDFS_CLIENT_KEYTAB);++ String tmpKrb5Path = TMP_DIR + "/krb5.conf_tmp";+ String krb5Path = TMP_DIR + "/krb5.conf";+ kerberosHiveContainer.getContainer().copyFileFromContainer("/etc/krb5.conf", tmpKrb5Path);++ // Modify the krb5.conf and change the kdc and admin_server to the container IP+ String ip = containerSuite.getKerberosHiveContainer().getContainerIpAddress();+ String content = FileUtils.readFileToString(new File(tmpKrb5Path), StandardCharsets.UTF_8);+ content = content.replace("kdc = localhost:88", "kdc = " + ip + ":88");+ content = content.replace("admin_server = localhost", "admin_server = " + ip + ":749");+ FileUtils.write(new File(krb5Path), content, StandardCharsets.UTF_8);++ LOG.info("Kerberos kdc config:\n{}, path: {}", content, krb5Path);+ System.setProperty("java.security.krb5.conf", krb5Path);+ System.setProperty("sun.security.krb5.debug", "true");++ refreshKerberosConfig();+ KerberosName.resetDefaultRealm();++ LOG.info("Kerberos default realm: {}", KerberosUtil.getDefaultRealm());+ }++ private static void refreshKerberosConfig() {+ Class<?> classRef;+ try {+ if (System.getProperty("java.vendor").contains("IBM")) {+ classRef = Class.forName("com.ibm.security.krb5.internal.Config");+ } else {+ classRef = Class.forName("sun.security.krb5.Config");+ }++ Method refershMethod = classRef.getMethod("refresh");+ refershMethod.invoke(null);+ } catch (Exception e) {+ throw new RuntimeException(e);+ }+ }++ private static void addKerberosConfig() {+ AbstractIT.customConfigs.put("gravitino.authenticator", "kerberos");+ AbstractIT.customConfigs.put(+ "gravitino.authenticator.kerberos.principal", GRAVITINO_SERVER_PRINCIPAL);+ AbstractIT.customConfigs.put(+ "gravitino.authenticator.kerberos.keytab", TMP_DIR + GRAVITINO_SERVER_KEYTAB);+ AbstractIT.customConfigs.put(SDK_KERBEROS_KEYTAB_KEY, TMP_DIR + GRAVITINO_CLIENT_KEYTAB);+ AbstractIT.customConfigs.put(SDK_KERBEROS_PRINCIPAL_KEY, GRAVITINO_CLIENT_PRINCIPAL);+ }++ @Test+ void testPaimonWithKerberos() {+ KerberosTokenProvider provider =+ KerberosTokenProvider.builder()+ .withClientPrincipal(GRAVITINO_CLIENT_PRINCIPAL)+ .withKeyTabFile(new File(TMP_DIR + GRAVITINO_CLIENT_KEYTAB))+ .build();+ adminClient = GravitinoAdminClient.builder(serverUri).withKerberosAuth(provider).build();++ String metalakeName = GravitinoITUtils.genRandomName("test_metalake");+ GravitinoMetalake gravitinoMetalake =+ adminClient.createMetalake(metalakeName, null, ImmutableMap.of());++ // Create a catalog+ Map<String, String> properties = Maps.newHashMap();+ properties.put(AUTH_TYPE_KEY, "kerberos");+ // Not user impersonation here+ properties.put(KEY_TAB_URI_KEY, TMP_DIR + HDFS_CLIENT_KEYTAB);+ properties.put(PRINCIPAL_KEY, HDFS_CLIENT_PRINCIPAL);++ properties.put(PaimonCatalogPropertiesMetadata.GRAVITINO_CATALOG_BACKEND, TYPE);+ properties.put(PaimonCatalogPropertiesMetadata.WAREHOUSE, WAREHOUSE);++ Catalog catalog =+ gravitinoMetalake.createCatalog(+ CATALOG_NAME, Catalog.Type.RELATIONAL, "lakehouse-paimon", "comment", properties);++ // Test create schema+ Exception exception =+ Assertions.assertThrows(+ Exception.class,+ () -> catalog.asSchemas().createSchema(SCHEMA_NAME, "comment", ImmutableMap.of()));+ String exceptionMessage = Throwables.getStackTraceAsString(exception);++ // Make sure the real user is 'cli' because no impersonation here.+ Assertions.assertTrue(exceptionMessage.contains("Permission denied: user=cli, access=WRITE"));++ // Now try to permit the user to create the schema again+ kerberosHiveContainer.executeInContainer(+ "hadoop", "fs", "-mkdir", "/user/hive/paimon_catalog_warehouse");+ kerberosHiveContainer.executeInContainer(+ "hadoop", "fs", "-chmod", "-R", "777", "/user/hive/paimon_catalog_warehouse");+ Assertions.assertDoesNotThrow(+ () -> catalog.asSchemas().createSchema(SCHEMA_NAME, "comment", ImmutableMap.of()));++ // Create table+ NameIdentifier tableNameIdentifier = NameIdentifier.of(SCHEMA_NAME, TABLE_NAME);+ catalog+ .asTableCatalog()+ .createTable(+ tableNameIdentifier,+ createColumns(),+ "",+ ImmutableMap.of(),+ Transforms.EMPTY_TRANSFORM,+ Distributions.NONE,+ SortOrders.NONE);++ // Load table+ Table loadTable = catalog.asTableCatalog().loadTable(tableNameIdentifier);+ Assertions.assertEquals(loadTable.name(), tableNameIdentifier.name());++ // Drop table+ catalog.asTableCatalog().dropTable(tableNameIdentifier);+ Assertions.assertFalse(catalog.asTableCatalog().tableExists(tableNameIdentifier));++ // Drop schema+ catalog.asSchemas().dropSchema(SCHEMA_NAME, false);+ Assertions.assertFalse(catalog.asSchemas().schemaExists(SCHEMA_NAME));++ // Drop catalog+ Assertions.assertTrue(gravitinoMetalake.dropCatalog(CATALOG_NAME));++ // Drop warehouse path+ kerberosHiveContainer.executeInContainer(+ "hadoop", "fs", "-rm", "-r", "/user/hive/paimon_catalog_warehouse");+ }++ private static Column[] createColumns() {+ Column col1 = Column.of(FILESYSTEM_COL_NAME1, Types.IntegerType.get(), "col_1_comment");+ Column col2 = Column.of(FILESYSTEM_COL_NAME2, Types.DateType.get(), "col_2_comment");+ Column col3 = Column.of(FILESYSTEM_COL_NAME3, Types.StringType.get(), "col_3_comment");+ return new Column[] {col1, col2, col3};+ }+}diff --git a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TestCatalogUtils.java b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TestCatalogUtils.javaindex 409d9c6fd0..8072c16547 100644--- a/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TestCatalogUtils.java+++ b/catalogs/catalog-lakehouse-paimon/src/test/java/org/apache/gravitino/catalog/lakehouse/paimon/utils/TestCatalogUtils.java@@ -53,17 +53,18 @@ public class TestCatalogUtils {private void assertCatalog(String metastore, Consumer<Catalog> consumer) throws Exception {try (Catalog catalog =loadCatalogBackend(- new PaimonConfig(- ImmutableMap.of(- PaimonConfig.CATALOG_BACKEND.getKey(),- metastore,- PaimonConfig.CATALOG_WAREHOUSE.getKey(),- String.join(- File.separator,- System.getProperty("java.io.tmpdir"),- "paimon_catalog_warehouse"),- PaimonConfig.CATALOG_URI.getKey(),- "uri")))) {+ new PaimonConfig(+ ImmutableMap.of(+ PaimonConfig.CATALOG_BACKEND.getKey(),+ metastore,+ PaimonConfig.CATALOG_WAREHOUSE.getKey(),+ String.join(+ File.separator,+ System.getProperty("java.io.tmpdir"),+ "paimon_catalog_warehouse"),+ PaimonConfig.CATALOG_URI.getKey(),+ "uri")))+ .getCatalog()) {consumer.accept(catalog);}}