-
Notifications
You must be signed in to change notification settings - Fork 31
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Settings for django_mongodb_backend/tests with AWS Key Management System. | ||
| import os | ||
|
|
||
| from encrypted_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="djangotests_encrypted.__keyVault", | ||
| kms_providers={ | ||
| "aws": { | ||
| "accessKeyId": os.environ["AWS_ACCESS_KEY_ID"], | ||
| "secretAccessKey": os.environ["AWS_SECRET_ACCESS_KEY"], | ||
| } | ||
| }, | ||
| crypt_shared_lib_path=os.environ["CRYPT_SHARED_LIB_PATH"], | ||
| crypt_shared_lib_required=True, | ||
| ), | ||
| }, | ||
| "KMS_CREDENTIALS": { | ||
| "aws": { | ||
| "key": os.environ["AWS_KMS_ARN"], | ||
| "region": os.environ["AWS_DEFAULT_REGION"], | ||
| } | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Settings for django_mongodb_backend/tests when encryption is supported. | ||
| 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="djangotests_encrypted.__keyVault", | ||
| kms_providers={"local": {"key": os.urandom(96)}}, | ||
| crypt_shared_lib_path=os.environ["CRYPT_SHARED_LIB_PATH"], | ||
| crypt_shared_lib_required=True, | ||
| ), | ||
| "directConnection": True, | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| class EncryptedRouter: | ||
| def db_for_read(self, model, **hints): | ||
| # All models in the encryption_ app use the encrypted database. | ||
| if model._meta.app_label == "encryption_": | ||
| return "encrypted" | ||
| return None | ||
|
|
||
| db_for_write = db_for_read | ||
|
|
||
| def allow_migrate(self, db, app_label, model_name=None, **hints): | ||
| # Create the encryption_ app's models only in the encrypted database. | ||
| if app_label == "encryption_": | ||
| return db == "encrypted" | ||
| # Don't create other apps' models in the encrypted database. | ||
| if db == "encrypted": | ||
| return False | ||
| return None | ||
|
|
||
|
|
||
| DATABASE_ROUTERS.append(EncryptedRouter()) # noqa: F405 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| # Settings for django_mongodb_backend/tests. | ||
| # Settings for django_mongodb_backend/tests when encryption isn't supported. | ||
| from django_settings import * # noqa: F403 | ||
|
|
||
| DATABASES["encrypted"] = {} # noqa: F405 | ||
| DATABASE_ROUTERS = ["django_mongodb_backend.routers.MongoRouter"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| name: Python Tests on Atlas with Encryption | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - '**.py' | ||
| - '!setup.py' | ||
| - '.github/workflows/test-python-encryption.yml' | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| defaults: | ||
| run: | ||
| shell: bash -eux {0} | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Django Test Suite | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout django-mongodb-backend | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| persist-credentials: false | ||
| - name: install django-mongodb-backend | ||
| run: | | ||
| pip3 install --upgrade pip | ||
| pip3 install -e .[encryption] | ||
| - name: Checkout Django | ||
| uses: actions/checkout@v6 | ||
|
||
| with: | ||
| repository: 'mongodb-forks/django' | ||
| ref: 'mongodb-6.0.x' | ||
| path: 'django_repo' | ||
| persist-credentials: false | ||
| - name: Install system packages for Django's Python test dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install libmemcached-dev | ||
| - name: Install Django and its Python test dependencies | ||
| run: | | ||
| cd django_repo/tests/ | ||
| pip3 install -e .. | ||
| pip3 install -r requirements/py3.txt | ||
| - name: Copy the test settings files | ||
| run: cp .github/workflows/*_settings.py django_repo/tests/ | ||
| - name: Copy the test runner file | ||
| run: cp .github/workflows/runtests.py django_repo/tests/runtests_.py | ||
| - name: Start local Atlas | ||
| working-directory: . | ||
| run: bash .github/workflows/start_local_atlas.sh mongodb/mongodb-atlas-local:8.0 | ||
| - name: Download mongo_crypt_shared | ||
| run: | | ||
| wget https://downloads.mongodb.com/linux/mongo_crypt_shared_v1-linux-x86_64-enterprise-ubuntu2404-8.2.3.tgz | ||
| tar -xvzf mongo_crypt_shared_v1-linux-x86_64-enterprise-ubuntu2404-8.2.3.tgz lib/mongo_crypt_v1.so | ||
| - name: Run tests | ||
| run: python3 django_repo/tests/runtests_.py | ||
| permissions: | ||
| contents: read | ||
| env: | ||
| CRYPT_SHARED_LIB_PATH: "${{ github.workspace }}/lib/mongo_crypt_v1.so" | ||
| DJANGO_SETTINGS_MODULE: "encrypted_settings" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.