mongodb 5.1.0 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -22
- package/lib/change_stream.js +1 -1
- package/lib/cmap/auth/auth_provider.js +21 -10
- package/lib/cmap/auth/auth_provider.js.map +1 -1
- package/lib/cmap/auth/gssapi.js +71 -116
- package/lib/cmap/auth/gssapi.js.map +1 -1
- package/lib/cmap/auth/mongo_credentials.js +7 -9
- package/lib/cmap/auth/mongo_credentials.js.map +1 -1
- package/lib/cmap/auth/mongocr.js +20 -29
- package/lib/cmap/auth/mongocr.js.map +1 -1
- package/lib/cmap/auth/mongodb_aws.js +125 -140
- package/lib/cmap/auth/mongodb_aws.js.map +1 -1
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js +28 -0
- package/lib/cmap/auth/mongodb_oidc/aws_service_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js +178 -0
- package/lib/cmap/auth/mongodb_oidc/callback_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js +41 -0
- package/lib/cmap/auth/mongodb_oidc/service_workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js +115 -0
- package/lib/cmap/auth/mongodb_oidc/token_entry_cache.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc/workflow.js +3 -0
- package/lib/cmap/auth/mongodb_oidc/workflow.js.map +1 -0
- package/lib/cmap/auth/mongodb_oidc.js +59 -0
- package/lib/cmap/auth/mongodb_oidc.js.map +1 -1
- package/lib/cmap/auth/plain.js +4 -5
- package/lib/cmap/auth/plain.js.map +1 -1
- package/lib/cmap/auth/providers.js +1 -1
- package/lib/cmap/auth/providers.js.map +1 -1
- package/lib/cmap/auth/scram.js +45 -73
- package/lib/cmap/auth/scram.js.map +1 -1
- package/lib/cmap/auth/x509.js +8 -11
- package/lib/cmap/auth/x509.js.map +1 -1
- package/lib/cmap/command_monitoring_events.js +8 -5
- package/lib/cmap/command_monitoring_events.js.map +1 -1
- package/lib/cmap/commands.js +1 -1
- package/lib/cmap/commands.js.map +1 -1
- package/lib/cmap/connect.js +72 -86
- package/lib/cmap/connect.js.map +1 -1
- package/lib/cmap/connection.js +19 -23
- package/lib/cmap/connection.js.map +1 -1
- package/lib/cmap/connection_pool.js +49 -11
- package/lib/cmap/connection_pool.js.map +1 -1
- package/lib/cmap/message_stream.js.map +1 -1
- package/lib/cmap/wire_protocol/shared.js +1 -16
- package/lib/cmap/wire_protocol/shared.js.map +1 -1
- package/lib/collection.js +10 -10
- package/lib/connection_string.js +11 -17
- package/lib/connection_string.js.map +1 -1
- package/lib/cursor/abstract_cursor.js +1 -1
- package/lib/cursor/find_cursor.js +1 -1
- package/lib/db.js +2 -2
- package/lib/error.js +2 -1
- package/lib/error.js.map +1 -1
- package/lib/mongo_client.js +22 -2
- package/lib/mongo_client.js.map +1 -1
- package/lib/mongo_logger.js +17 -1
- package/lib/mongo_logger.js.map +1 -1
- package/lib/operations/execute_operation.js +8 -27
- package/lib/operations/execute_operation.js.map +1 -1
- package/lib/operations/find.js +1 -1
- package/lib/read_concern.js +1 -1
- package/lib/read_preference.js +2 -2
- package/lib/sdam/topology.js +0 -16
- package/lib/sdam/topology.js.map +1 -1
- package/lib/utils.js +15 -70
- package/lib/utils.js.map +1 -1
- package/lib/write_concern.js +1 -1
- package/mongodb.d.ts +103 -70
- package/package.json +29 -30
- package/src/bulk/common.ts +1 -1
- package/src/change_stream.ts +5 -5
- package/src/cmap/auth/auth_provider.ts +29 -16
- package/src/cmap/auth/gssapi.ts +102 -149
- package/src/cmap/auth/mongo_credentials.ts +14 -23
- package/src/cmap/auth/mongocr.ts +31 -36
- package/src/cmap/auth/mongodb_aws.ts +166 -189
- package/src/cmap/auth/mongodb_oidc/aws_service_workflow.ts +26 -0
- package/src/cmap/auth/mongodb_oidc/callback_workflow.ts +259 -0
- package/src/cmap/auth/mongodb_oidc/service_workflow.ts +47 -0
- package/src/cmap/auth/mongodb_oidc/token_entry_cache.ts +166 -0
- package/src/cmap/auth/mongodb_oidc/workflow.ts +21 -0
- package/src/cmap/auth/mongodb_oidc.ts +101 -17
- package/src/cmap/auth/plain.ts +6 -6
- package/src/cmap/auth/providers.ts +2 -2
- package/src/cmap/auth/scram.ts +56 -90
- package/src/cmap/auth/x509.ts +12 -18
- package/src/cmap/command_monitoring_events.ts +5 -2
- package/src/cmap/commands.ts +1 -1
- package/src/cmap/connect.ts +90 -114
- package/src/cmap/connection.ts +36 -24
- package/src/cmap/connection_pool.ts +75 -14
- package/src/cmap/message_stream.ts +0 -2
- package/src/cmap/wire_protocol/compression.ts +1 -1
- package/src/cmap/wire_protocol/shared.ts +1 -23
- package/src/collection.ts +10 -10
- package/src/connection_string.ts +12 -17
- package/src/cursor/abstract_cursor.ts +2 -2
- package/src/cursor/change_stream_cursor.ts +5 -5
- package/src/cursor/find_cursor.ts +1 -1
- package/src/db.ts +2 -2
- package/src/deps.ts +3 -2
- package/src/error.ts +3 -2
- package/src/index.ts +1 -0
- package/src/mongo_client.ts +35 -10
- package/src/mongo_logger.ts +20 -2
- package/src/mongo_types.ts +2 -2
- package/src/operations/aggregate.ts +1 -1
- package/src/operations/create_collection.ts +1 -1
- package/src/operations/execute_operation.ts +8 -25
- package/src/operations/find.ts +1 -1
- package/src/operations/find_and_modify.ts +4 -4
- package/src/operations/set_profiling_level.ts +1 -1
- package/src/operations/stats.ts +1 -1
- package/src/read_concern.ts +2 -2
- package/src/read_preference.ts +3 -3
- package/src/sdam/common.ts +2 -2
- package/src/sdam/topology.ts +0 -20
- package/src/transactions.ts +1 -1
- package/src/utils.ts +24 -98
- package/src/write_concern.ts +1 -1
|
@@ -4,6 +4,7 @@ exports.MongoDBAWS = void 0;
|
|
|
4
4
|
const crypto = require("crypto");
|
|
5
5
|
const http = require("http");
|
|
6
6
|
const url = require("url");
|
|
7
|
+
const util_1 = require("util");
|
|
7
8
|
const BSON = require("../../bson");
|
|
8
9
|
const deps_1 = require("../../deps");
|
|
9
10
|
const error_1 = require("../../error");
|
|
@@ -23,28 +24,26 @@ const bsonOptions = {
|
|
|
23
24
|
bsonRegExp: false
|
|
24
25
|
};
|
|
25
26
|
class MongoDBAWS extends auth_provider_1.AuthProvider {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
constructor() {
|
|
28
|
+
super();
|
|
29
|
+
this.randomBytesAsync = (0, util_1.promisify)(crypto.randomBytes);
|
|
30
|
+
}
|
|
31
|
+
async auth(authContext) {
|
|
32
|
+
const { connection } = authContext;
|
|
33
|
+
if (!authContext.credentials) {
|
|
34
|
+
throw new error_1.MongoMissingCredentialsError('AuthContext must provide credentials.');
|
|
30
35
|
}
|
|
31
36
|
if ('kModuleError' in deps_1.aws4) {
|
|
32
|
-
|
|
37
|
+
throw deps_1.aws4['kModuleError'];
|
|
33
38
|
}
|
|
34
39
|
const { sign } = deps_1.aws4;
|
|
35
40
|
if ((0, utils_1.maxWireVersion)(connection) < 9) {
|
|
36
|
-
|
|
37
|
-
return;
|
|
41
|
+
throw new error_1.MongoCompatibilityError('MONGODB-AWS authentication requires MongoDB version 4.4 or later');
|
|
38
42
|
}
|
|
39
|
-
if (!credentials.username) {
|
|
40
|
-
makeTempCredentials(credentials
|
|
41
|
-
if (err || !tempCredentials)
|
|
42
|
-
return callback(err);
|
|
43
|
-
authContext.credentials = tempCredentials;
|
|
44
|
-
this.auth(authContext, callback);
|
|
45
|
-
});
|
|
46
|
-
return;
|
|
43
|
+
if (!authContext.credentials.username) {
|
|
44
|
+
authContext.credentials = await makeTempCredentials(authContext.credentials);
|
|
47
45
|
}
|
|
46
|
+
const { credentials } = authContext;
|
|
48
47
|
const accessKeyId = credentials.username;
|
|
49
48
|
const secretAccessKey = credentials.password;
|
|
50
49
|
const sessionToken = credentials.mechanismProperties.AWS_SESSION_TOKEN;
|
|
@@ -55,80 +54,67 @@ class MongoDBAWS extends auth_provider_1.AuthProvider {
|
|
|
55
54
|
? { accessKeyId, secretAccessKey }
|
|
56
55
|
: undefined;
|
|
57
56
|
const db = credentials.source;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
};
|
|
111
|
-
if (sessionToken) {
|
|
112
|
-
payload.t = sessionToken;
|
|
113
|
-
}
|
|
114
|
-
const saslContinue = {
|
|
115
|
-
saslContinue: 1,
|
|
116
|
-
conversationId: 1,
|
|
117
|
-
payload: BSON.serialize(payload, bsonOptions)
|
|
118
|
-
};
|
|
119
|
-
connection.command((0, utils_1.ns)(`${db}.$cmd`), saslContinue, undefined, callback);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
57
|
+
const nonce = await this.randomBytesAsync(32);
|
|
58
|
+
const saslStart = {
|
|
59
|
+
saslStart: 1,
|
|
60
|
+
mechanism: 'MONGODB-AWS',
|
|
61
|
+
payload: BSON.serialize({ r: nonce, p: ASCII_N }, bsonOptions)
|
|
62
|
+
};
|
|
63
|
+
const saslStartResponse = await connection.commandAsync((0, utils_1.ns)(`${db}.$cmd`), saslStart, undefined);
|
|
64
|
+
const serverResponse = BSON.deserialize(saslStartResponse.payload.buffer, bsonOptions);
|
|
65
|
+
const host = serverResponse.h;
|
|
66
|
+
const serverNonce = serverResponse.s.buffer;
|
|
67
|
+
if (serverNonce.length !== 64) {
|
|
68
|
+
// TODO(NODE-3483)
|
|
69
|
+
throw new error_1.MongoRuntimeError(`Invalid server nonce length ${serverNonce.length}, expected 64`);
|
|
70
|
+
}
|
|
71
|
+
if (!utils_1.ByteUtils.equals(serverNonce.subarray(0, nonce.byteLength), nonce)) {
|
|
72
|
+
// throw because the serverNonce's leading 32 bytes must equal the client nonce's 32 bytes
|
|
73
|
+
// https://github.com/mongodb/specifications/blob/875446db44aade414011731840831f38a6c668df/source/auth/auth.rst#id11
|
|
74
|
+
// TODO(NODE-3483)
|
|
75
|
+
throw new error_1.MongoRuntimeError('Server nonce does not begin with client nonce');
|
|
76
|
+
}
|
|
77
|
+
if (host.length < 1 || host.length > 255 || host.indexOf('..') !== -1) {
|
|
78
|
+
// TODO(NODE-3483)
|
|
79
|
+
throw new error_1.MongoRuntimeError(`Server returned an invalid host: "${host}"`);
|
|
80
|
+
}
|
|
81
|
+
const body = 'Action=GetCallerIdentity&Version=2011-06-15';
|
|
82
|
+
const options = sign({
|
|
83
|
+
method: 'POST',
|
|
84
|
+
host,
|
|
85
|
+
region: deriveRegion(serverResponse.h),
|
|
86
|
+
service: 'sts',
|
|
87
|
+
headers: {
|
|
88
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
89
|
+
'Content-Length': body.length,
|
|
90
|
+
'X-MongoDB-Server-Nonce': utils_1.ByteUtils.toBase64(serverNonce),
|
|
91
|
+
'X-MongoDB-GS2-CB-Flag': 'n'
|
|
92
|
+
},
|
|
93
|
+
path: '/',
|
|
94
|
+
body
|
|
95
|
+
}, awsCredentials);
|
|
96
|
+
const payload = {
|
|
97
|
+
a: options.headers.Authorization,
|
|
98
|
+
d: options.headers['X-Amz-Date']
|
|
99
|
+
};
|
|
100
|
+
if (sessionToken) {
|
|
101
|
+
payload.t = sessionToken;
|
|
102
|
+
}
|
|
103
|
+
const saslContinue = {
|
|
104
|
+
saslContinue: 1,
|
|
105
|
+
conversationId: 1,
|
|
106
|
+
payload: BSON.serialize(payload, bsonOptions)
|
|
107
|
+
};
|
|
108
|
+
await connection.commandAsync((0, utils_1.ns)(`${db}.$cmd`), saslContinue, undefined);
|
|
122
109
|
}
|
|
123
110
|
}
|
|
124
111
|
exports.MongoDBAWS = MongoDBAWS;
|
|
125
|
-
function makeTempCredentials(credentials
|
|
126
|
-
function
|
|
112
|
+
async function makeTempCredentials(credentials) {
|
|
113
|
+
function makeMongoCredentialsFromAWSTemp(creds) {
|
|
127
114
|
if (!creds.AccessKeyId || !creds.SecretAccessKey || !creds.Token) {
|
|
128
|
-
|
|
129
|
-
return;
|
|
115
|
+
throw new error_1.MongoMissingCredentialsError('Could not obtain temporary MONGODB-AWS credentials');
|
|
130
116
|
}
|
|
131
|
-
|
|
117
|
+
return new mongo_credentials_1.MongoCredentials({
|
|
132
118
|
username: creds.AccessKeyId,
|
|
133
119
|
password: creds.SecretAccessKey,
|
|
134
120
|
source: credentials.source,
|
|
@@ -136,7 +122,7 @@ function makeTempCredentials(credentials, callback) {
|
|
|
136
122
|
mechanismProperties: {
|
|
137
123
|
AWS_SESSION_TOKEN: creds.Token
|
|
138
124
|
}
|
|
139
|
-
})
|
|
125
|
+
});
|
|
140
126
|
}
|
|
141
127
|
const credentialProvider = (0, deps_1.getAwsCredentialProvider)();
|
|
142
128
|
// Check if the AWS credential provider from the SDK is present. If not,
|
|
@@ -145,30 +131,25 @@ function makeTempCredentials(credentials, callback) {
|
|
|
145
131
|
// If the environment variable AWS_CONTAINER_CREDENTIALS_RELATIVE_URI
|
|
146
132
|
// is set then drivers MUST assume that it was set by an AWS ECS agent
|
|
147
133
|
if (process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI) {
|
|
148
|
-
request(`${AWS_RELATIVE_URI}${process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}
|
|
149
|
-
if (err)
|
|
150
|
-
return callback(err);
|
|
151
|
-
done(res);
|
|
152
|
-
});
|
|
153
|
-
return;
|
|
134
|
+
return makeMongoCredentialsFromAWSTemp(await request(`${AWS_RELATIVE_URI}${process.env.AWS_CONTAINER_CREDENTIALS_RELATIVE_URI}`));
|
|
154
135
|
}
|
|
155
136
|
// Otherwise assume we are on an EC2 instance
|
|
156
137
|
// get a token
|
|
157
|
-
request(`${AWS_EC2_URI}/latest/api/token`, {
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
});
|
|
138
|
+
const token = await request(`${AWS_EC2_URI}/latest/api/token`, {
|
|
139
|
+
method: 'PUT',
|
|
140
|
+
json: false,
|
|
141
|
+
headers: { 'X-aws-ec2-metadata-token-ttl-seconds': 30 }
|
|
142
|
+
});
|
|
143
|
+
// get role name
|
|
144
|
+
const roleName = await request(`${AWS_EC2_URI}/${AWS_EC2_PATH}`, {
|
|
145
|
+
json: false,
|
|
146
|
+
headers: { 'X-aws-ec2-metadata-token': token }
|
|
147
|
+
});
|
|
148
|
+
// get temp credentials
|
|
149
|
+
const creds = await request(`${AWS_EC2_URI}/${AWS_EC2_PATH}/${roleName}`, {
|
|
150
|
+
headers: { 'X-aws-ec2-metadata-token': token }
|
|
171
151
|
});
|
|
152
|
+
return makeMongoCredentialsFromAWSTemp(creds);
|
|
172
153
|
}
|
|
173
154
|
else {
|
|
174
155
|
/*
|
|
@@ -183,18 +164,18 @@ function makeTempCredentials(credentials, callback) {
|
|
|
183
164
|
*/
|
|
184
165
|
const { fromNodeProviderChain } = credentialProvider;
|
|
185
166
|
const provider = fromNodeProviderChain();
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
167
|
+
try {
|
|
168
|
+
const creds = await provider();
|
|
169
|
+
return makeMongoCredentialsFromAWSTemp({
|
|
189
170
|
AccessKeyId: creds.accessKeyId,
|
|
190
171
|
SecretAccessKey: creds.secretAccessKey,
|
|
191
172
|
Token: creds.sessionToken,
|
|
192
173
|
Expiration: creds.expiration
|
|
193
174
|
});
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
throw new error_1.MongoAWSError(error.message);
|
|
178
|
+
}
|
|
198
179
|
}
|
|
199
180
|
}
|
|
200
181
|
function deriveRegion(host) {
|
|
@@ -204,35 +185,39 @@ function deriveRegion(host) {
|
|
|
204
185
|
}
|
|
205
186
|
return parts[1];
|
|
206
187
|
}
|
|
207
|
-
function request(uri,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
188
|
+
async function request(uri, options = {}) {
|
|
189
|
+
return new Promise((resolve, reject) => {
|
|
190
|
+
const requestOptions = {
|
|
191
|
+
method: 'GET',
|
|
192
|
+
timeout: 10000,
|
|
193
|
+
json: true,
|
|
194
|
+
...url.parse(uri),
|
|
195
|
+
...options
|
|
196
|
+
};
|
|
197
|
+
const req = http.request(requestOptions, res => {
|
|
198
|
+
res.setEncoding('utf8');
|
|
199
|
+
let data = '';
|
|
200
|
+
res.on('data', d => {
|
|
201
|
+
data += d;
|
|
202
|
+
});
|
|
203
|
+
res.once('end', () => {
|
|
204
|
+
if (options.json === false) {
|
|
205
|
+
resolve(data);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
try {
|
|
209
|
+
const parsed = JSON.parse(data);
|
|
210
|
+
resolve(parsed);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
// TODO(NODE-3483)
|
|
214
|
+
reject(new error_1.MongoRuntimeError(`Invalid JSON response: "${data}"`));
|
|
215
|
+
}
|
|
216
|
+
});
|
|
230
217
|
});
|
|
218
|
+
req.once('timeout', () => req.destroy(new error_1.MongoAWSError(`AWS request to ${uri} timed out after ${options.timeout} ms`)));
|
|
219
|
+
req.once('error', error => reject(error));
|
|
220
|
+
req.end();
|
|
231
221
|
});
|
|
232
|
-
req.on('timeout', () => {
|
|
233
|
-
req.destroy(new error_1.MongoAWSError(`AWS request to ${uri} timed out after ${options.timeout} ms`));
|
|
234
|
-
});
|
|
235
|
-
req.on('error', err => callback(err));
|
|
236
|
-
req.end();
|
|
237
222
|
}
|
|
238
223
|
//# sourceMappingURL=mongodb_aws.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb_aws.js","sourceRoot":"","sources":["../../../src/cmap/auth/mongodb_aws.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,6BAA6B;AAC7B,2BAA2B;
|
|
1
|
+
{"version":3,"file":"mongodb_aws.js","sourceRoot":"","sources":["../../../src/cmap/auth/mongodb_aws.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,6BAA6B;AAC7B,2BAA2B;AAC3B,+BAAiC;AAGjC,mCAAmC;AACnC,qCAA4D;AAC5D,uCAKqB;AACrB,uCAA4D;AAC5D,mDAA4D;AAC5D,2DAAuD;AACvD,2CAA4C;AAE5C,MAAM,OAAO,GAAG,GAAG,CAAC;AACpB,MAAM,gBAAgB,GAAG,sBAAsB,CAAC;AAChD,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAC7C,MAAM,YAAY,GAAG,4CAA4C,CAAC;AAClE,MAAM,WAAW,GAAyB;IACxC,WAAW,EAAE,KAAK;IAClB,YAAY,EAAE,IAAI;IAClB,aAAa,EAAE,I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GAAG,EAAE,CAAC;YACd,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE;gBACjB,IAAI,IAAI,CAAC,CAAC;YACZ,CAAC,CAAC,CAAC;YAEH,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE;gBACnB,IAAI,OAAO,CAAC,IAAI,KAAK,KAAK,EAAE;oBAC1B,OAAO,CAAC,IAAI,CAAC,CAAC;oBACd,OAAO;iBACR;gBAED,IAAI;oBACF,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;oBAChC,OAAO,CAAC,MAAM,CAAC,CAAC;iBACjB;gBAAC,MAAM;oBACN,kBAAkB;oBAClB,MAAM,CAAC,IAAI,yBAAiB,CAAC,2BAA2B,IAAI,GAAG,CAAC,CAAC,CAAC;iBACnE;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,GAAG,CAAC,IAAI,CAAC,SAAS,EAAE,GAAG,EAAE,CACvB,GAAG,CAAC,OAAO,CAAC,IAAI,qBAAa,CAAC,kBAAkB,GAAG,oBAAoB,OAAO,CAAC,OAAO,KAAK,CAAC,CAAC,CAC9F,CAAC;QACF,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAC1C,GAAG,CAAC,GAAG,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AwsServiceWorkflow = void 0;
|
|
4
|
+
const promises_1 = require("fs/promises");
|
|
5
|
+
const error_1 = require("../../../error");
|
|
6
|
+
const service_workflow_1 = require("./service_workflow");
|
|
7
|
+
/**
|
|
8
|
+
* Device workflow implementation for AWS.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
class AwsServiceWorkflow extends service_workflow_1.ServiceWorkflow {
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Get the token from the environment.
|
|
18
|
+
*/
|
|
19
|
+
async getToken() {
|
|
20
|
+
const tokenFile = process.env.AWS_WEB_IDENTITY_TOKEN_FILE;
|
|
21
|
+
if (!tokenFile) {
|
|
22
|
+
throw new error_1.MongoAWSError('AWS_WEB_IDENTITY_TOKEN_FILE must be set in the environment.');
|
|
23
|
+
}
|
|
24
|
+
return (0, promises_1.readFile)(tokenFile, 'utf8');
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.AwsServiceWorkflow = AwsServiceWorkflow;
|
|
28
|
+
//# sourceMappingURL=aws_service_workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws_service_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/aws_service_workflow.ts"],"names":[],"mappings":";;;AAAA,0CAAuC;AAEvC,0CAA+C;AAC/C,yDAAqD;AAErD;;;;GAIG;AACH,MAAa,kBAAmB,SAAQ,kCAAe;IACrD;QACE,KAAK,EAAE,CAAC;IACV,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC;QAC1D,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,qBAAa,CAAC,6DAA6D,CAAC,CAAC;SACxF;QACD,OAAO,IAAA,mBAAQ,EAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACrC,CAAC;CACF;AAfD,gDAeC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CallbackWorkflow = void 0;
|
|
4
|
+
const bson_1 = require("bson");
|
|
5
|
+
const error_1 = require("../../../error");
|
|
6
|
+
const utils_1 = require("../../../utils");
|
|
7
|
+
const providers_1 = require("../providers");
|
|
8
|
+
const token_entry_cache_1 = require("./token_entry_cache");
|
|
9
|
+
/* 5 minutes in milliseconds */
|
|
10
|
+
const TIMEOUT_MS = 300000;
|
|
11
|
+
/**
|
|
12
|
+
* OIDC implementation of a callback based workflow.
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
class CallbackWorkflow {
|
|
16
|
+
/**
|
|
17
|
+
* Instantiate the workflow
|
|
18
|
+
*/
|
|
19
|
+
constructor() {
|
|
20
|
+
this.cache = new token_entry_cache_1.TokenEntryCache();
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Get the document to add for speculative authentication. Is empty when
|
|
24
|
+
* callbacks are in play.
|
|
25
|
+
*/
|
|
26
|
+
speculativeAuth() {
|
|
27
|
+
return Promise.resolve({});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Execute the workflow.
|
|
31
|
+
*
|
|
32
|
+
* Steps:
|
|
33
|
+
* - If an entry is in the cache
|
|
34
|
+
* - If it is not expired
|
|
35
|
+
* - Skip step one and use the entry to execute step two.
|
|
36
|
+
* - If it is expired
|
|
37
|
+
* - If the refresh callback exists
|
|
38
|
+
* - remove expired entry from cache
|
|
39
|
+
* - call the refresh callback.
|
|
40
|
+
* - put the new entry in the cache.
|
|
41
|
+
* - execute step two.
|
|
42
|
+
* - If the refresh callback does not exist.
|
|
43
|
+
* - remove expired entry from cache
|
|
44
|
+
* - call the request callback.
|
|
45
|
+
* - put the new entry in the cache.
|
|
46
|
+
* - execute step two.
|
|
47
|
+
* - If no entry is in the cache.
|
|
48
|
+
* - execute step one.
|
|
49
|
+
* - call the refresh callback.
|
|
50
|
+
* - put the new entry in the cache.
|
|
51
|
+
* - execute step two.
|
|
52
|
+
*/
|
|
53
|
+
async execute(connection, credentials, reauthenticate = false) {
|
|
54
|
+
const request = credentials.mechanismProperties.REQUEST_TOKEN_CALLBACK;
|
|
55
|
+
const refresh = credentials.mechanismProperties.REFRESH_TOKEN_CALLBACK;
|
|
56
|
+
const entry = this.cache.getEntry(connection.address, credentials.username, request || null, refresh || null);
|
|
57
|
+
if (entry) {
|
|
58
|
+
// Check if the entry is not expired and if we are reauthenticating.
|
|
59
|
+
if (!reauthenticate && entry.isValid()) {
|
|
60
|
+
// Skip step one and execute the step two saslContinue.
|
|
61
|
+
try {
|
|
62
|
+
const result = await finishAuth(entry.tokenResult, undefined, connection, credentials);
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
// If authentication errors when using a cached token we remove it from
|
|
67
|
+
// the cache.
|
|
68
|
+
this.cache.deleteEntry(connection.address, credentials.username || '', request || null, refresh || null);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// Remove the expired entry from the cache.
|
|
74
|
+
this.cache.deleteEntry(connection.address, credentials.username || '', request || null, refresh || null);
|
|
75
|
+
// Execute a refresh of the token and finish auth.
|
|
76
|
+
return this.refreshAndFinish(connection, credentials, entry.serverResult, entry.tokenResult);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// No entry means to start with the step one saslStart.
|
|
81
|
+
const result = await connection.commandAsync((0, utils_1.ns)(credentials.source), startCommandDocument(credentials), undefined);
|
|
82
|
+
const stepOne = bson_1.BSON.deserialize(result.payload.buffer);
|
|
83
|
+
// Call the request callback and finish auth.
|
|
84
|
+
return this.requestAndFinish(connection, credentials, stepOne, result.conversationId);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Execute the refresh callback if it exists, otherwise the request callback, then
|
|
89
|
+
* finish the authentication.
|
|
90
|
+
*/
|
|
91
|
+
async refreshAndFinish(connection, credentials, stepOneResult, tokenResult, conversationId) {
|
|
92
|
+
const request = credentials.mechanismProperties.REQUEST_TOKEN_CALLBACK;
|
|
93
|
+
const refresh = credentials.mechanismProperties.REFRESH_TOKEN_CALLBACK;
|
|
94
|
+
// If a refresh callback exists, use it. Otherwise use the request callback.
|
|
95
|
+
if (refresh) {
|
|
96
|
+
const result = await refresh(credentials.username, stepOneResult, tokenResult, TIMEOUT_MS);
|
|
97
|
+
// Validate the result.
|
|
98
|
+
if (!result || !result.accessToken) {
|
|
99
|
+
throw new error_1.MongoMissingCredentialsError('REFRESH_TOKEN_CALLBACK must return a valid object with an accessToken');
|
|
100
|
+
}
|
|
101
|
+
// Cache a new entry and continue with the saslContinue.
|
|
102
|
+
this.cache.addEntry(connection.address, credentials.username || '', request || null, refresh, result, stepOneResult);
|
|
103
|
+
return finishAuth(result, conversationId, connection, credentials);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
// Fallback to using the request callback.
|
|
107
|
+
return this.requestAndFinish(connection, credentials, stepOneResult, conversationId);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Execute the request callback and finish authentication.
|
|
112
|
+
*/
|
|
113
|
+
async requestAndFinish(connection, credentials, stepOneResult, conversationId) {
|
|
114
|
+
// Call the request callback.
|
|
115
|
+
const request = credentials.mechanismProperties.REQUEST_TOKEN_CALLBACK;
|
|
116
|
+
const refresh = credentials.mechanismProperties.REFRESH_TOKEN_CALLBACK;
|
|
117
|
+
// Always clear expired entries from the cache on each finish as cleanup.
|
|
118
|
+
this.cache.deleteExpiredEntries();
|
|
119
|
+
if (!request) {
|
|
120
|
+
// Request callback must be present.
|
|
121
|
+
throw new error_1.MongoInvalidArgumentError('Auth mechanism property REQUEST_TOKEN_CALLBACK is required.');
|
|
122
|
+
}
|
|
123
|
+
const tokenResult = await request(credentials.username, stepOneResult, TIMEOUT_MS);
|
|
124
|
+
// Validate the result.
|
|
125
|
+
if (!tokenResult || !tokenResult.accessToken) {
|
|
126
|
+
throw new error_1.MongoMissingCredentialsError('REQUEST_TOKEN_CALLBACK must return a valid object with an accessToken');
|
|
127
|
+
}
|
|
128
|
+
// Cache a new entry and continue with the saslContinue.
|
|
129
|
+
this.cache.addEntry(connection.address, credentials.username || '', request, refresh || null, tokenResult, stepOneResult);
|
|
130
|
+
return finishAuth(tokenResult, conversationId, connection, credentials);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.CallbackWorkflow = CallbackWorkflow;
|
|
134
|
+
/**
|
|
135
|
+
* Cache the result of the user supplied callback and execute the
|
|
136
|
+
* step two saslContinue.
|
|
137
|
+
*/
|
|
138
|
+
async function finishAuth(result, conversationId, connection, credentials) {
|
|
139
|
+
// Execute the step two saslContinue.
|
|
140
|
+
return connection.commandAsync((0, utils_1.ns)(credentials.source), continueCommandDocument(result.accessToken, conversationId), undefined);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Generate the saslStart command document.
|
|
144
|
+
*/
|
|
145
|
+
function startCommandDocument(credentials) {
|
|
146
|
+
const payload = {};
|
|
147
|
+
if (credentials.username) {
|
|
148
|
+
payload.n = credentials.username;
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
saslStart: 1,
|
|
152
|
+
autoAuthorize: 1,
|
|
153
|
+
mechanism: providers_1.AuthMechanism.MONGODB_OIDC,
|
|
154
|
+
payload: new bson_1.Binary(bson_1.BSON.serialize(payload))
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Generate the saslContinue command document.
|
|
159
|
+
*/
|
|
160
|
+
function continueCommandDocument(token, conversationId) {
|
|
161
|
+
if (conversationId) {
|
|
162
|
+
return {
|
|
163
|
+
saslContinue: 1,
|
|
164
|
+
conversationId: conversationId,
|
|
165
|
+
payload: new bson_1.Binary(bson_1.BSON.serialize({ jwt: token }))
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
// saslContinue requires a conversationId in the command to be valid so in this
|
|
169
|
+
// case the server allows "step two" to actually be a saslStart with the token
|
|
170
|
+
// as the jwt since the use of the cached value has no correlating conversating
|
|
171
|
+
// on the particular connection.
|
|
172
|
+
return {
|
|
173
|
+
saslStart: 1,
|
|
174
|
+
mechanism: providers_1.AuthMechanism.MONGODB_OIDC,
|
|
175
|
+
payload: new bson_1.Binary(bson_1.BSON.serialize({ jwt: token }))
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=callback_workflow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callback_workflow.js","sourceRoot":"","sources":["../../../../src/cmap/auth/mongodb_oidc/callback_workflow.ts"],"names":[],"mappings":";;;AAAA,+BAAmD;AAEnD,0CAAyF;AACzF,0CAAoC;AAIpC,4CAA6C;AAC7C,2DAAsD;AAGtD,+BAA+B;AAC/B,MAAM,UAAU,GAAG,MAAM,CAAC;AAE1B;;;GAGG;AACH,MAAa,gBAAgB;IAG3B;;OAEG;IACH;QACE,IAAI,CAAC,KAAK,GAAG,IAAI,mCAAe,EAAE,CAAC;IACrC,CAAC;IAED;;;OAGG;IACH,eAAe;QACb,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,KAAK,CAAC,OAAO,CACX,UAAsB,EACtB,WAA6B,EAC7B,cAAc,GAAG,KAAK;QAEtB,MAAM,OAAO,GAAG,WAAW,CAAC,mBAAmB,CAAC,sBAAsB,CAAC;QACvE,MAAM,OAAO,GAAG,WAAW,CAAC,mBAAmB,CAAC,sBAAsB,CAAC;QAEvE,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAC/B,UAAU,CAAC,OAAO,EAClB,WAAW,CAAC,QAAQ,EACpB,OAAO,IAAI,IAAI,EACf,OAAO,IAAI,IAAI,CAChB,CAAC;QACF,IAAI,KAAK,EAAE;YACT,oEAAoE;YACpE,IAAI,CAAC,cAAc,IAAI,KAAK,CAAC,OAAO,EAAE,EAAE;gBACtC,uDAAuD;gBACvD,IAAI;oBACF,M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Y,EAAE,CAAC;YACf,cAAc,EAAE,cAAc;YAC9B,OAAO,EAAE,IAAI,aAAM,CAAC,WAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;SACpD,CAAC;KACH;IACD,+EAA+E;IAC/E,8EAA8E;IAC9E,+EAA+E;IAC/E,gCAAgC;IAChC,OAAO;QACL,SAAS,EAAE,CAAC;QACZ,SAAS,EAAE,yBAAa,CAAC,YAAY;QACrC,OAAO,EAAE,IAAI,aAAM,CAAC,WAAI,CAAC,SAAS,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;KACpD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.commandDocument = exports.ServiceWorkflow = void 0;
|
|
4
|
+
const bson_1 = require("bson");
|
|
5
|
+
const utils_1 = require("../../../utils");
|
|
6
|
+
const providers_1 = require("../providers");
|
|
7
|
+
/**
|
|
8
|
+
* Common behaviour for OIDC device workflows.
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
class ServiceWorkflow {
|
|
12
|
+
/**
|
|
13
|
+
* Execute the workflow. Looks for AWS_WEB_IDENTITY_TOKEN_FILE in the environment
|
|
14
|
+
* and then attempts to read the token from that path.
|
|
15
|
+
*/
|
|
16
|
+
async execute(connection, credentials) {
|
|
17
|
+
const token = await this.getToken();
|
|
18
|
+
const command = commandDocument(token);
|
|
19
|
+
return connection.commandAsync((0, utils_1.ns)(credentials.source), command, undefined);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the document to add for speculative authentication.
|
|
23
|
+
*/
|
|
24
|
+
async speculativeAuth() {
|
|
25
|
+
const token = await this.getToken();
|
|
26
|
+
return { speculativeAuthenticate: commandDocument(token) };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ServiceWorkflow = ServiceWorkflow;
|
|
30
|
+
/**
|
|
31
|
+
* Create the saslStart command document.
|
|
32
|
+
*/
|
|
33
|
+
function commandDocument(token) {
|
|
34
|
+
return {
|
|
35
|
+
saslStart: 1,
|
|
36
|
+
mechanism: providers_1.AuthMechanism.MONGODB_OIDC,
|
|
37
|
+
payload: bson_1.BSON.serialize({ jwt: token })
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
exports.commandDocument = commandDocument;
|
|
41
|
+
//# sourceMappingURL=service_workflow.js.map
|