Skip to content

Conversation

@GromNaN GromNaN changed the title Add autoEncryption configuration to the client (#889) Enable auto encryption Jun 19, 2025
@GromNaN GromNaN marked this pull request as ready for review July 2, 2025 13:43
@GromNaN GromNaN requested a review from alcaeus July 2, 2025 13:43
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.

One question about docs, but code changes LGTM!

GromNaN and others added 6 commits August 11, 2025 15:31
* Update required version of mongodb driver and odm

* Update minimum phpunit version to support readonly properties in nikic/php-parser
)

* Inject auto encryption options into ODM configuration

* Add tests on ODM configuration settings
Co-authored-by: Andreas Braun <git@alcaeus.org>
…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
@GromNaN GromNaN force-pushed the feature/queryable-encryption branch from f1d8d87 to 8a8bdd4 Compare August 11, 2025 16:02
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 enables auto encryption support for MongoDB ODM by integrating MongoDB's Client-Side Field-Level Encryption (CSFLE) and Queryable Encryption (QE) features into DoctrineMongoDBBundle. The implementation allows developers to configure encryption settings at the connection level and provides diagnostic tools for troubleshooting encryption configurations.

Key changes include:

  • Added comprehensive auto encryption configuration options to the bundle's configuration system
  • Implemented diagnostic commands to check encryption support and configuration status
  • Enhanced test infrastructure to support MongoDB connections with configurable URIs

Reviewed Changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/TestCase.php Updated test infrastructure to use configurable MongoDB connection URI
tests/DependencyInjection/Fixtures/config/yml/full.yml Added comprehensive auto encryption configuration examples in YAML format
tests/DependencyInjection/Fixtures/config/xml/full.xml Added auto encryption configuration examples in XML format with CDATA support
tests/DependencyInjection/DoctrineMongoDBExtensionTest.php Added extensive test coverage for auto encryption configuration scenarios
tests/DependencyInjection/ConfigurationTest.php Enhanced configuration tests with auto encryption validation and JSON parsing support
tests/Command/ConnectionDiagnosticCommandTest.php Added tests for the new diagnostic command functionality
src/DependencyInjection/DoctrineMongoDBExtension.php Core implementation of auto encryption configuration processing and service injection
src/DependencyInjection/Configuration.php Added comprehensive auto encryption configuration schema with validation
src/DataCollector/EncryptionDiagnostic.php Implemented encryption environment diagnostics for PHP extension and mongocryptd
src/DataCollector/ConnectionDiagnostic.php Implemented connection-specific encryption diagnostics and server compatibility checks
src/Command/DumpEncryptedFieldsMapCommand.php Added command to dump encrypted fields mapping configuration
src/Command/ConnectionDiagnosticCommand.php Added command to diagnose MongoDB encryption configuration and capabilities
phpunit.xml.dist Added environment variable for configurable MongoDB server URI
phpstan.neon.dist Added type analysis configuration for ClassMetadata generics
phpstan-baseline.neon Updated static analysis baseline with new code patterns
docs/encryption.rst Added comprehensive documentation for encryption configuration and usage
docs/config.rst Updated configuration documentation with auto encryption options
config/schema/mongodb-1.0.xsd Added XML schema definitions for auto encryption configuration
config/command.php Registered new diagnostic and dump commands with dependency injection
composer.json Updated MongoDB extension and ODM dependencies for encryption support
.github/workflows/*.yml Updated CI workflows to support feature branches and new driver version

@GromNaN GromNaN force-pushed the feature/queryable-encryption branch from 2aa0d81 to 61a8118 Compare August 11, 2025 16:17
* Add keyVaultClient to XML configuration

* Require 1 kms provider in the XML config

* Remove tls attributes from kms-provider node

* Add cryptSharedLibRequired to XSD and test

* Clean tlsOptions and wrap into an array with the kms provider name as key

* Add comment for duplicate options
@GromNaN GromNaN force-pushed the feature/queryable-encryption branch from 81a7ddb to 953613d Compare August 19, 2025 14:53
@GromNaN GromNaN force-pushed the feature/queryable-encryption branch from 3372f85 to 7028b0e Compare August 21, 2025 09:20
@GromNaN GromNaN force-pushed the feature/queryable-encryption branch from 2fe6f34 to c49d20d Compare August 21, 2025 16:37
$providerOpts = new Definition('stdClass');
}

$autoEncryption['kmsProviders'] = [$provider => $providerOpts];
Copy link
Member

Choose a reason for hiding this comment

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

Why does this assign a kmsProviders key, which is later removed by the array_diff_key() in loadDocumentManager() (when calling normalizeAutoEncryption())?

In the calling context, $authEncryption['kmsProvider'] still gets used to queue up a call to setKmsProvider(), but it doesn't look like any of the normalization treatment above will affect that.

Please let me know if I'm overlooking something.

Copy link
Member Author

@GromNaN GromNaN Aug 22, 2025

Choose a reason for hiding this comment

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

Good catch, we don't need to set the kmsProviders here.

The method normalizeAutoEncryption is also used to generate driverOptions that are injected into the client constructor. We cannot use the Configuration class to get the driver options because the Client connection is independent from the document manager and its configuration.

Copy link
Member

Choose a reason for hiding this comment

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

In that case, shouldn't the normalizeDriverOptions calling context use its own array_diff_key() to unset the kmsProvider key specific to ODM? Otherwise, I think you're passing an unrecognized option to PHPLIB and, ultimately, PHPC. It'd be silently ignored now but could become a possible low-level log message down the line.

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 had the idea that we could use the ODMConfiguration class at build time to generate the driverOptions. But that would not work very well with environment variables. And would increase the required version of doctrine/mongodb-odm.

'autoEncryption' => [
'keyVaultNamespace' => 'db.vault',
'keyVaultClient' => $dummyServiceId,
'kmsProvider' => ['type' => 'local', 'key' => 'cGFzc3dvcmQ='],
Copy link
Member

Choose a reason for hiding this comment

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

cGFzc3dvcmQ= is "password" after base64 decoding. Should this actually be a 96-byte string? I suppose it doesn't really matter since you're not validating that in the configuration. And I assume that's intentional and you're relying on the server to complain (not that it matters for this unit test).

Copy link
Member

Choose a reason for hiding this comment

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

@GromNaN: Feel free to resolve if my assumption above is correct.

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, that's just a random string (actually provided by copilot).

Copy link
Member

Choose a reason for hiding this comment

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

(actually provided by copilot)

In that case I'm going to assume it was actually leaked credentials from another repository that snuck into the Copilot training data. 😆

@GromNaN GromNaN requested a review from jmikola August 22, 2025 17:44
…lds map (#915)

* Fix query option min/max type for exported encrypted fields map

* Type 'decimal' is not a supported equality indexed type
Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

A few questions, but you can certainly address those on your own (or rule out my concerns). I do think some XSD changes might be required for masterKey, though.

Other than that, note that there are still two unchecked TODOs in the PR description. I noted #902 is deferred. The other to bump composer.json might already have been done, and just needs checking.

@GromNaN GromNaN force-pushed the feature/queryable-encryption branch from 3ec0793 to f13fde6 Compare August 28, 2025 16:15
@GromNaN GromNaN merged commit 6701879 into 5.4.x Aug 28, 2025
34 checks passed
@GromNaN GromNaN deleted the feature/queryable-encryption branch August 28, 2025 16:44
@GromNaN GromNaN added this to the 5.4.0 milestone Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants