Skip to content

Commit 60cc9c2

Browse files
committed
Add autoEncryption configuration to the client
1 parent 2e5fc45 commit 60cc9c2

File tree

7 files changed

+1259
-81
lines changed

7 files changed

+1259
-81
lines changed

config/schema/mongodb-1.0.xsd

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,108 @@
8484
</xsd:complexType>
8585

8686
<xsd:complexType name="connection-driver-options">
87+
<xsd:all>
88+
<xsd:element name="autoEncryption" type="auto-encryption" minOccurs="0"/>
89+
</xsd:all>
8790
<xsd:attribute name="context" type="xsd:string" />
8891
</xsd:complexType>
8992

93+
<xsd:complexType name="auto-encryption">
94+
<xsd:all>
95+
<xsd:element name="bypassAutoEncryption" type="xsd:boolean" minOccurs="0" />
96+
<xsd:element name="keyVaultClient" type="xsd:string" minOccurs="0" />
97+
<xsd:element name="keyVaultNamespace" type="xsd:string" minOccurs="0" />
98+
<xsd:element name="kmsProviders" minOccurs="0">
99+
<xsd:complexType>
100+
<xsd:all>
101+
<xsd:element name="aws" type="kms-provider-aws" minOccurs="0" />
102+
<xsd:element name="azure" type="kms-provider-azure" minOccurs="0" />
103+
<xsd:element name="gcp" type="kms-provider-gcp" minOccurs="0" />
104+
<xsd:element name="kmip" type="kms-provider-kmip" minOccurs="0" />
105+
<xsd:element name="local" type="kms-provider-local" minOccurs="0" />
106+
</xsd:all>
107+
</xsd:complexType>
108+
</xsd:element>
109+
<xsd:element name="schemaMap" type="map-like-options" minOccurs="0" />
110+
<xsd:element name="encryptedFieldsMap" type="map-like-options" minOccurs="0" />
111+
<xsd:element name="extraOptions" type="map-like-options" minOccurs="0" />
112+
<xsd:element name="bypassQueryAnalysis" type="xsd:boolean" minOccurs="0" />
113+
<xsd:element name="tlsOptions" type="tls-options" minOccurs="0">
114+
<xsd:annotation>
115+
<xsd:documentation><![CDATA[TLS options for the Key Vault client if keyVaultClient is not specified.]]></xsd:documentation>
116+
</xsd:annotation>
117+
</xsd:element>
118+
</xsd:all>
119+
</xsd:complexType>
120+
121+
<xsd:complexType name="tls-options">
122+
<xsd:all>
123+
<xsd:element name="tlsCAFile" type="xsd:string" minOccurs="0" />
124+
<xsd:element name="tlsCertificateKeyFile" type="xsd:string" minOccurs="0" />
125+
<xsd:element name="tlsCertificateKeyFilePassword" type="xsd:string" minOccurs="0" />
126+
<xsd:element name="tlsAllowInvalidCertificates" type="xsd:boolean" minOccurs="0" />
127+
<xsd:element name="tlsAllowInvalidHostnames" type="xsd:boolean" minOccurs="0" />
128+
<xsd:element name="tlsDisableCertificateRevocationCheck" type="xsd:boolean" minOccurs="0" />
129+
<xsd:element name="tlsDisableOCSPEndpointCheck" type="xsd:boolean" minOccurs="0" />
130+
<xsd:element name="tlsInsecure" type="xsd:boolean" minOccurs="0" />
131+
</xsd:all>
132+
</xsd:complexType>
133+
134+
<xsd:complexType name="map-like-options">
135+
<xsd:sequence>
136+
<xsd:any namespace="##any" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
137+
</xsd:sequence>
138+
<xsd:anyAttribute namespace="##any" processContents="lax"/>
139+
</xsd:complexType>
140+
141+
<xsd:complexType name="kms-provider-aws">
142+
<xsd:all>
143+
<xsd:element name="accessKeyId" type="xsd:string" minOccurs="0"/>
144+
<xsd:element name="secretAccessKey" type="xsd:string" minOccurs="0"/>
145+
<xsd:element name="sessionToken" type="xsd:string" minOccurs="0"/>
146+
</xsd:all>
147+
</xsd:complexType>
148+
149+
<xsd:complexType name="kms-provider-azure">
150+
<xsd:all>
151+
<xsd:element name="tenantId" type="xsd:string" minOccurs="0"/>
152+
<xsd:element name="clientId" type="xsd:string" minOccurs="0"/>
153+
<xsd:element name="clientSecret" type="xsd:string" minOccurs="0"/>
154+
<xsd:element name="keyVaultEndpoint" type="xsd:string" minOccurs="0"/>
155+
<xsd:element name="identityPlatformEndpoint" type="xsd:string" minOccurs="0"/>
156+
<xsd:element name="keyName" type="xsd:string" minOccurs="0"/>
157+
<xsd:element name="keyVersion" type="xsd:string" minOccurs="0"/>
158+
</xsd:all>
159+
</xsd:complexType>
160+
161+
<xsd:complexType name="kms-provider-gcp">
162+
<xsd:all>
163+
<xsd:element name="email" type="xsd:string" minOccurs="0"/>
164+
<xsd:element name="privateKey" type="xsd:string" minOccurs="0"/>
165+
<xsd:element name="endpoint" type="xsd:string" minOccurs="0"/>
166+
<xsd:element name="projectId" type="xsd:string" minOccurs="0"/>
167+
<xsd:element name="location" type="xsd:string" minOccurs="0"/>
168+
<xsd:element name="keyRing" type="xsd:string" minOccurs="0"/>
169+
<xsd:element name="keyName" type="xsd:string" minOccurs="0"/>
170+
<xsd:element name="keyVersion" type="xsd:string" minOccurs="0"/>
171+
</xsd:all>
172+
</xsd:complexType>
173+
174+
<xsd:complexType name="kms-provider-kmip">
175+
<xsd:all>
176+
<xsd:element name="endpoint" type="xsd:string" minOccurs="0"/>
177+
<xsd:element name="tlsCAFile" type="xsd:string" minOccurs="0"/>
178+
<xsd:element name="tlsClientCertificateKeyFile" type="xsd:string" minOccurs="0"/>
179+
<xsd:element name="tlsClientCertificateKeyFilePassword" type="xsd:string" minOccurs="0"/>
180+
</xsd:all>
181+
</xsd:complexType>
182+
183+
<xsd:complexType name="kms-provider-local">
184+
<xsd:all>
185+
<xsd:element name="key" type="xsd:string" minOccurs="0"/>
186+
</xsd:all>
187+
</xsd:complexType>
188+
90189
<xsd:simpleType name="auth-mechanism">
91190
<xsd:restriction base="xsd:string">
92191
<xsd:enumeration value="SCRAM-SHA-1" />

