Skip to content

Commit b34cd2b

Browse files
authored
CDRIVER-4801 support named KMS providers (#1509)
* copy in new unified tests * copy in new legacy spec test * add new KMS providers to test runner add partial support for JSON schema 1.18 * implement `encrypt` and `decrypt` operations in unified test runner * export env vars in run-tests.sh * update prose test 11 for named KMS providers * add map for TLS options Required to configure TLS options on named KMS providers * check out libmongocrypt with changes of MONGOCRYPT-605 * update docs to reflect spec terminology KMS provider is specified with string `<KMS provider type>` or `<KMS provider type>:<KMS provider name>`
1 parent 3c091ac commit b34cd2b

18 files changed

+2685
-42
lines changed

.evergreen/scripts/compile-libmongocrypt.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,21 @@ compile_libmongocrypt() {
99
# libmongocrypt's kms-message in `src/kms-message`. Run
1010
# `.evergreen/scripts/kms-divergence-check.sh` to ensure that there is no
1111
# divergence in the copied files.
12-
git clone -q --depth=1 https://github.com/mongodb/libmongocrypt --branch 1.8.0 || return
1312

14-
# Remove this workaround once fcf2b5b5 is included in the minimum libmongocrypt commit.
13+
# TODO: once 1.9.0 is released (containing MONGOCRYPT-605) replace the following with:
14+
# git clone -q --depth=1 https://github.com/mongodb/libmongocrypt --branch 1.9.0 || return
1515
{
16-
git -C libmongocrypt fetch -q origin master || return
17-
git -C libmongocrypt cherry-pick --no-commit fcf2b5b5 || return
18-
git -C libmongocrypt diff HEAD
16+
git clone -q https://github.com/mongodb/libmongocrypt || return
17+
# Check out commit containing MONGOCRYPT-605
18+
git -C libmongocrypt checkout c87cc3489c9a68875ff7fab541154841469991fb
1919
}
2020

2121
declare -a crypt_cmake_flags=(
2222
"-DMONGOCRYPT_MONGOC_DIR=${mongoc_dir}"
2323
"-DBUILD_TESTING=OFF"
2424
"-DENABLE_ONLINE_TESTS=OFF"
2525
"-DENABLE_MONGOC=OFF"
26+
"-DBUILD_VERSION=1.9.0-pre"
2627
)
2728

2829
DEBUG="0" \

.evergreen/scripts/run-tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ if [[ -n "${CLIENT_SIDE_ENCRYPTION}" ]]; then
9595
export MONGOC_TEST_AWS_TEMP_SESSION_TOKEN="${CSFLE_AWS_TEMP_SESSION_TOKEN:?}"
9696
export MONGOC_TEST_AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY}"
9797
export MONGOC_TEST_AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}"
98+
export MONGOC_TEST_AWSNAME2_SECRET_ACCESS_KEY="${client_side_encryption_awsname2_secret_access_key}"
99+
export MONGOC_TEST_AWSNAME2_ACCESS_KEY_ID="${client_side_encryption_awsname2_access_key_id}"
98100
export MONGOC_TEST_AZURE_TENANT_ID="${client_side_encryption_azure_tenant_id:?}"
99101
export MONGOC_TEST_AZURE_CLIENT_ID="${client_side_encryption_azure_client_id:?}"
100102
export MONGOC_TEST_AZURE_CLIENT_SECRET="${client_side_encryption_azure_client_secret:?}"

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ For AWS:
247247

248248
* `MONGOC_TEST_AWS_SECRET_ACCESS_KEY=<string>`
249249
* `MONGOC_TEST_AWS_ACCESS_KEY_ID=<string>`
250+
* `MONGOC_TEST_AWSNAME2_SECRET_ACCESS_KEY=<string>`
251+
* `MONGOC_TEST_AWSNAME2_ACCESS_KEY_ID=<string>`
250252

251253
An Azure:
252254

src/libmongoc/doc/mongoc_auto_encryption_opts_set_kms_providers.rst

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ Parameters
1919
* ``opts``: The :symbol:`mongoc_auto_encryption_opts_t`
2020
* ``kms_providers``: A :symbol:`bson_t` containing configuration for an external Key Management Service (KMS).
2121

22-
``kms_providers`` is a BSON document containing configuration for each KMS provider. Currently ``aws``, ``local``, ``azure``, ``gcp``, and ``kmip`` are supported. At least one must be specified.
22+
``kms_providers`` is a BSON document containing configuration for each KMS provider.
2323

24-
The format for "aws" is as follows:
24+
KMS providers are specified as a string of the form ``<KMS provider type>`` or ``<KMS provider type>:<KMS provider name>``.
25+
The supported KMS provider types are ``aws``, ``azure``, ``gcp``, ``local``, and ``kmip``. The optional name enables configuring multiple KMS providers with the same KMS provider type (e.g. ``aws:name1`` and ``aws:name2`` can refer to different AWS accounts).
26+
At least one KMS provider must be specified.
27+
28+
The format for the KMS provider type ``aws`` is as follows:
2529

