Skip to content

Commit 2078ab2

Browse files
CDRIVER-4206 KMIP support (#881)
Co-authored-by: Ezra Chung <[email protected]>
1 parent 02b91f4 commit 2078ab2

32 files changed

+6584
-195
lines changed

.evergreen/config.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,8 @@ functions:
439439
export MONGOC_TEST_AZURE_CLIENT_SECRET="${client_side_encryption_azure_client_secret}"
440440
export MONGOC_TEST_GCP_EMAIL="${client_side_encryption_gcp_email}"
441441
export MONGOC_TEST_GCP_PRIVATEKEY="${client_side_encryption_gcp_privatekey}"
442+
export MONGOC_TEST_CSFLE_TLS_CA_FILE=../drivers-evergreen-tools/.evergreen/x509gen/ca.pem
443+
export MONGOC_TEST_CSFLE_TLS_CERTIFICATE_KEY_FILE=../drivers-evergreen-tools/.evergreen/x509gen/client.pem
442444
fi
443445
export LOADBALANCED=${LOADBALANCED}
444446
export SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}"
@@ -781,6 +783,8 @@ functions:
781783
python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/server.pem --port 7999 &
782784
python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/expired.pem --port 8000 &
783785
python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/wrong-host.pem --port 8001 &
786+
python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/server.pem --port 8002 --require_client_cert &
787+
python -u kms_kmip_server.py &
784788
echo "Starting mock KMS servers... done."
785789
start load balancer:
786790
- command: shell.exec

.evergreen/run-tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ if [ "$CLIENT_SIDE_ENCRYPTION" = "on" ]; then
139139
wait_for_kms_server 7999
140140
wait_for_kms_server 8000
141141
wait_for_kms_server 8001
142+
wait_for_kms_server 8002
143+
wait_for_kms_server 5698
142144
echo "Waiting for mock KMS servers to start... done."
143145
fi
144146

CONTRIBUTING.md

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,26 @@ start mongocryptd on port 27020 and set the following:
251251

252252
* `MONGOC_TEST_MONGOCRYPTD_BYPASS_SPAWN=on`
253253

