-
Notifications
You must be signed in to change notification settings - Fork 3.8k
druid-pac4j: add ability to use custom ssl trust store while talking to auth server #9637
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
Merged
Changes from all commits
Commits
Show all changes
2 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 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
60 changes: 60 additions & 0 deletions
60
...druid-pac4j/src/main/java/org/apache/druid/security/pac4j/CustomSSLResourceRetriever.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,60 @@ | ||
| /* | ||
| * 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.security.pac4j; | ||
|
|
||
|
|
||
| import com.google.common.primitives.Ints; | ||
| import com.nimbusds.jose.util.DefaultResourceRetriever; | ||
|
|
||
| import javax.net.ssl.HttpsURLConnection; | ||
| import javax.net.ssl.SSLSocketFactory; | ||
| import java.io.IOException; | ||
| import java.net.HttpURLConnection; | ||
| import java.net.URL; | ||
|
|
||
|
|
||
| /** | ||
| * This class exists only to enable use of custom SSLSocketFactory on top of builtin class. This could be removed | ||
| * when same functionality has been added to original class com.nimbusds.jose.util.DefaultResourceRetriever. | ||
| */ | ||
| public class CustomSSLResourceRetriever extends DefaultResourceRetriever | ||
| { | ||
| private SSLSocketFactory sslSocketFactory; | ||
|
|
||
| public CustomSSLResourceRetriever(long readTimeout, SSLSocketFactory sslSocketFactory) | ||
| { | ||
| // super(..) has to be the very first statement in constructor. | ||
| super(Ints.checkedCast(readTimeout), Ints.checkedCast(readTimeout)); | ||
|
|
||
| this.sslSocketFactory = sslSocketFactory; | ||
| } | ||
|
|
||
| @Override | ||
| protected HttpURLConnection openConnection(final URL url) throws IOException | ||
| { | ||
| HttpURLConnection con = super.openConnection(url); | ||
|
|
||
| if (sslSocketFactory != null && con instanceof HttpsURLConnection) { | ||
| ((HttpsURLConnection) con).setSSLSocketFactory(sslSocketFactory); | ||
| } | ||
|
|
||
| return con; | ||
| } | ||
| } |
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
68 changes: 68 additions & 0 deletions
68
...ons-core/druid-pac4j/src/main/java/org/apache/druid/security/pac4j/Pac4jCommonConfig.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,68 @@ | ||
| /* | ||
| * 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.security.pac4j; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import com.google.common.base.Preconditions; | ||
| import org.apache.druid.metadata.PasswordProvider; | ||
| import org.joda.time.Duration; | ||
|
|
||
| public class Pac4jCommonConfig | ||
| { | ||
| @JsonProperty | ||
| private final boolean enableCustomSslContext; | ||
|
|
||
| @JsonProperty | ||
| private final PasswordProvider cookiePassphrase; | ||
|
|
||
| @JsonProperty | ||
| private final Duration readTimeout; | ||
|
|
||
| @JsonCreator | ||
| public Pac4jCommonConfig( | ||
| @JsonProperty("enableCustomSslContext") boolean enableCustomSslContext, | ||
| @JsonProperty("cookiePassphrase") PasswordProvider cookiePassphrase, | ||
| @JsonProperty("readTimeout") Duration readTimeout | ||
| ) | ||
| { | ||
| this.enableCustomSslContext = enableCustomSslContext; | ||
| this.cookiePassphrase = Preconditions.checkNotNull(cookiePassphrase, "null cookiePassphrase"); | ||
| this.readTimeout = readTimeout == null ? Duration.millis(5000) : readTimeout; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public boolean isEnableCustomSslContext() | ||
| { | ||
| return enableCustomSslContext; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public PasswordProvider getCookiePassphrase() | ||
| { | ||
| return cookiePassphrase; | ||
| } | ||
|
|
||
| @JsonProperty | ||
| public Duration getReadTimeout() | ||
| { | ||
| return readTimeout; | ||
| } | ||
| } |
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
48 changes: 48 additions & 0 deletions
48
...nsions-core/druid-pac4j/src/test/java/org/apache/druid/security/pac4j/OIDCConfigTest.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,48 @@ | ||
| /* | ||
| * 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.security.pac4j; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| public class OIDCConfigTest | ||
| { | ||
| @Test | ||
| public void testSerde() throws Exception | ||
| { | ||
| ObjectMapper jsonMapper = new ObjectMapper(); | ||
|
|
||
| String jsonStr = "{\n" | ||
| + " \"clientID\": \"testid\",\n" | ||
| + " \"clientSecret\": \"testsecret\",\n" | ||
| + " \"discoveryURI\": \"testdiscoveryuri\"\n" | ||
| + "}\n"; | ||
|
|
||
| OIDCConfig conf = jsonMapper.readValue( | ||
| jsonMapper.writeValueAsString(jsonMapper.readValue(jsonStr, OIDCConfig.class)), | ||
| OIDCConfig.class | ||
| ); | ||
|
|
||
| Assert.assertEquals("testid", conf.getClientID()); | ||
| Assert.assertEquals("testsecret", conf.getClientSecret().getPassword()); | ||
| Assert.assertEquals("testdiscoveryuri", conf.getDiscoveryURI()); | ||
| } | ||
| } |
49 changes: 49 additions & 0 deletions
49
...core/druid-pac4j/src/test/java/org/apache/druid/security/pac4j/Pac4jCommonConfigTest.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,49 @@ | ||
| /* | ||
| * 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.security.pac4j; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import org.apache.druid.jackson.DefaultObjectMapper; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| public class Pac4jCommonConfigTest | ||
| { | ||
| @Test | ||
| public void testSerde() throws Exception | ||
| { | ||
| ObjectMapper jsonMapper = new DefaultObjectMapper(); | ||
|
|
||
| String jsonStr = "{\n" | ||
| + " \"cookiePassphrase\": \"testpass\",\n" | ||
| + " \"readTimeout\": \"PT10S\",\n" | ||
| + " \"enableCustomSslContext\": true\n" | ||
| + "}\n"; | ||
|
|
||
| Pac4jCommonConfig conf = jsonMapper.readValue( | ||
| jsonMapper.writeValueAsString(jsonMapper.readValue(jsonStr, Pac4jCommonConfig.class)), | ||
| Pac4jCommonConfig.class | ||
| ); | ||
|
|
||
| Assert.assertEquals("testpass", conf.getCookiePassphrase().getPassword()); | ||
| Assert.assertEquals(10_000L, conf.getReadTimeout().getMillis()); | ||
| Assert.assertTrue(conf.isEnableCustomSslContext()); | ||
| } | ||
| } |
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
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.
I think reusing
simple-client-sslcontextis good for now since the client is the same entity (a Druid server); are there any potential cases where you'd want to use a different truststore or keystore when talking to the auth server here vs. another Druid server?Uh oh!
There was an error while loading. Please reload this page.
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.
thanks for looking, valid question.
I chose to go this route instead of adding separate config for a brand new ssl context to reduce amount of configuration user has. That said, I see that
ldapdoesn't use druid's common ssl context but builds one separately. I haven't personally seen the use cases for this separation yet but I am not a security expert and could be wrong :)If we come across such use case, then I think we should add support for another SSLContext inside druid core code .. one for talking to external auth services (oauth server, ldap server etc) so that we don't repeat this thing for all auth extensions that happen to talk to external services.