-
Notifications
You must be signed in to change notification settings - Fork 232
[Encryption] Fix format of encryptedFieldsMaps
in the autoEncryption
configuration
#905
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
GromNaN
merged 6 commits into
doctrine:feature/queryable-encryption
from
GromNaN:encryptedFieldsMap
Aug 1, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
048f9b1
Fix format of encryptedFieldsMaps in the configuration
GromNaN 3fe3a84
EncryptedFieldsMaps loaded from a JSON string from XML configuration
GromNaN 9b30ccb
Enable client configuration for tests - partial
GromNaN 3eb3779
Fix test
GromNaN e699745
Fix documentation
GromNaN 93eae7e
Apply suggestion from @alcaeus
GromNaN 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
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
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
use Doctrine\ODM\MongoDB\DocumentManager; | ||
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; | ||
use Doctrine\ODM\MongoDB\Utility\EncryptedFieldsMapGenerator; | ||
use MongoDB\BSON\PackedArray; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
|
@@ -16,10 +16,7 @@ | |
use Symfony\Component\Yaml\Dumper; | ||
use Symfony\Contracts\Service\ServiceCollectionInterface; | ||
|
||
use function array_combine; | ||
use function array_keys; | ||
use function array_map; | ||
use function array_values; | ||
use function json_decode; | ||
use function json_encode; | ||
use function sprintf; | ||
use function var_export; | ||
|
@@ -63,24 +60,25 @@ protected function execute(InputInterface $input, OutputInterface $output): int | |
$dumper = new Dumper(); | ||
|
||
foreach ($this->documentManagers as $name => $documentManager) { | ||
$generator = new EncryptedFieldsMapGenerator($documentManager->getMetadataFactory()); | ||
$encryptedFieldsMap = $generator->getEncryptedFieldsMap(); | ||
$encryptedFieldsMap = []; | ||
foreach ($documentManager->getMetadataFactory()->getAllMetadata() as $metadata) { | ||
$database = $documentManager->getDocumentDatabase($metadata->getName()); | ||
$collectionInfoIterator = $database->listCollections(['filter' => ['name' => $metadata->getCollection()]]); | ||
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 is inspired by the |
||
|
||
foreach ($collectionInfoIterator as $collectionInfo) { | ||
if ($collectionInfo['options']['encryptedFields'] ?? null) { | ||
$encryptedFieldsMap[$this->getDocumentNamespace($metadata, $database->getDatabaseName())] = $collectionInfo['options']['encryptedFields']; | ||
alcaeus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
} | ||
|
||
if (empty($encryptedFieldsMap)) { | ||
continue; | ||
} | ||
|
||
$encryptedFieldsMap = array_combine( | ||
// Convert class names in keys to their full namespaces | ||
array_map( | ||
fn (string $fqcn): string => $this->getDocumentNamespace( | ||
$documentManager->getClassMetadata($fqcn), | ||
$documentManager->getConfiguration()->getDefaultDB(), | ||
), | ||
array_keys($encryptedFieldsMap), | ||
), | ||
array_values($encryptedFieldsMap), | ||
); | ||
foreach ($encryptedFieldsMap as $ns => $encryptedFields) { | ||
$encryptedFieldsMap[$ns] = json_decode(PackedArray::fromPHP($encryptedFields['fields'])->toRelaxedExtendedJSON(), true); | ||
alcaeus marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
$io->section(sprintf('Dumping encrypted fields map for document manager "%s"', $name)); | ||
switch ($format) { | ||
|
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.
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.
For PHP, should we suggest people create a
Binary
instance?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.
Uh oh!
There was an error while loading. Please reload this page.
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.
BSON binary is not supported because I use
json_encode
on the value inDoctrineMongoDBExtension
.There is no function that is able to read a mix of BSON and RelaxedExtendedJSON in an array.