Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/Doctrine/ODM/MongoDB/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,8 @@ private static function getVersion(): string
private function getAutoEncryptionOptions(): array
{
return [
'kmsProviders' => [$this->attributes['kmsProvider']['type'] => array_diff_key($this->attributes['kmsProvider'], ['type' => 0])],
// Each kmsProvider must be an object, it can be empty
'kmsProviders' => [$this->attributes['kmsProvider']['type'] => (object) array_diff_key($this->attributes['kmsProvider'], ['type' => 0])],
Copy link
Member

Choose a reason for hiding this comment

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

Slight correction to the PR description, since you said only mentioned AWS there.

credentialProviders talks about only supporting AWS, but Automatic Credentials mentions that AWS, Azure, and GCP are all supported. The struct definition in kmsProviders also demonstrates that those three provider types might be expressed as an empty object.

I'll also note that libmongocrypt supports named KMS providers (e.g. aws:foo), which in turn do not support fetching automatic credentials from the environment.

I don't think this changes the code you have here, but I wanted to clarify.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I updated the PR description.

'keyVaultNamespace' => $this->getDefaultDB() . '.datakeys',
...$this->attributes['autoEncryption'] ?? [],
];
Expand Down
18 changes: 9 additions & 9 deletions tests/Doctrine/ODM/MongoDB/Tests/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testLocalKmsProvider(): void
self::assertNull($c->getDefaultMasterKey());
self::assertEquals([
'kmsProviders' => [
'local' => ['key' => '1234567890123456789012345678901234567890123456789012345678901234'],
'local' => (object) ['key' => '1234567890123456789012345678901234567890123456789012345678901234'],
],
'extraOptions' => ['mongocryptdURI' => 'mongodb://localhost:27020'],
// Default key vault namespace
Expand All @@ -74,7 +74,7 @@ public function testKmsProvider(): void
self::assertSame($masterKey, $c->getDefaultMasterKey());
self::assertEquals([
'kmsProviders' => [
'aws' => ['accessKeyId' => 'AKIA', 'secretAccessKey' => 'SECRET'],
'aws' => (object) ['accessKeyId' => 'AKIA', 'secretAccessKey' => 'SECRET'],
],
// Key vault namespace from the configuration
'keyVaultNamespace' => 'keyvault.datakeys',
Expand All @@ -88,27 +88,27 @@ public function testAutoEncryptionOptions(): void
'keyVaultClient' => $keyVaultClient = new Manager(),
'keyVaultNamespace' => 'keyvault.datakeys',
'extraOptions' => ['mongocryptdURI' => 'mongodb://localhost:27020'],
'tlsOptions' => ['tlsDisableOCSPEndpointCheck' => true],
'tlsOptions' => ['local' => ['tlsDisableOCSPEndpointCheck' => true]],
]);
$c->setKmsProvider(['type' => 'local', 'key' => '1234567890123456789012345678901234567890123456789012345678901234']);

self::assertSame([
self::assertEquals([
'kmsProviders' => [
'local' => ['key' => '1234567890123456789012345678901234567890123456789012345678901234'],
'local' => (object) ['key' => '1234567890123456789012345678901234567890123456789012345678901234'],
],
'keyVaultNamespace' => 'keyvault.datakeys',
'keyVaultClient' => $keyVaultClient,
'extraOptions' => ['mongocryptdURI' => 'mongodb://localhost:27020'],
'tlsOptions' => ['tlsDisableOCSPEndpointCheck' => true],
'tlsOptions' => ['local' => ['tlsDisableOCSPEndpointCheck' => true]],
], $c->getDriverOptions()['autoEncryption']);

self::assertSame([
self::assertEquals([
'kmsProviders' => [
'local' => ['key' => '1234567890123456789012345678901234567890123456789012345678901234'],
'local' => (object) ['key' => '1234567890123456789012345678901234567890123456789012345678901234'],
],
'keyVaultNamespace' => 'keyvault.datakeys',
'keyVaultClient' => $keyVaultClient,
'tlsOptions' => ['tlsDisableOCSPEndpointCheck' => true],
'tlsOptions' => ['local' => ['tlsDisableOCSPEndpointCheck' => true]],
], $c->getClientEncryptionOptions());
}

Expand Down
Loading