Skip to content

Commit a07aa56

Browse files
authored
test(NODE-3409): support AWS temp credentials in CSFLE tests (#2968)
1 parent eae0e05 commit a07aa56

File tree

9 files changed

+315
-44
lines changed

9 files changed

+315
-44
lines changed

.evergreen/config.yml

+3-42
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ functions:
9595
cat <<EOT > prepare_client_encryption.sh
9696
export CLIENT_ENCRYPTION=${CLIENT_ENCRYPTION}
9797
export CSFLE_KMS_PROVIDERS='${CSFLE_KMS_PROVIDERS}'
98+
export AWS_ACCESS_KEY_ID='${AWS_ACCESS_KEY_ID}'
99+
export AWS_SECRET_ACCESS_KEY='${AWS_SECRET_ACCESS_KEY}'
100+
export AWS_DEFAULT_REGION='us-east-1'
98101
EOT
99102
fi
100103
- command: shell.exec
@@ -549,39 +552,6 @@ tasks:
549552
- func: run tests
550553
vars:
551554
UNIFIED: 1
552-
- name: test-5.0-server
553-
tags:
554-
- '5.0'
555-
- server
556-
commands:
557-
- func: install dependencies
558-
- func: bootstrap mongo-orchestration
559-
vars:
560-
VERSION: '5.0'
561-
TOPOLOGY: server
562-
- func: run tests
563-
- name: test-5.0-replica_set
564-
tags:
565-
- '5.0'
566-
- replica_set
567-
commands:
568-
- func: install dependencies
569-
- func: bootstrap mongo-orchestration
570-
vars:
571-
VERSION: '5.0'
572-
TOPOLOGY: replica_set
573-
- func: run tests
574-
- name: test-5.0-sharded_cluster
575-
tags:
576-
- '5.0'
577-
- sharded_cluster
578-
commands:
579-
- func: install dependencies
580-
- func: bootstrap mongo-orchestration
581-
vars:
582-
VERSION: '5.0'
583-
TOPOLOGY: sharded_cluster
584-
- func: run tests
585555
- name: test-5.0-server-unified
586556
tags:
587557
- '5.0'
@@ -1843,9 +1813,6 @@ buildvariants:
18431813
- test-latest-server-unified
18441814
- test-latest-replica_set-unified
18451815
- test-latest-sharded_cluster-unified
1846-
- test-5.0-server
1847-
- test-5.0-replica_set
1848-
- test-5.0-sharded_cluster
18491816
- test-5.0-server-unified
18501817
- test-5.0-replica_set-unified
18511818
- test-5.0-sharded_cluster-unified
@@ -1966,9 +1933,6 @@ buildvariants:
19661933
- test-latest-server-unified
19671934
- test-latest-replica_set-unified
19681935
- test-latest-sharded_cluster-unified
1969-
- test-5.0-server
1970-
- test-5.0-replica_set
1971-
- test-5.0-sharded_cluster
19721936
- test-5.0-server-unified
19731937
- test-5.0-replica_set-unified
19741938
- test-5.0-sharded_cluster-unified
@@ -2166,9 +2130,6 @@ buildvariants:
21662130
- test-latest-server-unified
21672131
- test-latest-replica_set-unified
21682132
- test-latest-sharded_cluster-unified
2169-
- test-5.0-server
2170-
- test-5.0-replica_set
2171-
- test-5.0-sharded_cluster
21722133
- test-5.0-server-unified
21732134
- test-5.0-replica_set-unified
21742135
- test-5.0-sharded_cluster-unified

.evergreen/config.yml.in

+3
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ functions:
114114
cat <<EOT > prepare_client_encryption.sh
115115
export CLIENT_ENCRYPTION=${CLIENT_ENCRYPTION}
116116
export CSFLE_KMS_PROVIDERS='${CSFLE_KMS_PROVIDERS}'
117+
export AWS_ACCESS_KEY_ID='${AWS_ACCESS_KEY_ID}'
118+
export AWS_SECRET_ACCESS_KEY='${AWS_SECRET_ACCESS_KEY}'
119+
export AWS_DEFAULT_REGION='us-east-1'
117120
EOT
118121
fi
119122
- command: shell.exec

.evergreen/generate_evergreen_tasks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const LEGACY_MONGODB_VERSIONS = new Set(['4.4', '4.2', '4.0', '3.6', '3.4', '3.2
99
const MONGODB_VERSIONS = ['latest', '5.0'].concat(Array.from(LEGACY_MONGODB_VERSIONS));
1010
const AWS_AUTH_VERSIONS = ['latest', '5.0', '4.4'];
1111
const OCSP_VERSIONS = ['latest', '5.0', '4.4'];
12-
const TLS_VERSIONS = ['latest', '5.0', '4.2']; // also test on 4.2 because 4.4+ currently skipped on windows
12+
const TLS_VERSIONS = ['latest', '5.0', '4.4', '4.2']; // also test on 4.2 because 4.4+ currently skipped on windows
1313
const NODE_VERSIONS = ['fermium', 'erbium', 'dubnium', 'carbon', 'boron', 'argon'];
1414
const LEGACY_TOPOLOGIES = new Set(['server', 'replica_set', 'sharded_cluster']);
1515
const UNIFIED_TOPOLOGIES = Array.from(LEGACY_TOPOLOGIES).map(topology => `${topology}-unified`);

.evergreen/run-custom-csfle-tests.sh

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ if [ -z ${CSFLE_KMS_PROVIDERS+omitted} ]; then echo "CSFLE_KMS_PROVIDERS is unse
1010
set -o xtrace # Write all commands first to stderr
1111
set -o errexit # Exit the script with error if any of the commands fail
1212

13+
# Get access to the AWS temporary credentials:
14+
echo "adding temporary AWS credentials to environment"
15+
# CSFLE_AWS_TEMP_ACCESS_KEY_ID, CSFLE_AWS_TEMP_SECRET_ACCESS_KEY, CSFLE_AWS_TEMP_SESSION_TOKEN
16+
. $DRIVERS_TOOLS/.evergreen/csfle/set-temp-creds.sh
17+
1318
# Environment Variables:
1419
# CSFLE_GIT_REF - set the git reference to checkout for a custom CSFLE version
1520
# CDRIVER_GIT_REF - set the git reference to checkout for a custom CDRIVER version (this is for libbson)

.evergreen/run-tests.sh

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ if [[ -z "${CLIENT_ENCRYPTION}" ]]; then
5353
unset AWS_SECRET_ACCESS_KEY;
5454
else
5555
npm install mongodb-client-encryption@latest
56+
57+
# Get access to the AWS temporary credentials:
58+
echo "adding temporary AWS credentials to environment"
59+
# CSFLE_AWS_TEMP_ACCESS_KEY_ID, CSFLE_AWS_TEMP_SECRET_ACCESS_KEY, CSFLE_AWS_TEMP_SESSION_TOKEN
60+
. $DRIVERS_TOOLS/.evergreen/csfle/set-temp-creds.sh
5661
fi
5762

5863
nvm use 12

test/functional/mongodb_aws.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('MONGODB-AWS', function() {
4646
authMechanismProperties: { AWS_SESSION_TOKEN: '' }
4747
});
4848
expect(client)
49-
.to.have.nested.property('options.credentials.mechanismProperties.AWS_SESSION_TOKEN')
49+
.to.have.nested.property('s.options.authMechanismProperties.AWS_SESSION_TOKEN')
5050
.that.equals('');
5151
});
5252
});

