@edirect/mongo 11.0.41 → 11.0.42
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/dist/package.json +6 -2
- package/dist/src/aws.d.ts +3 -3
- package/dist/src/aws.d.ts.map +1 -1
- package/dist/src/aws.js +22 -32
- package/dist/src/mongo.providers.d.ts.map +1 -1
- package/dist/src/mongo.providers.js +25 -11
- package/package.json +6 -2
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edirect/mongo",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.41",
|
|
4
4
|
"main": "./dist/src/index.js",
|
|
5
5
|
"types": "./dist/src/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -17,11 +17,15 @@
|
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@aws-sdk/credential-providers": "^3.975.0",
|
|
20
|
-
"@edirect/config": "^11.0.
|
|
20
|
+
"@edirect/config": "^11.0.41",
|
|
21
21
|
"@nestjs/common": "^11.1.12",
|
|
22
|
+
"aws4": "^1.13.2",
|
|
22
23
|
"mongodb": "^7.0.0",
|
|
23
24
|
"mongoose": "^9.1.5",
|
|
24
25
|
"tslib": "^2.8.1"
|
|
25
26
|
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/aws4": "^1.11.6"
|
|
29
|
+
},
|
|
26
30
|
"type": "commonjs"
|
|
27
31
|
}
|
package/dist/src/aws.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AWSCredentials } from 'mongodb';
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare
|
|
2
|
+
export declare const MONGODB_AWS_ROLE_ARN: string | undefined;
|
|
3
|
+
export declare const AWS_WEB_IDENTITY_TOKEN_FILE: string | undefined;
|
|
4
|
+
export declare function getMongoAwsCredentialProvider(): () => Promise<AWSCredentials>;
|
|
5
5
|
//# sourceMappingURL=aws.d.ts.map
|
package/dist/src/aws.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws.d.ts","sourceRoot":"","sources":["../../src/aws.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aws.d.ts","sourceRoot":"","sources":["../../src/aws.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAOzC,eAAO,MAAM,oBAAoB,oBAAmC,CAAC;AACrE,eAAO,MAAM,2BAA2B,oBACC,CAAC;AAI1C,wBAAgB,6BAA6B,IAAI,MAAM,OAAO,CAAC,cAAc,CAAC,CAY7E"}
|
package/dist/src/aws.js
CHANGED
|
@@ -1,36 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.AWS_WEB_IDENTITY_TOKEN_FILE = exports.MONGODB_AWS_ROLE_ARN = void 0;
|
|
4
|
+
exports.getMongoAwsCredentialProvider = getMongoAwsCredentialProvider;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
4
6
|
const credential_providers_1 = require("@aws-sdk/credential-providers");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const aws4_1 = tslib_1.__importDefault(require("aws4"));
|
|
8
|
+
aws4_1.default.RequestSigner; // ensure types are loaded
|
|
9
|
+
// Environment variables required for IRSA/EKS role assumption authentication:
|
|
10
|
+
// MONGODB_AWS_ROLE_ARN: the AWS IAM Role ARN to assume
|
|
11
|
+
// AWS_WEB_IDENTITY_TOKEN_FILE: path to serviceAccount token (set by kubelet when IRSA is enabled)
|
|
12
|
+
exports.MONGODB_AWS_ROLE_ARN = process.env.MONGODB_AWS_ROLE_ARN;
|
|
13
|
+
exports.AWS_WEB_IDENTITY_TOKEN_FILE = process.env.AWS_WEB_IDENTITY_TOKEN_FILE;
|
|
14
|
+
// A dynamic credentials provider for the MongoDB driver that will always fetch fresh AWS credentials (using IRSA+STS)
|
|
15
|
+
// ALWAYS use this as the value of AWS_CREDENTIAL_PROVIDER in authMechanismProperties. Never embed static keys/tokens in the URI.
|
|
16
|
+
function getMongoAwsCredentialProvider() {
|
|
17
|
+
if (!exports.MONGODB_AWS_ROLE_ARN || !exports.AWS_WEB_IDENTITY_TOKEN_FILE) {
|
|
18
|
+
throw new Error('[mongo] MONGODB_AWS_ROLE_ARN or AWS_WEB_IDENTITY_TOKEN_FILE are not set. ' +
|
|
19
|
+
'These are required for AWS IAM auth (IRSA, STS assume role), and must be set in the environment!');
|
|
13
20
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
exports.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
if (exports.shouldAssumeRole) {
|
|
22
|
-
const credentials = await (0, exports.generateAwsCredentials)();
|
|
23
|
-
if (credentials) {
|
|
24
|
-
const url = new URL(cnn);
|
|
25
|
-
url.username = credentials.accessKeyId || '';
|
|
26
|
-
url.password = credentials.secretAccessKey || '';
|
|
27
|
-
if (credentials.sessionToken) {
|
|
28
|
-
url.searchParams.set('authMechanismProperties', `AWS_SESSION_TOKEN:${credentials.sessionToken}`);
|
|
29
|
-
}
|
|
30
|
-
return url.toString();
|
|
31
|
-
}
|
|
32
|
-
throw new Error('Failed to assume role with web identity');
|
|
33
|
-
}
|
|
34
|
-
return cnn;
|
|
35
|
-
};
|
|
36
|
-
exports.generateConnectionString = generateConnectionString;
|
|
21
|
+
// This permanently produces a rotating credentials chain using the specified roleArn, IRSA, and web identity token
|
|
22
|
+
const credentialChain = (0, credential_providers_1.fromNodeProviderChain)({
|
|
23
|
+
roleArn: exports.MONGODB_AWS_ROLE_ARN,
|
|
24
|
+
});
|
|
25
|
+
return () => credentialChain();
|
|
26
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongo.providers.d.ts","sourceRoot":"","sources":["../../src/mongo.providers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAU1C,eAAO,MAAM,cAAc,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"mongo.providers.d.ts","sourceRoot":"","sources":["../../src/mongo.providers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAU1C,eAAO,MAAM,cAAc,EAAE,QAAQ,EA8BpC,CAAC"}
|
|
@@ -9,17 +9,31 @@ const mongoUrl = (configService) => configService.get('MONGO_URL') ?? configServ
|
|
|
9
9
|
exports.MongoProviders = [
|
|
10
10
|
{
|
|
11
11
|
provide: 'MONGO_CONNECTION',
|
|
12
|
-
useFactory: async (configService) =>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
useFactory: async (configService) => {
|
|
13
|
+
const connectionString = mongoUrl(configService);
|
|
14
|
+
if (!connectionString)
|
|
15
|
+
throw new Error('MongoDB connection string is not defined');
|
|
16
|
+
const options = {};
|
|
17
|
+
// Always use dynamic AWS credential provider for MongoDB-AWS mechanism
|
|
18
|
+
if ((connectionString ?? '').includes('MONGODB-AWS')) {
|
|
19
|
+
options.authMechanismProperties = {
|
|
20
|
+
// This will provide rotating, always-fresh AWS credentials via IRSA
|
|
21
|
+
AWS_CREDENTIAL_PROVIDER: (0, aws_1.getMongoAwsCredentialProvider)(),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
// Pool sizing for dev/test only
|
|
25
|
+
if (isNotProductionOrLive(configService.get('NODE_ENV'))) {
|
|
26
|
+
options.minPoolSize = 0;
|
|
27
|
+
options.maxPoolSize = 10;
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
return await (0, mongoose_1.connect)(connectionString, options);
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
console.error('[mongo] Failed to connect to MongoDB:', err);
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
},
|
|
23
37
|
inject: [config_1.ConfigService],
|
|
24
38
|
},
|
|
25
39
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@edirect/mongo",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.42",
|
|
4
4
|
"packageScope": "@edirect",
|
|
5
5
|
"main": "./dist/src/index.js",
|
|
6
6
|
"types": "./dist/src/index.d.ts",
|
|
@@ -19,10 +19,11 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@aws-sdk/credential-providers": "^3.975.0",
|
|
21
21
|
"@nestjs/common": "^11.1.12",
|
|
22
|
+
"aws4": "^1.13.2",
|
|
22
23
|
"mongodb": "^7.0.0",
|
|
23
24
|
"mongoose": "^9.1.5",
|
|
24
25
|
"tslib": "^2.8.1",
|
|
25
|
-
"@edirect/config": "11.0.
|
|
26
|
+
"@edirect/config": "11.0.42"
|
|
26
27
|
},
|
|
27
28
|
"nx": {
|
|
28
29
|
"name": "@edirect/mongo",
|
|
@@ -40,5 +41,8 @@
|
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
}
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@types/aws4": "^1.11.6"
|
|
43
47
|
}
|
|
44
48
|
}
|