@@ -4,6 +4,10 @@ Configuring Queryable Encryption
44
55.. versionadded :: 5.2.0rc1
66
7+ This guide is similar to the
8+ :doc: `manual:core/queryable-encryption/quick-start ` but with some additional
9+ steps required to configure Queryable Encryption with Django MongoDB Backend.
10+
711.. admonition :: MongoDB requirements
812
913 Queryable Encryption can be used with MongoDB replica sets or sharded
@@ -94,27 +98,72 @@ configure a custom router for Queryable Encryption:
9498
9599 DATABASE_ROUTERS = [EncryptedRouter]
96100
97- Configuring KMS Providers
98- =========================
99-
100- To use Queryable Encryption, you must configure a Key Management Service (KMS)
101- provider. The KMS provider is responsible for managing the encryption keys used
102- to encrypt and decrypt data. The following table summarizes the available KMS
103- provider options and how to configure them:
104-
105- +-------------------------------------------------------------------------+---------------------------------------+
106- | :setting: `KMS_CREDENTIALS <DATABASE-KMS-CREDENTIALS> ` | A dictionary of Key Management |
107- | | Service (KMS) credentials |
108- | | configured in the |
109- | | :setting: `django:DATABASES ` |
110- | | setting. |
111- +-------------------------------------------------------------------------+---------------------------------------+
112- | :class: `kms_providers <pymongo.encryption_options.AutoEncryptionOpts> ` | Map of KMS provider credentials and |
113- | | options. The ``kms_providers `` map |
114- | | values differ by provider and are |
115- | | required to access KMS services. |
116- +-------------------------------------------------------------------------+---------------------------------------+
117- | ``kms_provider `` | A single KMS provider name |
118- | | configured in your custom database |
119- | | router. |
120- +-------------------------------------------------------------------------+---------------------------------------+
101+ Configuring the Key Management Service (KMS)
102+ ============================================
103+
104+ To use Queryable Encryption, you must configure a Key Management Service (KMS).
105+ The KMS is responsible for managing the encryption keys used to encrypt and
106+ decrypt data. The following table summarizes the available KMS configuration
107+ options followed by an example of how to use them.
108+
109+ +-------------------------------------------------------------------------+--------------------------------------------------------+
110+ | :setting: `KMS_CREDENTIALS <DATABASE-KMS-CREDENTIALS> ` | A dictionary of Key Management Service (KMS) |
111+ | | credentials configured in the |
112+ | | :setting: `django:DATABASES ` setting. |
113+ +-------------------------------------------------------------------------+--------------------------------------------------------+
114+ | :class: `kms_providers <pymongo.encryption_options.AutoEncryptionOpts> ` | A dictionary of KMS provider credentials used to |
115+ | | access the KMS with |
116+ | | :setting: `KMS_CREDENTIALS <DATABASE-KMS-CREDENTIALS> `. |
117+ +-------------------------------------------------------------------------+--------------------------------------------------------+
118+ | ``kms_provider `` | A single KMS provider name |
119+ | | configured in your custom database |
120+ | | router. |
121+ +-------------------------------------------------------------------------+--------------------------------------------------------+
122+
123+ Example of KMS configuration with AWS KMS:
124+
125+ .. code-block :: python
126+
127+ from django_mongodb_backend import parse_uri
128+ from pymongo.encryption_options import AutoEncryptionOpts
129+
130+ DATABASES = {
131+ " encrypted" : parse_uri(
132+ DATABASE_URL ,
133+ options = {
134+ " auto_encryption_opts" : AutoEncryptionOpts(
135+ key_vault_namespace = " keyvault.keyvault" ,
136+ kms_providers = {
137+ " aws" : {
138+ " accessKeyId" : " your-access-key-id" ,
139+ " secretAccessKey" : " your-secret-access-key" ,
140+ }
141+ },
142+ )
143+ },
144+ db_name = " encrypted" ,
145+ ),
146+ }
147+
148+ DATABASES [" encrypted" ][" KMS_CREDENTIALS" ] = {
149+ " aws" : {
150+ " key" : os.getenv(" AWS_KEY_ARN" , " " ),
151+ " region" : os.getenv(" AWS_KEY_REGION" , " " ),
152+ },
153+ }
154+
155+
156+ class EncryptedRouter :
157+ # ...
158+ def kms_provider (self , model , ** hints ):
159+ return " aws"
160+
161+
162+ Configuring the ``encrypted_fields_map ``
163+ ========================================
164+
165+ Configuring the Crypt Shared Library
166+ ====================================
167+
168+ You are now ready to :doc: `develop with Queryable Encryption
169+ </topics/queryable-encryption>` in Django MongoDB Backend!
0 commit comments