test/functional/spec-runner/index.js

+15
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,21 @@ function translateClientOptions(options) {
4848
kmsProviders.local = options.autoEncryptOpts.kmsProviders.local;
4949
}
5050

51+
if (options.autoEncryptOpts.kmsProviders.awsTemporary) {
52+
kmsProviders.aws = {
53+
accessKeyId: process.env.CSFLE_AWS_TEMP_ACCESS_KEY_ID,
54+
secretAccessKey: process.env.CSFLE_AWS_TEMP_SECRET_ACCESS_KEY,
55+
sessionToken: process.env.CSFLE_AWS_TEMP_SESSION_TOKEN
56+
};
57+
}
58+
59+
if (options.autoEncryptOpts.kmsProviders.awsTemporaryNoSessionToken) {
60+
kmsProviders.aws = {
61+
accessKeyId: process.env.CSFLE_AWS_TEMP_ACCESS_KEY_ID,
62+
secretAccessKey: process.env.CSFLE_AWS_TEMP_SECRET_ACCESS_KEY
63+
};
64+
}
65+
5166
options.autoEncryption.kmsProviders = kmsProviders;
5267
}
5368

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
{
2+
"runOn": [
3+
{
4+
"minServerVersion": "4.1.10"
5+
}
6+
],
7+
"database_name": "default",
8+
"collection_name": "default",
9+
"data": [],
10+
"json_schema": {
11+
"properties": {
12+
"encrypted_w_altname": {
13+
"encrypt": {
14+
"keyId": "/altname",
15+
"bsonType": "string",
16+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
17+
}
18+
},
19+
"encrypted_string": {
20+
"encrypt": {
21+
"keyId": [
22+
{
23+
"$binary": {
24+
"base64": "AAAAAAAAAAAAAAAAAAAAAA==",
25+
"subType": "04"
26+
}
27+
}
28+
],
29+
"bsonType": "string",
30+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
31+
}
32+
},
33+
"random": {
34+
"encrypt": {
35+
"keyId": [
36+
{
37+
"$binary": {
38+
"base64": "AAAAAAAAAAAAAAAAAAAAAA==",
39+
"subType": "04"
40+
}
41+
}
42+
],
43+
"bsonType": "string",
44+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Random"
45+
}
46+
},
47+
"encrypted_string_equivalent": {
48+
"encrypt": {
49+
"keyId": [
50+
{
51+
"$binary": {
52+
"base64": "AAAAAAAAAAAAAAAAAAAAAA==",
53+
"subType": "04"
54+
}
55+
}
56+
],
57+
"bsonType": "string",
58+
"algorithm": "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic"
59+
}
60+
}
61+
},
62+
"bsonType": "object"
63+
},
64+
"key_vault_data": [
65+
{
66+
"status": 1,
67+
"_id": {
68+
"$binary": {
69+
"base64": "AAAAAAAAAAAAAAAAAAAAAA==",
70+
"subType": "04"
71+
}
72+
},
73+
"masterKey": {
74+
"provider": "aws",
75+
"key": "arn:aws:kms:us-east-1:579766882180:key/89fcc2c4-08b0-4bd9-9f25-e30687b580d0",
76+
"region": "us-east-1"
77+
},
78+
"updateDate": {
79+
"$date": {
80+
"$numberLong": "1552949630483"
81+
}
82+
},
83+
"keyMaterial": {
84+
"$binary": {
85+
"base64": "AQICAHhQNmWG2CzOm1dq3kWLM+iDUZhEqnhJwH9wZVpuZ94A8gEqnsxXlR51T5EbEVezUqqKAAAAwjCBvwYJKoZIhvcNAQcGoIGxMIGuAgEAMIGoBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDHa4jo6yp0Z18KgbUgIBEIB74sKxWtV8/YHje5lv5THTl0HIbhSwM6EqRlmBiFFatmEWaeMk4tO4xBX65eq670I5TWPSLMzpp8ncGHMmvHqRajNBnmFtbYxN3E3/WjxmdbOOe+OXpnGJPcGsftc7cB2shRfA4lICPnE26+oVNXT6p0Lo20nY5XC7jyCO",
86+
"subType": "00"
87+
}
88+
},
89+
"creationDate": {
90+
"$date": {
91+
"$numberLong": "1552949630483"
92+
}
93+
},
94+
"keyAltNames": [
95+
"altname",
96+
"another_altname"
97+
]
98+
}
99+
],
100+
"tests": [
101+
{
102+
"description": "Insert a document with auto encryption using the AWS provider with temporary credentials",
103+
"clientOptions": {
104+
"autoEncryptOpts": {
105+
"kmsProviders": {
106+
"awsTemporary": {}
107+
}
108+
}
109+
},
110+
"operations": [
111+
{
112+
"name": "insertOne",
113+
"arguments": {
114+
"document": {
115+
"_id": 1,
116+
"encrypted_string": "string0"
117+
}
118+
}
119+
}
120+
],
121+
"expectations": [
122+
{
123+
"command_started_event": {
124+
"command": {
125+
"listCollections": 1,
126+
"filter": {
127+
"name": "default"
128+
}
129+
},
130+
"command_name": "listCollections"
131+
}
132+
},
133+
{
134+
"command_started_event": {
135+
"command": {
136+
"find": "datakeys",
137+
"filter": {
138+
"$or": [
139+
{
140+
"_id": {
141+
"$in": [
142+
{
143+
"$binary": {
144+
"base64": "AAAAAAAAAAAAAAAAAAAAAA==",
145+
"subType": "04"
146+
}
147+
}
148+
]
149+
}
150+
},
151+
{
152+
"keyAltNames": {
153+
"$in": []
154+
}
155+
}
156+
]
157+
},
158+
"$db": "keyvault"
159+
},
160+
"command_name": "find"
161+
}
162+
},
163+
{
164+
"command_started_event": {
165+
"command": {
166+
"insert": "default",
167+
"documents": [
168+
{
169+
"_id": 1,
170+
"encrypted_string": {
171+
"$binary": {
172+
"base64": "AQAAAAAAAAAAAAAAAAAAAAACwj+3zkv2VM+aTfk60RqhXq6a/77WlLwu/BxXFkL7EppGsju/m8f0x5kBDD3EZTtGALGXlym5jnpZAoSIkswHoA==",
173+
"subType": "06"
174+
}
175+
}
176+
}
177+
],
178+
"ordered": true
179+
},
180+
"command_name": "insert"
181+
}
182+
}
183+
],
184+
"outcome": {
185+
"collection": {
186+
"data": [
187+
{
188+
"_id": 1,
189+
"encrypted_string": {
190+
"$binary": {
191+
"base64": "AQAAAAAAAAAAAAAAAAAAAAACwj+3zkv2VM+aTfk60RqhXq6a/77WlLwu/BxXFkL7EppGsju/m8f0x5kBDD3EZTtGALGXlym5jnpZAoSIkswHoA==",
192+
"subType": "06"
193+
}
194+
}
195+
}
196+
]
197+
}
198+
}
199+
},
200+
{
201+
"description": "Insert with invalid temporary credentials",
202+
"clientOptions": {
203+
"autoEncryptOpts": {
204+
"kmsProviders": {
205+
"awsTemporaryNoSessionToken": {}
206+
}
207+
}
208+
},
209+
"operations": [
210+
{
211+
"name": "insertOne",
212+
"arguments": {
213+
"document": {
214+
"_id": 1,
215+
"encrypted_string": "string0"
216+
}
217+
},
218+
"result": {
219+
"errorContains": "security token"
220+
}
221+
}
222+
]
223+
}
224+
]
225+
}

0 commit comments

Comments
 (0)