Skip to content

Commit 4661284

Browse files
(DOCSP-19240) CSFLE KMIP Java (#776)
1 parent 26037b7 commit 4661284

File tree

3 files changed

+136
-0
lines changed

3 files changed

+136
-0
lines changed

snooty.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ version = 4.0
1010
package-name-org = "docs-ecosystem"
1111
pgp-version = "{+version+}"
1212
csharp-docs-versioned = "https://mongodb.github.io/mongo-csharp-driver/2.14"
13+
14+
java-version = 4.4
15+
java-api = "https://mongodb.github.io/mongo-java-driver/{+java-version+}"
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
title: Configure Your KMIP KMS
2+
ref: configure-kmip-kms
3+
content: |
4+
5+
To connect a MongoDB driver client to your KMIP KMS, you must configure your KMS
6+
such that it accepts your client's TLS certificate.
7+
8+
Consult the documentation for your KMIP KMS for information on how
9+
to accept your client certificate with your specific KMS.
10+
11+
---
12+
title: Specify your Certificates
13+
ref: specify-certificates
14+
content: |
15+
16+
Your client must connect to your KMIP KMS through TLS and present
17+
a client certificate accepted by your KMS server.
18+
19+
.. tabs-drivers::
20+
21+
.. tab::
22+
:tabid: java-sync
23+
24+
Specify the following Java system properties to configure your client's
25+
TLS connection:
26+
27+
.. code-block:: shell
28+
29+
-Djavax.net.ssl.keyStoreType=pkcs12
30+
-Djavax.net.ssl.keyStore=<path to pkcs12 KeyStore containing your client certificate>
31+
-Djavax.net.ssl.keyStorePassword=<KeyStore password>
32+
33+
.. note:: Configure Client With SSLContext
34+
35+
If you would rather configure your KMIP client using an SSL context, use the
36+
`kmsProviderSslContextMap <{+java-api+}/apidocs/mongodb-driver-core/com/mongodb/ClientEncryptionSettings.Builder.html#kmsProviderSslContextMap(java.util.Map)>`__
37+
method.
38+
39+
---
40+
title: Create a New Data Encryption Key
41+
ref: create-a-new-data-key
42+
content: |
43+
To encrypt your data, you need a data encryption key generated from your
44+
KMS-hosted **master key**. The following diagram shows the requests you need
45+
to make from the client application to create and store a new **data
46+
encryption key**:
47+
48+
.. image:: /figures/CSFLE_Data_Key_KMS.png
49+
:alt: Diagram that describes creating a data encryption key when using a KMS provider
50+
51+
1. First, specify the following information to access the master key:
52+
53+
.. list-table::
54+
:header-rows: 1
55+
:stub-columns: 1
56+
:widths: 30 15 45
57+
58+
* - Field
59+
- Required
60+
- Description
61+
62+
* - keyId
63+
- No
64+
- The ``keyId`` field of a 96 byte
65+
`Secret Data managed object <http://docs.oasis-open.org/kmip/spec/v1.4/os/kmip-spec-v1.4-os.html#_Toc490660780>`__
66+
stored in your KMIP KMS.
67+
68+
.. note:: Create a New Master Key
69+
70+
If you do not specify the ``keyId`` field in the ``masterKey`` document
71+
you send to your KMIP KMS, the driver creates a new
72+
96 Byte Secret Data managed object in your KMS to act as your
73+
master key.
74+
75+
* - endpoint
76+
- Yes
77+
- The URI of your KMIP KMS.
78+
79+
2. Once you have the required information, update and run the following code
80+
to generate the new data encryption key:
81+
82+
.. include:: /includes/substitute-placeholders.rst
83+
84+
.. tabs-drivers::
85+
86+
.. tab::
87+
:tabid: java-sync
88+
89+
.. code-block:: java
90+
91+
Map<String, Map<String, Object>> kmsProviderProperties = new HashMap<>();
92+
Map<String, Object> providerDetails = new HashMap<>();
93+
providerDetails.put("endpoint", "<KMIP KMS URI>");
94+
kmsProviderProperties.put(kmsProvider, providerDetails);
95+
String keyVaultCollection = "<MongoDB namespace where you store your keys>"
96+
97+
ClientEncryption clientEncryption = ClientEncryptions.create(ClientEncryptionSettings.builder()
98+
.keyVaultMongoClientSettings(MongoClientSettings.builder()
99+
.applyConnectionString(new ConnectionString("<MongoDB connection string>"))
100+
.build())
101+
.keyVaultNamespace(keyVaultNamespace)
102+
.kmsProviders(kmsProviders)
103+
.build());
104+
105+
DataKeyOptions dataKeyOptions = new DataKeyOptions().masterKey(
106+
new BsonDocument()
107+
.append("keyId", "<your KeyId>"));
108+
109+
BsonBinary dataKeyId = clientEncryption.createDataKey("kmip", dataKeyOptions);
110+
111+
System.out.println("DataKeyId [UUID]: " + dataKeyId.asUuid().toString());
112+
113+
.. note::
114+
115+
To use a KMIP KMS, you must use `mongodb-crypt <https://mvnrepository.com/artifact/org.mongodb/mongodb-crypt>`__
116+
version 1.3 or later in your application's environment.
117+
118+
---
119+
title: Update the Automatic Encryption JSON Schema
120+
ref: update-the-json-schema
121+
content: |
122+
If you previously embedded the key ID of your data encryption key in your
123+
automatic encryption rules, update the :ref:`JSON Schema <fle-define-a-json-schema>`
124+
with your new data encryption key ID.
125+
126+
Your client application is now ready to automatically encrypt your data
127+
using the master key on your KMS provider.

source/security/client-side-field-level-encryption-local-key-to-kms.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Currently, MongoDB drivers support the following Key Management Providers:
2525
- `Amazon Web Services KMS <https://aws.amazon.com/kms/>`__
2626
- `Azure Key Vault <https://azure.microsoft.com/en-us/services/key-vault/>`__
2727
- `Google Cloud Platform Key Management <https://cloud.google.com/security-key-management>`__
28+
- `Any KMIP Compliant KMS <https://docs.oasis-open.org/kmip/spec/v1.0/os/kmip-spec-1.0-os.html>`__
2829
- Local KMS provider
2930

3031
Once you complete the steps in this guide, you should have:
@@ -92,6 +93,11 @@ provider:
9293

9394
.. include:: /includes/steps/fle-convert-to-a-remote-master-key-gcp.rst
9495

96+
.. tab:: KMIP KMS
97+
:tabid: kmip-kms
98+
99+
.. include:: /includes/steps/fle-convert-to-a-remote-master-key-kmip.rst
100+
95101
Further Reading
96102
---------------
97103

0 commit comments

Comments
 (0)