Skip to content

Commit 14d0540

Browse files
infvgananthugnair1
andcommitted
Add TLS support for Druid
Co-authored-by: Ananthu-Nair <[email protected]>
1 parent 57a85ce commit 14d0540

File tree

5 files changed

+94
-12
lines changed

5 files changed

+94
-12
lines changed

presto-druid/src/main/java/com/facebook/presto/druid/DruidConfig.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import com.facebook.airlift.configuration.Config;
1717
import com.facebook.airlift.configuration.ConfigDescription;
18+
import com.facebook.airlift.configuration.ConfigSecuritySensitive;
1819
import com.google.common.base.Splitter;
1920
import com.google.common.base.StandardSystemProperty;
2021
import com.google.common.collect.ImmutableList;
@@ -45,6 +46,10 @@ public class DruidConfig
4546
private boolean caseInsensitiveNameMatching;
4647
private Duration caseInsensitiveNameMatchingCacheTtl = new Duration(1, MINUTES);
4748

49+
private boolean tlsEnabled;
50+
private String trustStorePath;
51+
private String truststorePassword;
52+
4853
public enum DruidAuthenticationType
4954
{
5055
NONE,
@@ -226,4 +231,41 @@ public DruidConfig setCaseInsensitiveNameMatchingCacheTtl(Duration caseInsensiti
226231
this.caseInsensitiveNameMatchingCacheTtl = caseInsensitiveNameMatchingCacheTtl;
227232
return this;
228233
}
234+
235+
public boolean isTlsEnabled()
236+
{
237+
return tlsEnabled;
238+
}
239+
240+
@Config("druid.tls.enabled")
241+
public DruidConfig setTlsEnabled(boolean tlsEnabled)
242+
{
243+
this.tlsEnabled = tlsEnabled;
244+
return this;
245+
}
246+
247+
public String getTrustStorePath()
248+
{
249+
return trustStorePath;
250+
}
251+
252+
@Config("druid.tls.truststore-path")
253+
public DruidConfig setTrustStorePath(String path)
254+
{
255+
this.trustStorePath = path;
256+
return this;
257+
}
258+
259+
public String getTrustStorePassword()
260+
{
261+
return truststorePassword;
262+
}
263+
264+
@Config("druid.tls.truststore-password")
265+
@ConfigSecuritySensitive
266+
public DruidConfig setTrustStorePassword(String password)
267+
{
268+
this.truststorePassword = password;
269+
return this;
270+
}
229271
}

presto-druid/src/main/java/com/facebook/presto/druid/DruidConnectorFactory.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.facebook.presto.common.type.TypeManager;
1919
import com.facebook.presto.druid.authentication.DruidAuthenticationModule;
2020
import com.facebook.presto.spi.ConnectorHandleResolver;
21+
import com.facebook.presto.spi.classloader.ThreadContextClassLoader;
2122
import com.facebook.presto.spi.connector.Connector;
2223
import com.facebook.presto.spi.connector.ConnectorContext;
2324
import com.facebook.presto.spi.connector.ConnectorFactory;
@@ -35,6 +36,13 @@
3536
public class DruidConnectorFactory
3637
implements ConnectorFactory
3738
{
39+
private final ClassLoader classLoader;
40+
41+
public DruidConnectorFactory(ClassLoader classLoader)
42+
{
43+
this.classLoader = classLoader;
44+
}
45+
3846
@Override
3947
public String getName()
4048
{
@@ -51,7 +59,7 @@ public ConnectorHandleResolver getHandleResolver()
5159
public Connector create(String catalogName, Map<String, String> config, ConnectorContext context)
5260
{
5361
requireNonNull(config, "config is null");
54-
try {
62+
try (ThreadContextClassLoader ignore = new ThreadContextClassLoader(classLoader)) {
5563
Bootstrap app = new Bootstrap(
5664
new JsonModule(),
5765
new DruidModule(),

presto-druid/src/main/java/com/facebook/presto/druid/DruidPlugin.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ public class DruidPlugin
2323
@Override
2424
public Iterable<ConnectorFactory> getConnectorFactories()
2525
{
26-
return ImmutableList.of(new DruidConnectorFactory());
26+
return ImmutableList.of(new DruidConnectorFactory(getClassLoader()));
27+
}
28+
29+
private static ClassLoader getClassLoader()
30+
{
31+
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
32+
if (classLoader == null) {
33+
classLoader = DruidPlugin.class.getClassLoader();
34+
}
35+
return classLoader;
2736
}
2837
}

presto-druid/src/main/java/com/facebook/presto/druid/authentication/DruidAuthenticationModule.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,19 @@ public class DruidAuthenticationModule
3333
@Override
3434
protected void setup(Binder binder)
3535
{
36+
DruidConfig druidConfig = buildConfigObject(DruidConfig.class);
37+
3638
bindAuthenticationModule(
3739
config -> config.getDruidAuthenticationType() == NONE,
3840
noneAuthenticationModule());
3941

4042
bindAuthenticationModule(
4143
config -> config.getDruidAuthenticationType() == BASIC,
42-
basicAuthenticationModule());
44+
basicAuthenticationModule(druidConfig));
4345

4446
bindAuthenticationModule(
4547
config -> config.getDruidAuthenticationType() == KERBEROS,
46-
kerberosbAuthenticationModule());
48+
kerberosbAuthenticationModule(druidConfig));
4749
}
4850

4951
private void bindAuthenticationModule(Predicate<DruidConfig> predicate, Module module)
@@ -56,19 +58,31 @@ private static Module noneAuthenticationModule()
5658
return binder -> httpClientBinder(binder).bindHttpClient("druid-client", ForDruidClient.class);
5759
}
5860

59-
private static Module basicAuthenticationModule()
61+
private static Module basicAuthenticationModule(DruidConfig druidConfig)
6062
{
6163
return binder -> httpClientBinder(binder).bindHttpClient("druid-client", ForDruidClient.class)
6264
.withConfigDefaults(
63-
config -> config.setAuthenticationEnabled(false) //disable Kerberos auth
65+
config -> {
66+
config.setAuthenticationEnabled(false); //disable Kerberos auth
67+
if (druidConfig.isTlsEnabled()) {
68+
config.setTrustStorePath(druidConfig.getTrustStorePath());
69+
config.setTrustStorePassword(druidConfig.getTrustStorePassword());
70+
}
71+
}
6472
).withFilter(
6573
DruidBasicAuthHttpRequestFilter.class);
6674
}
6775

68-
private static Module kerberosbAuthenticationModule()
76+
private static Module kerberosbAuthenticationModule(DruidConfig druidConfig)
6977
{
7078
return binder -> httpClientBinder(binder).bindHttpClient("druid-client", ForDruidClient.class)
7179
.withConfigDefaults(
72-
config -> config.setAuthenticationEnabled(true));
80+
config -> {
81+
config.setAuthenticationEnabled(true);
82+
if (druidConfig.isTlsEnabled()) {
83+
config.setTrustStorePath(druidConfig.getTrustStorePath());
84+
config.setTrustStorePassword(druidConfig.getTrustStorePassword());
85+
}
86+
});
7387
}
7488
}

