-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Allow custom TLS cert checks #6432
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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 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 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,57 @@ | ||
[program:druid-router-custom-check-tls] | ||
command=java | ||
-server | ||
-Xmx128m | ||
-XX:+UseConcMarkSweepGC | ||
-XX:+PrintGCDetails | ||
-XX:+PrintGCTimeStamps | ||
-Duser.timezone=UTC | ||
-Dfile.encoding=UTF-8 | ||
-Ddruid.host=%(ENV_HOST_IP)s | ||
-Ddruid.plaintextPort=8891 | ||
-Ddruid.tlsPort=9091 | ||
-Ddruid.zk.service.host=druid-zookeeper-kafka | ||
-Ddruid.server.http.numThreads=100 | ||
-Ddruid.lookup.numLookupLoadingThreads=1 | ||
-Ddruid.router.managementProxy.enabled=true | ||
-Ddruid.auth.authenticatorChain="[\"basic\"]" | ||
-Ddruid.auth.authenticator.basic.type=basic | ||
-Ddruid.auth.authenticator.basic.initialAdminPassword=priest | ||
-Ddruid.auth.authenticator.basic.initialInternalClientPassword=warlock | ||
-Ddruid.auth.authenticator.basic.authorizerName=basic | ||
-Ddruid.auth.basic.common.cacheDirectory=/tmp/authCache/router-custom-check-tls | ||
-Ddruid.escalator.type=basic | ||
-Ddruid.escalator.internalClientUsername=druid_system | ||
-Ddruid.escalator.internalClientPassword=warlock | ||
-Ddruid.escalator.authorizerName=basic | ||
-Ddruid.auth.authorizers="[\"basic\"]" | ||
-Ddruid.auth.authorizer.basic.type=basic | ||
-Ddruid.sql.enable=true | ||
-Ddruid.sql.avatica.enable=true | ||
-Ddruid.enableTlsPort=true | ||
-Ddruid.server.https.keyStorePath=/tls/server.jks | ||
-Ddruid.server.https.keyStoreType=jks | ||
-Ddruid.server.https.certAlias=druid | ||
-Ddruid.server.https.keyManagerPassword=druid123 | ||
-Ddruid.server.https.keyStorePassword=druid123 | ||
-Ddruid.server.https.requireClientCertificate=true | ||
-Ddruid.server.https.trustStorePath=/tls/truststore.jks | ||
-Ddruid.server.https.trustStorePassword=druid123 | ||
-Ddruid.server.https.trustStoreAlgorithm=PKIX | ||
-Ddruid.server.https.validateHostnames=true | ||
-Ddruid.client.https.trustStoreAlgorithm=PKIX | ||
-Ddruid.client.https.protocol=TLSv1.2 | ||
-Ddruid.client.https.trustStorePath=/tls/truststore.jks | ||
-Ddruid.client.https.trustStorePassword=druid123 | ||
-Ddruid.client.https.keyStorePath=/tls/server.jks | ||
-Ddruid.client.https.certAlias=druid | ||
-Ddruid.client.https.keyManagerPassword=druid123 | ||
-Ddruid.client.https.keyStorePassword=druid123 | ||
-Ddruid.client.https.validateHostnames=false | ||
-Ddruid.tls.certificateChecker=integration-test | ||
-cp /shared/docker/lib/* | ||
org.apache.druid.cli.Main server router | ||
redirect_stderr=true | ||
priority=100 | ||
autorestart=false | ||
stdout_logfile=/shared/logs/router-custom-check-tls.log |
This file contains 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 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 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 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 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
53 changes: 53 additions & 0 deletions
53
...ion-tests/src/main/java/org/apache/druid/testing/guice/ITTLSCertificateCheckerModule.java
This file contains 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,53 @@ | ||
/* | ||
* 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.druid.testing.guice; | ||
|
||
import com.fasterxml.jackson.databind.Module; | ||
import com.google.inject.Binder; | ||
|
||
import com.google.inject.name.Names; | ||
import org.apache.druid.initialization.DruidModule; | ||
import org.apache.druid.server.security.TLSCertificateChecker; | ||
import org.apache.druid.testing.utils.ITTLSCertificateChecker; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class ITTLSCertificateCheckerModule implements DruidModule | ||
{ | ||
private final ITTLSCertificateChecker INSTANCE = new ITTLSCertificateChecker(); | ||
|
||
public static final String IT_CHECKER_TYPE = "integration-test"; | ||
|
||
@Override | ||
public void configure(Binder binder) | ||
{ | ||
binder.bind(TLSCertificateChecker.class) | ||
.annotatedWith(Names.named(IT_CHECKER_TYPE)) | ||
.toInstance(INSTANCE); | ||
} | ||
|
||
@Override | ||
public List<? extends Module> getJacksonModules() | ||
{ | ||
return Collections.EMPTY_LIST; | ||
} | ||
} | ||
|
63 changes: 63 additions & 0 deletions
63
integration-tests/src/main/java/org/apache/druid/testing/utils/ITTLSCertificateChecker.java
This file contains 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,63 @@ | ||
/* | ||
* 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.druid.testing.utils; | ||
|
||
import org.apache.druid.java.util.common.logger.Logger; | ||
import org.apache.druid.server.security.TLSCertificateChecker; | ||
|
||
import javax.net.ssl.SSLEngine; | ||
import javax.net.ssl.X509ExtendedTrustManager; | ||
import java.security.cert.CertificateException; | ||
import java.security.cert.X509Certificate; | ||
|
||
public class ITTLSCertificateChecker implements TLSCertificateChecker | ||
{ | ||
private static final Logger log = new Logger(ITTLSCertificateChecker.class); | ||
|
||
@Override | ||
public void checkClient( | ||
X509Certificate[] chain, | ||
String authType, | ||
SSLEngine engine, | ||
X509ExtendedTrustManager baseTrustManager | ||
) throws CertificateException | ||
{ | ||
// only the integration test client with "thisisprobablynottherighthostname" cert is allowed to talk to me | ||
if (!chain[0].toString().contains("thisisprobablynottherighthostname") || !engine.getPeerHost().contains("172.172.172.1")) { | ||
throw new CertificateException("Custom check rejected request from client."); | ||
} | ||
} | ||
|
||
@Override | ||
public void checkServer( | ||
X509Certificate[] chain, | ||
String authType, | ||
SSLEngine engine, | ||
X509ExtendedTrustManager baseTrustManager | ||
) throws CertificateException | ||
{ | ||
baseTrustManager.checkServerTrusted(chain, authType, engine); | ||
|
||
// fail intentionally when trying to talk to the broker | ||
if (chain[0].toString().contains("172.172.172.8")) { | ||
throw new CertificateException("Custom check intentionally terminated request to broker."); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...on-tests/src/main/resources/META-INF/services/org.apache.druid.initialization.DruidModule
This file contains 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 @@ | ||
org.apache.druid.testing.guice.ITTLSCertificateCheckerModule |
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.
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.
nit: i find this kind of jarring since outer is
var == null
and then inside it's flipped tonull != var
, but I don't think it's a big dealThere 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.
hm, it follows the convention for the other nodes in that file, i'll leave this unchanged in this PR
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.
👍