Skip to content

Commit bd5212a

Browse files
authored
Add autoEncryption configuration to the client (#889)
1 parent 912b12b commit bd5212a

File tree

13 files changed

+1230
-32
lines changed

13 files changed

+1230
-32
lines changed

config/command.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

55
use Doctrine\Bundle\MongoDBBundle\Command\ClearMetadataCacheDoctrineODMCommand;
6+
use Doctrine\Bundle\MongoDBBundle\Command\ConnectionDiagnosticCommand;
67
use Doctrine\Bundle\MongoDBBundle\Command\CreateSchemaDoctrineODMCommand;
78
use Doctrine\Bundle\MongoDBBundle\Command\DropSchemaDoctrineODMCommand;
89
use Doctrine\Bundle\MongoDBBundle\Command\GenerateHydratorsDoctrineODMCommand;
@@ -15,12 +16,17 @@
1516
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
1617

1718
use function Symfony\Component\DependencyInjection\Loader\Configurator\service;
19+
use function Symfony\Component\DependencyInjection\Loader\Configurator\tagged_locator;
1820

1921
return static function (ContainerConfigurator $containerConfigurator): void {
2022
$containerConfigurator->services()
2123
->set('doctrine_mongodb.odm.command.clear_metadata_cache', ClearMetadataCacheDoctrineODMCommand::class)
2224
->tag('console.command', ['command' => 'doctrine:mongodb:cache:clear-metadata'])
2325

26+
->set('doctrine_mongodb.odm.command.connection_diagnostic', ConnectionDiagnosticCommand::class)
27+
->tag('console.command', ['command' => 'doctrine:mongodb:connection:diagnostic'])
28+
->args([tagged_locator('doctrine_mongodb.connection_diagnostic', 'name')])
29+
2430
->set('doctrine_mongodb.odm.command.create_schema', CreateSchemaDoctrineODMCommand::class)
2531
->tag('console.command', ['command' => 'doctrine:mongodb:schema:create'])
2632

config/schema/mongodb-1.0.xsd

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<xsd:sequence>
4949
<xsd:element name="options" type="connection-options" minOccurs="0" maxOccurs="1" />
5050
<xsd:element name="driver-options" type="connection-driver-options" minOccurs="0" maxOccurs="1" />
51+
<xsd:element name="autoEncryption" type="auto-encryption" minOccurs="0" maxOccurs="1" />
5152
</xsd:sequence>
5253
<xsd:attribute name="id" type="xsd:string" use="required" />
5354
<xsd:attribute name="server" type="xsd:string" />
@@ -84,6 +85,9 @@
8485
</xsd:complexType>
8586

8687
<xsd:complexType name="connection-driver-options">
88+
<xsd:all>
89+
<xsd:element name="autoEncryption" type="auto-encryption" minOccurs="0"/>
90+
</xsd:all>
8791
<xsd:attribute name="context" type="xsd:string" />
8892
</xsd:complexType>
8993

@@ -119,6 +123,99 @@
119123
<xsd:attribute name="value" type="xsd:string" use="required" />
120124
</xsd:complexType>
121125

126+
<xsd:complexType name="auto-encryption">
127+
<xsd:sequence>
128+
<xsd:element name="kmsProvider" type="kms-provider" minOccurs="0" maxOccurs="1" />
129+
<xsd:element name="masterKey" type="master-key" minOccurs="0" maxOccurs="1" />
130+
<xsd:element name="keyVaultNamespace" type="xsd:string" minOccurs="0" maxOccurs="1" />
131+
<xsd:element name="tlsOptions" type="tls-options" minOccurs="0" maxOccurs="1" />
132+
<xsd:element name="encryptedFieldsMap" type="encrypted-fields-map" minOccurs="0" maxOccurs="1" />
133+
<xsd:element name="extraOptions" type="extra-options" minOccurs="0" maxOccurs="1" />
134+
</xsd:sequence>
135+
<xsd:attribute name="bypassAutoEncryption" type="xsd:boolean" use="optional" />
136+
<xsd:attribute name="bypassQueryAnalysis" type="xsd:boolean" use="optional" />
137+
</xsd:complexType>
138+
139+
<xsd:complexType name="kms-provider">
140+
<xsd:attribute name="type" type="xsd:string" use="required" />
141+
<!-- AWS -->
142+
<xsd:attribute name="accessKeyId" type="xsd:string" use="optional" />
143+
<xsd:attribute name="secretAccessKey" type="xsd:string" use="optional" />
144+
<xsd:attribute name="sessionToken" type="xsd:string" use="optional" />
145+
<!-- Azure -->
146+
<xsd:attribute name="tenantId" type="xsd:string" use="optional" />
147+
<xsd:attribute name="clientId" type="xsd:string" use="optional" />
148+
<xsd:attribute name="clientSecret" type="xsd:string" use="optional" />
149+
<xsd:attribute name="keyVaultEndpoint" type="xsd:string" use="optional" />
150+
<xsd:attribute name="identityPlatformEndpoint" type="xsd:string" use="optional" />
151+
<xsd:attribute name="keyName" type="xsd:string" use="optional" />
152+
<xsd:attribute name="keyVersion" type="xsd:string" use="optional" />
153+
<!-- GCP -->
154+
<xsd:attribute name="email" type="xsd:string" use="optional" />
155+
<xsd:attribute name="privateKey" type="xsd:string" use="optional" />
156+
<xsd:attribute name="endpoint" type="xsd:string" use="optional" />
157+
<xsd:attribute name="projectId" type="xsd:string" use="optional" />
158+
<xsd:attribute name="location" type="xsd:string" use="optional" />
159+
<xsd:attribute name="keyRing" type="xsd:string" use="optional" />
160+
<!-- <xsd:attribute name="keyName" type="xsd:string" use="optional" /> -->
161+
<!-- <xsd:attribute name="keyVersion" type="xsd:string" use="optional" /> -->
162+
<!-- KMIP -->
163+
<!-- <xsd:attribute name="endpoint" type="xsd:string" use="optional" /> -->
164+
<xsd:attribute name="tlsCAFile" type="xsd:string" use="optional" />
165+
<xsd:attribute name="tlsClientCertificateKeyFile" type="xsd:string" use="optional" />
166+
<xsd:attribute name="tlsClientCertificateKeyFilePassword" type="xsd:string" use="optional" />
167+
<!-- Local -->
168+
<xsd:attribute name="key" type="xsd:string" use="optional" />
169+
</xsd:complexType>
170+
171+
<xsd:complexType name="master-key">
172+
<xsd:attribute name="key" type="xsd:string" use="required" />
173+
</xsd:complexType>
174+
175+
<xsd:complexType name="tls-options">
176+
<xsd:attribute name="tlsCAFile" type="xsd:string" use="optional" />
177+
<xsd:attribute name="tlsCertificateKeyFile" type="xsd:string" use="optional" />
178+
<xsd:attribute name="tlsCertificateKeyFilePassword" type="xsd:string" use="optional" />
179+
<xsd:attribute name="tlsDisableOCSPEndpointCheck" type="xsd:boolean" use="optional" />
180+
</xsd:complexType>
181+
182+
<xsd:complexType name="encrypted-fields-map">
183+
<xsd:sequence>
184+
<xsd:element name="encryptedFields" type="encrypted-fields" minOccurs="0" maxOccurs="unbounded" />
185+
</xsd:sequence>
186+
</xsd:complexType>
187+
188+
<xsd:complexType name="encrypted-fields">
189+
<xsd:sequence>
190+
<xsd:element name="field" type="encrypted-field" minOccurs="1" maxOccurs="unbounded" />
191+
</xsd:sequence>
192+
<xsd:attribute name="name" type="xsd:string" use="required" />
193+
</xsd:complexType>
194+
195+
<xsd:complexType name="encrypted-field">
196+
<xsd:sequence>
197+
<xsd:element name="queries" type="encrypted-queries" minOccurs="0" maxOccurs="1" />
198+
</xsd:sequence>
199+
<xsd:attribute name="path" type="xsd:string" use="required" />
200+
<xsd:attribute name="bsonType" type="xsd:string" use="required" />
201+
</xsd:complexType>
202+
203+
<xsd:complexType name="encrypted-queries">
204+
<xsd:attribute name="queryType" type="xsd:string" use="required" />
205+
<xsd:attribute name="min" type="xsd:string" use="optional" />
206+
<xsd:attribute name="max" type="xsd:string" use="optional" />
207+
<xsd:attribute name="sparsity" type="xsd:string" use="optional" />
208+
<xsd:attribute name="trimFactor" type="xsd:string" use="optional" />
209+
</xsd:complexType>
210+
211+
<xsd:complexType name="extra-options">
212+
<xsd:attribute name="mongocryptdURI" type="xsd:string" use="optional" />
213+
<xsd:attribute name="mongocryptdBypassSpawn" type="xsd:boolean" use="optional" />
214+
<xsd:attribute name="mongocryptdSpawnPath" type="xsd:string" use="optional" />
215+
<xsd:attribute name="mongocryptdSpawnArgs" type="xsd:string" use="optional" />
216+
<xsd:attribute name="cryptSharedLibPath" type="xsd:string" use="optional" />
217+
</xsd:complexType>
218+
122219
<xsd:complexType name="document-manager">
123220
<xsd:choice maxOccurs="unbounded">
124221
<xsd:element name="filter" type="filter" minOccurs="0" maxOccurs="unbounded" />

docs/config.rst

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,10 @@ Otherwise you will get a *auth failed* exception.
624624
]);
625625
};
626626
627+
Using Queryable Encryption
628+
--------------------------
629+
630+
TODO: Add documentation for queryable encryption configuration.
627631