2630
.. code-block:: javascript
2731
@@ -30,15 +34,15 @@ The format for "aws" is as follows:
3034
secretAccessKey: String
3135
}
3236
33-
The format for "local" is as follows:
37+
The format for the KMS provider type ``local`` is as follows:
3438

3539
.. code-block:: javascript
3640
3741
local: {
3842
key: <96 byte BSON binary of subtype 0> or String /* The master key used to encrypt/decrypt data keys. May be passed as a base64 encoded string. */
3943
}
4044
41-
The format for "azure" is as follows:
45+
The format for the KMS provider type ``azure`` is as follows:
4246

4347
.. code-block:: javascript
4448
@@ -49,7 +53,7 @@ The format for "azure" is as follows:
4953
identityPlatformEndpoint: Optional<String> /* Defaults to login.microsoftonline.com */
5054
}
5155
52-
The format for "gcp" is as follows:
56+
The format for the KMS provider type ``gcp`` is as follows:
5357

5458
.. code-block:: javascript
5559
@@ -59,14 +63,27 @@ The format for "gcp" is as follows:
5963
endpoint: Optional<String> /* Defaults to oauth2.googleapis.com */
6064
}
6165
62-
The format for "kmip" is as follows:
66+
The format for the KMS provider type ``kmip`` is as follows:
6367

6468
.. code-block:: javascript
6569
6670
kmip: {
6771
endpoint: String
6872
}
6973
74+
KMS providers may include an optional name suffix separate with a colon. This enables configuring multiple KMS providers with the same KMS provider type. Example:
75+
76+
.. code-block:: javascript
77+
78+
"aws:name1": {
79+
accessKeyId: String,
80+
secretAccessKey: String
81+
},
82+
"aws:name2": {
83+
accessKeyId: String,
84+
secretAccessKey: String
85+
}
86+
7087
.. seealso::
7188

7289
| :symbol:`mongoc_client_enable_auto_encryption()`

src/libmongoc/doc/mongoc_auto_encryption_opts_set_tls_opts.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ Parameters
1717
----------
1818

1919
* ``opts``: The :symbol:`mongoc_auto_encryption_opts_t`
20-
* ``tls_opts``: A :symbol:`bson_t` mapping a Key Management Service (KMS) provider name to a BSON document with TLS options.
20+
* ``tls_opts``: A :symbol:`bson_t` mapping a Key Management Service (KMS) provider to a BSON document with TLS options.
2121

2222
``tls_opts`` is a BSON document of the following form:
2323

2424
.. code-block:: javascript
2525
26-
<KMS provider name>: {
26+
<KMS provider>: {
2727
tlsCaFile: Optional<String>
2828
tlsCertificateKeyFile: Optional<String>
2929
tlsCertificateKeyFilePassword: Optional<String>
3030
}
3131
32-
The KMS providers ``aws``, ``azure``, ``gcp``, and ``kmip`` are supported as keys in the ``tls_opts`` document.
32+
The KMS providers ``aws``, ``azure``, ``gcp``, and ``kmip`` are supported as keys in the ``tls_opts`` document. They may include an optional name suffix separated with a colon. Example: ``aws:name2``.
3333

3434
``tls_opts`` maps the KMS provider name to a BSON document for TLS options.
3535

src/libmongoc/doc/mongoc_client_encryption_datakey_opts_set_masterkey.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ Parameters
2323
Description
2424
-----------
2525

26-
Setting the masterkey is required when creating a data key with the KMS providers: ``aws``, ``azure``, ``gcp``, and ``kmip``.
26+
Setting the masterkey is required when creating a data key with the KMS provider types: ``aws``, ``azure``, ``gcp``, and ``kmip``.
2727

28-
Setting the masterkey is prohibited with the KMS provider ``local``.
28+
Setting the masterkey is prohibited with the KMS provider type ``local``.
2929

30-
The format of ``masterkey`` for "aws" is as follows:
30+
The format of ``masterkey`` for the KMS provider type ``aws`` is as follows:
3131

3232
.. code-block:: javascript
3333
@@ -37,7 +37,7 @@ The format of ``masterkey`` for "aws" is as follows:
3737
endpoint: Optional<String> /* An alternate host identifier to send KMS requests to. May include port number. Defaults to "kms.<region>.amazonaws.com" */
3838
}
3939
40-
The format of ``masterkey`` for "azure" is as follows:
40+
The format of ``masterkey`` for the KMS provider type ``azure`` is as follows:
4141

4242
.. code-block:: javascript
4343
@@ -47,7 +47,7 @@ The format of ``masterkey`` for "azure" is as follows:
4747
keyVersion: Optional<String> /* A specific version of the named key, defaults to using the key's primary version. */
4848
}
4949
50-
The format of ``masterkey`` for "gcp" is as follows:
50+
The format of ``masterkey`` for the KMS provider type ``gcp`` is as follows:
5151

5252
.. code-block:: javascript
5353
@@ -60,11 +60,11 @@ The format of ``masterkey`` for "gcp" is as follows:
6060
endpoint: Optional<String> /* Host with optional port. Defaults to "cloudkms.googleapis.com". */
6161
}
6262
63-
The format of ``masterkey`` for "kmip" is as follows:
63+
The format of ``masterkey`` for the KMS provider type ``kmip`` is as follows:
6464