docs/config.rst

Lines changed: 55 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -627,85 +627,11 @@ Otherwise you will get a *auth failed* exception.
627627
Specifying a context service
628628
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
629629

630-
The MongoDB driver supports receiving a stream context to set SSL and logging
631-
options. This can be used to authenticate using SSL certificates. To do so,
632-
create a service that creates your logging context:
630+
The MongoDB driver supports receiving a stream context to set SSL and logging options. This can be used to authenticate using SSL certificates.
633631

634-
.. configuration-block::
635-
636-
.. code-block:: yaml
637-
638-
services:
639-
# ...
640-
641-
app.mongodb.context_service:
642-
class: 'resource'
643-
factory: 'stream_context_create'
644-
arguments:
645-
- { ssl: { verify_expiry: true } }
646-
647-
.. code-block:: php
648-
649-
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
650-
651-
return static function (ContainerConfigurator $container): void {
652-
$container->services()
653-
->set('app.mongodb.context_service', 'resource')
654-
->factory('stream_context_create')
655-
->args([
656-
['ssl' => ['verify_expiry' => true]],
657-
])
658-
;
659-
};
660-
661-
Note: the ``class`` option is not used when creating the service, but has to be
662-
provided for the service definition to be valid.
663-
664-
You can then use this service in your configuration:
665-
666-
.. configuration-block::
667-
668-
.. code-block:: yaml
669-
670-
doctrine_mongodb:
671-
# ...
672-
connections:
673-
default:
674-
server: "mongodb://localhost:27017"
675-
driver_options:
676-
context: "app.mongodb.context_service"
677-
678-
.. code-block:: xml
679-
680-
<?xml version="1.0" ?>
681-
682-
<container xmlns="http://symfony.com/schema/dic/services"
683-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
684-
xmlns:doctrine="http://symfony.com/schema/dic/doctrine/odm/mongodb"
685-
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd
686-
http://symfony.com/schema/dic/doctrine/odm/mongodb https://symfony.com/schema/dic/doctrine/odm/mongodb/mongodb-1.0.xsd">
632+
.. seealso::
687633

688-
<doctrine:mongodb>
689-
<doctrine:connection id="default" server="mongodb://localhost:27017" />
690-
<doctrine:driver-options
691-
context="app.mongodb.context_service"
692-
>
693-
</doctrine:options>
694-
</doctrine:connection>
695-
</doctrine:mongodb>
696-
</container>
697-
698-
.. code-block:: php
699-
700-
use Symfony\Config\DoctrineMongodbConfig;
701-
702-
return static function (DoctrineMongodbConfig $config): void {
703-
$config->connection('default')
704-
->server('mongodb://localhost:27017')
705-
->driverOptions([
706-
'context' => 'app.mongodb.context_service',
707-
]);
708-
};
634+
For full documentation and configuration examples for Client-Side Field-Level Encryption (CSFLE) and Queryable Encryption (QE), see :doc:`csfle_qe`
709635