presto-druid/src/test/java/com/facebook/presto/druid/TestDruidConfig.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,18 @@ public void testDefaults()
4545
.setBasicAuthenticationPassword(null)
4646
.setIngestionStoragePath(StandardSystemProperty.JAVA_IO_TMPDIR.value())
4747
.setCaseInsensitiveNameMatching(false)
48-
.setCaseInsensitiveNameMatchingCacheTtl(new Duration(1, MINUTES)));
48+
.setCaseInsensitiveNameMatchingCacheTtl(new Duration(1, MINUTES))
49+
.setTlsEnabled(false)
50+
.setTrustStorePath(null)
51+
.setTrustStorePassword(null));
4952
}
5053

5154
@Test
5255
public void testExplicitPropertyMappings()
5356
{
5457
Map<String, String> properties = new ImmutableMap.Builder<String, String>()
55-
.put("druid.broker-url", "http://druid.broker:1234")
56-
.put("druid.coordinator-url", "http://druid.coordinator:4321")
58+
.put("druid.broker-url", "https://druid.broker:1234")
59+
.put("druid.coordinator-url", "https://druid.coordinator:4321")
5760
.put("druid.schema-name", "test")
5861
.put("druid.compute-pushdown-enabled", "true")
5962
.put("druid.hadoop.config.resources", "/etc/core-site.xml,/etc/hdfs-site.xml")
@@ -63,6 +66,9 @@ public void testExplicitPropertyMappings()
6366
.put("druid.ingestion.storage.path", "hdfs://foo/bar/")
6467
.put("druid.case-insensitive-name-matching", "true")
6568
.put("druid.case-insensitive-name-matching.cache-ttl", "1s")
69+
.put("druid.tls.enabled", "true")
70+
.put("druid.tls.truststore-path", "/tmp/truststore")
71+
.put("druid.tls.truststore-password", "truststore-password")
6672
.build();
6773

6874
DruidConfig expected = new DruidConfig()
@@ -76,7 +82,10 @@ public void testExplicitPropertyMappings()
7682
.setBasicAuthenticationPassword("http_basic_password")
7783
.setIngestionStoragePath("hdfs://foo/bar/")
7884
.setCaseInsensitiveNameMatching(true)
79-
.setCaseInsensitiveNameMatchingCacheTtl(new Duration(1, SECONDS));
85+
.setCaseInsensitiveNameMatchingCacheTtl(new Duration(1, SECONDS))
86+
.setTlsEnabled(true)
87+
.setTrustStorePath(("/tmp/truststore"))
88+
.setTrustStorePassword("truststore-password");
8089

8190
ConfigAssertions.assertFullMapping(properties, expected);
8291
}

0 commit comments

Comments
 (0)