ag-awsauth 0.0.247 → 0.0.249
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/helpers/awsconfig.js +2 -2
- package/dist/helpers/browser.js +27 -20
- package/dist/helpers/getCredentialsFilepath.d.ts +3 -0
- package/dist/helpers/getCredentialsFilepath.js +32 -0
- package/dist/helpers/sso.js +13 -11
- package/dist/helpers/sts.js +10 -10
- package/dist/helpers/version.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +12 -12
|
@@ -14,14 +14,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.updateAwsCredentials = exports.getAwsCredentials = void 0;
|
|
16
16
|
const shared_ini_file_loader_1 = require("@aws-sdk/shared-ini-file-loader");
|
|
17
|
-
//@ts-ignore
|
|
18
|
-
const getCredentialsFilepath_1 = require("@aws-sdk/shared-ini-file-loader/dist-cjs/getCredentialsFilepath");
|
|
19
17
|
const log_1 = require("ag-common/dist/common/helpers/log");
|
|
20
18
|
const fs_1 = __importDefault(require("fs"));
|
|
21
19
|
const ini_1 = require("ini");
|
|
20
|
+
const getCredentialsFilepath_1 = require("./getCredentialsFilepath");
|
|
22
21
|
const getAwsCredentials = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
22
|
const config = yield (0, shared_ini_file_loader_1.loadSharedConfigFiles)();
|
|
24
23
|
const creds = config.credentialsFile;
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
25
25
|
if (!creds.default) {
|
|
26
26
|
creds.default = {};
|
|
27
27
|
}
|
package/dist/helpers/browser.js
CHANGED
|
@@ -33,7 +33,7 @@ exports.closeBrowser = closeBrowser;
|
|
|
33
33
|
const launchBrowser = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
34
|
const opt = {
|
|
35
35
|
defaultViewport: { height: 1000, width: 500 },
|
|
36
|
-
headless: (__1.globalargs === null || __1.globalargs === void 0 ? void 0 : __1.globalargs.verbose) ? false :
|
|
36
|
+
headless: (__1.globalargs === null || __1.globalargs === void 0 ? void 0 : __1.globalargs.verbose) ? false : true,
|
|
37
37
|
ignoreHTTPSErrors: true,
|
|
38
38
|
devtools: false,
|
|
39
39
|
};
|
|
@@ -75,8 +75,8 @@ const goToPage = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
75
75
|
});
|
|
76
76
|
exports.goToPage = goToPage;
|
|
77
77
|
function getMFA(p) {
|
|
78
|
-
var _a;
|
|
79
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
var _a;
|
|
80
80
|
//go to browser site for auth
|
|
81
81
|
(0, log_1.info)('start mfa');
|
|
82
82
|
const page = yield (0, exports.goToPage)(p.verificationUriComplete);
|
|
@@ -157,31 +157,38 @@ function getMFA(p) {
|
|
|
157
157
|
retry = false;
|
|
158
158
|
}
|
|
159
159
|
}
|
|
160
|
+
try {
|
|
161
|
+
(0, log_1.info)('wait for access prompt');
|
|
162
|
+
const messageDiv = yield page.waitForSelector('[data-testid="allow-access-button"]', {
|
|
163
|
+
timeout: config_1.timeoutShortMs,
|
|
164
|
+
});
|
|
165
|
+
if (messageDiv) {
|
|
166
|
+
(0, log_1.info)('click access prompt');
|
|
167
|
+
yield messageDiv.click();
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
throw new Error('access prompt not found');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
catch (e) {
|
|
174
|
+
const em = e.toString();
|
|
175
|
+
if (!em.includes('exceeded')) {
|
|
176
|
+
const em2 = `mfa error:` + em + ' retry';
|
|
177
|
+
(0, log_1.error)(em2);
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
retry = false;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
160
183
|
} while (retry);
|
|
161
184
|
//
|
|
162
|
-
yield (0, sleep_1.sleep)(config_1.timeoutShortMs);
|
|
163
|
-
yield page.waitForNetworkIdle({ idleTime: 250 });
|
|
164
|
-
(0, log_1.info)('waiting for sign in button');
|
|
165
|
-
yield page.waitForSelector('#cli_login_button', {
|
|
166
|
-
timeout: config_1.timeoutShortMs,
|
|
167
|
-
});
|
|
168
|
-
(0, log_1.info)('pressing sign in');
|
|
169
|
-
yield page.$eval('#cli_login_button', (el) => el.click());
|
|
170
|
-
(0, log_1.info)('waiting for completion');
|
|
171
|
-
yield (0, sleep_1.sleep)(250);
|
|
172
|
-
try {
|
|
173
|
-
yield page.waitForNetworkIdle({ idleTime: 250, timeout: config_1.timeoutShortMs });
|
|
174
|
-
}
|
|
175
|
-
catch (e) {
|
|
176
|
-
//
|
|
177
|
-
}
|
|
178
185
|
(0, log_1.info)('waiting for success');
|
|
179
186
|
yield page.waitForSelector('[data-analytics-alert="success"]', {
|
|
180
187
|
timeout: config_1.timeoutMs,
|
|
181
188
|
});
|
|
182
189
|
(0, log_1.warn)('mfa success');
|
|
183
|
-
const cookies = yield
|
|
184
|
-
const ssoAuthn = (_a = cookies
|
|
190
|
+
const cookies = yield page.cookies();
|
|
191
|
+
const ssoAuthn = (_a = cookies.find((c) => c.name === 'x-amz-sso_authn')) === null || _a === void 0 ? void 0 : _a.value;
|
|
185
192
|
if (!ssoAuthn) {
|
|
186
193
|
throw new Error('no aws authn');
|
|
187
194
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCredentialsFilepath = exports.ENV_CREDENTIALS_PATH = exports.getHomeDir = void 0;
|
|
4
|
+
const os_1 = require("os");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const homeDirCache = {};
|
|
7
|
+
const getHomeDirCacheKey = () => {
|
|
8
|
+
// geteuid is only available on POSIX platforms (i.e. not Windows or Android).
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
10
|
+
if (process && process.geteuid) {
|
|
11
|
+
return `${process.geteuid()}`;
|
|
12
|
+
}
|
|
13
|
+
return 'DEFAULT';
|
|
14
|
+
};
|
|
15
|
+
const getHomeDir = () => {
|
|
16
|
+
const { HOME, USERPROFILE, HOMEPATH, HOMEDRIVE = `C:${path_1.sep}` } = process.env;
|
|
17
|
+
if (HOME)
|
|
18
|
+
return HOME;
|
|
19
|
+
if (USERPROFILE)
|
|
20
|
+
return USERPROFILE;
|
|
21
|
+
if (HOMEPATH)
|
|
22
|
+
return `${HOMEDRIVE}${HOMEPATH}`;
|
|
23
|
+
const homeDirCacheKey = getHomeDirCacheKey();
|
|
24
|
+
if (!homeDirCache[homeDirCacheKey])
|
|
25
|
+
homeDirCache[homeDirCacheKey] = (0, os_1.homedir)();
|
|
26
|
+
return homeDirCache[homeDirCacheKey];
|
|
27
|
+
};
|
|
28
|
+
exports.getHomeDir = getHomeDir;
|
|
29
|
+
exports.ENV_CREDENTIALS_PATH = 'AWS_SHARED_CREDENTIALS_FILE';
|
|
30
|
+
const getCredentialsFilepath = () => process.env[exports.ENV_CREDENTIALS_PATH] ||
|
|
31
|
+
(0, path_1.join)((0, exports.getHomeDir)(), '.aws', 'credentials');
|
|
32
|
+
exports.getCredentialsFilepath = getCredentialsFilepath;
|
package/dist/helpers/sso.js
CHANGED
|
@@ -21,7 +21,7 @@ const config_1 = require("../config");
|
|
|
21
21
|
const awsconfig_1 = require("./awsconfig");
|
|
22
22
|
const sts_1 = require("./sts");
|
|
23
23
|
const getAssumedRole = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
-
var _a, _b, _c, _d
|
|
24
|
+
var _a, _b, _c, _d;
|
|
25
25
|
const sso = new client_sso_1.SSOClient({ region: config_1.identityCenterRegion });
|
|
26
26
|
let accountId = p.accountId;
|
|
27
27
|
if (!accountId) {
|
|
@@ -35,10 +35,10 @@ const getAssumedRole = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
35
35
|
accessToken: p.accessToken,
|
|
36
36
|
accountId,
|
|
37
37
|
}));
|
|
38
|
-
const roles = (
|
|
38
|
+
const roles = (_d = (_c = rolesResult.roleList) === null || _c === void 0 ? void 0 : _c.map((r) => ({
|
|
39
39
|
accountId: r.accountId || '',
|
|
40
40
|
roleName: r.roleName || '',
|
|
41
|
-
}))
|
|
41
|
+
})).filter((r) => r.accountId && r.roleName)) !== null && _d !== void 0 ? _d : [];
|
|
42
42
|
if (roles.length === 0) {
|
|
43
43
|
throw new Error('no roles can be assumed');
|
|
44
44
|
}
|
|
@@ -55,9 +55,9 @@ const getOIDCCredentialsFromAccessToken = (p) => __awaiter(void 0, void 0, void
|
|
|
55
55
|
const ssoResp = yield sso.send(new client_sso_1.GetRoleCredentialsCommand(Object.assign(Object.assign({}, role), { accessToken: p.accessToken })));
|
|
56
56
|
const rc = ssoResp.roleCredentials;
|
|
57
57
|
if (!(rc === null || rc === void 0 ? void 0 : rc.accessKeyId) ||
|
|
58
|
-
!
|
|
59
|
-
!
|
|
60
|
-
!
|
|
58
|
+
!rc.expiration ||
|
|
59
|
+
!rc.secretAccessKey ||
|
|
60
|
+
!rc.sessionToken) {
|
|
61
61
|
throw new Error('role creds undefined:' + JSON.stringify(rc, null, 2));
|
|
62
62
|
}
|
|
63
63
|
return Object.assign(Object.assign({}, p), { accessKeyId: rc.accessKeyId, secretAccessKey: rc.secretAccessKey, sessionToken: rc.sessionToken, region: config_1.identityCenterRegion });
|
|
@@ -66,7 +66,8 @@ exports.getOIDCCredentialsFromAccessToken = getOIDCCredentialsFromAccessToken;
|
|
|
66
66
|
function appInstances(p) {
|
|
67
67
|
return __awaiter(this, void 0, void 0, function* () {
|
|
68
68
|
const ai = (yield (yield (0, node_fetch_1.default)(`https://portal.sso.${config_1.identityCenterRegion}.amazonaws.com/instance/appinstances`, { headers: { 'x-amz-sso_bearer_token': p.ssoAuthn } })).json());
|
|
69
|
-
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
70
|
+
if (!ai.result) {
|
|
70
71
|
throw new Error('appinstance error' + JSON.stringify(ai, null, 2));
|
|
71
72
|
}
|
|
72
73
|
return ai.result.sort((a, b) => (a.name < b.name ? -1 : 1));
|
|
@@ -74,10 +75,10 @@ function appInstances(p) {
|
|
|
74
75
|
}
|
|
75
76
|
exports.appInstances = appInstances;
|
|
76
77
|
function getSamlAssertion(p, instance) {
|
|
77
|
-
var _a, _b;
|
|
78
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
var _a;
|
|
79
80
|
const det = (yield (yield (0, node_fetch_1.default)(`https://portal.sso.${config_1.identityCenterRegion}.amazonaws.com/instance/appinstance/${instance.id}/profiles`, { headers: { 'x-amz-sso_bearer_token': p.ssoAuthn } })).json());
|
|
80
|
-
const asserturl = (
|
|
81
|
+
const asserturl = (_a = det.result[0]) === null || _a === void 0 ? void 0 : _a.url;
|
|
81
82
|
if (!asserturl) {
|
|
82
83
|
throw new Error('assertion url cant be found');
|
|
83
84
|
}
|
|
@@ -95,7 +96,7 @@ function getSamlAssertion(p, instance) {
|
|
|
95
96
|
}
|
|
96
97
|
exports.getSamlAssertion = getSamlAssertion;
|
|
97
98
|
const tryExistingCredentials = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
|
-
var
|
|
99
|
+
var _e;
|
|
99
100
|
const credraw = yield (0, awsconfig_1.getAwsCredentials)();
|
|
100
101
|
if (!credraw.default.aws_access_token) {
|
|
101
102
|
return undefined;
|
|
@@ -124,7 +125,8 @@ const tryExistingCredentials = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
124
125
|
catch (e) {
|
|
125
126
|
//
|
|
126
127
|
const em = e.toString();
|
|
127
|
-
|
|
128
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
129
|
+
if ((_e = em.includes('is expired')) !== null && _e !== void 0 ? _e : em.includes('or invalid')) {
|
|
128
130
|
(0, log_1.info)('access token or sso expired, need to wipe');
|
|
129
131
|
}
|
|
130
132
|
else {
|
package/dist/helpers/sts.js
CHANGED
|
@@ -15,8 +15,8 @@ const log_1 = require("ag-common/dist/common/helpers/log");
|
|
|
15
15
|
const config_1 = require("../config");
|
|
16
16
|
const sso_1 = require("./sso");
|
|
17
17
|
function validateCredentials(credentials) {
|
|
18
|
-
var _a, _b;
|
|
19
18
|
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
+
var _a;
|
|
20
20
|
const sts = new client_sts_1.STS({
|
|
21
21
|
credentials,
|
|
22
22
|
region: credentials.region,
|
|
@@ -24,7 +24,7 @@ function validateCredentials(credentials) {
|
|
|
24
24
|
try {
|
|
25
25
|
const stub = yield sts.getCallerIdentity({});
|
|
26
26
|
yield (0, sso_1.appInstances)(credentials);
|
|
27
|
-
if (((
|
|
27
|
+
if (((_a = stub.$metadata.httpStatusCode) !== null && _a !== void 0 ? _a : 500) < 400 &&
|
|
28
28
|
stub.Account &&
|
|
29
29
|
stub.Arn) {
|
|
30
30
|
(0, log_1.info)(`test cached credentials OK`);
|
|
@@ -43,8 +43,8 @@ function validateCredentials(credentials) {
|
|
|
43
43
|
}
|
|
44
44
|
exports.validateCredentials = validateCredentials;
|
|
45
45
|
function getApplicationCreds(p) {
|
|
46
|
-
var _a, _b, _c, _d;
|
|
47
46
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
var _a, _b;
|
|
48
48
|
const sts = new client_sts_1.STS({
|
|
49
49
|
credentials: p.originCreds,
|
|
50
50
|
region: p.targetRegion,
|
|
@@ -59,9 +59,9 @@ function getApplicationCreds(p) {
|
|
|
59
59
|
(0, log_1.error)('bad assume saml role', ret);
|
|
60
60
|
throw new Error('bad assume saml role');
|
|
61
61
|
}
|
|
62
|
-
if (!((_b = ret
|
|
63
|
-
!
|
|
64
|
-
!
|
|
62
|
+
if (!((_b = ret.Credentials) === null || _b === void 0 ? void 0 : _b.AccessKeyId) ||
|
|
63
|
+
!ret.Credentials.SecretAccessKey ||
|
|
64
|
+
!ret.Credentials.SessionToken) {
|
|
65
65
|
throw new Error('no creds');
|
|
66
66
|
}
|
|
67
67
|
return Object.assign(Object.assign({}, p.originCreds), { region: p.targetRegion, accessKeyId: ret.Credentials.AccessKeyId, secretAccessKey: ret.Credentials.SecretAccessKey, sessionToken: ret.Credentials.SessionToken });
|
|
@@ -69,8 +69,8 @@ function getApplicationCreds(p) {
|
|
|
69
69
|
}
|
|
70
70
|
exports.getApplicationCreds = getApplicationCreds;
|
|
71
71
|
function directStsAssume(p) {
|
|
72
|
-
var _a, _b, _c, _d;
|
|
73
72
|
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
var _a, _b;
|
|
74
74
|
const role = yield (0, sso_1.getAssumedRole)({
|
|
75
75
|
accessToken: p.credentials.accessToken,
|
|
76
76
|
accountId: p.metadata.AccountId,
|
|
@@ -87,9 +87,9 @@ function directStsAssume(p) {
|
|
|
87
87
|
if (((_a = ar.$metadata.httpStatusCode) !== null && _a !== void 0 ? _a : 500) >= 400) {
|
|
88
88
|
throw new Error('assume role error' + JSON.stringify(ar, null, 2));
|
|
89
89
|
}
|
|
90
|
-
if (!((_b = ar
|
|
91
|
-
!
|
|
92
|
-
!
|
|
90
|
+
if (!((_b = ar.Credentials) === null || _b === void 0 ? void 0 : _b.AccessKeyId) ||
|
|
91
|
+
!ar.Credentials.SecretAccessKey ||
|
|
92
|
+
!ar.Credentials.SessionToken) {
|
|
93
93
|
throw new Error('no creds');
|
|
94
94
|
}
|
|
95
95
|
return Object.assign(Object.assign({}, p.credentials), { region: p.targetRegion, accessKeyId: ar.Credentials.AccessKeyId, secretAccessKey: ar.Credentials.SecretAccessKey, sessionToken: ar.Credentials.SessionToken });
|
package/dist/helpers/version.js
CHANGED
|
@@ -38,7 +38,7 @@ const getUpstreamVersion = () => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
38
38
|
try {
|
|
39
39
|
const r = yield (0, node_fetch_1.default)('https://api.github.com/repos/andreigec/ag-awsauth/tags', { headers: { Accept: 'application/json' } });
|
|
40
40
|
const tags = (yield r.json());
|
|
41
|
-
return (_a = tags
|
|
41
|
+
return (_a = tags[0]) === null || _a === void 0 ? void 0 : _a.name;
|
|
42
42
|
}
|
|
43
43
|
catch (e) {
|
|
44
44
|
(0, log_1.warn)(`error getting upstream version:` + e.message);
|
package/dist/index.js
CHANGED
|
@@ -67,7 +67,7 @@ function main(args) {
|
|
|
67
67
|
return;
|
|
68
68
|
}
|
|
69
69
|
let credentials = yield (0, sso_1.tryExistingCredentials)();
|
|
70
|
-
if (!(credentials === null || credentials === void 0 ? void 0 : credentials.accessToken) || !
|
|
70
|
+
if (!(credentials === null || credentials === void 0 ? void 0 : credentials.accessToken) || !credentials.ssoAuthn) {
|
|
71
71
|
(0, log_1.info)('no creds, get access token through manual sign in');
|
|
72
72
|
credentials = yield (0, oidc_1.requestMFA)({
|
|
73
73
|
identityCenterRegion: config_1.identityCenterRegion,
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"author": "andrei gec (andreigec@hotmail.com)",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"private": false,
|
|
8
|
-
"version": "0.0.
|
|
8
|
+
"version": "0.0.249",
|
|
9
9
|
"preferGlobal": true,
|
|
10
10
|
"scripts": {
|
|
11
11
|
"format": "eslint --ext .ts,.tsx src --fix",
|
|
@@ -25,25 +25,25 @@
|
|
|
25
25
|
"LICENSE.md"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aws-sdk/client-sso": "3.
|
|
29
|
-
"@aws-sdk/client-sso-oidc": "3.
|
|
30
|
-
"@aws-sdk/client-sts": "3.
|
|
31
|
-
"@aws-sdk/shared-ini-file-loader": "3.
|
|
32
|
-
"ag-common": "0.0.
|
|
28
|
+
"@aws-sdk/client-sso": "3.590.0",
|
|
29
|
+
"@aws-sdk/client-sso-oidc": "3.590.0",
|
|
30
|
+
"@aws-sdk/client-sts": "3.590.0",
|
|
31
|
+
"@aws-sdk/shared-ini-file-loader": "^3.374.0",
|
|
32
|
+
"ag-common": "0.0.711",
|
|
33
33
|
"cli-select": "1.1.2",
|
|
34
|
-
"dotenv": "16.4.
|
|
34
|
+
"dotenv": "16.4.5",
|
|
35
35
|
"envfile": "7.1.0",
|
|
36
|
-
"eslint-config-e7npm": "0.0.
|
|
37
|
-
"ini": "4.1.
|
|
36
|
+
"eslint-config-e7npm": "0.0.105",
|
|
37
|
+
"ini": "4.1.3",
|
|
38
38
|
"node-fetch": "2.7.0",
|
|
39
|
-
"puppeteer": "
|
|
39
|
+
"puppeteer": "22.10.0",
|
|
40
40
|
"readline-sync": "1.4.10",
|
|
41
|
-
"typescript": "5.
|
|
41
|
+
"typescript": "5.4.5",
|
|
42
42
|
"yargs": "17.7.2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/ini": "4.1.0",
|
|
46
|
-
"@types/node": "20.
|
|
46
|
+
"@types/node": "20.14.1",
|
|
47
47
|
"@types/node-fetch": "2.6.11",
|
|
48
48
|
"@types/readline-sync": "1.4.8",
|
|
49
49
|
"@types/yargs": "17.0.32"
|