@@ -114,6 +114,10 @@ It is also possible to require using the shared library by passing
114
114
``crypt_shared_lib_required: true`` option when creating a client. In this case,
115
115
an error will be raised if the shared library cannot be loaded.
116
116
117
+ .. note::
118
+ All ``Mongo::Client`` objects in the same process should use the same setting
119
+ ``:crypt_shared_lib_path``, as it is an error to load more that one crypt_shared dynamic library simultaneously in a single operating system process.
120
+
117
121
mongocryptd
118
122
~~~~~~~~~~~
119
123
@@ -166,6 +170,20 @@ in order to perform automatic encryption.
166
170
167
171
Automatic encryption requires the authenticated user to have the listCollections privilege action.
168
172
173
+ .. note::
174
+
175
+ When using Automatic Encryption, and a ``Mongo::Client`` instance that is configured
176
+ with ``:auto_encryption_options`` has a limited connection pool size
177
+ (i.e a non-zero ``:max_pool_size``, which is the default setting), a separate
178
+ internal ``Mongo::Client`` instance is created if any of the following are true:
179
+
180
+ - ``auto_encryption_options[:key_vault_client]`` is not passed.
181
+ - ``auto_encryption_options[:bypass_automatic_encryption]`` is not passed or false.
182
+
183
+ If an internal ``Mongo::Client`` instance is created, it is configured with
184
+ the same options as the parent client except ``:min_pool_size`` is set to 0
185
+ and ``:auto_encryption_options`` is omitted.
186
+
169
187
.. code-block:: ruby
170
188
171
189
require 'mongo'
@@ -249,7 +267,7 @@ in order to perform automatic encryption.
249
267
['localhost:27017'],
250
268
database: 'encryption_db',
251
269
)
252
- client_no_encryption. ['encryption_coll'].find.first['encrypted_field']
270
+ client_no_encryption['encryption_coll'].find.first['encrypted_field']
253
271
# => <BSON::Binary... type=ciphertext...>
254
272
255
273
The example above demonstrates using automatic encryption with a local master key.
@@ -401,7 +419,7 @@ Below is an example of using automatic queryable encryption using the Ruby drive
401
419
402
420
# The key vault client is a Mongo::Client instance
403
421
# that will be used to store your data keys.
404
- key_vault_client = Mongo::Client.new([' localhost:27017'] )
422
+ key_vault_client = Mongo::Client.new('mongodb:// localhost:27017,localhost:27018' )
405
423
406
424
# Use an instance of Mongo::ClientEncryption to create a new data key
407
425
client_encryption = Mongo::ClientEncryption.new(
@@ -435,7 +453,7 @@ Below is an example of using automatic queryable encryption using the Ruby drive
435
453
436
454
# Configure the client for automatic encryption
437
455
client = Mongo::Client.new(
438
- [' localhost:27017'] ,
456
+ 'mongodb:// localhost:27017,localhost:27018' ,
439
457
auto_encryption_options: {
440
458
key_vault_namespace: 'encryption.__keyVault',
441
459
kms_providers: kms_providers,
@@ -496,7 +514,7 @@ Below is an example of explicit queryable encryption.
496
514
497
515
# The key vault client is a Mongo::Client instance
498
516
# that will be used to store your data keys.
499
- key_vault_client = Mongo::Client.new([' localhost:27017'] )
517
+ key_vault_client = Mongo::Client.new('mongodb:// localhost:27017,localhost:27018' )
500
518
501
519
# Use an instance of Mongo::ClientEncryption to create a new data key
502
520
client_encryption = Mongo::ClientEncryption.new(
@@ -511,27 +529,39 @@ Below is an example of explicit queryable encryption.
511
529
##########################################
512
530
# Step 3: Create an encrypted collection #
513
531
##########################################
514
-
515
- # Create the client you will use to read and write the data to MongoDB
516
- client = Mongo::Client.new(['localhost:27017'], database: 'encryption_db')
517
-
518
532
encrypted_fields = {
519
533
fields: [
520
534
{
521
535
path: 'encrypted_field',
522
536
bsonType: 'string',
523
537
keyId: data_key_id,
524
538
queries: {
525
- queryType: 'equality'
539
+ queryType: 'equality',
540
+ contention: 0
526
541
}
527
542
}
528
543
]
529
544
}
530
545
546
+ # Create the client you will use to read and write the data to MongoDB
547
+ # Please note that to insert or query with an "Indexed" encrypted payload,
548
+ # you should use a ``Mongo::Client`` that is configured with ``:auto_encryption_options``.
549
+ # ``auto_encryption_options[:bypass_query_analysis]`` may be true.
550
+ # ``auto_encryption_options[:bypass_auto_encryption]`` must be not set or false.
551
+ client = Mongo::Client.new(
552
+ ['localhost:27017'],
553
+ auto_encryption_options: {
554
+ key_vault_namespace: 'encryption.__keyVault',
555
+ kms_providers: kms_providers,
556
+ bypass_query_analysis: true,
557
+ },
558
+ database: 'encryption_db',
559
+ )
560
+
531
561
# Make sure there is no data in the collection.
532
- client['encryption_coll'].drop(encrypted_field : encrypted_fields)
562
+ client['encryption_coll'].drop(encrypted_fields : encrypted_fields)
533
563
# Create encrypted collection explicitly.
534
- collection = client['encryption_coll'].create(encrypted_fields: encrypted_fields)
564
+ client['encryption_coll'].create(encrypted_fields: encrypted_fields)
535
565
536
566
#####################################################
537
567
# Step 4: Encrypt a string with explicit encryption #
@@ -545,24 +575,27 @@ Below is an example of explicit queryable encryption.
545
575
'sensitive data',
546
576
{
547
577
key_id: data_key_id,
548
- algorithm: "Indexed"
578
+ algorithm: "Indexed",
579
+ contention_factor: 0
549
580
}
550
581
)
551
582
552
583
# Insert the encrypted value into the collection
553
- collection .insert_one(encrypted_field: insert_payload)
584
+ client['encryption_coll'] .insert_one(encrypted_field: insert_payload)
554
585
555
586
# Use the client to read the encrypted value from the database, then
556
- # use the ClientEncryption object to decrypt it
587
+ # use the ClientEncryption object to decrypt it.
557
588
find_payload = client_encryption.encrypt(
558
589
'sensitive data',
559
590
{
560
591
key_id: data_key_id,
561
592
algorithm: "Indexed",
593
+ contention_factor: 0,
562
594
query_type: "equality"
563
595
}
564
596
)
565
- find_result = collection.find(encrypted_field: find_payload).first['encrypted_field']
597
+
598
+ find_result = client['encryption_coll'].find(encrypted_field: find_payload).first['encrypted_field']
566
599
# => 'sensitive data'
567
600
568
601
0 commit comments