@@ -57,12 +57,179 @@ cubilia Curae; Nunc non interdum purus, ultricies laoreet tortor.
57
57
B. Define a JSON Schema
58
58
~~~~~~~~~~~~~~~~~~~~~~~
59
59
60
- Proin non mi a felis luctus vulputate nec pharetra odio. Ut pretium
61
- scelerisque nulla, sed euismod nisi pellentesque sit amet. Proin mollis
62
- mauris eu libero ullamcorper rutrum. Pellentesque vitae enim sed magna
63
- accumsan maximus et quis mi. Ut vel laoreet turpis. Vivamus vitae odio
64
- sed arcu finibus pretium vel maximus nisi. Nullam gravida consequat
65
- porta.
60
+ `JSON Schema
61
+ <http://json-schema.org/>`_ is a vocabulary that allows you to annotate and
62
+ validate JSON documents. MongoDB extends the JSON Schema standard to allow CSFLE
63
+ to use automatically encrypt and decrypt the fields of documents in a collection.
64
+
65
+ The following fields are required in the JSON Schema to enable automatic
66
+ encryption and decryption for each field:
67
+
68
+ * The encryption algorithm (:manual:`Deterministic Encryption </core/security-client-side-encryption#deterministic-encryption>` or :manual:`Random Encryption </core/security-client-side-encryption#random-encryption>`)
69
+ * The data key
70
+ * The BSON Type (only required by deterministically encrypted fields)
71
+
72
+ .. note::
73
+
74
+ A single data key can be used for all encrypted fields, or you can use individual data keys that are specific to each field.
75
+
76
+
77
+ The MedcoMD engineers receive specific requirements for the fields of
78
+ data and their encryption strategies. The following table illustrates
79
+ the data model of the Medco Management System.
80
+
81
+
82
+
83
+ .. list-table::
84
+ :header-rows: 1
85
+
86
+ * - Field type
87
+ - Encryption Algorithm
88
+ - BSON Type
89
+ * - Name
90
+ - Non-Encrypted
91
+ - String
92
+ * - SSN
93
+ - Deterministic
94
+ - Int
95
+ * - Blood Type
96
+ - Random
97
+ - String
98
+ * - Medical Records
99
+ - Random
100
+ - Array
101
+ * - Insurance: Policy Number
102
+ - Deterministic
103
+ - Int (embedded inside `insurance` object)
104
+ * - Insurance: Provider
105
+ - Non-Encrypted
106
+ - String (embedded inside `insurance` object)
107
+
108
+
109
+
110
+
111
+ To automatically encrypt and decrypt data, the MedcoMD engineers create
112
+ a JSON Schema that specifies which fields should be encrypted, and which
113
+ encryption method to use. Initially, they define a data key for all
114
+ fields in the data model by specifying the `encryptMetadata
115
+ <https://docs.mongodb.com/manual/reference/security-client-side-automatic-json-schema/#encryptmetadata-schema-keyword>`_
116
+ attribute. All child properties will inherit this encryption key unless
117
+ specifically overwritten.
118
+
119
+ .. code-block:: javascript
120
+
121
+ {
122
+ "bsonType" : "object",
123
+ "encryptMetadata" : {
124
+ "keyId" : // copy and paste your keyID generated here
125
+ },
126
+ "properties": {
127
+ // copy and paste your fields here
128
+ }
129
+ }
130
+
131
+ MedcoMD engineers create JSON objects for each field and append them to
132
+ the `properties` map.
133
+
134
+ SSN
135
+ +++
136
+ ``ssn`` is a field representing the patient's social security number. This
137
+ field is sensitive and should be encrypted. MedcoMD engineers decide
138
+ upon deterministic encryption based on the following properties:
139
+
140
+ * Queryable
141
+ * High cardinality
142
+
143
+ .. code-block:: json
144
+
145
+ "ssn": {
146
+ "encrypt": {
147
+ "bsonType": "int",
148
+ "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
149
+ }
150
+ }
151
+
152
+
153
+
154
+ Blood Type
155
+ ++++++++++
156
+ ``bloodType`` is a field representing the patient's blood type. This field is
157
+ sensitive and should be encrypted. MedcoMD engineers decide
158
+ upon random encryption based on the following properties:
159
+
160
+ * No plans to query
161
+ * Low cardinality
162
+
163
+ .. code-block:: json
164
+
165
+ "bloodType": {
166
+ "encrypt": {
167
+ "bsonType": "string",
168
+ "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
169
+ }
170
+ }
171
+
172
+
173
+ Medical Records
174
+ +++++++++++++++
175
+ ``medicalRecords`` is an array field holding a set of medical records. Each
176
+ medical record document specifies information, such as the patient's blood
177
+ pressure, weight, and heart rate. This field is sensitive and should be
178
+ encrypted. MedcoMD engineers decide upon random encryption based on
179
+ the following properties:
180
+
181
+ * Array fields must use random encryption with CSFLE to enable auto-encryption
182
+
183
+ .. code-block:: json
184
+
185
+ "medicalRecords": {
186
+ "encrypt": {
187
+ "bsonType": "array",
188
+ "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
189
+ }
190
+ }
191
+
192
+ Insurance: Policy Number
193
+ ++++++++++++++++++++++++
194
+ ``insurance.policyNumber`` is a field embedded inside the ``Insurance`` object
195
+ field and represents the patient's policy number. This policy number is a
196
+ distinct and sensitive field. MedcoMD engineers decide upon
197
+ deterministic encryption based on the following properties:
198
+
199
+ * Queryable
200
+ * High cardinality
201
+
202
+ .. code-block:: json
203
+
204
+ "insurance": {
205
+ "bsonType": "object",
206
+ "properties": {
207
+ "policyNumber": {
208
+ "encrypt": {
209
+ "bsonType": "int",
210
+ "algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
211
+ }
212
+ }
213
+ }
214
+ }
215
+
216
+
217
+ Recap
218
+ +++++++
219
+ MedcoMD engineers created a JSON Schema that satisfies their requirements of
220
+ making sensitive data queryable and secure. View the full `JSON Schema
221
+ for the Medco Medical Management System <https://raw.githubusercontent.com/mongodb/docs-assets/DOCSP-json-schema-helper-and-json/MedcoMDSchema.json>`_.
222
+
223
+
224
+ .. tabs::
225
+
226
+ tabs:
227
+
228
+ - id: java-jsonschema-generation
229
+ name: "Java"
230
+ content: |
231
+
232
+ View the `helper code in Java <https://gist.github.com/ccho-mongodb/088176b1bed3b9e54cdc0c2c3c537d1b>`_.
66
233
67
234
C. Configure the MongoDB Client
68
235
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments