-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add kerberos auth support to kudu connector #10953
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
Merged
hashhar
merged 4 commits into
trinodb:master
from
grantatspothero:gn/kuduKerberosSupport
Feb 24, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
684f30b
Put usages of kuduclient behind an interface
grantatspothero f73090e
Modify KuduModule to use AbstractConfigurationAwareModule
grantatspothero 5d065b2
Adds kerberos support for kudu connector
grantatspothero 44b872c
Extract SystemProperties into plugin-toolkit module
grantatspothero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/util/SystemProperties.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * 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.trino.plugin.base.util; | ||
|
|
||
| import java.util.Objects; | ||
|
|
||
| import static com.google.common.base.Preconditions.checkState; | ||
|
|
||
| public final class SystemProperties | ||
| { | ||
| public static final String JAVA_SECURITY_KRB5_CONF = "java.security.krb5.conf"; | ||
|
|
||
| private SystemProperties() {} | ||
|
|
||
| public static synchronized void setJavaSecurityKrb5Conf(String value) | ||
| { | ||
| set(JAVA_SECURITY_KRB5_CONF, value); | ||
| } | ||
|
|
||
| public static synchronized void set(String key, String newValue) | ||
| { | ||
| String currentValue = System.getProperty(key); | ||
| checkSameValues(key, newValue, currentValue); | ||
| System.setProperty(key, newValue); | ||
| } | ||
|
|
||
| private static void checkSameValues(String key, String newValue, String currentValue) | ||
| { | ||
| checkState( | ||
| currentValue == null || Objects.equals(currentValue, newValue), | ||
| "Refusing to set system property '%s' to '%s', it is already set to '%s'", | ||
| key, | ||
| newValue, | ||
| currentValue); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
plugin/trino-kudu/src/main/java/io/trino/plugin/kudu/ForwardingKuduClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /* | ||
| * 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.trino.plugin.kudu; | ||
|
|
||
| import org.apache.kudu.Schema; | ||
| import org.apache.kudu.client.AlterTableOptions; | ||
| import org.apache.kudu.client.AlterTableResponse; | ||
| import org.apache.kudu.client.CreateTableOptions; | ||
| import org.apache.kudu.client.DeleteTableResponse; | ||
| import org.apache.kudu.client.KuduClient; | ||
| import org.apache.kudu.client.KuduException; | ||
| import org.apache.kudu.client.KuduScanToken; | ||
| import org.apache.kudu.client.KuduScanner; | ||
| import org.apache.kudu.client.KuduSession; | ||
| import org.apache.kudu.client.KuduTable; | ||
| import org.apache.kudu.client.ListTablesResponse; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public abstract class ForwardingKuduClient | ||
| implements KuduClientWrapper | ||
| { | ||
| protected abstract KuduClient delegate(); | ||
|
|
||
| @Override | ||
| public KuduTable createTable(String name, Schema schema, CreateTableOptions builder) | ||
| throws KuduException | ||
| { | ||
| return delegate().createTable(name, schema, builder); | ||
| } | ||
|
|
||
| @Override | ||
| public DeleteTableResponse deleteTable(String name) | ||
| throws KuduException | ||
| { | ||
| return delegate().deleteTable(name); | ||
| } | ||
|
|
||
| @Override | ||
| public AlterTableResponse alterTable(String name, AlterTableOptions ato) | ||
| throws KuduException | ||
| { | ||
| return delegate().alterTable(name, ato); | ||
| } | ||
|
|
||
| @Override | ||
| public ListTablesResponse getTablesList() | ||
| throws KuduException | ||
| { | ||
| return delegate().getTablesList(); | ||
| } | ||
|
|
||
| @Override | ||
| public ListTablesResponse getTablesList(String nameFilter) | ||
| throws KuduException | ||
| { | ||
| return delegate().getTablesList(nameFilter); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean tableExists(String name) | ||
| throws KuduException | ||
| { | ||
| return delegate().tableExists(name); | ||
| } | ||
|
|
||
| @Override | ||
| public KuduTable openTable(final String name) | ||
| throws KuduException | ||
| { | ||
| return delegate().openTable(name); | ||
| } | ||
|
|
||
| @Override | ||
| public KuduScanner.KuduScannerBuilder newScannerBuilder(KuduTable table) | ||
| { | ||
| return delegate().newScannerBuilder(table); | ||
| } | ||
|
|
||
| @Override | ||
| public KuduScanToken.KuduScanTokenBuilder newScanTokenBuilder(KuduTable table) | ||
| { | ||
| return delegate().newScanTokenBuilder(table); | ||
| } | ||
|
|
||
| @Override | ||
| public KuduSession newSession() | ||
| { | ||
| return delegate().newSession(); | ||
| } | ||
|
|
||
| @Override | ||
| public KuduScanner deserializeIntoScanner(byte[] serializedScanToken) | ||
| throws IOException | ||
| { | ||
| return KuduScanToken.deserializeIntoScanner(serializedScanToken, delegate()); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() | ||
| throws KuduException | ||
| { | ||
| delegate().close(); | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
plugin/trino-kudu/src/main/java/io/trino/plugin/kudu/KerberizedKuduClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * 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.trino.plugin.kudu; | ||
|
|
||
| import io.trino.plugin.base.authentication.CachingKerberosAuthentication; | ||
| import org.apache.kudu.client.KuduClient; | ||
|
|
||
| import javax.security.auth.Subject; | ||
|
|
||
| import java.security.PrivilegedAction; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
| import static org.apache.kudu.client.KuduClient.KuduClientBuilder; | ||
|
|
||
| public class KerberizedKuduClient | ||
|
grantatspothero marked this conversation as resolved.
Outdated
|
||
| extends ForwardingKuduClient | ||
| { | ||
| private final KuduClient kuduClient; | ||
| private final CachingKerberosAuthentication cachingKerberosAuthentication; | ||
|
|
||
| KerberizedKuduClient(KuduClientBuilder kuduClientBuilder, CachingKerberosAuthentication cachingKerberosAuthentication) | ||
| { | ||
| requireNonNull(kuduClientBuilder, "kuduClientBuilder is null"); | ||
| this.cachingKerberosAuthentication = requireNonNull(cachingKerberosAuthentication, "cachingKerberosAuthentication is null"); | ||
| kuduClient = Subject.doAs(cachingKerberosAuthentication.getSubject(), (PrivilegedAction<KuduClient>) (kuduClientBuilder::build)); | ||
| } | ||
|
|
||
| @Override | ||
| protected KuduClient delegate() | ||
| { | ||
| cachingKerberosAuthentication.reauthenticateIfSoonWillBeExpired(); | ||
| return kuduClient; | ||
| } | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
plugin/trino-kudu/src/main/java/io/trino/plugin/kudu/KuduAuthenticationConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * 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.trino.plugin.kudu; | ||
|
|
||
| import io.airlift.configuration.Config; | ||
| import io.airlift.configuration.ConfigDescription; | ||
|
|
||
| public class KuduAuthenticationConfig | ||
| { | ||
| private KuduAuthenticationType authenticationType = KuduAuthenticationType.NONE; | ||
|
|
||
| public enum KuduAuthenticationType | ||
| { | ||
| NONE, | ||
| KERBEROS; | ||
| } | ||
|
|
||
| public KuduAuthenticationType getAuthenticationType() | ||
| { | ||
| return authenticationType; | ||
| } | ||
|
|
||
| @Config("kudu.authentication.type") | ||
| @ConfigDescription("Kudu authentication type") | ||
| public KuduAuthenticationConfig setAuthenticationType(KuduAuthenticationType authenticationType) | ||
| { | ||
| this.authenticationType = authenticationType; | ||
| return this; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.