@@ -29,7 +29,7 @@ to connect to; if no database name is specified, the client will use the
29
29
.. code-block:: ruby
30
30
31
31
Mongo::Client.new([ '127.0.0.1:27017' ], database: 'mydb')
32
-
32
+
33
33
# Or using the URI syntax:
34
34
Mongo::Client.new("mongodb://127.0.0.1:27017/mydb")
35
35
@@ -82,7 +82,7 @@ The database can be specified during ``Client`` construction:
82
82
83
83
# Using Ruby client options:
84
84
client = Mongo::Client.new(['localhost'], database: 'mydb')
85
-
85
+
86
86
# Using a MongoDB URI:
87
87
client = Mongo::Client.new('mongodb://localhost/mydb')
88
88
@@ -92,9 +92,9 @@ new ``Client`` instance configured with the specified database:
92
92
.. code-block:: ruby
93
93
94
94
client = Mongo::Client.new(['localhost'], database: 'mydb')
95
-
95
+
96
96
admin_client = client.use('admin')
97
-
97
+
98
98
# Issue an administrative command
99
99
admin_client.database.command(replSetGetConfig: 1).documents.first
100
100
@@ -125,7 +125,7 @@ To force all operations to be performed on the designated server, specify the
125
125
.. code-block:: ruby
126
126
127
127
Mongo::Client.new([ '1.2.3.4:27017' ], database: 'mydb', direct_connection: true)
128
-
128
+
129
129
# Or using the URI syntax:
130
130
Mongo::Client.new("mongodb://1.2.3.4:27017/mydb?directConnection=true")
131
131
@@ -153,7 +153,7 @@ connect to the replica set.
153
153
154
154
Mongo::Client.new([ '127.0.0.1:27017', '127.0.0.1:27018' ],
155
155
:database => 'mydb', replica_set: 'myapp')
156
-
156
+
157
157
# Or using the URI syntax:
158
158
Mongo::Client.new("mongodb://127.0.0.1:27017,127.0.0.1:27018/mydb?replicaSet=myapp")
159
159
@@ -186,7 +186,7 @@ spread the operation load accordingly.
186
186
.. code-block:: ruby
187
187
188
188
Mongo::Client.new([ '1.2.3.4:27017', '1.2.3.5:27017' ], :database => 'mydb')
189
-
189
+
190
190
Mongo::Client.new("mongodb://1.2.3.4:27017,1.2.3.5:27017/mydb")
191
191
192
192
@@ -270,7 +270,7 @@ Ruby Options
270
270
271
271
* - ``:auth_mech_properties``
272
272
- Provides additional authentication mechanism properties.
273
-
273
+
274
274
The keys in properties are interpreted case-insensitively.
275
275
When the client is created, keys are lowercased.
276
276
@@ -436,11 +436,11 @@ Ruby Options
436
436
max_staleness: 5,
437
437
}
438
438
}
439
-
439
+
440
440
If tag sets are provided, they must be an array of hashes. A server
441
441
satisfies the read preference if its tags match any one hash in the
442
442
provided tag sets.
443
-
443
+
444
444
Each tag set must be a hash, and will be converted internally to
445
445
a ``BSON::Document`` instance prior to being used for server selection.
446
446
Hash keys can be strings or symbols. The keys are case sensitive.
@@ -480,12 +480,12 @@ Ruby Options
480
480
subscriber not receiving some of the SDAM events. The ``:sdam_proc``
481
481
option permits adding event subscribers on the client being constructed
482
482
before any SDAM events are published.
483
-
483
+
484
484
Pass a ``Proc`` which will be called with the ``Client`` as the argument
485
485
after the client's event subscription mechanism has been initialized
486
486
but before any of the servers are added to the client. Use this
487
487
``Proc`` to set up SDAM event subscribers on the client.
488
-
488
+
489
489
Note: the client is not fully constructed when the ``Proc`` provided in
490
490
``:sdam_proc is invoked, in particular the cluster is nil at this time.
491
491
``:sdam_proc`` procedure should limit itself to calling
@@ -1090,6 +1090,50 @@ file and both must be stored in the same file. Example usage:
1090
1090
URI option values must be properly URI escaped. This applies, for example, to
1091
1091
slashes in the paths.
1092
1092
1093
+ Modifying ``SSLContext``
1094
+ ------------------------
1095
+ It may be desirable to further configure TLS options in the driver, for example
1096
+ by enabling or disabling certain ciphers. Currently, the Ruby driver does not
1097
+ provide a way to do this when initializing a ``Mongo::Client``.
1098
+
1099
+ However, the Ruby driver provides a way to set global "TLS context hooks" --
1100
+ these are user-provided ``Proc``s that will be invoked before any TLS socket
1101
+ connection and can be used to modify the underlying ``OpenSSL::SSL::SSLContext``
1102
+ object used by the socket.
1103
+
1104
+ To set the TLS context hooks, add ``Proc``s to the ``Mongo.tls_context_hooks``
1105
+ array. This should be done before creating any Mongo::Client instances.
1106
+ For example, in a Rails application this code could be placed in an initializer.
1107
+
1108
+ .. code-block:: ruby
1109
+
1110
+ Mongo.tls_context_hooks.push(
1111
+ Proc.new { |context|
1112
+ context.ciphers = ["AES256-SHA"]
1113
+ }
1114
+ )
1115
+
1116
+ # Only the AES256-SHA cipher will be enabled from this point forward
1117
+
1118
+ Every ``Proc`` in ``Mongo.tls_context_hooks`` will be passed an
1119
+ ``OpenSSL::SSL::SSLContext`` object as its sole argument. These ``Proc``s will
1120
+ be executed sequentially during the creation of every ``Mongo::Socket::SSL`` object.
1121
+
1122
+ It is possible to assign the entire array of hooks calling ``Mongo.tls_context_hooks=``,
1123
+ but doing so will remove any previously assigned hooks. It is recommended to use
1124
+ the ``Array#push`` or ``Array#unshift`` methods to add new hooks.
1125
+
1126
+ It is also possible to remove hooks from ``Mongo.tls_context_hooks`` by storing
1127
+ a reference to the ``Proc``s somewhere else in the application, and then using
1128
+ ``Array#delete_if`` to remove the desired hooks.
1129
+
1130
+ ..warning ::
1131
+
1132
+ TLS context hooks are global and will affect every instance of ``Mongo::Client``.
1133
+ Any library that allows applications to enable these hooks should expose methods to
1134
+ modify the hooks (which can be called by the application) rather than
1135
+ automatically enabling the hooks when the library is loaded.
1136
+
1093
1137
Further information on configuring MongoDB server for TLS is available in the
1094
1138
:manual:`MongoDB manual </tutorial/configure-ssl/>`.
1095
1139
@@ -1162,7 +1206,7 @@ The ``:ssl_ca_cert_string`` option supports specifying only one CA certificate.
1162
1206
CA certificate options. Doing so would elevate the intermediate certificates
1163
1207
to the status of root certificates, rather than verifying intermediate
1164
1208
certificates against the root certificates.
1165
-
1209
+
1166
1210
If intermediate certificates need to be used, specify them as part of the
1167
1211
client or server TLS certificate files.
1168
1212
@@ -1300,7 +1344,7 @@ Usage with Forking Servers
1300
1344
==========================
1301
1345
1302
1346
.. note::
1303
-
1347
+
1304
1348
Applications using Mongoid should follow `Mongoid's forking guidance
1305
1349
<https://docs.mongodb.com/mongoid/current/tutorials/mongoid-configuration/#usage-with-forking-servers>`_.
1306
1350
The guidance and sample code below is provided for applications using the
@@ -1316,7 +1360,7 @@ This is because:
1316
1360
2. File descriptors like network sockets are shared between parent and
1317
1361
child processes.
1318
1362
1319
- The driver attempts to detect client use from forked processes and
1363
+ The driver attempts to detect client use from forked processes and
1320
1364
reestablish network connections when such use is detected, alleviating
1321
1365
the issue of file descriptor sharing.
1322
1366
0 commit comments