Skip to content

Add support for Field-Level Automatic and Queryable Encryption #2759

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

Draft
wants to merge 19 commits into
base: feature/queryable-encryption
Choose a base branch
from

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Apr 25, 2025

Q A
Type feature
BC Break no
Fixed issues PHPORM-317

Summary

⚠️ This feature requires a MongoDB Atlas or Enterprise license.

Client-Side Field Level Encryption (CSFLE) is a feature that enables you to encrypt data in your application before you send it over the network to MongoDB. With CSFLE enabled, no MongoDB product has access to your data in an unencrypted form.

Queryable Encryption gives you the ability to perform the following tasks:

  • Encrypt sensitive data fields from the client-side.
  • Store sensitive data fields as fully randomized encrypted data on the database server-side.
  • Run expressive queries on the encrypted data.

Implementation:

The encrypted collection must be created using the schema manager (odm:schema:create command)

@GromNaN GromNaN changed the base branch from 2.11.x to 2.12.x April 28, 2025 20:08
@GromNaN GromNaN force-pushed the fle branch 2 times, most recently from a6ec9ed to 81f3e90 Compare April 30, 2025 14:46
@GromNaN GromNaN changed the base branch from 2.12.x to feature/queryable-encryption May 5, 2025 13:48
Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

Left some questions, and phpstan seems to be unhappy about some of the mapping types.

The logic and tests for it look solid.

<xs:element name="field" type="odm:field" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="embed-one" type="odm:embed-one" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="embed-many" type="odm:embed-many" minOccurs="0" maxOccurs="unbounded" />
<xs:element name="encrypt" type="odm:encrypt-field" minOccurs="0" maxOccurs="1" />
Copy link
Member

Choose a reason for hiding this comment

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

Why is this an element instead of an attribute? Is it to future-proof this in case there will be options for encrypting entire documents in future?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I plan to add a "key" attribute to the element.

$this->dm->getClientEncryption(),
$this->dm->getConfiguration()->getKmsProvider(),
null, // @todo when is it necessary to set the master key?
$options,
Copy link
Member

Choose a reason for hiding this comment

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

Should you be using $this->getWriteOptions here like below and add the encrypted field config?

@GromNaN GromNaN force-pushed the fle branch 2 times, most recently from 0fc420d to 34a9d06 Compare May 21, 2025 14:14
Comment on lines +322 to +328
'min', 'max' => match ($mapping['type']) {
Type::INT => (int) $encryptValue,
Type::FLOAT => (float) $encryptValue,
Type::DECIMAL128 => new Decimal128((string) $encryptValue),
Type::DATE, Type::DATE_IMMUTABLE => new UTCDateTime(new DateTimeImmutable((string) $encryptValue)),
default => null, // Invalid
},
Copy link
Member Author

Choose a reason for hiding this comment

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

I've added the transformation of values from string to native BSON types here; should use the Type::convertToDatabaseValue() inside EncryptionFieldMap.

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.

2 participants