FANNG1 commented on code in PR #9565: URL: https://github.com/apache/gravitino/pull/9565#discussion_r2654991322
########## flink-connector/flink/src/test/java/org/apache/gravitino/flink/connector/integration/test/hive/FlinkHiveKerberosClientIT.java: ########## @@ -0,0 +1,243 @@ +/* + * 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.flink.connector.integration.test.hive; + +import static org.apache.gravitino.server.authentication.KerberosConfig.KEYTAB; +import static org.apache.gravitino.server.authentication.KerberosConfig.PRINCIPAL; +import static org.apache.hadoop.minikdc.MiniKdc.MAX_TICKET_LIFETIME; + +import com.google.common.collect.Maps; +import java.io.File; +import java.security.PrivilegedAction; +import java.util.Arrays; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; +import org.apache.flink.configuration.Configuration; +import org.apache.flink.table.api.EnvironmentSettings; +import org.apache.flink.table.api.TableEnvironment; +import org.apache.flink.table.catalog.Catalog; +import org.apache.flink.table.catalog.CommonCatalogOptions; +import org.apache.flink.table.catalog.hive.factories.HiveCatalogFactoryOptions; +import org.apache.gravitino.Configs; +import org.apache.gravitino.auth.AuthenticatorType; +import org.apache.gravitino.catalog.hive.HiveConstants; +import org.apache.gravitino.flink.connector.PropertiesConverter; +import org.apache.gravitino.flink.connector.hive.GravitinoHiveCatalog; +import org.apache.gravitino.flink.connector.hive.GravitinoHiveCatalogFactoryOptions; +import org.apache.gravitino.flink.connector.integration.test.FlinkEnvIT; +import org.apache.gravitino.flink.connector.store.GravitinoCatalogStoreFactoryOptions; +import org.apache.hadoop.minikdc.KerberosSecurityTestcase; +import org.apache.hadoop.security.UserGroupInformation; +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; + +/** + * Integration test for creating Gravitino Hive catalogs with Kerberos authentication. This test + * verifies that catalog creation works correctly when the Gravitino server is configured with + * Kerberos authentication. The test extends FlinkEnvIT directly to keep the test scope focused on + * Kerberos-specific scenarios. + */ +@Tag("gravitino-docker-test") +public class FlinkHiveKerberosClientIT extends FlinkEnvIT { + + private static final KerberosSecurityTestcase kdc = + new KerberosSecurityTestcase() { + @Override + public void createMiniKdcConf() { + super.createMiniKdcConf(); + // Use a very short ticket lifetime to speed up Kerberos expiration in tests. + // The test operations are executed immediately after the MiniKdc is started and + // are not long-running, so a 5-second lifetime is sufficient and keeps the test + // fast. If this test ever becomes flaky on slower environments or CI systems, + // consider increasing this value to a more forgiving lifetime (for example, 60s). + getConf().setProperty(MAX_TICKET_LIFETIME, "5"); Review Comment: AI review comment, could you confirm it? ``` In FlinkHiveKerberosClientIT, the MiniKdc ticket lifetime is set with getConf().setProperty(MAX_TICKET_LIFETIME, "5"), but the MAX_TICKET_LIFETIME property expects milliseconds. This config therefore produces tickets that expire after 5 milliseconds rather than the intended 5 seconds, so any catalog operations are immediately using expired credentials, making the Kerberos integration test flaky or consistently failing on slower runs. Use a millisecond value (e.g., 5000) if a 5‑second lifetime is desired. ``` ########## flink-connector/flink/src/main/java/org/apache/gravitino/flink/connector/catalog/GravitinoCatalogManager.java: ########## @@ -206,4 +240,60 @@ private static boolean checkEqual( && gravitinoCatalogManager.metalakeName.equals(metalakeName) && gravitinoCatalogManager.gravitinoClientConfig.equals(gravitinoClientConfig); } + + private static GravitinoAdminClient buildOAuthClient( + String gravitinoUri, Map<String, String> config) { + String serverUri = config.get(GravitinoCatalogStoreFactoryOptions.OAUTH2_SERVER_URI); + String credential = config.get(GravitinoCatalogStoreFactoryOptions.OAUTH2_CREDENTIAL); + String path = config.get(GravitinoCatalogStoreFactoryOptions.OAUTH2_TOKEN_PATH); + String scope = config.get(GravitinoCatalogStoreFactoryOptions.OAUTH2_SCOPE); + Preconditions.checkArgument( + StringUtils.isNoneBlank(serverUri, credential, path, scope), + "OAuth2 authentication requires: gravitino.client.oauth2.serverUri, " Review Comment: could you replace `gravitino.client.oauth2.serverUri` with String constants? ########## docs/flink-connector/flink-authentication-with-gravitino.md: ########## @@ -0,0 +1,37 @@ +--- +title: "Flink authentication with Gravitino server" +slug: /flink-connector/flink-authentication +keyword: flink connector authentication oauth2 kerberos +license: "This software is licensed under the Apache License version 2." +--- + +## Overview + +Flink connector supports `simple`, `oauth2`, and `kerberos` authentication when accessing the Gravitino server. + +| Property | Type | Default Value | Description | Required | Since Version | +|----------------------------|--------|---------------|------------------------------------------------------------------------------------------------------------------------------------------|----------|---------------| +| gravitino.client.auth.type | string | (none) | When explicitly set, only `oauth` is supported. If unset, Flink selects Kerberos or simple authentication based on its security settings. | No | 1.2.0 | + +## Simple mode + +In simple mode, the username originates from Flink. The resolution order is: +1. `HADOOP_USER_NAME` environment variable +2. The logged-in OS user + +## OAuth2 mode + +In OAuth2 mode, configure the following settings to fetch an OAuth2 token to access the Gravitino server: Review Comment: How should user configurate belew settings? `gravitino.client.oauth2.serverUri` or `table.catalog-store.gravitino.gravitino.client.oauth2.serverUri`? could you provide an example? -- 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]
