Skip to content

Commit 084f9a2

Browse files
authored
RUST-1386 Implement the remainder of the FLE prose tests (#767)
1 parent 1037712 commit 084f9a2

File tree

22 files changed

+1840
-88
lines changed

22 files changed

+1840
-88
lines changed

.evergreen/config.yml

Lines changed: 100 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -475,28 +475,28 @@ functions:
475475
476476
"fetch crypt_shared":
477477
- command: shell.exec
478-
type: test
479478
params:
480479
shell: bash
481480
working_dir: "src"
482481
script: |
483482
${PREPARE_SHELL}
484-
python3 ${DRIVERS_TOOLS}/.evergreen/mongodl.py --component=crypt_shared --version=${CRYPT_SHARED_VERSION} --out=./crypt_shared/
485-
ls -R ${PROJECT_DIRECTORY}/crypt_shared
483+
if [ "${DISABLE_CRYPT_SHARED}" == "true" ]; then
484+
echo "crypt_shared is disabled, not fetching"
485+
else
486+
${PYTHON} ${DRIVERS_TOOLS}/.evergreen/mongodl.py --component=crypt_shared --version=${CRYPT_SHARED_VERSION} --out=./crypt_shared/
487+
ls -R ${PROJECT_DIRECTORY}/crypt_shared
488+
fi
486489
487490
"run kmip server":
488491
- command: shell.exec
489-
type: test
490492
params:
491493
shell: bash
492494
working_dir: "src"
493495
background: true
494496
script: |
495497
${PREPARE_SHELL}
496-
cd ${DRIVERS_TOOLS}/.evergreen/csfle
497-
. ./activate_venv.sh
498-
# TMPDIR is required to avoid "AF_UNIX path too long" errors.
499-
TMPDIR="$(dirname ${DRIVERS_TOOLS})" python3 kms_kmip_server.py
498+
export TLS_FEATURE=${TLS_FEATURE}
499+
.evergreen/run-csfle-kmip-servers.sh
500500
501501
"run csfle tests":
502502
- command: shell.exec
@@ -509,6 +509,8 @@ functions:
509509
export ASYNC_RUNTIME=${ASYNC_RUNTIME}
510510
export CSFLE_TLS_CERT_DIR=$DRIVERS_TOOLS_X509
511511
export CSFLE_SHARED_LIB_PATH=$(.evergreen/find-crypt_shared.sh "$PROJECT_DIRECTORY/crypt_shared/lib/")
512+
export DISABLE_CRYPT_SHARED=${DISABLE_CRYPT_SHARED}
513+
export TLS_FEATURE=${TLS_FEATURE}
512514
# Exported without xtrace to avoid leaking credentials
513515
set +o xtrace
514516
export KMS_PROVIDERS=$(cat << "EOF"
@@ -1177,8 +1179,6 @@ tasks:
11771179
- func: "install junit dependencies"
11781180
- func: "fetch crypt_shared"
11791181
- func: "bootstrap mongo-orchestration"
1180-
vars:
1181-
TOPOLOGY: "server"
11821182
- func: "run kmip server"
11831183
- func: "run csfle tests"
11841184

@@ -1569,6 +1569,7 @@ axes:
15691569
display_name: "latest"
15701570
variables:
15711571
MONGODB_VERSION: "latest"
1572+
CRYPT_SHARED_VERSION: "latest"
15721573
- id: "rapid"
15731574
display_name: "rapid"
15741575
variables:
@@ -1653,6 +1654,18 @@ axes:
16531654
SSL: "nossl"
16541655
TLS_FEATURE: ""
16551656

1657+
- id: "tls-feature"
1658+
display_name: "TLS Feature"
1659+
values:
1660+
- id: "default"
1661+
display_name: "rustls TLS"
1662+
variables:
1663+
TLS_FEATURE: ""
1664+
- id: "openssl"
1665+
display_name: "OpenSSL TLS"
1666+
variables:
1667+
TLS_FEATURE: "openssl-tls"
1668+
16561669
- id: "compressor"
16571670
display_name: "Compressor"
16581671
values:
@@ -1678,29 +1691,29 @@ axes:
16781691
display_name: "Ubuntu 18.04"
16791692
run_on: ubuntu1804-test
16801693
variables:
1681-
PYTHON: "/opt/mongodbtoolchain/v3/bin/python"
1694+
PYTHON: "/opt/mongodbtoolchain/v3/bin/python3"
16821695
VENV_BIN_DIR: "bin"
16831696
LIBMONGOCRYPT_OS: "ubuntu1804-64"
16841697
- id: ubuntu-20.04
16851698
display_name: "Ubuntu 20.04"
16861699
run_on: ubuntu2004-test
16871700
variables:
1688-
PYTHON: "/opt/mongodbtoolchain/v3/bin/python"
1701+
PYTHON: "/opt/mongodbtoolchain/v3/bin/python3"
16891702
VENV_BIN_DIR: "bin"
16901703
LIBMONGOCRYPT_OS: "ubuntu2004-64"
16911704
- id: ubuntu-18.04-arm64
16921705
display_name: "ARM64 Ubuntu 18.04"
16931706
run_on: ubuntu1804-arm64-test
16941707
variables:
1695-
PYTHON: "/opt/mongodbtoolchain/v3/bin/python"
1708+
PYTHON: "/opt/mongodbtoolchain/v3/bin/python3"
16961709
VENV_BIN_DIR: "bin"
16971710
LIBMONGOCRYPT_OS: "ubuntu1804-arm64"
16981711
- id: macos-11.00
16991712
display_name: "MacOS 11.00"
17001713
run_on: macos-1100
17011714
variables:
17021715
SINGLE_THREAD: true
1703-
PYTHON: "/opt/mongodbtoolchain/v3/bin/python"
1716+
PYTHON: "/opt/mongodbtoolchain/v3/bin/python3"
17041717
VENV_BIN_DIR: "bin"
17051718
LIBMONGOCRYPT_OS: "macos"
17061719
- id: windows-64-vs2017
@@ -1720,6 +1733,18 @@ axes:
17201733
REQUIRE_API_VERSION: "1"
17211734
MONGODB_API_VERSION: "1"
17221735

1736+
- id: "crypt-shared"
1737+
display_name: "crypt_shared"
1738+
values:
1739+
- id: enabled
1740+
display_name: "crypt_shared enabled"
1741+
variables:
1742+
DISABLE_CRYPT_SHARED: ""
1743+
- id: disabled
1744+
display_name: "crypt_shared disabled"
1745+
variables:
1746+
DISABLE_CRYPT_SHARED: "true"
1747+
17231748
task_groups:
17241749
- name: serverless_task_group
17251750
setup_group_can_fail_task: true
@@ -1868,14 +1893,72 @@ buildvariants:
18681893
tasks:
18691894
- "serverless_task_group"
18701895

1871-
# TODO(RUST-1386): Expand the os and version listing
1872-
- matrix_name: "csfle"
1896+
- matrix_name: "csfle-topology"
18731897
matrix_spec:
18741898
os:
18751899
- ubuntu-20.04
18761900
mongodb-version:
18771901
- "6.0"
1878-
display_name: "CSFLE on mongodb ${mongodb-version} / ${os}"
1902+
topology:
1903+
- "standalone"
1904+
- "replica-set"
1905+
crypt-shared:
1906+
- "enabled"
1907+
tls-feature:
1908+
- "default"
1909+
display_name: "CSFLE (${crypt-shared}, ${tls-feature}) on mongodb ${mongodb-version} ${topology} / ${os}"
1910+
tasks:
1911+
- "test-csfle"
1912+
1913+
- matrix_name: "csfle-os"
1914+
matrix_spec:
1915+
os:
1916+
- macos-11.00
1917+
- windows-64-vs2017
1918+
mongodb-version:
1919+
- "6.0"
1920+
topology:
1921+
- "standalone"
1922+
crypt-shared:
1923+
- "enabled"
1924+
tls-feature:
1925+
- "default"
1926+
display_name: "CSFLE (${crypt-shared}, ${tls-feature}) on mongodb ${mongodb-version} ${topology} / ${os}"
1927+
tasks:
1928+
- "test-csfle"
1929+
1930+
- matrix_name: "csfle-crypt-shared"
1931+
matrix_spec:
1932+
os:
1933+
- ubuntu-20.04
1934+
mongodb-version:
1935+
- "5.0"
1936+
- "6.0"
1937+
topology:
1938+
- "standalone"
1939+
crypt-shared:
1940+
- "disabled"
1941+
tls-feature:
1942+
- "default"
1943+
display_name: "CSFLE (${crypt-shared}, ${tls-feature}) on mongodb ${mongodb-version} ${topology} / ${os}"
1944+
tasks:
1945+
- "test-csfle"
1946+
1947+
- matrix_name: "csfle-tls"
1948+
matrix_spec:
1949+
os:
1950+
- ubuntu-20.04
1951+
- macos-11.00
1952+
- windows-64-vs2017
1953+
mongodb-version:
1954+
- "6.0"
1955+
topology:
1956+
- "standalone"
1957+
crypt-shared:
1958+
- "enabled"
1959+
tls-feature:
1960+
- "openssl"
1961+
display_name: "CSFLE (${crypt-shared}, ${tls-feature}) on mongodb ${mongodb-version} ${topology} / ${os}"
18791962
tasks:
18801963
- "test-csfle"
18811964

.evergreen/configure-rust.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ export CARGO_HOME="${PROJECT_DIRECTORY}/.cargo"
66
export PATH="${CARGO_HOME}/bin:$PATH"
77

88
if [[ "Windows_NT" == "$OS" ]]; then
9+
# Update path for DLLs
10+
export PATH="${MONGOCRYPT_LIB_DIR}/../bin:$PATH"
11+
912
# rustup/cargo need the native Windows paths; $PROJECT_DIRECTORY is a cygwin path
1013
export RUSTUP_HOME=$(cygpath ${RUSTUP_HOME} --windows)
1114
export CARGO_HOME=$(cygpath ${CARGO_HOME} --windows)
15+
export MONGOCRYPT_LIB_DIR=$(cygpath ${MONGOCRYPT_LIB_DIR} --windows)
1216
fi
1317

1418
. ${CARGO_HOME}/env

.evergreen/find-crypt_shared.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#!/usr/bin/env bash
22

3-
if [ "$1" = "" ]; then
4-
echo "crypt_shared library directory required"
5-
exit 1
6-
fi
7-
8-
crypt_shared_glob=("$1"/*)
9-
10-
if [ "${#crypt_shared_glob[@]}" != "1" ]; then
11-
echo "Wrong number of files found: ${crypt_shared_glob[@]}"
12-
exit 1
13-
fi
14-
15-
echo ${crypt_shared_glob[0]}
3+
if [[ "Windows_NT" == "$OS" ]]; then
4+
cygpath ${PROJECT_DIRECTORY}/crypt_shared/bin/mongo_crypt_v1.dll --windows
5+
else
6+
CS_PATH=${PROJECT_DIRECTORY}/crypt_shared/lib
7+
crypt_shared_glob=("$CS_PATH"/*)
8+
9+
if [ "${#crypt_shared_glob[@]}" != "1" ]; then
10+
echo "Wrong number of files found: ${crypt_shared_glob[@]}"
11+
exit 1
12+
fi
13+
14+
echo ${crypt_shared_glob[0]}
15+
fi

.evergreen/run-csfle-kmip-servers.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
if [ "$TLS_FEATURE" != "openssl-tls" ]; then
4+
echo "Skipping kms servers: openssl-tls not enabled"
5+
exit
6+
fi
7+
8+
cd ${DRIVERS_TOOLS}/.evergreen/csfle
9+
. ./activate_venv.sh
10+
# TMPDIR is required to avoid "AF_UNIX path too long" errors.
11+
export TMPDIR="$(dirname ${DRIVERS_TOOLS})"
12+
13+
python kms_kmip_server.py &
14+
python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/expired.pem --port 9000 &
15+
python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/wrong-host.pem --port 9001 &
16+
python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/server.pem --port 9002 --require_client_cert

.evergreen/run-csfle-tests.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,19 @@ source ./.evergreen/env.sh
77

88
set -o xtrace
99

10-
FEATURE_FLAGS="openssl-tls,csfle"
10+
FEATURE_FLAGS="csfle,${TLS_FEATURE}"
1111
OPTIONS="-- -Z unstable-options --format json --report-time"
1212

1313
if [ "$SINGLE_THREAD" = true ]; then
1414
OPTIONS="$OPTIONS --test-threads=1"
1515
fi
1616

17+
if [ "$OS" = "Windows_NT" ]; then
18+
export CSFLE_TLS_CERT_DIR=$(cygpath ${CSFLE_TLS_CERT_DIR} --windows)
19+
export SSL_CERT_FILE=$(cygpath /etc/ssl/certs/ca-bundle.crt --windows)
20+
export SSL_CERT_DIR=$(cygpath /etc/ssl/certs --windows)
21+
fi
22+
1723
echo "cargo test options: --features ${FEATURE_FLAGS} ${OPTIONS}"
1824

1925
CARGO_RESULT=0

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ Cargo.lock
1212
# we install cargo and rustup in the project directory on Evergreen.
1313
.cargo
1414
.rustup
15+
mongocryptd.pid

src/client/csfle.rs

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub mod client_encryption;
22
pub mod options;
33
mod state_machine;
44

5-
use std::path::Path;
5+
use std::{path::Path, time::Duration};
66

77
use derivative::Derivative;
88
use mongocrypt::Crypt;
@@ -44,15 +44,33 @@ struct AuxClients {
4444
}
4545

4646
impl ClientState {
47+
const MONGOCRYPTD_DEFAULT_URI: &'static str = "mongodb://localhost:27020";
48+
const MONGOCRYPTD_SERVER_SELECTION_TIMEOUT: Duration = Duration::from_millis(10_000);
49+
4750
pub(super) async fn new(client: &Client, mut opts: AutoEncryptionOptions) -> Result<Self> {
4851
let crypt = Self::make_crypt(&opts)?;
4952
let mongocryptd_opts = Self::make_mongocryptd_opts(&opts, &crypt)?;
5053
let aux_clients = Self::make_aux_clients(client, &opts)?;
54+
let mongocryptd_connect = opts.bypass_auto_encryption != Some(true)
55+
&& opts.bypass_query_analysis != Some(true)
56+
&& crypt.shared_lib_version().is_none()
57+
&& opts.extra_option(&EO_CRYPT_SHARED_REQUIRED)? != Some(true);
58+
let mongocryptd_client = if mongocryptd_connect {
59+
let uri = opts
60+
.extra_option(&EO_MONGOCRYPTD_URI)?
61+
.unwrap_or(Self::MONGOCRYPTD_DEFAULT_URI);
62+
let mut options = crate::options::ClientOptions::parse_uri(uri, None).await?;
63+
options.server_selection_timeout = Some(Self::MONGOCRYPTD_SERVER_SELECTION_TIMEOUT);
64+
Some(Client::with_options(options)?)
65+
} else {
66+
None
67+
};
5168
let exec = CryptExecutor::new_implicit(
5269
aux_clients.key_vault_client,
5370
opts.key_vault_namespace.clone(),
5471
opts.tls_options.take(),
5572
mongocryptd_opts,
73+
mongocryptd_client,
5674
aux_clients.metadata_client,
5775
)
5876
.await?;
@@ -83,11 +101,20 @@ impl ClientState {
83101
if let Some(m) = &opts.schema_map {
84102
builder = builder.schema_map(&bson::to_document(m)?)?;
85103
}
86-
if Some(true) != opts.bypass_auto_encryption {
87-
builder = builder.append_crypt_shared_lib_search_path(Path::new("$SYSTEM"))?;
104+
#[cfg(not(test))]
105+
let disable_crypt_shared = false;
106+
#[cfg(test)]
107+
let disable_crypt_shared = opts.disable_crypt_shared.unwrap_or(false);
108+
if !disable_crypt_shared {
109+
if Some(true) != opts.bypass_auto_encryption {
110+
builder = builder.append_crypt_shared_lib_search_path(Path::new("$SYSTEM"))?;
111+
}
112+
if let Some(p) = opts.extra_option(&EO_CRYPT_SHARED_LIB_PATH)? {
113+
builder = builder.set_crypt_shared_lib_path_override(Path::new(p))?;
114+
}
88115
}
89-
if let Some(p) = opts.extra_option(&EO_CRYPT_SHARED_LIB_PATH)? {
90-
builder = builder.set_crypt_shared_lib_path_override(Path::new(p))?;
116+
if opts.bypass_query_analysis == Some(true) {
117+
builder = builder.bypass_query_analysis();
91118
}
92119
let crypt = builder.build()?;
93120
if opts.extra_option(&EO_CRYPT_SHARED_REQUIRED)? == Some(true)
@@ -105,6 +132,7 @@ impl ClientState {
105132
crypt: &Crypt,
106133
) -> Result<Option<MongocryptdOptions>> {
107134
if opts.bypass_auto_encryption == Some(true)
135+
|| opts.bypass_query_analysis == Some(true)
108136
|| opts.extra_option(&EO_MONGOCRYPTD_BYPASS_SPAWN)? == Some(true)
109137
|| crypt.shared_lib_version().is_some()
110138
|| opts.extra_option(&EO_CRYPT_SHARED_REQUIRED)? == Some(true)
@@ -123,13 +151,9 @@ impl ClientState {
123151
spawn_args.push(str_arg.to_string());
124152
}
125153
}
126-
let uri = opts
127-
.extra_option(&EO_MONGOCRYPTD_URI)?
128-
.map(|s| s.to_string());
129154
Ok(Some(MongocryptdOptions {
130155
spawn_path,
131156
spawn_args,
132-
uri,
133157
}))
134158
}
135159

0 commit comments

Comments
 (0)