-
Notifications
You must be signed in to change notification settings - Fork 28
INTPYTHON-527 Add Queryable Encryption support #329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 25 commits
36bd1e5
70c946b
cb3512c
46ca9dc
87b1dc9
d39f3b3
3f8b5c2
441c584
c9cc301
332decb
0317fba
e3da2f6
fe790c7
2270058
e38b496
36c6bfd
86486eb
59865f7
fc87e9f
75873e9
324c959
13ed19a
b23c4f2
a0cd197
65b96b2
80881fa
25e7da1
ff84902
23f20a4
01ec095
8a3ccf5
9bfa86d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os | ||
|
||
from mongodb_settings import * # noqa: F403 | ||
from pymongo.encryption import AutoEncryptionOpts | ||
|
||
DATABASES["encrypted"] = { # noqa: F405 | ||
"ENGINE": "django_mongodb_backend", | ||
"NAME": "djangotests-encrypted", | ||
"OPTIONS": { | ||
"auto_encryption_opts": AutoEncryptionOpts( | ||
key_vault_namespace="my_encrypted_database.keyvault", | ||
kms_providers={"local": {"key": os.urandom(96)}}, | ||
# crypt_shared_lib_path="lib/mongo_crypt_v1.so", | ||
), | ||
"directConnection": True, | ||
}, | ||
"KMS_CREDENTIALS": {}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
DATABASES = { | ||
"default": {**db_settings, "NAME": "djangotests"}, | ||
"other": {**db_settings, "NAME": "djangotests-other"}, | ||
"encrypted": {}, | ||
} | ||
else: | ||
DATABASES = { | ||
|
@@ -28,8 +29,26 @@ | |
"NAME": "djangotests-other", | ||
"OPTIONS": {"directConnection": True}, | ||
}, | ||
"encrypted": {}, | ||
} | ||
|
||
|
||
class EncryptedRouter: | ||
def allow_migrate(self, db, app_label, model_name=None, **hints): | ||
# The encryption_ app's models are only created in the encrypted | ||
# database. | ||
if app_label == "encryption_": | ||
return db == "encrypted" | ||
# Don't create other app's models in the encrypted database. | ||
if db == "encrypted": | ||
return False | ||
return None | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In a refactor, you removed the test router than had:
thus the current tests aren't stored objects in the encrypted database. These methods must also be added to the example router in the documentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed it because I thought we could rely on the test runner settings ? I'll update the docs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These methods direct querysets where to send their queries. Without this guidance, all queries go the "default" database. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. I mean I have this in my test runner settings:
So do we need a router in the tests or can we rely on the test runner's router ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can put in the test runner's router. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment was resolved but the changes weren't made. |
||
def kms_provider(self, model, **hints): | ||
return "local" | ||
|
||
|
||
DATABASE_ROUTERS = [EncryptedRouter()] | ||
DEFAULT_AUTO_FIELD = "django_mongodb_backend.fields.ObjectIdAutoField" | ||
PASSWORD_HASHERS = ("django.contrib.auth.hashers.MD5PasswordHasher",) | ||
SECRET_KEY = "django_tests_secret_key" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any objection to combining this line and the next line into
pip install -e .[encryption]
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be best to have this line run only on builds that test encryption, so that we don't inadvertently add some top-level import for an optional dependency (similar reason to why we have a separate build for GIS that installs gdal-bin.) Perhaps the encryption build could set an environment variable like
RUNNING_ENCRYPTION_TESTS
that this script could consult.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK filing under CI todo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it doesn't appear we're going to run the encrypted tests on evergreen, we can remove this line.