Skip to content

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Jul 4, 2025

In driver options, the encryptedFieldsMap option must:

  1. contain a fields key with the list of fields
  2. convert query.min and query.max to the same BSON type as the field
  3. contain the keyId. But this value will change every time the database is reset.

This needs to be improved by leveraging keyAltNames.

$encryptedFieldsMap = [];
foreach ($documentManager->getMetadataFactory()->getAllMetadata() as $metadata) {
$database = $documentManager->getDocumentDatabase($metadata->getName());
$collectionInfoIterator = $database->listCollections(['filter' => ['name' => $metadata->getCollection()]]);
Copy link
Member Author

Choose a reason for hiding this comment

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

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.

I think this change is reasonable. We need to make sure how to properly generate the encryptedFieldsMap for use in the configuration. For a future improvement, we can consider dumping the encryptedFieldsMap based on the return value of createEncryptedCollection calls in the schema:create command.

@GromNaN GromNaN force-pushed the encryptedFieldsMap branch from 125545d to 96849e3 Compare July 10, 2025 09:25
<doctrine:queries queryType="equality" />
</doctrine:field>
</doctrine:encryptedFields>
<![CDATA[
Copy link
Member Author

Choose a reason for hiding this comment

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

@alcaeus Since the XML format is set to disappear, I have simplified the configuration here. EncryptedFieldsMap is a JSON string that is copied from the dump command in the XML. It is too complicated to convert this to XML tags, and most likely unusable anyway.

Copy link
Member

Choose a reason for hiding this comment

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

That makes sense 👍

@GromNaN GromNaN changed the title Fix format of encryptedFieldsMaps in the autoEncryption configuration [Encryption] Fix format of encryptedFieldsMaps in the autoEncryption configuration Jul 10, 2025
@GromNaN GromNaN marked this pull request as ready for review July 10, 2025 09:30
@GromNaN GromNaN force-pushed the encryptedFieldsMap branch from 96849e3 to 3eb3779 Compare July 10, 2025 09:30
@GromNaN GromNaN requested a review from paulinevos July 10, 2025 11:01
@GromNaN GromNaN mentioned this pull request Jul 10, 2025
11 tasks
@GromNaN GromNaN requested a review from alcaeus July 28, 2025 11:32
],
[
'path' => 'sensitive_field',
'keyId' => ['$binary' => ['base64' => '2CSosXLSTEKaYphcSnUuCw==', 'subType' => '04' ] ],
Copy link
Member

Choose a reason for hiding this comment

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

For PHP, should we suggest people create a Binary instance?

Suggested change
'keyId' => ['$binary' => ['base64' => '2CSosXLSTEKaYphcSnUuCw==', 'subType' => '04' ] ],
'keyId' => new Binary(base64_decode('2CSosXLSTEKaYphcSnUuCw=='), Binary::TYPE_UUID),

On second thought after reviewing the rest of this PR, I'm guessing this format is created by the PHP dumper in the command that dumps the encryptedFieldsMap. Feel free to disregard in that case.

Copy link
Member Author

@GromNaN GromNaN Jul 31, 2025

Choose a reason for hiding this comment

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

BSON binary is not supported because I use json_encode on the value in DoctrineMongoDBExtension.

There is no function that is able to read a mix of BSON and RelaxedExtendedJSON in an array.

Co-authored-by: Andreas Braun <[email protected]>
@GromNaN GromNaN merged commit 7bf0b5c into doctrine:feature/queryable-encryption Aug 1, 2025
18 checks passed
@GromNaN GromNaN deleted the encryptedFieldsMap branch August 1, 2025 08:30
GromNaN added a commit that referenced this pull request Aug 11, 2025
…on` configuration (#905)

* Fix format of encryptedFieldsMaps in the configuration
* EncryptedFieldsMaps loaded from a JSON string from XML configuration
* Enable client configuration for tests - partial
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