Skip to content

Commit 29fbddb

Browse files
Properly test FLE with crypt_shared (mongodb#3000)
* Properly test FLE with crypt_shared * Fix failures * wip * Fix rubocop complaints * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Fix the fix * wip * wip * wip * wip * wip * wip --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 3229fc5 commit 29fbddb

20 files changed

Lines changed: 180 additions & 33 deletions

.evergreen/config.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,10 @@ axes:
10631063
display_name: via LMC path
10641064
variables:
10651065
FLE: path
1066+
- id: "mongocryptd"
1067+
display_name: mongocryptd (no crypt_shared)
1068+
variables:
1069+
FLE: mongocryptd
10661070

10671071
- id: ocsp-algorithm
10681072
display_name: OCSP Algorithm
@@ -1532,6 +1536,19 @@ buildvariants:
15321536
tasks:
15331537
- name: "test-fle"
15341538

1539+
- matrix_name: "fle-mongocryptd"
1540+
matrix_spec:
1541+
auth-and-ssl: "noauth-and-nossl"
1542+
ruby: "ruby-4.0"
1543+
topology: [replica-set, sharded-cluster]
1544+
mongodb-version: "8.0"
1545+
os: ubuntu2204
1546+
fle: mongocryptd
1547+
display_name: "FLE mongocryptd: ${mongodb-version} ${topology} ${ruby}"
1548+
tags: ["pr"]
1549+
tasks:
1550+
- name: "test-fle"
1551+
15351552
- matrix_name: "kerberos-unit"
15361553
matrix_spec:
15371554
ruby: "ruby-4.0"

.evergreen/config/axes.yml.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,10 @@ axes:
288288
display_name: via LMC path
289289
variables:
290290
FLE: path
291+
- id: "mongocryptd"
292+
display_name: mongocryptd (no crypt_shared)
293+
variables:
294+
FLE: mongocryptd
291295

292296
- id: ocsp-algorithm
293297
display_name: OCSP Algorithm

.evergreen/config/standard.yml.erb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,19 @@ buildvariants:
355355
tasks:
356356
- name: "test-fle"
357357

358+
- matrix_name: "fle-mongocryptd"
359+
matrix_spec:
360+
auth-and-ssl: "noauth-and-nossl"
361+
ruby: <%= latest_ruby %>
362+
topology: [replica-set, sharded-cluster]
363+
mongodb-version: <%= latest_stable_mdb %>
364+
os: ubuntu2204
365+
fle: mongocryptd
366+
display_name: "FLE mongocryptd: ${mongodb-version} ${topology} ${ruby}"
367+
tags: ["pr"]
368+
tasks:
369+
- name: "test-fle"
370+
358371
- matrix_name: "kerberos-unit"
359372
matrix_spec:
360373
ruby: <%= latest_ruby %>

.evergreen/run-tests.sh

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ fi
6565

6666
# Make sure cmake is installed (in case we need to install the libmongocrypt
6767
# helper)
68-
if [ "$FLE" = "helper" ]; then
68+
if [ -n "$FLE" ]; then
6969
install_cmake
7070
fi
7171

@@ -193,23 +193,25 @@ elif test "$AUTH" = kerberos; then
193193
fi
194194

195195
if test -n "$FLE"; then
196-
# Downloading crypt shared lib
197-
if [ -z "$MONGO_CRYPT_SHARED_DOWNLOAD_URL" ]; then
198-
crypt_shared_version=${CRYPT_SHARED_VERSION:-$("${BINDIR}"/mongod --version | grep -oP 'db version v\K.*')}
199-
python3 -u .evergreen/mongodl.py --component crypt_shared -V ${crypt_shared_version} --out $(pwd)/csfle_lib --target $(host_distro) || true
200-
if test -f $(pwd)/csfle_lib/lib/mongo_crypt_v1.so
201-
then
202-
export MONGO_RUBY_DRIVER_CRYPT_SHARED_LIB_PATH=$(pwd)/csfle_lib/lib/mongo_crypt_v1.so
196+
# Downloading crypt shared lib (skipped for mongocryptd-only configuration)
197+
if test "$FLE" != "mongocryptd"; then
198+
if [ -z "$MONGO_CRYPT_SHARED_DOWNLOAD_URL" ]; then
199+
crypt_shared_version=${CRYPT_SHARED_VERSION:-$("${BINDIR}"/mongod --version | grep -oP 'db version v\K.*')}
200+
python3 -u .evergreen/mongodl.py --component crypt_shared -V ${crypt_shared_version} --out $(pwd)/csfle_lib --target $(host_distro) || true
201+
if test -f $(pwd)/csfle_lib/lib/mongo_crypt_v1.so
202+
then
203+
export MONGO_RUBY_DRIVER_CRYPT_SHARED_LIB_PATH=$(pwd)/csfle_lib/lib/mongo_crypt_v1.so
204+
else
205+
echo 'Could not find crypt_shared library'
206+
fi
203207
else
204-
echo 'Could not find crypt_shared library'
208+
echo "Downloading crypt_shared package from $MONGO_CRYPT_SHARED_DOWNLOAD_URL"
209+
mkdir -p $(pwd)/csfle_lib
210+
cd $(pwd)/csfle_lib
211+
curl --retry 3 -fL $MONGO_CRYPT_SHARED_DOWNLOAD_URL | tar zxf -
212+
export MONGO_RUBY_DRIVER_CRYPT_SHARED_LIB_PATH=$(pwd)/lib/mongo_crypt_v1.so
213+
cd -
205214
fi
206-
else
207-
echo "Downloading crypt_shared package from $MONGO_CRYPT_SHARED_DOWNLOAD_URL"
208-
mkdir -p $(pwd)/csfle_lib
209-
cd $(pwd)/csfle_lib
210-
curl --retry 3 -fL $MONGO_CRYPT_SHARED_DOWNLOAD_URL | tar zxf -
211-
export MONGO_RUBY_DRIVER_CRYPT_SHARED_LIB_PATH=$(pwd)/lib/mongo_crypt_v1.so
212-
cd -
213215
fi
214216

215217
# Start the KMS servers first so that they are launching while we are
@@ -236,7 +238,7 @@ if test -n "$FLE"; then
236238
# Obtain temporary AWS credentials
237239
PYTHON=python3 . .evergreen/csfle/set-temp-creds.sh
238240

239-
if test "$FLE" = helper; then
241+
if [[ "$FLE" == "helper" || "$FLE" == "mongocryptd" ]]; then
240242
echo "Using helper gem"
241243
elif test "$FLE" = path; then
242244
if false; then

gemfiles/standard.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,6 @@ def standard_dependencies
6969
gem 'ruby-lsp', platforms: :mri
7070
end
7171

72-
gem 'libmongocrypt-helper', '~> 1.14.0' if ENV['FLE'] == 'helper'
72+
gem 'libmongocrypt-helper', '~> 1.14.0' if %w[helper mongocryptd].include?(ENV['FLE'])
7373
end
7474
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/BlockLength

lib/mongo/crypt/auto_encrypter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def initialize(options)
105105
bypass_query_analysis: @options[:bypass_query_analysis],
106106
crypt_shared_lib_path: @options[:extra_options][:crypt_shared_lib_path],
107107
crypt_shared_lib_required: @options[:extra_options][:crypt_shared_lib_required],
108+
disable_crypt_shared_lib_search: @options[:extra_options][:disable_crypt_shared_lib_search],
108109
)
109110

