Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion presto-docs/src/main/sphinx/connector/kudu.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,22 @@ replacing the properties as appropriate:
## Disable Kudu client's collection of statistics.
#kudu.client.disable-statistics = false

#######################
Copy link
Copy Markdown
Member

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?

### Advanced Kudu Kerberos authentication configuration
#######################

## Whether to enable kerberos authentication, default is false
#kudu.kerberos-auth.enabled=true

# whether to output kerberos debug information, default is false
#kudu.kerberos-auth.debug.enabled=true

# The Kerberos principal that Presto will use when connecting to Kudu
#kudu.kerberos-auth.principal=xxx

# Kudu client keytab location
#kudu.kerberos-auth.keytab=xxx.keytab


Querying Data
-------------
Expand Down Expand Up @@ -625,4 +641,3 @@ Known limitations
-----------------

- Only lower case table and column names in Kudu are supported.
- Using a secured Kudu cluster has not been tested.
5 changes: 5 additions & 0 deletions presto-kudu/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.prestosql.hadoop</groupId>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move it to other compile dependencies.

<artifactId>hadoop-apache</artifactId>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need entire hadoop dependency for this?

</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public class KuduClientConfig
private boolean disableStatistics;
private boolean schemaEmulationEnabled;
private String schemaEmulationPrefix = "presto::";
private boolean kerberosAuthEnabled;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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)
Expand Down Expand Up @@ -138,4 +142,52 @@ public KuduClientConfig setSchemaEmulationEnabled(boolean enabled)
this.schemaEmulationEnabled = enabled;
return this;
}

public boolean isKerberosAuthEnabled()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add kudu.authentication.type property that accepts KERBEROS or NONE

{
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")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kudu.client.principal ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kerberos related properties should not be allowed to be configures if kudu.authentication.type=NONE. Please see usages how it typically achieved by look at usages of io.airlift.configuration.ConditionalModule#installModuleIf.

public KuduClientConfig setKerberosPrincipal(String principal)
{
this.kerberosPrincipal = principal;
return this;
}

public String getKerberosKeytab()
{
return kerberosKeytab;
}

@Config("kudu.kerberos-auth.keytab")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kudu.client.keytab

public KuduClientConfig setKerberosKeytab(String keytab)
{
this.kerberosKeytab = keytab;
return this;
}

public boolean isKerberosAuthDebugEnabled()
{
return kerberosAuthDebugEnabled;
}

@Config("kudu.kerberos-auth.debug.enabled")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this property. One can add it using jvm.config

public KuduClientConfig setKerberosAuthDebugEnabled(boolean enabled)
{
this.kerberosAuthDebugEnabled = enabled;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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);
}

Expand All @@ -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());
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -210,6 +218,7 @@ public List<KuduSplit> buildKuduSplits(KuduTableHandle tableHandle)

public KuduScanner createScanner(KuduSplit kuduSplit)
{
reTryKerberos(kerberosAuthEnabled);
try {
return KuduScanToken.deserializeIntoScanner(kuduSplit.getSerializedScanToken(), client);
}
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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()) {
Expand All @@ -99,6 +99,6 @@ KuduClientSession createKuduClientSession(KuduClientConfig config)
else {
strategy = new NoSchemaEmulation();
}
return new KuduClientSession(client, strategy);
return new KuduClientSession(client, strategy, config.isKerberosAuthEnabled());
}
}
98 changes: 98 additions & 0 deletions presto-kudu/src/main/java/io/prestosql/plugin/kudu/KuduUtil.java
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use io.prestosql.plugin.base.authentication.KerberosAuthentication and io.prestosql.plugin.base.authentication.CachingKerberosAuthentication

{
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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add hadoop dependencies ? How about reusing KerberosAuthentication in presto plugiin toolkit ?

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);
}
}
}
}