@@ -977,33 +977,83 @@ on the client or passed to individual operations under ``:write_concern``.
977977TLS Connections
978978===============
979979
980- To connect to the MongoDB cluster using TLS, pass the ``ssl`` Ruby option or
981- the ``tls`` URI option to the ``Mongo::Client`` constructor. TLS must be
982- explicitly requested on the client side when the deployment requires TLS
983- connections - there is currently no automatic detection of whether the
984- deployment requires TLS.
980+ To connect to the MongoDB deployment using TLS:
985981
986- The driver will attempt to verify the server's TLS certificate by default, and
987- will abort the connection if this verification fails. In order for this
988- verification to succeed, you may need to specify the certificate authority
989- that the server certificate is signed with via ``tlsCAFile`` URI option or
990- ``ssl_ca_cert`` Ruby option. If these options are not given, the driver will
991- use the default system root certificate store as the trust anchor; if these
992- options are given, the default system root certificate store will not be used.
993- To omit TLS certificate verification by the client, which is not
994- recommended, specify ``tlsInsecure=true`` URI option or ``ssl_verify: false``
995- Ruby option.
996-
997- By default, MongoDB server will verify the connecting clients' TLS certificates,
998- which requires the client to specify a client certificate when connecting.
999- This can be accomplished through ``tlsCertificateKeyFile`` URI option which
1000- takes as the argument the path to a single file containing both the certificate
1001- and the corresponding private key, or through ``:ssl_cert`` and ``:ssl_key``
1002- Ruby options. The Ruby options allow passing separace certificate and key files
1003- to the driver, but also can be pointed at the single PEM file containing both
1004- the certificate and the corresponding private key. Further information on
1005- configuring MongoDB server for TLS is available in the `MongoDB manual
1006- <https://docs.mongodb.com/manual/tutorial/configure-ssl/>`_.
982+ - Enable TLS connections in ``Mongo::Client``.
983+ - Specify the client TLS certificate.
984+ - Specify the CA certificate to verify the server's TLS certificate.
985+
986+ Enable TLS Connections
987+ ----------------------
988+
989+ TLS must be explicitly requested on the client side when the deployment
990+ requires TLS connections - there is currently no automatic detection of
991+ whether the deployment requires TLS.
992+
993+ To request TLS connections, specify the following client options when
994+ constructing a ``Mongo::Client``:
995+
996+ - The ``:ssl`` Ruby option.
997+ - The ``tls`` URI option.
998+ - The ``ssl`` URI option (deprecated).
999+
1000+ Specify Client TLS Certificate
1001+ ------------------------------
1002+
1003+ By default, MongoDB server will attempt to verify the connecting clients'
1004+ TLS certificates, which requires the clients to specify their TLS certificates
1005+ when connecting. This can be accomplished via:
1006+
1007+ - The ``:ssl_cert``/``:ssl_cert_object``/``:ssl_cert_string` and
1008+ ``:ssl_key``/``:ssl_key_object``/``:ssl_key_string``/``:ssl_key_pass_phrase``
1009+ Ruby options.
1010+ - The``tlsCertificateKeyFile`` URI option.
1011+
1012+ When using the Ruby options, the client TLS certificate and the corresponding
1013+ private key may be provided separately. For example, if the certificate is
1014+ stored in ``client.crt`` and the private key is stored in ``client.key``,
1015+ a ``Mongo::Client`` may be constructed as follows:
1016+
1017+ .. code-block:: ruby
1018+
1019+ client = Mongo::Client.new(["localhost:27017"],
1020+ ssl: true,
1021+ ssl_cert: 'path/to/client.crt',
1022+ ssl_key: 'path/to/client.key',
1023+ ssl_ca_cert: 'path/to/ca.crt',
1024+ )
1025+
1026+ ``ssl_cert``, ``ssl_cert_string``, ``ssl_key`` and ``ssl_key_string`` Ruby
1027+ options also permit the certificate and the key to be provided in the same
1028+ file or string, respectively. The files containing both certificate and
1029+ private key frequently have the ``.pem`` extension. When both certificate
1030+ and the private key are provided in the same file or string, both the
1031+ certifcate and the key options must be utilized, as follows:
1032+
1033+ .. code-block:: ruby
1034+
1035+ client = Mongo::Client.new(["localhost:27017"],
1036+ ssl: true,
1037+ ssl_cert: 'path/to/client.pem',
1038+ ssl_key: 'path/to/client.pem',
1039+ ssl_ca_cert: 'path/to/ca.crt',
1040+ )
1041+
1042+ When using the URI option, the certificate and the key must be stored in a
1043+ file and both must be stored in the same file. Example usage:
1044+
1045+ .. code-block:: ruby
1046+
1047+ client = Mongo::Client.new(
1048+ "mongodb://localhost:27017/?tls=true&tlsCertificateKeyFile=path%2fto%2fclient.pem&tlsCertificateKeyFile=path%2fto%2fca.crt")
1049+
1050+ .. note::
1051+
1052+ URI option values must be properly URI escaped. This applies, for example, to
1053+ slashes in the paths.
1054+
1055+ Further information on configuring MongoDB server for TLS is available in the
1056+ :manual:`MongoDB manual </tutorial/configure-ssl/>`.
10071057
10081058Using Intermediate Certificates
10091059```````````````````````````````
@@ -1034,22 +1084,48 @@ so, the intermediate certificates are elevated to trusted status and are
10341084themselves not verified against the actual CA root. More information on this
10351085issue is available `here <https://mail.python.org/pipermail/cryptography-dev/2016-August/000676.html>`_.
10361086
1087+ Specify CA Certificate
1088+ ----------------------
1089+
1090+ The driver will attempt to verify the server's TLS certificate by default, and
1091+ will abort the connection if this verification fails. By default, the driver
1092+ will use the default system root certificate store as the trust anchor.
1093+ To specify the CA certificate that the server's certificate is signed with,
1094+ use:
1095+
1096+ - The ``:ssl_ca_cert``/``:ssl_ca_cert_string``/``:ssl_ca_cert_object``
1097+ Ruby options
1098+ - The ``tlsCAFile`` URI option.
1099+
1100+ If any of these options are given, the server's certificate will be verified
1101+ only against the specified CA certificate and the default system root
1102+ certificate store will not be used.
1103+
1104+ To not perform server TLS certificate verification, which is not
1105+ recommended, specify the ``ssl_verify: false`` Ruby option or the
1106+ ``tlsInsecure=true`` URI option.
1107+
10371108Specifying Multiple CA Certificates
10381109```````````````````````````````````
10391110
1040- ``:ssl_ca_cert`` Ruby option and ``tlsCAFile`` URI option can be used with
1111+ The ``:ssl_ca_cert`` Ruby option and ``tlsCAFile`` URI option can be used with
10411112a file containing multiple certificates. All certificates thus referenced
10421113will become trust anchors.
10431114
1044- ``:ssl_ca_cert_object`` option takes an array of certificates, and thus
1115+ The ``:ssl_ca_cert_object`` option takes an array of certificates, and thus
10451116can also be used to add multiple certificates as certificate authorities.
10461117
1047- ``:ssl_ca_cert_string`` option supports passing only one CA certificate to the
1048- driver.
1118+ The ``:ssl_ca_cert_string`` option supports specifying only one CA certificate.
10491119
1050- Intermediate certificates should not be specified in files given to any
1051- of these options, because they would then not be verified against actual
1052- trusted CA certificates.
1120+ .. warning::
1121+
1122+ Intermediate certificates must not be provided in files specified by the
1123+ CA certificate options. Doing so would elevate the intermediate certificates
1124+ to the status of root certificates, rather than verifying intermediate
1125+ certificates against the root certificates.
1126+
1127+ If intermediate certificates need to be used, specify them as part of the
1128+ client or server TLS certificate files.
10531129
10541130
10551131IPv4/IPv6 Connections
0 commit comments