Skip to content

Commit b54ba27

Browse files
DOCSP-22096 - Discuss patternProperties (#1347)
* added patternProperties to fundamentals and reference pages * typos * feedback * feedback on other page
1 parent da28ce4 commit b54ba27

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

source/core/csfle/fundamentals/create-schema.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,26 @@ containing ``encryptMetadata`` have the following structure:
6565
.. literalinclude:: /includes/fundamentals/encryptmetadata-keyword.json
6666
:language: json
6767

68+
.. _csfle-fundamentals-pattern-properties:
69+
70+
patternProperties Keyword
71+
~~~~~~~~~~~~~~~~~~~~~~~~~
72+
73+
You can use the ``patternProperties`` keyword in your encryption schema to
74+
define encryption rules for all fields with names that match a regular expression.
75+
This allows you to specify multiple fields for encryption based on a single regular
76+
expression, or to specify them by only using a part of the field name. The
77+
``patternProperties`` keyword replaces ``properties`` in your encryption schema.
78+
79+
Specify encryption rules with ``patternProperties`` using the following
80+
structure:
81+
82+
.. literalinclude:: /includes/fundamentals/patternProperties-keyword.json
83+
:language: json
84+
85+
To see an example of how to use ``patternProperties`` see
86+
:ref:`field-level-encryption-auto-encrypt-with-pattern-properties`
87+
6888
.. _fle-define-a-json-schema:
6989

7090
Example

source/core/csfle/reference/encryption-schemas.txt

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,3 +553,97 @@ see the :ref:`Encryption algorithms <csfle-reference-encryption-algorithms>` pag
553553

554554
To learn more about {+csfle-abbrev+}-specific ``MongoClient`` options,
555555
see the :ref:`mongo client <csfle-reference-mongo-client>` page.
556+
557+
.. _field-level-encryption-auto-encrypt-with-pattern-properties:
558+
559+
Encryption Schema - Encrypt with Pattern Properties
560+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
561+
562+
You can use the ``patternProperties`` keyword in your encryption schema to
563+
define encryption rules for all fields with names that match a regular expression.
564+
565+
Consider a collection ``MedCo.patients`` where each document has
566+
the following structure:
567+
568+
.. code-block:: none
569+
570+
{
571+
"fname" : "<string>",
572+
"lname" : "<string>",
573+
"passportId_PIIString" : "<string>",
574+
"bloodType_PIIString" : "<string>",
575+
"medicalRecords_PIIArray" : [
576+
{<object>}
577+
],
578+
"insurance" : {
579+
"policyNumber_PIINumber" : "<number>",
580+
"provider_PIIString" : "<string>"
581+
}
582+
}
583+
584+
The fields that contain private data are identified by a "_PII<type>"
585+
tag appended the end of the field name.
586+
587+
- ``passportId_PIIString``
588+
- ``bloodType_PIIString``
589+
- ``medicalRecords_PIIArray``
590+
- ``insurance.policyNumber_PIINumber``
591+
- ``insurance.provider_PIIString``
592+
593+
You can use the ``patternProperties`` keyword to configure these fields for
594+
encryption, without identifying each field individually, and without using the
595+
full field name. Do this by using regular expressions that match all fields that
596+
end with the "_PII<type>" tag.
597+
598+
The following JSON schema uses ``patternProperties`` and regular expressions to
599+
specify which fields to encrypt.
600+
601+
.. code-block:: json
602+
603+
{
604+
"MedCo.patients": {
605+
"bsonType": "object",
606+
"patternProperties": {
607+
"_PIIString$": {
608+
"encrypt": {
609+
"keyId": [UUID("6c512f5e-09bc-434f-b6db-c42eee30c6b1")],
610+
"bsonType": "string",
611+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic",
612+
},
613+
},
614+
"_PIIArray$": {
615+
"encrypt": {
616+
"keyId": [UUID("6c512f5e-09bc-434f-b6db-c42eee30c6b1")],
617+
"bsonType": "array",
618+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random",
619+
},
620+
},
621+
"insurance": {
622+
"bsonType": "object",
623+
"patternProperties": {
624+
"_PIINumber$": {
625+
"encrypt": {
626+
"keyId": [UUID("6c512f5e-09bc-434f-b6db-c42eee30c6b1")],
627+
"bsonType": "int",
628+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic",
629+
},
630+
},
631+
"_PIIString$": {
632+
"encrypt": {
633+
"keyId": [UUID("6c512f5e-09bc-434f-b6db-c42eee30c6b1")],
634+
"bsonType": "string",
635+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic",
636+
},
637+
},
638+
},
639+
},
640+
},
641+
},
642+
}
643+
644+
The above automatic encryption rules mark the ``passportId_PIIString``,
645+
``bloodType_PIIString``, ``medicalRecords_PIIArray``, ``insurance.policyNumber_PIINumber``,
646+
``insurance.provider_PIIString`` fields for encryption.
647+
648+
To Learn more about the ``patternProperties`` keyword, see
649+
:ref:`csfle-fundamentals-pattern-properties`.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"bsonType": "object",
2+
"patternProperties": {
3+
"<regular expression to match>": {
4+
"encrypt": {
5+
"algorithm": "<encryption algorithm to use>",
6+
"bsonType": "<bson type of field>",
7+
"keyId": [UUID("<UUID of Data Encryption Key to encrypt and decrypt this document>")]
8+
}
9+
}

0 commit comments

Comments
 (0)