6565
.. code-block:: javascript
6666
6767
{
6868
keyId: Optional<String>,
6969
endpoint: Optional<String> /* Host with optional port. */
70-
}
70+
}

src/libmongoc/doc/mongoc_client_encryption_opts_set_kms_providers.rst

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ Parameters
1818
* ``opts``: The :symbol:`mongoc_client_encryption_opts_t`
1919
* ``kms_providers``: A :symbol:`bson_t` containing configuration for an external Key Management Service (KMS).
2020

21-
``kms_providers`` is a BSON document containing configuration for each KMS provider. Currently ``aws``, ``local``, ``azure``, ``gcp``, and ``kmip`` are supported. At least one must be specified.
21+
``kms_providers`` is a BSON document containing configuration for each KMS provider.
2222

23-
The format for "aws" is as follows:
23+
KMS providers are specified as a string of the form ``<KMS provider type>`` or ``<KMS provider type>:<KMS provider name>``.
24+
The supported KMS provider types are ``aws``, ``azure``, ``gcp``, ``local``, and ``kmip``. The optional name enables configuring multiple KMS providers with the same KMS provider type (e.g. ``aws:name1`` and ``aws:name2`` can refer to different AWS accounts).
25+
At least one KMS provider must be specified.
26+
27+
The format for the KMS provider type ``aws`` is as follows:
2428

2529
.. code-block:: javascript
2630
@@ -29,15 +33,15 @@ The format for "aws" is as follows:
2933
secretAccessKey: String
3034
}
3135
32-
The format for "local" is as follows:
36+
The format for the KMS provider type ``local`` is as follows:
3337

3438
.. code-block:: javascript
3539
3640
local: {
3741
key: <96 byte BSON binary of subtype 0> or String /* The master key used to encrypt/decrypt data keys. May be passed as a base64 encoded string. */
3842
}
3943
40-
The format for "azure" is as follows:
44+
The format for the KMS provider type ``azure`` is as follows:
4145

4246
.. code-block:: javascript
4347
@@ -48,7 +52,7 @@ The format for "azure" is as follows:
4852
identityPlatformEndpoint: Optional<String> /* Defaults to login.microsoftonline.com */
4953
}
5054
51-
The format for "gcp" is as follows:
55+
The format for the KMS provider type ``gcp`` is as follows:
5256

5357
.. code-block:: javascript
5458
@@ -58,14 +62,26 @@ The format for "gcp" is as follows:
5862
endpoint: Optional<String> /* Defaults to oauth2.googleapis.com */
5963
}
6064
61-
The format for "kmip" is as follows:
65+
The format for the KMS provider type ``kmip`` is as follows:
6266

6367
.. code-block:: javascript
6468
6569
kmip: {
6670
endpoint: String
6771
}
6872
73+
KMS providers may include an optional name suffix separate with a colon. This enables configuring multiple KMS providers with the same KMS provider type. Example:
74+
75+
.. code-block:: javascript
76+
77+
"aws:name1": {
78+
accessKeyId: String,
79+
secretAccessKey: String
80+
},
81+
"aws:name2": {
82+
accessKeyId: String,
83+
secretAccessKey: String
84+
}
6985
7086
.. seealso::
7187

src/libmongoc/doc/mongoc_client_encryption_opts_set_tls_opts.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,22 @@ Parameters
1717
----------
1818

1919
* ``opts``: The :symbol:`mongoc_client_encryption_opts_t`
20-
* ``tls_opts``: A :symbol:`bson_t` mapping a Key Management Service (KMS) provider name to a BSON document with TLS options.
20+
* ``tls_opts``: A :symbol:`bson_t` mapping a Key Management Service (KMS) provider to a BSON document with TLS options.
2121

2222
``tls_opts`` is a BSON document of the following form:
2323

2424
.. code-block:: javascript
2525
26-
<KMS provider name>: {
26+
<KMS provider>: {
2727
tlsCaFile: Optional<String>
2828
tlsCertificateKeyFile: Optional<String>
2929
tlsCertificateKeyFilePassword: Optional<String>
3030
}
3131
32-
The KMS providers ``aws``, ``azure``, ``gcp``, and ``kmip`` are supported as keys in the ``tls_opts`` document.
32+
KMS providers are specified as a string of the form ``<KMS provider type>`` or ``<KMS provider type>:<KMS provider name>``.
33+
The supported KMS provider types are ``aws``, ``azure``, ``gcp``, ``local``, and ``kmip``. The optional name enables configuring multiple KMS providers with the same KMS provider type (e.g. ``aws:name1`` and ``aws:name2`` can refer to different AWS accounts).
3334

34-
``tls_opts`` maps the KMS provider name to a BSON document for TLS options.
35+
``tls_opts`` maps the KMS provider to a BSON document for TLS options.
3536

3637
The BSON document for TLS options may contain the following keys:
3738

0 commit comments

Comments
 (0)