254-
KMS TLS tests for Client-Side Field Level Encryption require mock KMS servers to be running in the background according to the instructions given in the Client Side Encryption Tests specification.
255-
The set of mock KMS servers running in the background and their corresponding port number, CA file, and cert file must be as follows:
256-
257-
| Port | CA File | Cert File |
258-
| --- | --- | --- |
259-
| 7999 | ca.pem | server.pem |
260-
| 8000 | ca.pem | expired.pem |
261-
| 8001 | ca.pem | wrong-host.pem |
254+
KMS TLS tests for Client-Side Field Level Encryption require mock KMS servers to be running in the background.
255+
256+
The [Setup instructions](https://github.com/mongodb/specifications/tree/master/source/client-side-encryption/tests#setup-3) given in the Client Side Encryption Tests specification provide additional information.
257+
258+
The mock server scripts are located in the [mongodb-labs/drivers-evergreen-tools](https://github.com/mongodb-labs/drivers-evergreen-tools) in the [csfle directory](https://github.com/mongodb-labs/drivers-evergreen-tools/tree/master/.evergreen/csfle). The mock servers use certificates located in the [x509gen](https://github.com/mongodb-labs/drivers-evergreen-tools/tree/master/.evergreen/x509gen) directory.
259+
260+
The set of mock KMS servers running in the background and their corresponding invocation command must be as follows:
261+
262+
| Port | CA File | Cert File | Command |
263+
| --- | --- | --- | --- |
264+
| 7999 | ca.pem | server.pem | python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/server.pem --port 7999
265+
| 8000 | ca.pem | expired.pem | python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/expired.pem --port 8000
266+
| 8001 | ca.pem | wrong-host.pem | python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/wrong-host.pem --port 8001
267+
| 8002 | ca.pem | server.pem | python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/server.pem --port 8002 --require_client_cert
268+
| 5698 | ca.pem | server.pem | python -u kms_kmip_server.py
269+
270+
The path to `ca.pem` and `client.pem` must be passed through the following environment variables:
271+
272+
* `MONGOC_TEST_CSFLE_TLS_CA_FILE=<string>`
273+
* `MONGOC_TEST_CSFLE_TLS_CERTIFICATE_KEY_FILE=<string>`
262274

263275
KMS TLS tests for Client-Side Field Level Encryption can be skipped by defining:
264276

build/evergreen_config_lib/functions.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@
310310
311311
export MONGOC_TEST_GCP_EMAIL="${client_side_encryption_gcp_email}"
312312
export MONGOC_TEST_GCP_PRIVATEKEY="${client_side_encryption_gcp_privatekey}"
313+
314+
export MONGOC_TEST_CSFLE_TLS_CA_FILE=../drivers-evergreen-tools/.evergreen/x509gen/ca.pem
315+
export MONGOC_TEST_CSFLE_TLS_CERTIFICATE_KEY_FILE=../drivers-evergreen-tools/.evergreen/x509gen/client.pem
313316
fi
314317
export LOADBALANCED=${LOADBALANCED}
315318
export SINGLE_MONGOS_LB_URI="${SINGLE_MONGOS_LB_URI}"
@@ -564,6 +567,8 @@
564567
python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/server.pem --port 7999 &
565568
python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/expired.pem --port 8000 &
566569
python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/wrong-host.pem --port 8001 &
570+
python -u kms_http_server.py --ca_file ../x509gen/ca.pem --cert_file ../x509gen/server.pem --port 8002 --require_client_cert &
571+
python -u kms_kmip_server.py &
567572
echo "Starting mock KMS servers... done."
568573
''', test=False, background=True),
569574
)),

src/libmongoc/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,7 @@ if (MONGOC_ENABLE_CLIENT_SIDE_ENCRYPTION)
11011101
mongoc_add_example (client-side-encryption-server-schema TRUE ${PROJECT_SOURCE_DIR}/examples/client-side-encryption-server-schema.c ${PROJECT_SOURCE_DIR}/examples/client-side-encryption-helpers.c)
11021102
mongoc_add_example (client-side-encryption-explicit TRUE ${PROJECT_SOURCE_DIR}/examples/client-side-encryption-explicit.c ${PROJECT_SOURCE_DIR}/examples/client-side-encryption-helpers.c)
11031103
mongoc_add_example (client-side-encryption-auto-decryption TRUE ${PROJECT_SOURCE_DIR}/examples/client-side-encryption-auto-decryption.c ${PROJECT_SOURCE_DIR}/examples/client-side-encryption-helpers.c)
1104+
mongoc_add_example (client-side-encryption-doc-snippets TRUE ${PROJECT_SOURCE_DIR}/examples/client-side-encryption-doc-snippets.c)
11041105
endif ()
11051106

11061107
file (COPY ${PROJECT_SOURCE_DIR}/tests/binary DESTINATION ${PROJECT_BINARY_DIR}/tests)

src/libmongoc/doc/includes/tls-options.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* - MONGOC_URI_TLSCERTIFICATEKEYFILE
1111
- tlscertificatekeyfile
1212
- Path to PEM formatted Private Key, with its Public Certificate concatenated at the end.
13-
* - MONGOC_URI_TLSCERTIFICATEKEYPASSWORD
13+
* - MONGOC_URI_TLSCERTIFICATEKEYFILEPASSWORD
1414
- tlscertificatekeypassword
1515
- The password, if any, to use to unlock encrypted Private Key.
1616
* - MONGOC_URI_TLSCAFILE

src/libmongoc/doc/mongoc_auto_encryption_opts_set_kms_providers.rst

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,52 @@ 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`` or ``local`` are supported. At least one must be specified.
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.
2323

2424
The format for "aws" is as follows:
2525

2626
.. code-block:: javascript
2727
2828
aws: {
29-
accessKeyId: <string>,
30-
secretAccessKey: <string>
29+
accessKeyId: String,
30+
secretAccessKey: String
3131
}
3232
3333
The format for "local" is as follows:
3434

3535
.. code-block:: javascript
3636
3737
local: {
38-
key: <96 byte BSON binary of subtype 0> // The master key used to encrypt/decrypt data keys.
38+
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. */
39+
}
40+
41+
The format for "azure" is as follows:
42+
43+
.. code-block:: javascript
44+
45+
azure: {
46+
tenantId: String,
47+
clientId: String,
48+
clientSecret: String,
49+
identityPlatformEndpoint: Optional<String> /* Defaults to login.microsoftonline.com */
50+
}
51+
52+
The format for "gcp" is as follows:
53+
54+
.. code-block:: javascript
55+
56+
gcp: {
57+
email: String,
58+
privateKey: byte[] or String, /* May be passed as a base64 encoded string. */
59+
endpoint: Optional<String> /* Defaults to oauth2.googleapis.com */
60+
}
61+
62+
The format for "kmip" is as follows:
63+
64+
.. code-block:: javascript
65+
66+
kmip: {
67+
endpoint: String
3968
}
4069
4170
.. seealso::
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
:man_page: mongoc_auto_encryption_opts_set_tls_opts
2+
3+
mongoc_auto_encryption_opts_set_tls_opts()
4+
==========================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
void
12+
mongoc_auto_encryption_opts_set_tls_opts (
13+
mongoc_auto_encryption_opts_t *opts, const bson_t *tls_opts);
14+
15+
16+
Parameters
17+
----------
18+
19+
* ``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.
21+
22+
``tls_opts`` is a BSON document of the following form:
23+
24+
.. code-block:: javascript
25+
26+
<KMS provider name>: {
27+
tlsCaFile: Optional<String>
28+
tlsCertificateKeyFile: Optional<String>
29+
tlsCertificateKeyFilePassword: Optional<String>
30+
}
31+
32+
The KMS providers ``aws``, ``azure``, ``gcp``, and ``kmip`` are supported as keys in the ``tls_opts`` document.
33+
34+
``tls_opts`` maps the KMS provider name to a BSON document for TLS options.
35+
36+
The BSON document for TLS options may contain the following keys:
37+
38+
- ``MONGOC_URI_TLSCERTIFICATEKEYFILE``
39+
- ``MONGOC_URI_TLSCERTIFICATEKEYFILEPASSWORD``
40+
- ``MONGOC_URI_TLSCAFILE``
41+
42+
.. literalinclude:: ../examples/client-side-encryption-doc-snippets.c
43+
:caption: Example use
44+
:start-after: BEGIN:mongoc_auto_encryption_opts_set_tls_opts
45+
:end-before: END:mongoc_auto_encryption_opts_set_tls_opts
46+
:dedent: 6
47+
48+
See :doc:`configuring_tls` for a description of the behavior of these options.
49+
50+
.. seealso::
51+
52+
| :symbol:`mongoc_client_enable_auto_encryption()`
53+
54+
| The guide for :doc:`Using Client-Side Field Level Encryption <using_client_side_encryption>`
55+

src/libmongoc/doc/mongoc_auto_encryption_opts_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ Synopsis
3434
mongoc_auto_encryption_opts_set_schema_map
3535
mongoc_auto_encryption_opts_set_bypass_auto_encryption
3636
mongoc_auto_encryption_opts_set_extra
37+
mongoc_auto_encryption_opts_set_tls_opts
3738

src/libmongoc/doc/mongoc_client_encryption_datakey_opts_set_masterkey.rst

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,48 @@ Parameters
2323
Description
2424
-----------
2525

26-
Setting the masterkey is required if using AWS KMS, and ``masterkey`` must have the form:
26+
Setting the masterkey is required when creating a data key with the KMS providers: ``aws``, ``azure``, ``gcp``, and ``kmip``.
27+
28+
Setting the masterkey is prohibited with the KMS provider ``local``.
29+
30+
The format of ``masterkey`` for "aws" is as follows:
2731

2832
.. code-block:: javascript
2933
3034
{
31-
region: <string>, // Required.
32-
key: <string>, // Required. The Amazon Resource Name (ARN) to the AWS customer master key (CMK).
33-
endpoint: <string> // Optional. An alternate host identifier to send KMS requests to. May include port number.
35+
region: String,
36+
key: String, /* The Amazon Resource Name (ARN) to the AWS customer master key (CMK). */
37+
endpoint: Optional<String> /* An alternate host identifier to send KMS requests to. May include port number. Defaults to "kms.<region>.amazonaws.com" */
3438
}
3539
36-
The value of "endpoint" is a host name with optional port number separated by a colon. E.g. "kms.us-east-1.amazonaws.com" or "kms.us-east-1.amazonaws.com:443"
40+
The format of ``masterkey`` for "azure" is as follows:
3741

38-
This function is only applicable for the "aws" KMS provider. It is not applicable for creating data keys with the "local" KMS provider (as configured in :symbol:`mongoc_client_encryption_opts_set_kms_providers()`).
42+
.. code-block:: javascript
43+
44+
{
45+
keyVaultEndpoint: String, /* Host with optional port. Example: "example.vault.azure.net". */
46+
keyName: String,
47+
keyVersion: Optional<String> /* A specific version of the named key, defaults to using the key's primary version. */
48+
}
49+
50+
The format of ``masterkey`` for "gcp" is as follows:
51+
52+
.. code-block:: javascript
53+
54+
{
55+
projectId: String,
56+
location: String,
57+
keyRing: String,
58+
keyName: String,
59+
keyVersion: Optional<String>, /* A specific version of the named key, defaults to using the key's primary version. */
60+
endpoint: Optional<String> /* Host with optional port. Defaults to "cloudkms.googleapis.com". */
61+
}
62+
63+
The format of ``masterkey`` for "kmip" is as follows:
64+
65+
.. code-block:: javascript
66+
67+
{
68+
keyId: Optional<String>,
69+
endpoint: Optional<String> /* Host with optional port. */
70+
}

src/libmongoc/doc/mongoc_client_encryption_opts_set_kms_providers.rst

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,52 @@ 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`` or ``local`` are supported. At least one must be specified.
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.
2222

2323
The format for "aws" is as follows:
2424

2525
.. code-block:: javascript
2626
2727
aws: {
28-
accessKeyId: <string>,
29-
secretAccessKey: <string>
28+
accessKeyId: String,
29+
secretAccessKey: String
3030
}
3131
3232
The format for "local" is as follows:
3333

3434
.. code-block:: javascript
3535
3636
local: {
37-
key: <96 byte BSON binary of subtype 0> // The master key used to encrypt/decrypt data keys.
37+
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. */
38+
}
39+
40+
The format for "azure" is as follows:
41+
42+
.. code-block:: javascript
43+
44+
azure: {
45+
tenantId: String,
46+
clientId: String,
47+
clientSecret: String,
48+
identityPlatformEndpoint: Optional<String> /* Defaults to login.microsoftonline.com */
49+
}
50+
51+
The format for "gcp" is as follows:
52+
53+
.. code-block:: javascript
54+
55+
gcp: {
56+
email: String,
57+
privateKey: byte[] or String, /* May be passed as a base64 encoded string. */
58+
endpoint: Optional<String> /* Defaults to oauth2.googleapis.com */
59+
}
60+
61+
The format for "kmip" is as follows:
62+
63+
.. code-block:: javascript
64+
65+
kmip: {
66+
endpoint: String
3867
}
3968
4069
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
:man_page: mongoc_client_encryption_opts_set_tls_opts
2+
3+
mongoc_client_encryption_opts_set_tls_opts()
4+
============================================
5+
6+
Synopsis
7+
--------
8+
9+
.. code-block:: c
10+
11+
void
12+
mongoc_client_encryption_opts_set_tls_opts (
13+
mongoc_client_encryption_opts_t *opts, const bson_t *tls_opts);
14+
15+
16+
Parameters
17+
----------
18+
19+
* ``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.
21+
22+
``tls_opts`` is a BSON document of the following form:
23+
24+
.. code-block:: javascript
25+
26+
<KMS provider name>: {
27+
tlsCaFile: Optional<String>
28+
tlsCertificateKeyFile: Optional<String>
29+
tlsCertificateKeyFilePassword: Optional<String>
30+
}
31+
32+
The KMS providers ``aws``, ``azure``, ``gcp``, and ``kmip`` are supported as keys in the ``tls_opts`` document.
33+
34+
``tls_opts`` maps the KMS provider name to a BSON document for TLS options.
35+
36+
The BSON document for TLS options may contain the following keys:
37+
38+
- ``MONGOC_URI_TLSCERTIFICATEKEYFILE``
39+
- ``MONGOC_URI_TLSCERTIFICATEKEYFILEPASSWORD``
40+
- ``MONGOC_URI_TLSCAFILE``
41+
42+
.. literalinclude:: ../examples/client-side-encryption-doc-snippets.c
43+
:caption: Example use
44+
:start-after: BEGIN:mongoc_client_encryption_opts_set_tls_opts
45+
:end-before: END:mongoc_client_encryption_opts_set_tls_opts
46+
:dedent: 6
47+
48+
See :doc:`configuring_tls` for a description of the behavior of these options.
49+
50+
.. seealso::
51+
52+
| The guide for :doc:`Using Client-Side Field Level Encryption <using_client_side_encryption>`
53+

src/libmongoc/doc/mongoc_client_encryption_opts_t.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Used to set options for :symbol:`mongoc_client_encryption_new()`.
2626
mongoc_client_encryption_opts_set_keyvault_client
2727
mongoc_client_encryption_opts_set_keyvault_namespace
2828
mongoc_client_encryption_opts_set_kms_providers
29+
mongoc_client_encryption_opts_set_tls_opts
2930

3031
.. seealso::
3132

0 commit comments

Comments
 (0)