110111
@mongocryptd_options = @options[:extra_options].slice(

lib/mongo/crypt/handle.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class Handle
6262
# @option options [ Boolean | nil ] :explicit_encryption_only Whether this
6363
# handle is going to be used only for explicit encryption. If true,
6464
# libmongocrypt is instructed not to load crypt shared library.
65+
# @option options [ Boolean | nil ] :disable_crypt_shared_lib_search When
66+
# true, suppresses the automatic "$SYSTEM" search for crypt_shared. Use
67+
# this when a previous Handle in the same process has already loaded the
68+
# library via a path override and you want to avoid the conflicting-load
69+
# error that libmongocrypt raises on a subsequent "$SYSTEM" search.
6570
# @option options [ Logger ] :logger A Logger object to which libmongocrypt logs
6671
# will be sent
6772
def initialize(kms_providers, kms_tls_options, options={})
@@ -85,9 +90,10 @@ def initialize(kms_providers, kms_tls_options, options={})
8590

8691
@crypt_shared_lib_path = options[:crypt_shared_lib_path]
8792
@explicit_encryption_only = options[:explicit_encryption_only]
93+
@disable_crypt_shared_lib_search = options[:disable_crypt_shared_lib_search]
8894
if @crypt_shared_lib_path
8995
Binding.setopt_set_crypt_shared_lib_path_override(self, @crypt_shared_lib_path)
90-
elsif !@bypass_query_analysis && !@explicit_encryption_only
96+
elsif !@bypass_query_analysis && !@explicit_encryption_only && !@disable_crypt_shared_lib_search
9197
Binding.setopt_append_crypt_shared_lib_search_path(self, "$SYSTEM")
9298
end
9399

spec/integration/client_side_encryption/auto_encryption_mongocryptd_spawn_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
schema_map: { 'auto_encryption.users' => schema_map },
2222
extra_options: {
2323
mongocryptd_spawn_path: 'echo hello world',
24-
mongocryptd_spawn_args: []
24+
mongocryptd_spawn_args: [],
25+
# Suppress $SYSTEM crypt_shared search to avoid "existing library"
26+
# conflicts on macOS when another spec in the same process has
27+
# already loaded crypt_shared via an explicit path override.
28+
disable_crypt_shared_lib_search: true,
2529
}
2630
},
2731
database: 'auto_encryption'

spec/integration/client_side_encryption/auto_encryption_reconnect_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@
1111
# actually require a clean slate. https://jira.mongodb.org/browse/RUBY-2138
1212
clean_slate
1313

14+
# This spec tests reconnection with mongocryptd as the encryption backend.
15+
# It directly manipulates mongocryptd_client, which is only created when
16+
# crypt_shared is not available. Force the mongocryptd path regardless of
17+
# whether MONGO_RUBY_DRIVER_CRYPT_SHARED_LIB_PATH is set.
18+
around do |example|
19+
SpecConfig.instance.without_crypt_shared_lib_path { example.run }
20+
end
21+
1422
include_context 'define shared FLE helpers'
1523

1624
let(:client) do

spec/integration/client_side_encryption/bypass_mongocryptd_spawn_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
mongocryptd_bypass_spawn: true,
3232
mongocryptd_uri: "mongodb://localhost:#{mongocryptd_port}/db?serverSelectionTimeoutMS=1000",
3333
mongocryptd_spawn_args: [ "--pidfilepath=bypass-spawning-mongocryptd.pid", "--port=#{mongocryptd_port}"],
34+
disable_crypt_shared_lib_search: true,
3435
},
3536
},
3637
database: 'db'
@@ -56,6 +57,7 @@
5657
bypass_auto_encryption: true,
5758
extra_options: {
5859
mongocryptd_spawn_args: [ "--pidfilepath=bypass-spawning-mongocryptd.pid", "--port=#{mongocryptd_port}"],
60+
disable_crypt_shared_lib_search: true,
5961
},
6062
},
6163
database: 'db'

0 commit comments

Comments
 (0)