710636
Full Default Configuration
711637
--------------------------
@@ -781,6 +707,32 @@ Full Default Configuration
781707
wTimeoutMS: ~
782708
driver_options:
783709
context: ~ # stream context to use for connection
710+
autoEncryption: # Options for client-side field-level encryption
711+
bypassAutoEncryption: false # Disables auto-encryption
712+
keyVaultClient: null # Service ID of a MongoDB\Driver\Manager for the key vault
713+
keyVaultNamespace: null # The namespace for the key vault collection (e.g., "encryption.__keyVault")
714+
kmsProviders: [] # Configuration for Key Management System providers (see specific examples above)
715+
# e.g., local: { key: "YOUR_BASE64_KEY" }
716+
# e.g., aws: { accessKeyId: "...", secretAccessKey: "..." }
717+
schemaMap: [] # Document schemas for explicit encryption
718+
encryptedFieldsMap: [] # Map of collections to their encrypted fields configuration
719+
extraOptions: [] # Extra options for mongocryptd
720+
# mongocryptdURI: "mongodb://localhost:27020"
721+
# mongocryptdBypassSpawn: false
722+
# mongocryptdSpawnPath: "/usr/local/bin/mongocryptd"
723+
# mongocryptdSpawnArgs: ["--idleShutdownTimeoutSecs=60"]
724+
# cryptSharedLibPath: null # Path to the crypt_shared library
725+
# cryptSharedLibRequired: false # If true, fails if the crypt_shared library cannot be loaded
726+
bypassQueryAnalysis: false # Disables automatic analysis of read and write operations for encryption
727+
tlsOptions: # TLS options for the Key Vault client (if keyVaultClient is not specified)
728+
tlsCAFile: null # Path to CA file, e.g., /path/to/key-vault-ca.pem
729+
tlsCertificateKeyFile: null # Path to client cert/key file, e.g., /path/to/key-vault-client.pem
730+
tlsCertificateKeyFilePassword: null # Password for client cert/key file
731+
tlsAllowInvalidCertificates: false # Bypass server certificate validation (use with caution)
732+
tlsAllowInvalidHostnames: false # Bypass server hostname validation (use with caution)
733+
tlsDisableCertificateRevocationCheck: false # Disable CRL checks
734+
tlsDisableOCSPEndpointCheck: false # Disable OCSP checks
735+
tlsInsecure: false # Allow invalid/no server cert (use with extreme caution)
784736
785737
proxy_namespace: MongoDBODMProxies
786738
proxy_dir: "%kernel.cache_dir%/doctrine/odm/mongodb/Proxies"
@@ -909,6 +861,32 @@ Full Default Configuration
909861
->server('mongodb://localhost')
910862
->driverOptions([
911863
'context' => null, // stream context to use for connection
864+
'autoEncryption' => [ // Options for client-side field-level encryption
865+
'bypassAutoEncryption' => false, // Disables auto-encryption
866+
'keyVaultClient' => null, // Service ID of a MongoDB\Driver\Manager for the key vault
867+
'keyVaultNamespace' => null, // The namespace for the key vault collection (e.g., "encryption.__keyVault")
868+
'kmsProviders' => [ // Configuration for Key Management System providers
869+
// e.g., 'local' => ['key' => 'YOUR_BASE64_KEY'],
870+
// e.g., 'aws' => ['accessKeyId' => '...', 'secretAccessKey' => '...'],
871+
],
872+
'schemaMap' => [], // Document schemas for explicit encryption
873+
'encryptedFieldsMap' => [], // Map of collections to their encrypted fields configuration
874+
'extraOptions' => [ // Extra options for mongocryptd
875+
// 'cryptSharedLibPath' => null, // Path to the crypt_shared library
876+
// 'cryptSharedLibRequired' => false, // If true, fails if the crypt_shared library cannot be loaded
877+
],
878+
'bypassQueryAnalysis' => false, // Disables automatic analysis of read and write operations for encryption
879+
'tlsOptions' => [ // TLS options for the Key Vault client (if keyVaultClient is not specified)
880+
// 'tlsCAFile' => null, // Path to CA file, e.g., /path/to/key-vault-ca.pem
881+
// 'tlsCertificateKeyFile' => null, // Path to client cert/key file, e.g., /path/to/key-vault-client.pem
882+
// 'tlsCertificateKeyFilePassword' => null, // Password for client cert/key file
883+
// 'tlsAllowInvalidCertificates' => false, // Bypass server certificate validation (use with caution)
884+
// 'tlsAllowInvalidHostnames' => false, // Bypass server hostname validation (use with caution)
885+
// 'tlsDisableCertificateRevocation' => false, // Disable CRL checks
886+
// 'tlsDisableOCSPEndpointCheck' => false, // Disable OCSP checks
887+
// 'tlsInsecure' => false, // Allow invalid/no server cert (use with extreme caution)
888+
],
889+
],
912890
])
913891
->options([
914892
'authMechanism' => null,

0 commit comments

Comments
 (0)