Skip to content

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

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

aclark4life
Copy link
Collaborator

@aclark4life aclark4life commented Jun 27, 2025

Previous attempts and additional context here:

@aclark4life

This comment was marked as resolved.

@timgraham

This comment was marked as resolved.

@aclark4life

This comment was marked as resolved.

@timgraham

This comment was marked as resolved.

@aclark4life

This comment was marked as resolved.

@aclark4life

This comment was marked as resolved.

@aclark4life

This comment was marked as resolved.

@aclark4life

This comment was marked as resolved.

@timgraham

This comment was marked as resolved.

@aclark4life

This comment was marked as resolved.

@aclark4life

This comment was marked as resolved.

@aclark4life

This comment was marked as resolved.

@timgraham

This comment was marked as resolved.

@aclark4life

This comment was marked as resolved.

@timgraham

This comment was marked as resolved.

Comment on lines 440 to 444
raise ImproperlyConfigured(
"Encrypted fields found but "
"DATABASES[[self.connection.alias}]['OPTIONS'] is missing "
"auto_encryption_opts. Please set `auto_encryption_opts` "
"in the connection settings."
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you try adding a test for this exception?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested it manually but haven't written a test for it yet.

Comment on lines 70 to 71
"KMS_PROVIDERS": {},
"KMS_CREDENTIALS": {},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For KMS_CREDENTIALS, I believe the options are documented here: https://pymongo.readthedocs.io/en/stable/api/pymongo/encryption.html#pymongo.encryption.ClientEncryption.create_data_key (but pymongo docs are deprecated?)

So a minimal example for AWS: "KMS_CREDENTIALS": {"aws": {"region": "...", "key": "..."}


.. _server-side-queryable-encryption-settings:

Server-side Queryable Encryption

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely not a phrase we should be using in documentation; the core point of CSFLE/QE is that the encryption itself is primarily a client-side feature, and this title sounds like some of the encryption logic actually happens on the server side. This should be something like "Server-side schema for Queryable Encryption".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂 OK will fix

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


.. _client-side-queryable-encryption:

Client-side Queryable Encryption

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

"OPTIONS": {
"auto_encryption_opts": AutoEncryptionOpts(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this include an example of how to specify the crypt_shared library path?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Will add.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

aclark4life and others added 2 commits August 11, 2025 22:23
- Removed all signs of client side vs. server side configuration of
  Queryable Encryption which can be too easily confused with client-side
  encryption, which is what Queryable Encryption is.
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for MongoDB's Queryable Encryption feature to the Django MongoDB Backend, allowing developers to store sensitive data in encrypted fields that can still be queried using specific query types. The implementation includes encrypted field classes, schema support, management commands, and comprehensive documentation.

  • Adds encrypted field types that wrap Django's built-in fields with encryption capabilities
  • Implements schema editor support for creating collections with encrypted fields and managing data keys
  • Provides management command for generating encrypted fields maps and creating encryption keys

Reviewed Changes

Copilot reviewed 32 out of 33 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
django_mongodb_backend/fields/encryption.py Defines encrypted field classes and mixin for queryable encryption
django_mongodb_backend/schema.py Adds schema editor support for creating encrypted collections and managing data keys
django_mongodb_backend/management/commands/showencryptedfieldsmap.py Management command for generating encrypted fields maps
django_mongodb_backend/features.py Adds feature detection for queryable encryption support
tests/encryption_/ Comprehensive test suite covering encrypted fields, schema operations, and management commands
docs/source/ Documentation for configuring and using queryable encryption
pyproject.toml Adds optional encryption dependency

@mongodb mongodb deleted a comment from Copilot AI Aug 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants