Skip to content

Commit 77e1496

Browse files
committed
Simplifying SSL configuration
Having to set sslProtocol was bothering me because I don't think there's any way for something besides "default" to work.
1 parent e45ed4d commit 77e1496

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

docs/configuration.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ These options define how the connector connects and authenticates with MarkLogic
2626
| spark.marklogic.client.cloud.apiKey | Required for MarkLogic `cloud` authentication. |
2727
| spark.marklogic.client.kerberos.principal | Required for `kerberos` authentication. |
2828
| spark.marklogic.client.saml.token | Required for `saml` authentication. |
29-
| spark.marklogic.client.sslProtocol | If `default`, an SSL connection is created using the JVM's default SSL context; else the value is passed to the [SSLContext method](https://docs.oracle.com/javase/8/docs/api/javax/net/ssl/SSLContext.html#getInstance-java.lang.String-) for instantiating an SSL context. |
30-
| spark.marklogic.client.sslHostnameVerifier | Either `any`, `common`, or `strict`. |
29+
| spark.marklogic.client.sslEnabled | If 'true', an SSL connection is created using the JVM's default SSL context.
30+
| spark.marklogic.client.sslHostnameVerifier | Either `any`, `common`, or `strict`; see the [MarkLogic Java Client documentation](https://docs.marklogic.com/javadoc/client/com/marklogic/client/DatabaseClientFactory.SSLHostnameVerifier.html) for more information on these choices. |
3131
| spark.marklogic.client.uri | Shortcut for setting the host, port, username, and password when using `basic` or `digest` authentication. See below for more information. |
3232

3333
### Connecting with a client URI
@@ -61,11 +61,10 @@ triplet. For example, a password of `sp@r:k` must appear in the `spark.marklogic
6161

6262
### Configuring SSL
6363

64-
If the MarkLogic app server that the connector will connect to requires SSL, you will need to configure the
65-
`spark.marklogic.client.sslProtocol` option. The common approach is to set this to `default`, causing the associated
66-
JVM's certificate store - typically the `$JAVA_HOME/jre/lib/security/cacerts` file - to be used for establishing an
67-
SSL connection. The certificate store should contain the public certificate associated with the SSL certificate template
68-
used by the MarkLogic app server.
64+
If the MarkLogic app server that the connector will connect to requires SSL, the `spark.marklogic.client.sslEnabled`
65+
option must be set to 'true'. This causes the associated JVM's certificate store - typically the
66+
`$JAVA_HOME/jre/lib/security/cacerts` file - to be used for establishing an SSL connection. The certificate store
67+
should contain the public certificate associated with the SSL certificate template used by the MarkLogic app server.
6968

7069
If you receive an error containing a message of "PKIX path building failed", the most likely issue is that your JVM's
7170
certificate store does not contain the public certificate associated with the MarkLogic app server, or your Spark
@@ -75,7 +74,9 @@ error.
7574

7675
If you receive an `javax.net.ssl.SSLPeerUnverifiedException` error, you will need to adjust the
7776
`spark.marklogic.client.sslHostnameVerifier` option. A value of `ANY` will disable hostname verification,
78-
which may be appropriate in a development or test environment.
77+
which may be appropriate in a development or test environment. The
78+
[MarkLogic Java Client documentation](https://docs.marklogic.com/javadoc/client/com/marklogic/client/DatabaseClientFactory.SSLHostnameVerifier.html)
79+
describes the other choices for this option.
7980

8081
## Read options
8182

src/main/java/com/marklogic/spark/ContextSupport.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ protected final Map<String, String> buildConnectionProperties() {
6262
parseClientUri(clientUri, connectionProps);
6363
}
6464

65+
if ("true".equalsIgnoreCase(properties.get(Options.CLIENT_SSL_ENABLED))) {
66+
connectionProps.put("spark.marklogic.client.sslProtocol", "default");
67+
}
68+
6569
return connectionProps;
6670
}
6771

src/main/java/com/marklogic/spark/Options.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
public interface Options {
1919

2020
String CLIENT_URI = "spark.marklogic.client.uri";
21+
String CLIENT_SSL_ENABLED = "spark.marklogic.client.sslEnabled";
2122

2223
String READ_OPTIC_QUERY = "spark.marklogic.read.opticQuery";
2324
String READ_NUM_PARTITIONS = "spark.marklogic.read.numPartitions";

src/test/java/com/marklogic/spark/BuildConnectionPropertiesTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Map;
2222

2323
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertFalse;
2425

2526
public class BuildConnectionPropertiesTest {
2627

@@ -48,4 +49,25 @@ void overrideDefaults() {
4849
assertEquals("direct", connectionProps.get(CONNECTION_TYPE));
4950
}
5051

52+
@Test
53+
void sslEnabled() {
54+
properties.put(Options.CLIENT_SSL_ENABLED, "true");
55+
56+
Map<String, String> connectionProps = new ContextSupport(properties).buildConnectionProperties();
57+
assertEquals("default", connectionProps.get("spark.marklogic.client.sslProtocol"),
58+
"While the Java Client allows for actual protocol values for the sslProtocol property, the SSLContext " +
59+
"that's created still needs an X509TrustManager. But since Spark options only allow for simple values, " +
60+
"there's no way for a Spark user to provide a custom X509TrustManager. It appears the only possibility " +
61+
"is to use the JVM's default trust manager. Thus, instead of forcing the user to set " +
62+
"sslProtocol=default (which implies there are other valid choices), the Spark connector lets a user " +
63+
"set sslEnabled=true, which is a shortcut for requesting that the JVM's default trust manager be used.");
64+
}
65+
66+
@Test
67+
void sslDisabled() {
68+
properties.put(Options.CLIENT_SSL_ENABLED, "false");
69+
70+
Map<String, String> connectionProps = new ContextSupport(properties).buildConnectionProperties();
71+
assertFalse(connectionProps.containsKey("spark.marklogic.client.sslProtocol"));
72+
}
5173
}

0 commit comments

Comments
 (0)