-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Support kerberos authentication for Kudu connector #3549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -168,6 +168,11 @@ | |
| <artifactId>testcontainers</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>io.prestosql.hadoop</groupId> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please move it to other |
||
| <artifactId>hadoop-apache</artifactId> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need entire hadoop dependency for this? |
||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,10 @@ public class KuduClientConfig | |
| private boolean disableStatistics; | ||
| private boolean schemaEmulationEnabled; | ||
| private String schemaEmulationPrefix = "presto::"; | ||
| private boolean kerberosAuthEnabled; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have this in a separate config file ? |
||
| private String kerberosPrincipal; | ||
| private String kerberosKeytab; | ||
| private boolean kerberosAuthDebugEnabled; | ||
|
|
||
| @NotNull | ||
| @Size(min = 1) | ||
|
|
@@ -138,4 +142,52 @@ public KuduClientConfig setSchemaEmulationEnabled(boolean enabled) | |
| this.schemaEmulationEnabled = enabled; | ||
| return this; | ||
| } | ||
|
|
||
| public boolean isKerberosAuthEnabled() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add |
||
| { | ||
| return kerberosAuthEnabled; | ||
| } | ||
|
|
||
| @Config("kudu.kerberos-auth.enabled") | ||
| public KuduClientConfig setKerberosAuthEnabled(boolean enabled) | ||
| { | ||
| this.kerberosAuthEnabled = enabled; | ||
| return this; | ||
| } | ||
|
|
||
| public String getKerberosPrincipal() | ||
| { | ||
| return kerberosPrincipal; | ||
| } | ||
|
|
||
| @Config("kudu.kerberos-auth.principal") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kerberos related properties should not be allowed to be configures if |
||
| public KuduClientConfig setKerberosPrincipal(String principal) | ||
| { | ||
| this.kerberosPrincipal = principal; | ||
| return this; | ||
| } | ||
|
|
||
| public String getKerberosKeytab() | ||
| { | ||
| return kerberosKeytab; | ||
| } | ||
|
|
||
| @Config("kudu.kerberos-auth.keytab") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| public KuduClientConfig setKerberosKeytab(String keytab) | ||
| { | ||
| this.kerberosKeytab = keytab; | ||
| return this; | ||
| } | ||
|
|
||
| public boolean isKerberosAuthDebugEnabled() | ||
| { | ||
| return kerberosAuthDebugEnabled; | ||
| } | ||
|
|
||
| @Config("kudu.kerberos-auth.debug.enabled") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove this property. One can add it using |
||
| public KuduClientConfig setKerberosAuthDebugEnabled(boolean enabled) | ||
| { | ||
| this.kerberosAuthDebugEnabled = enabled; | ||
| return this; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,7 @@ | |
|
|
||
| import static com.google.common.base.Verify.verify; | ||
| import static com.google.common.collect.ImmutableList.toImmutableList; | ||
| import static io.prestosql.plugin.kudu.KuduUtil.reTryKerberos; | ||
| import static io.prestosql.spi.StandardErrorCode.GENERIC_INTERNAL_ERROR; | ||
| import static io.prestosql.spi.StandardErrorCode.QUERY_REJECTED; | ||
| import static io.prestosql.spi.predicate.Marker.Bound.ABOVE; | ||
|
|
@@ -81,15 +82,18 @@ public class KuduClientSession | |
| public static final String DEFAULT_SCHEMA = "default"; | ||
| private final KuduClient client; | ||
| private final SchemaEmulation schemaEmulation; | ||
| private final boolean kerberosAuthEnabled; | ||
|
|
||
| public KuduClientSession(KuduClient client, SchemaEmulation schemaEmulation) | ||
| public KuduClientSession(KuduClient client, SchemaEmulation schemaEmulation, boolean kerberosAuthEnabled) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have it as a wrap of top of KuduClientSession ? |
||
| { | ||
| this.client = client; | ||
| this.schemaEmulation = schemaEmulation; | ||
| this.kerberosAuthEnabled = kerberosAuthEnabled; | ||
| } | ||
|
|
||
| public List<String> listSchemaNames() | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| return schemaEmulation.listSchemaNames(client); | ||
| } | ||
|
|
||
|
|
@@ -108,6 +112,7 @@ private List<String> internalListTables(String prefix) | |
|
|
||
| public List<SchemaTableName> listTables(Optional<String> optSchemaName) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| if (optSchemaName.isPresent()) { | ||
| return listTablesSingleSchema(optSchemaName.get()); | ||
| } | ||
|
|
@@ -136,18 +141,21 @@ private List<SchemaTableName> listTablesSingleSchema(String schemaName) | |
|
|
||
| public Schema getTableSchema(KuduTableHandle tableHandle) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| KuduTable table = tableHandle.getTable(this); | ||
| return table.getSchema(); | ||
| } | ||
|
|
||
| public Map<String, Object> getTableProperties(KuduTableHandle tableHandle) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| KuduTable table = tableHandle.getTable(this); | ||
| return KuduTableProperties.toMap(table); | ||
| } | ||
|
|
||
| public List<KuduSplit> buildKuduSplits(KuduTableHandle tableHandle) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| KuduTable table = tableHandle.getTable(this); | ||
| final int primaryKeyColumnCount = table.getSchema().getPrimaryKeyColumnCount(); | ||
| KuduScanToken.KuduScanTokenBuilder builder = client.newScanTokenBuilder(table); | ||
|
|
@@ -210,6 +218,7 @@ public List<KuduSplit> buildKuduSplits(KuduTableHandle tableHandle) | |
|
|
||
| public KuduScanner createScanner(KuduSplit kuduSplit) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| try { | ||
| return KuduScanToken.deserializeIntoScanner(kuduSplit.getSerializedScanToken(), client); | ||
| } | ||
|
|
@@ -220,6 +229,7 @@ public KuduScanner createScanner(KuduSplit kuduSplit) | |
|
|
||
| public KuduTable openTable(SchemaTableName schemaTableName) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| String rawName = schemaEmulation.toRawName(schemaTableName); | ||
| try { | ||
| return client.openTable(rawName); | ||
|
|
@@ -235,21 +245,25 @@ public KuduTable openTable(SchemaTableName schemaTableName) | |
|
|
||
| public KuduSession newSession() | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| return client.newSession(); | ||
| } | ||
|
|
||
| public void createSchema(String schemaName) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| schemaEmulation.createSchema(client, schemaName); | ||
| } | ||
|
|
||
| public void dropSchema(String schemaName) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| schemaEmulation.dropSchema(client, schemaName); | ||
| } | ||
|
|
||
| public void dropTable(SchemaTableName schemaTableName) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| try { | ||
| String rawName = schemaEmulation.toRawName(schemaTableName); | ||
| client.deleteTable(rawName); | ||
|
|
@@ -261,6 +275,7 @@ public void dropTable(SchemaTableName schemaTableName) | |
|
|
||
| public void renameTable(SchemaTableName schemaTableName, SchemaTableName newSchemaTableName) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| try { | ||
| String rawName = schemaEmulation.toRawName(schemaTableName); | ||
| String newRawName = schemaEmulation.toRawName(newSchemaTableName); | ||
|
|
@@ -275,6 +290,7 @@ public void renameTable(SchemaTableName schemaTableName, SchemaTableName newSche | |
|
|
||
| public KuduTable createTable(ConnectorTableMetadata tableMetadata, boolean ignoreExisting) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| try { | ||
| String rawName = schemaEmulation.toRawName(tableMetadata.getTable()); | ||
| if (ignoreExisting) { | ||
|
|
@@ -301,6 +317,7 @@ public KuduTable createTable(ConnectorTableMetadata tableMetadata, boolean ignor | |
|
|
||
| public void addColumn(SchemaTableName schemaTableName, ColumnMetadata column) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| try { | ||
| String rawName = schemaEmulation.toRawName(schemaTableName); | ||
| AlterTableOptions alterOptions = new AlterTableOptions(); | ||
|
|
@@ -315,6 +332,7 @@ public void addColumn(SchemaTableName schemaTableName, ColumnMetadata column) | |
|
|
||
| public void dropColumn(SchemaTableName schemaTableName, String name) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| try { | ||
| String rawName = schemaEmulation.toRawName(schemaTableName); | ||
| AlterTableOptions alterOptions = new AlterTableOptions(); | ||
|
|
@@ -328,6 +346,7 @@ public void dropColumn(SchemaTableName schemaTableName, String name) | |
|
|
||
| public void renameColumn(SchemaTableName schemaTableName, String oldName, String newName) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| try { | ||
| String rawName = schemaEmulation.toRawName(schemaTableName); | ||
| AlterTableOptions alterOptions = new AlterTableOptions(); | ||
|
|
@@ -341,11 +360,13 @@ public void renameColumn(SchemaTableName schemaTableName, String oldName, String | |
|
|
||
| public void addRangePartition(SchemaTableName schemaTableName, RangePartition rangePartition) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| changeRangePartition(schemaTableName, rangePartition, RangePartitionChange.ADD); | ||
| } | ||
|
|
||
| public void dropRangePartition(SchemaTableName schemaTableName, RangePartition rangePartition) | ||
| { | ||
| reTryKerberos(kerberosAuthEnabled); | ||
| changeRangePartition(schemaTableName, rangePartition, RangePartitionChange.DROP); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,14 +83,14 @@ KuduClientSession createKuduClientSession(KuduClientConfig config) | |
| { | ||
| requireNonNull(config, "config is null"); | ||
|
|
||
| KuduClient.KuduClientBuilder builder = new KuduClient.KuduClientBuilder(config.getMasterAddresses()); | ||
| builder.defaultAdminOperationTimeoutMs(config.getDefaultAdminOperationTimeout().toMillis()); | ||
| builder.defaultOperationTimeoutMs(config.getDefaultOperationTimeout().toMillis()); | ||
| builder.defaultSocketReadTimeoutMs(config.getDefaultSocketReadTimeout().toMillis()); | ||
| if (config.isDisableStatistics()) { | ||
| builder.disableStatistics(); | ||
| KuduClient client; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have separate module for the kerberos based KuduClient ? |
||
| if (!config.isKerberosAuthEnabled()) { | ||
| client = KuduUtil.createKuduClient(config); | ||
| } | ||
| else { | ||
| KuduUtil.initKerberosENV(config.getKerberosPrincipal(), config.getKerberosKeytab(), config.isKerberosAuthDebugEnabled()); | ||
| client = KuduUtil.createKuduKerberosClient(config); | ||
| } | ||
| KuduClient client = builder.build(); | ||
|
|
||
| SchemaEmulation strategy; | ||
| if (config.isSchemaEmulationEnabled()) { | ||
|
|
@@ -99,6 +99,6 @@ KuduClientSession createKuduClientSession(KuduClientConfig config) | |
| else { | ||
| strategy = new NoSchemaEmulation(); | ||
| } | ||
| return new KuduClientSession(client, strategy); | ||
| return new KuduClientSession(client, strategy, config.isKerberosAuthEnabled()); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * Licensed 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 io.prestosql.plugin.kudu; | ||
|
|
||
| import io.airlift.log.Logger; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.security.UserGroupInformation; | ||
| import org.apache.kudu.client.KuduClient; | ||
|
|
||
| import java.io.IOException; | ||
| import java.security.PrivilegedExceptionAction; | ||
|
|
||
| public class KuduUtil | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use |
||
| { | ||
| private static final Logger log = Logger.get(KuduUtil.class); | ||
|
|
||
| private KuduUtil() | ||
| { | ||
| // not allowed to be called to initialize instance | ||
| } | ||
|
|
||
| /** | ||
| * Initialize kerberos authentication | ||
| */ | ||
| static void initKerberosENV(String principal, String keytab, boolean debugEnabled) | ||
| { | ||
| try { | ||
| Configuration conf = new Configuration(false); | ||
| conf.set("hadoop.security.authentication", "kerberos"); | ||
| if (debugEnabled) { | ||
| System.setProperty("sun.security.krb5.debug", "true"); | ||
| } | ||
| UserGroupInformation.setConfiguration(conf); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to add hadoop dependencies ? How about reusing |
||
| UserGroupInformation.loginUserFromKeytab(principal, keytab); | ||
| log.info("Connecting to kudu with kerberos authentication"); | ||
| log.info("Current user: " + UserGroupInformation.getCurrentUser()); | ||
| log.info("Login user: " + UserGroupInformation.getLoginUser()); | ||
| } | ||
| catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| static KuduClient createKuduKerberosClient(KuduClientConfig config) | ||
| { | ||
| KuduClient client = null; | ||
| try { | ||
| reTryKerberos(true); | ||
| client = UserGroupInformation.getLoginUser().doAs( | ||
| (PrivilegedExceptionAction<KuduClient>) () -> createKuduClient(config)); | ||
| return client; | ||
| } | ||
| catch (Exception e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
|
|
||
| static KuduClient createKuduClient(KuduClientConfig config) | ||
| { | ||
| KuduClient.KuduClientBuilder builder = new KuduClient.KuduClientBuilder(config.getMasterAddresses()); | ||
| builder.defaultAdminOperationTimeoutMs(config.getDefaultAdminOperationTimeout().toMillis()); | ||
| builder.defaultOperationTimeoutMs(config.getDefaultOperationTimeout().toMillis()); | ||
| builder.defaultSocketReadTimeoutMs(config.getDefaultSocketReadTimeout().toMillis()); | ||
| if (config.isDisableStatistics()) { | ||
| builder.disableStatistics(); | ||
| } | ||
| return builder.build(); | ||
| } | ||
|
|
||
| static void reTryKerberos(boolean enabled) | ||
| { | ||
| if (enabled) { | ||
| log.debug("Try relogin kerberos at first!"); | ||
| try { | ||
| if (UserGroupInformation.isLoginKeytabBased()) { | ||
| UserGroupInformation.getLoginUser().reloginFromKeytab(); | ||
| } | ||
| else if (UserGroupInformation.isLoginTicketBased()) { | ||
| UserGroupInformation.getLoginUser().reloginFromTicketCache(); | ||
| } | ||
| } | ||
| catch (IOException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be a regular subsection.
Same applies to
### Advanced Kudu Java client configuration.@mosabua Any suggestsions?