|
| 1 | +.. _spark-configure-tls: |
| 2 | + |
| 3 | +================= |
| 4 | +Configure TLS/SSL |
| 5 | +================= |
| 6 | + |
| 7 | +.. contents:: On this page |
| 8 | + :local: |
| 9 | + :backlinks: none |
| 10 | + :depth: 2 |
| 11 | + :class: singlecol |
| 12 | + |
| 13 | +.. facet:: |
| 14 | + :name: genre |
| 15 | + :values: reference |
| 16 | + |
| 17 | +.. meta:: |
| 18 | + :keywords: code example, authenticate |
| 19 | + |
| 20 | +Overview |
| 21 | +-------- |
| 22 | + |
| 23 | +In this guide, you can learn how to configure :wikipedia:`TLS/SSL |
| 24 | +<Transport_Layer_Security>` to secure communications between the |
| 25 | +{+connector-long+} and your MongoDB deployment. |
| 26 | + |
| 27 | +To use TLS/SSL, your application and each of your Spark |
| 28 | +workers must have access to cryptographic certificates that prove their |
| 29 | +identity. Store the certificates in your JVM trust store and your JVM |
| 30 | +key store. You can configure access to these certificates through your Spark |
| 31 | +configuration file, or when launching a Spark job from the command line. |
| 32 | + |
| 33 | +Create a JVM Trust Store |
| 34 | +------------------------ |
| 35 | + |
| 36 | +The JVM trust store saves certificates that securely identify other applications |
| 37 | +with which your application interacts. Using these certificates, your |
| 38 | +application can prove that the connection to another application is genuine and |
| 39 | +secure. |
| 40 | + |
| 41 | +Create a trust store with the `keytool <https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html>`__ command line tool provided as part of the |
| 42 | +JDK: |
| 43 | + |
| 44 | +.. code-block:: sh |
| 45 | + |
| 46 | + keytool -importcert -trustcacerts -file <path to certificate authority file> |
| 47 | + -keystore <path to trust store> -storepass <password> |
| 48 | + |
| 49 | +Create a JVM Key Store |
| 50 | +---------------------- |
| 51 | + |
| 52 | +The JVM key store saves certificates that securely identify your application to |
| 53 | +other applications. Using these certificates, other |
| 54 | +applications can prove that the connection to your application is genuine and |
| 55 | +secure. |
| 56 | + |
| 57 | +Create a key store by using the `keytool |
| 58 | +<https://docs.oracle.com/javase/8/docs/technotes/tools/unix/keytool.html>`__, or |
| 59 | +`openssl <https://www.openssl.org/docs/>`__ command line tools. |
| 60 | + |
| 61 | +Enable TLS/SSL |
| 62 | +-------------- |
| 63 | + |
| 64 | +You can enable TLS/SSL for the connection to your MongoDB instance through the |
| 65 | +``tls`` parameter in your connection URI. |
| 66 | + |
| 67 | +The following example shows a connection URI with the ``tls`` option assigned |
| 68 | +to ``true`` to enable TLS/SSL: |
| 69 | + |
| 70 | +.. code-block:: none |
| 71 | + |
| 72 | + "mongodb+srv://<username>:<password>@<cluster-url>?tls=true" |
| 73 | + |
| 74 | +For more information about creating a connection string, see the |
| 75 | +:manual:`Connection String guide <reference/connection-string/>` on the server |
| 76 | +manual. |
| 77 | + |
| 78 | +Configure Access to Certificate Stores |
| 79 | +-------------------------------------- |
| 80 | + |
| 81 | +To configure your Spark application to access the certificates stored in your |
| 82 | +JVM trust store and JVM key store, the following system properties must be set: |
| 83 | + |
| 84 | +- javax.net.ssl.trustStore |
| 85 | +- javax.net.ssl.trustStorePassword |
| 86 | +- javax.net.ssl.keyStore |
| 87 | +- javax.net.ssl.keyStorePassword |
| 88 | + |
| 89 | +Set the Properties in Your Spark Configuration File |
| 90 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 91 | + |
| 92 | +You can set the system properties in your Spark configuration file as follows: |
| 93 | + |
| 94 | +.. code-block:: none |
| 95 | + |
| 96 | + spark.executor.extraJavaOptions=-Djavax.net.ssl.trustStore=<Path to your trust store> -Djavax.net.ssl.trustStorePassword=<Your trust store password> -Djavax.net.ssl.keyStore=<Path to your key store> -Djavax.net.ssl.keyStorePassword=<Your key store password>" |
| 97 | + |
| 98 | + spark.driver.extraJavaOptions=-Djavax.net.ssl.trustStore=<Path to your trust store> -Djavax.net.ssl.trustStorePassword=<Your trust store password> -Djavax.net.ssl.keyStore=<Path to your key store> -Djavax.net.ssl.keyStorePassword=<Your key store password>" |
| 99 | + |
| 100 | +Set the Properties From the Command Line |
| 101 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 102 | + |
| 103 | +You can set the system properties from the command line by adding them with the |
| 104 | +``--conf`` flag when you submit a Spark job: |
| 105 | + |
| 106 | +.. code-block:: sh |
| 107 | + |
| 108 | + ./bin/spark-submit --name "<Your app name>" \ |
| 109 | + --master "<Master URL>" \ |
| 110 | + --conf "spark.executor.extraJavaOptions=-Djavax.net.ssl.trustStore=<Path to your trust store> -Djavax.net.ssl.trustStorePassword=<Your trust store password> -Djavax.net.ssl.keyStore=<Path to your key store> -Djavax.net.ssl.keyStorePassword=<Your key store password>" \ |
| 111 | + sparkApplication.jar \ |
| 112 | + --conf "spark.driver.extraJavaOptions=-Djavax.net.ssl.trustStore=<Path to your trust store> -Djavax.net.ssl.trustStorePassword=<Your trust store password> -Djavax.net.ssl.keyStore=<Path to your key store> -Djavax.net.ssl.keyStorePassword=<Your key store password>" \ |
| 113 | + sparkApplication.jar |
0 commit comments