@prism-d1/cli 1.0.95 → 1.0.96
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/src/commands/bedrock-protection/scan-account.d.ts.map +1 -1
- package/dist/src/commands/bedrock-protection/scan-account.js +12 -10
- package/dist/src/commands/bedrock-protection/scan-account.js.map +1 -1
- package/dist/src/commands/bedrock-protection/scan-org.d.ts +23 -0
- package/dist/src/commands/bedrock-protection/scan-org.d.ts.map +1 -0
- package/dist/src/commands/bedrock-protection/scan-org.js +328 -0
- package/dist/src/commands/bedrock-protection/scan-org.js.map +1 -0
- package/dist/src/utils/audit-bedrock.d.ts +6 -5
- package/dist/src/utils/audit-bedrock.d.ts.map +1 -1
- package/dist/src/utils/audit-bedrock.js +13 -13
- package/dist/src/utils/audit-bedrock.js.map +1 -1
- package/dist/src/utils/audit-iam.d.ts +5 -4
- package/dist/src/utils/audit-iam.d.ts.map +1 -1
- package/dist/src/utils/audit-iam.js +13 -13
- package/dist/src/utils/audit-iam.js.map +1 -1
- package/dist/src/utils/audit-org.d.ts +80 -0
- package/dist/src/utils/audit-org.d.ts.map +1 -0
- package/dist/src/utils/audit-org.js +304 -0
- package/dist/src/utils/audit-org.js.map +1 -0
- package/dist/src/utils/aws.d.ts +33 -2
- package/dist/src/utils/aws.d.ts.map +1 -1
- package/dist/src/utils/aws.js +47 -5
- package/dist/src/utils/aws.js.map +1 -1
- package/dist/src/utils/exec.d.ts +12 -1
- package/dist/src/utils/exec.d.ts.map +1 -1
- package/dist/src/utils/exec.js +23 -2
- package/dist/src/utils/exec.js.map +1 -1
- package/package.json +1 -1
package/dist/src/utils/aws.d.ts
CHANGED
|
@@ -5,6 +5,23 @@
|
|
|
5
5
|
* exposed to shell interpretation even though callers pass a user-supplied
|
|
6
6
|
* --profile and --region.
|
|
7
7
|
*/
|
|
8
|
+
/**
|
|
9
|
+
* Where an AWS call should be made: a named CLI profile, or temporary
|
|
10
|
+
* credentials from an assumed role.
|
|
11
|
+
*
|
|
12
|
+
* Both are carried in one object so every check function is agnostic about how
|
|
13
|
+
* the caller authenticated. `scan-account` supplies a profile; `scan-org`
|
|
14
|
+
* supplies assumed-role credentials per member account. Credentials travel in
|
|
15
|
+
* the child process environment rather than being written to `~/.aws/config`,
|
|
16
|
+
* so nothing is persisted and the assumed role cannot leak into a later call.
|
|
17
|
+
*/
|
|
18
|
+
export interface AwsTarget {
|
|
19
|
+
/** AWS CLI profile name. */
|
|
20
|
+
profile?: string;
|
|
21
|
+
/** Temporary credentials injected into the child environment. A key mapped
|
|
22
|
+
* to undefined is removed from it. */
|
|
23
|
+
env?: Record<string, string | undefined>;
|
|
24
|
+
}
|
|
8
25
|
export interface AwsResult {
|
|
9
26
|
ok: boolean;
|
|
10
27
|
json: any;
|
|
@@ -21,7 +38,21 @@ export interface AwsResult {
|
|
|
21
38
|
* precisely the accounts that most need auditing. Empty output is normalised to
|
|
22
39
|
* {} here and interpreted by each individual check.
|
|
23
40
|
*/
|
|
24
|
-
export declare function aws(args: string[],
|
|
41
|
+
export declare function aws(args: string[], target?: AwsTarget): AwsResult;
|
|
42
|
+
/**
|
|
43
|
+
* Assume a role and return credentials as an env fragment, or an error string.
|
|
44
|
+
*
|
|
45
|
+
* Deliberately returns the failure rather than throwing: at org scale a role
|
|
46
|
+
* that cannot be assumed is an expected condition (an account onboarded without
|
|
47
|
+
* the role, an SCP denying it), and the caller must surface that account as
|
|
48
|
+
* INDETERMINATE rather than dropping it. A silently skipped account is exactly
|
|
49
|
+
* how an org audit ends up reporting on a subset while looking complete.
|
|
50
|
+
*/
|
|
51
|
+
export declare function assumeRole(accountId: string, roleName: string, sessionName: string, durationSeconds: number, from?: AwsTarget, region?: string): {
|
|
52
|
+
env: Record<string, string | undefined>;
|
|
53
|
+
} | {
|
|
54
|
+
error: string;
|
|
55
|
+
};
|
|
25
56
|
/**
|
|
26
57
|
* Resolve the caller's account id, or print guidance and return null.
|
|
27
58
|
*
|
|
@@ -29,7 +60,7 @@ export declare function aws(args: string[], profile?: string): AwsResult;
|
|
|
29
60
|
* --profile fails in the CLI's own config layer and never reaches the service,
|
|
30
61
|
* so fall back to its stderr rather than reporting "unknown error".
|
|
31
62
|
*/
|
|
32
|
-
export declare function resolveAccount(
|
|
63
|
+
export declare function resolveAccount(target?: AwsTarget): string | null;
|
|
33
64
|
export declare function daysSince(iso: string): number | null;
|
|
34
65
|
export declare const PROFILE_OPTION: {
|
|
35
66
|
flags: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws.d.ts","sourceRoot":"","sources":["../../../src/utils/aws.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,EAAE,GAAG,CAAC;IACV,+EAA+E;IAC/E,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,
|
|
1
|
+
{"version":3,"file":"aws.d.ts","sourceRoot":"","sources":["../../../src/utils/aws.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;;;;GASG;AACH,MAAM,WAAW,SAAS;IACxB,4BAA4B;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;2CACuC;IACvC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,EAAE,GAAG,CAAC;IACV,+EAA+E;IAC/E,SAAS,EAAE,MAAM,CAAC;IAClB,2DAA2D;IAC3D,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;;;;;;GAOG;AACH,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,EAAE,SAAS,GAAG,SAAS,CAejE;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,EACvB,IAAI,CAAC,EAAE,SAAS,EAChB,MAAM,CAAC,EAAE,MAAM,GACd;IAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAiCjE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAShE;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIpD;AAED,eAAO,MAAM,cAAc;;;CAG1B,CAAC"}
|
package/dist/src/utils/aws.js
CHANGED
|
@@ -14,9 +14,9 @@ import { run } from './exec.js';
|
|
|
14
14
|
* precisely the accounts that most need auditing. Empty output is normalised to
|
|
15
15
|
* {} here and interpreted by each individual check.
|
|
16
16
|
*/
|
|
17
|
-
export function aws(args,
|
|
18
|
-
const argv = profile ? [...args, '--profile', profile] : args;
|
|
19
|
-
const res = run('aws', [...argv, '--output', 'json']);
|
|
17
|
+
export function aws(args, target) {
|
|
18
|
+
const argv = target?.profile ? [...args, '--profile', target.profile] : args;
|
|
19
|
+
const res = run('aws', [...argv, '--output', 'json'], target?.env);
|
|
20
20
|
const body = (res.stdout || '').trim();
|
|
21
21
|
if (!res.ok) {
|
|
22
22
|
const m = /An error occurred \(([A-Za-z0-9.]+)\)/.exec(res.stderr || '');
|
|
@@ -31,6 +31,48 @@ export function aws(args, profile) {
|
|
|
31
31
|
return { ok: false, json: null, errorCode: 'UnparseableResponse', raw: body };
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Assume a role and return credentials as an env fragment, or an error string.
|
|
36
|
+
*
|
|
37
|
+
* Deliberately returns the failure rather than throwing: at org scale a role
|
|
38
|
+
* that cannot be assumed is an expected condition (an account onboarded without
|
|
39
|
+
* the role, an SCP denying it), and the caller must surface that account as
|
|
40
|
+
* INDETERMINATE rather than dropping it. A silently skipped account is exactly
|
|
41
|
+
* how an org audit ends up reporting on a subset while looking complete.
|
|
42
|
+
*/
|
|
43
|
+
export function assumeRole(accountId, roleName, sessionName, durationSeconds, from, region) {
|
|
44
|
+
const res = aws([
|
|
45
|
+
'sts', 'assume-role',
|
|
46
|
+
'--role-arn', `arn:aws:iam::${accountId}:role/${roleName}`,
|
|
47
|
+
'--role-session-name', sessionName,
|
|
48
|
+
'--duration-seconds', String(durationSeconds),
|
|
49
|
+
], from);
|
|
50
|
+
if (!res.ok) {
|
|
51
|
+
const reason = res.errorCode
|
|
52
|
+
|| (res.raw.split('\n').map((l) => l.trim()).filter(Boolean).pop() ?? 'unknown error');
|
|
53
|
+
return { error: reason };
|
|
54
|
+
}
|
|
55
|
+
const c = res.json?.Credentials;
|
|
56
|
+
if (!c?.AccessKeyId || !c?.SecretAccessKey || !c?.SessionToken) {
|
|
57
|
+
return { error: 'assume-role returned no usable credentials' };
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
env: {
|
|
61
|
+
AWS_ACCESS_KEY_ID: c.AccessKeyId,
|
|
62
|
+
AWS_SECRET_ACCESS_KEY: c.SecretAccessKey,
|
|
63
|
+
AWS_SESSION_TOKEN: c.SessionToken,
|
|
64
|
+
// REMOVED, not blanked. A profile left in the ambient environment takes
|
|
65
|
+
// precedence over the injected keys and would silently audit the WRONG
|
|
66
|
+
// account -- the worst failure available here, since every finding would
|
|
67
|
+
// be misattributed. Blanking instead of removing breaks the CLI outright.
|
|
68
|
+
AWS_PROFILE: undefined,
|
|
69
|
+
AWS_DEFAULT_PROFILE: undefined,
|
|
70
|
+
// The unset profile also took its region with it, so pin one explicitly
|
|
71
|
+
// rather than depending on whatever the CLI can still resolve.
|
|
72
|
+
...(region ? { AWS_REGION: region, AWS_DEFAULT_REGION: region } : {}),
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
34
76
|
/**
|
|
35
77
|
* Resolve the caller's account id, or print guidance and return null.
|
|
36
78
|
*
|
|
@@ -38,8 +80,8 @@ export function aws(args, profile) {
|
|
|
38
80
|
* --profile fails in the CLI's own config layer and never reaches the service,
|
|
39
81
|
* so fall back to its stderr rather than reporting "unknown error".
|
|
40
82
|
*/
|
|
41
|
-
export function resolveAccount(
|
|
42
|
-
const who = aws(['sts', 'get-caller-identity'],
|
|
83
|
+
export function resolveAccount(target) {
|
|
84
|
+
const who = aws(['sts', 'get-caller-identity'], target);
|
|
43
85
|
if (who.ok)
|
|
44
86
|
return who.json?.Account ?? null;
|
|
45
87
|
const reason = who.errorCode
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws.js","sourceRoot":"","sources":["../../../src/utils/aws.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"aws.js","sourceRoot":"","sources":["../../../src/utils/aws.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AA6BhC;;;;;;;GAOG;AACH,MAAM,UAAU,GAAG,CAAC,IAAc,EAAE,MAAkB;IACpD,MAAM,IAAI,GAAG,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7E,MAAM,GAAG,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC;IACnE,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,M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IAAI,EAAE,OAAO,IAAI,IAAI,CAAC;IAE7C,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS;WACvB,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,IAAI,eAAe,CAAC,CAAC;IACzF,OAAO,CAAC,KAAK,CAAC,oCAAoC,MAAM,EAAE,CAAC,CAAC;IAC5D,OAAO,CAAC,KAAK,CAAC,uDAAuD,CAAC,CAAC;IACvE,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,GAAW;IACnC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1B,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QAAE,OAAO,IAAI,CAAC;IACjC,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC;AACnD,CAAC;AAED,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,KAAK,EAAE,kBAAkB;IACzB,WAAW,EAAE,gEAAgE;CAC9E,CAAC"}
|
package/dist/src/utils/exec.d.ts
CHANGED
|
@@ -42,10 +42,21 @@ export interface RunResult {
|
|
|
42
42
|
* latter would arrive as a single argument and the command would fail, which
|
|
43
43
|
* is a loud failure rather than a silent injection.
|
|
44
44
|
*
|
|
45
|
+
* `extraEnv` is merged over the inherited environment. It exists so a caller
|
|
46
|
+
* can hand a child process temporary STS credentials without writing them to
|
|
47
|
+
* disk or mutating this process's own environment -- the latter would leak the
|
|
48
|
+
* assumed role into every later call in the same run.
|
|
49
|
+
*
|
|
50
|
+
* A key mapped to `undefined` is REMOVED rather than set. Blanking is not
|
|
51
|
+
* equivalent: `AWS_PROFILE=''` makes the AWS CLI look for a profile literally
|
|
52
|
+
* named `()` and fail with "The config profile () could not be found", so
|
|
53
|
+
* injected credentials are ignored and every call errors. Measured, not
|
|
54
|
+
* theoretical.
|
|
55
|
+
*
|
|
45
56
|
* Never throws: a non-zero exit, a missing binary, and a signal kill all come
|
|
46
57
|
* back as `ok: false`. Callers branch on `ok` and surface `stderr`.
|
|
47
58
|
*/
|
|
48
|
-
export declare function run(file: string, args: string[]): RunResult;
|
|
59
|
+
export declare function run(file: string, args: string[], extraEnv?: Record<string, string | undefined>): RunResult;
|
|
49
60
|
/**
|
|
50
61
|
* Like run(), but inherits stdio so the child can drive the terminal.
|
|
51
62
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../../src/utils/exec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED
|
|
1
|
+
{"version":3,"file":"exec.d.ts","sourceRoot":"","sources":["../../../src/utils/exec.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAIH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,SAAS,CAmB1G;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAOpE"}
|
package/dist/src/utils/exec.js
CHANGED
|
@@ -38,15 +38,36 @@ import { execFileSync } from 'node:child_process';
|
|
|
38
38
|
* latter would arrive as a single argument and the command would fail, which
|
|
39
39
|
* is a loud failure rather than a silent injection.
|
|
40
40
|
*
|
|
41
|
+
* `extraEnv` is merged over the inherited environment. It exists so a caller
|
|
42
|
+
* can hand a child process temporary STS credentials without writing them to
|
|
43
|
+
* disk or mutating this process's own environment -- the latter would leak the
|
|
44
|
+
* assumed role into every later call in the same run.
|
|
45
|
+
*
|
|
46
|
+
* A key mapped to `undefined` is REMOVED rather than set. Blanking is not
|
|
47
|
+
* equivalent: `AWS_PROFILE=''` makes the AWS CLI look for a profile literally
|
|
48
|
+
* named `()` and fail with "The config profile () could not be found", so
|
|
49
|
+
* injected credentials are ignored and every call errors. Measured, not
|
|
50
|
+
* theoretical.
|
|
51
|
+
*
|
|
41
52
|
* Never throws: a non-zero exit, a missing binary, and a signal kill all come
|
|
42
53
|
* back as `ok: false`. Callers branch on `ok` and surface `stderr`.
|
|
43
54
|
*/
|
|
44
|
-
export function run(file, args) {
|
|
55
|
+
export function run(file, args, extraEnv) {
|
|
56
|
+
let env = process.env;
|
|
57
|
+
if (extraEnv) {
|
|
58
|
+
env = { ...process.env };
|
|
59
|
+
for (const [k, v] of Object.entries(extraEnv)) {
|
|
60
|
+
if (v === undefined)
|
|
61
|
+
delete env[k];
|
|
62
|
+
else
|
|
63
|
+
env[k] = v;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
45
66
|
try {
|
|
46
67
|
const stdout = execFileSync(file, args, {
|
|
47
68
|
encoding: 'utf8',
|
|
48
69
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
49
|
-
env
|
|
70
|
+
env,
|
|
50
71
|
}).trim();
|
|
51
72
|
return { ok: true, stdout, stderr: '' };
|
|
52
73
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exec.js","sourceRoot":"","sources":["../../../src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