628632
Full Default Configuration
629633
--------------------------
@@ -699,6 +703,33 @@ Full Default Configuration
699703
wTimeoutMS: ~
700704
driver_options:
701705
context: ~ # stream context to use for connection
706+
autoEncryption: # Options for client-side field-level encryption
707+
keyVaultClient: null # Service ID of a MongoDB\Driver\Manager for the key vault
708+
keyVaultNamespace: null # The namespace for the key vault collection (e.g., "encryption.__keyVault")
709+
kmsProvider: {} # Configuration for Key Management System provider (see specific examples above)
710+
# e.g., { type: "local", key: "YOUR_BASE64_KEY" }
711+
# e.g., { type: "aws", accessKeyId: "...", secretAccessKey: "..." }
712+
masterKey: ~ # Default master key to use when creating a new encrypted collection
713+
schemaMap: [] # Document schemas for explicit encryption
714+
encryptedFieldsMap: [] # Map of collections to their encrypted fields configuration
715+
extraOptions: [] # Extra options for mongocryptd
716+
# mongocryptdURI: "mongodb://localhost:27020"
717+
# mongocryptdBypassSpawn: false
718+
# mongocryptdSpawnPath: "/usr/local/bin/mongocryptd"
719+
# mongocryptdSpawnArgs: ["--idleShutdownTimeoutSecs=60"]
720+
# cryptSharedLibPath: null # Path to the crypt_shared library
721+
# cryptSharedLibRequired: false # If true, fails if the crypt_shared library cannot be loaded
722+
bypassQueryAnalysis: false # Disables automatic analysis of read and write operations for encryption
723+
bypassAutoEncryption: false # Disables auto-encryption
724+
tlsOptions: # TLS options for the Key Vault client (if keyVaultClient is not specified)
725+
tlsCAFile: null # Path to CA file, e.g., /path/to/key-vault-ca.pem
726+
tlsCertificateKeyFile: null # Path to client cert/key file, e.g., /path/to/key-vault-client.pem
727+
tlsCertificateKeyFilePassword: null # Password for client cert/key file
728+
tlsAllowInvalidCertificates: false # Bypass server certificate validation (use with caution)
729+
tlsAllowInvalidHostnames: false # Bypass server hostname validation (use with caution)
730+
tlsDisableCertificateRevocationCheck: false # Disable CRL checks
731+
tlsDisableOCSPEndpointCheck: false # Disable OCSP checks
732+
tlsInsecure: false # Allow invalid/no server cert (use with extreme caution)
702733
703734
proxy_namespace: MongoDBODMProxies
704735
proxy_dir: "%kernel.cache_dir%/doctrine/odm/mongodb/Proxies"
@@ -825,8 +856,32 @@ Full Default Configuration
825856
826857
$config->connection('id')
827858
->server('mongodb://localhost')
828-
->driverOptions([
829-
'context' => null, // stream context to use for connection
859+
->driverOptions(['context' => null]), // stream context to use for connection
860+
->autoEncryption([ // Options for client-side field-level encryption
861+
'bypassAutoEncryption' => false, // Disables auto-encryption
862+
'keyVaultClient' => null, // Service ID of a MongoDB\Driver\Manager for the key vault
863+
'keyVaultNamespace' => null, // The namespace for the key vault collection (e.g., "encryption.__keyVault")
864+
'kmsProvider' => [ // Configuration for Key Management System provider
865+
// e.g., ['type' => 'local', 'key' => 'YOUR_BASE64_KEY']
866+
// e.g., ['type' => 'aws', 'accessKeyId' => '...', 'secretAccessKey' => '...']
867+
],
868+
'schemaMap' => [], // Document schemas for explicit encryption
869+
'encryptedFieldsMap' => [], // Map of collections to their encrypted fields configuration
870+
'extraOptions' => [ // Extra options for mongocryptd
871+
// 'cryptSharedLibPath' => null, // Path to the crypt_shared library
872+
// 'cryptSharedLibRequired' => false, // If true, fails if the crypt_shared library cannot be loaded
873+
],
874+
'bypassQueryAnalysis' => false, // Disables automatic analysis of read and write operations for encryption
875+
'tlsOptions' => [ // TLS options for the Key Vault client (if keyVaultClient is not specified)
876+
// 'tlsCAFile' => null, // Path to CA file, e.g., /path/to/key-vault-ca.pem
877+
// 'tlsCertificateKeyFile' => null, // Path to client cert/key file, e.g., /path/to/key-vault-client.pem
878+
// 'tlsCertificateKeyFilePassword' => null, // Password for client cert/key file
879+
// 'tlsAllowInvalidCertificates' => false, // Bypass server certificate validation (use with caution)
880+
// 'tlsAllowInvalidHostnames' => false, // Bypass server hostname validation (use with caution)
881+
// 'tlsDisableCertificateRevocation' => false, // Disable CRL checks
882+
// 'tlsDisableOCSPEndpointCheck' => false, // Disable OCSP checks
883+
// 'tlsInsecure' => false, // Allow invalid/no server cert (use with extreme caution)
884+
],
830885
])
831886
->options([
832887
'authMechanism' => null,

0 commit comments

Comments
 (0)