@cloud-copilot/iam-lens 0.1.1 → 0.1.3
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/cjs/accounts.d.ts +3 -0
- package/dist/cjs/accounts.d.ts.map +1 -0
- package/dist/cjs/accounts.js +8 -0
- package/dist/cjs/accounts.js.map +1 -0
- package/dist/cjs/collect/client.d.ts +238 -0
- package/dist/cjs/collect/client.d.ts.map +1 -0
- package/dist/cjs/collect/client.js +459 -0
- package/dist/cjs/collect/client.js.map +1 -0
- package/dist/cjs/collect/collect.d.ts +18 -0
- package/dist/cjs/collect/collect.d.ts.map +1 -0
- package/dist/cjs/collect/collect.js +26 -0
- package/dist/cjs/collect/collect.js.map +1 -0
- package/dist/cjs/principals.d.ts +40 -0
- package/dist/cjs/principals.d.ts.map +1 -0
- package/dist/cjs/principals.js +71 -0
- package/dist/cjs/principals.js.map +1 -0
- package/dist/cjs/resources.d.ts +19 -0
- package/dist/cjs/resources.d.ts.map +1 -0
- package/dist/cjs/resources.js +43 -0
- package/dist/cjs/resources.js.map +1 -0
- package/dist/cjs/util/arn.d.ts +26 -0
- package/dist/cjs/util/arn.d.ts.map +1 -0
- package/dist/cjs/util/arn.js +68 -0
- package/dist/cjs/util/arn.js.map +1 -0
- package/dist/esm/accounts.d.ts +3 -0
- package/dist/esm/accounts.d.ts.map +1 -0
- package/dist/esm/accounts.js +5 -0
- package/dist/esm/accounts.js.map +1 -0
- package/dist/esm/collect/client.d.ts +238 -0
- package/dist/esm/collect/client.d.ts.map +1 -0
- package/dist/esm/collect/client.js +454 -0
- package/dist/esm/collect/client.js.map +1 -0
- package/dist/esm/collect/collect.d.ts +18 -0
- package/dist/esm/collect/collect.d.ts.map +1 -0
- package/dist/esm/collect/collect.js +22 -0
- package/dist/esm/collect/collect.js.map +1 -0
- package/dist/esm/principals.d.ts +40 -0
- package/dist/esm/principals.d.ts.map +1 -0
- package/dist/esm/principals.js +66 -0
- package/dist/esm/principals.js.map +1 -0
- package/dist/esm/resources.d.ts +19 -0
- package/dist/esm/resources.d.ts.map +1 -0
- package/dist/esm/resources.js +39 -0
- package/dist/esm/resources.js.map +1 -0
- package/dist/esm/util/arn.d.ts +26 -0
- package/dist/esm/util/arn.d.ts.map +1 -0
- package/dist/esm/util/arn.js +64 -0
- package/dist/esm/util/arn.js.map +1 -0
- package/package.json +6 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { splitArnParts } from './util/arn.js';
|
|
2
|
+
/**
|
|
3
|
+
* Get the account ID for a given resource ARN. Lookup index if necessary to find the account ID.
|
|
4
|
+
*
|
|
5
|
+
* @param collectClient the IAM collect client to use for retrieving the account ID
|
|
6
|
+
* @param resourceArn the ARN of the resource to get the account ID for
|
|
7
|
+
* @returns the account ID for the specified resource, or undefined if not found
|
|
8
|
+
*/
|
|
9
|
+
export async function getAccountIdForResource(collectClient, resourceArn) {
|
|
10
|
+
const arnParts = splitArnParts(resourceArn);
|
|
11
|
+
let accountId = arnParts.accountId;
|
|
12
|
+
if (accountId) {
|
|
13
|
+
return accountId;
|
|
14
|
+
}
|
|
15
|
+
if (arnParts.service === 's3' && arnParts.resourceType === '') {
|
|
16
|
+
const bucketName = arnParts.resourcePath;
|
|
17
|
+
return collectClient.getAccountIdForBucket(bucketName);
|
|
18
|
+
}
|
|
19
|
+
else if (arnParts.service === 'apigateway' && arnParts.resourceType === 'restapis') {
|
|
20
|
+
const apiId = arnParts.resourcePath;
|
|
21
|
+
return collectClient.getAccountIdForRestApi(apiId);
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Get the resource control policies (RCPs) for a given resource ARN.
|
|
27
|
+
*
|
|
28
|
+
* @param collectClient the IAM collect client to use for retrieving RCPs
|
|
29
|
+
* @param resourceArn the ARN of the resource to get RCPs for
|
|
30
|
+
* @returns an array of resource control policies for the specified resource
|
|
31
|
+
*/
|
|
32
|
+
export async function getRcpsForResource(collectClient, resourceArn) {
|
|
33
|
+
const accountId = await getAccountIdForResource(collectClient, resourceArn);
|
|
34
|
+
if (!accountId) {
|
|
35
|
+
throw new Error(`Unable to determine account ID for resource ARN: ${resourceArn}`);
|
|
36
|
+
}
|
|
37
|
+
return collectClient.getRcpHierarchyForAccount(accountId);
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/resources.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAE7C;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,aAA+B,EAC/B,WAAmB;IAEnB,MAAM,QAAQ,GAAG,aAAa,CAAC,WAAW,CAAC,CAAA;IAC3C,IAAI,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAA;IAClC,IAAI,SAAS,EAAE,CAAC;QACd,OAAO,SAAS,CAAA;IAClB,CAAC;IACD,IAAI,QAAQ,CAAC,OAAO,KAAK,IAAI,IAAI,QAAQ,CAAC,YAAY,KAAK,EAAE,EAAE,CAAC;QAC9D,MAAM,UAAU,GAAG,QAAQ,CAAC,YAAa,CAAA;QACzC,OAAO,aAAa,CAAC,qBAAqB,CAAC,UAAU,CAAC,CAAA;IACxD,CAAC;SAAM,IAAI,QAAQ,CAAC,OAAO,KAAK,YAAY,IAAI,QAAQ,CAAC,YAAY,KAAK,UAAU,EAAE,CAAC;QACrF,MAAM,KAAK,GAAG,QAAQ,CAAC,YAAa,CAAA;QACpC,OAAO,aAAa,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAA;IACpD,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,aAA+B,EAC/B,WAAmB;IAEnB,MAAM,SAAS,GAAG,MAAM,uBAAuB,CAAC,aAAa,EAAE,WAAW,CAAC,CAAA;IAC3E,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,oDAAoD,WAAW,EAAE,CAAC,CAAA;IACpF,CAAC;IACD,OAAO,aAAa,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAA;AAC3D,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface ArnParts {
|
|
2
|
+
partition: string | undefined;
|
|
3
|
+
service: string | undefined;
|
|
4
|
+
region: string | undefined;
|
|
5
|
+
accountId: string | undefined;
|
|
6
|
+
resource: string | undefined;
|
|
7
|
+
resourceType: string | undefined;
|
|
8
|
+
resourcePath: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Split an ARN into its parts
|
|
12
|
+
*
|
|
13
|
+
* @param arn the arn to split
|
|
14
|
+
* @returns the parts of the ARN
|
|
15
|
+
*/
|
|
16
|
+
export declare function splitArnParts(arn: string): ArnParts;
|
|
17
|
+
/**
|
|
18
|
+
* Get the product/id segments of the resource portion of an ARN.
|
|
19
|
+
* The first segment is the product segment and the second segment is the resource id segment.
|
|
20
|
+
* This could be split by a colon or a slash, so it checks for both. It also checks for S3 buckets/objects.
|
|
21
|
+
*
|
|
22
|
+
* @param resource The resource to get the resource segments. Must be an ARN resource.
|
|
23
|
+
* @returns a tuple with the first segment being the product segment (without the separator) and the second segment being the resource id.
|
|
24
|
+
*/
|
|
25
|
+
export declare function getResourceSegments(service: string, accountId: string, region: string, resourceString: string): [string, string];
|
|
26
|
+
//# sourceMappingURL=arn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arn.d.ts","sourceRoot":"","sources":["../../../src/util/arn.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,QAAQ;IACvB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IAC3B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,SAAS,EAAE,MAAM,GAAG,SAAS,CAAA;IAC7B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;IAChC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAA;CACjC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,QAAQ,CAkBnD;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,GACrB,CAAC,MAAM,EAAE,MAAM,CAAC,CA+BlB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// Copied from https://github.com/cloud-copilot/iam-simulate/blob/main/src/util.ts
|
|
2
|
+
/**
|
|
3
|
+
* Split an ARN into its parts
|
|
4
|
+
*
|
|
5
|
+
* @param arn the arn to split
|
|
6
|
+
* @returns the parts of the ARN
|
|
7
|
+
*/
|
|
8
|
+
export function splitArnParts(arn) {
|
|
9
|
+
const parts = arn.split(':');
|
|
10
|
+
const partition = parts.at(1);
|
|
11
|
+
const service = parts.at(2);
|
|
12
|
+
const region = parts.at(3);
|
|
13
|
+
const accountId = parts.at(4);
|
|
14
|
+
const resource = parts.slice(5).join(':');
|
|
15
|
+
const [resourceType, resourcePath] = getResourceSegments(service, accountId, region, resource);
|
|
16
|
+
return {
|
|
17
|
+
partition,
|
|
18
|
+
service,
|
|
19
|
+
region,
|
|
20
|
+
accountId,
|
|
21
|
+
resource,
|
|
22
|
+
resourceType,
|
|
23
|
+
resourcePath
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get the product/id segments of the resource portion of an ARN.
|
|
28
|
+
* The first segment is the product segment and the second segment is the resource id segment.
|
|
29
|
+
* This could be split by a colon or a slash, so it checks for both. It also checks for S3 buckets/objects.
|
|
30
|
+
*
|
|
31
|
+
* @param resource The resource to get the resource segments. Must be an ARN resource.
|
|
32
|
+
* @returns a tuple with the first segment being the product segment (without the separator) and the second segment being the resource id.
|
|
33
|
+
*/
|
|
34
|
+
export function getResourceSegments(service, accountId, region, resourceString) {
|
|
35
|
+
// This is terrible, and I hate it
|
|
36
|
+
if ((service === 's3' && accountId === '' && region === '') ||
|
|
37
|
+
service === 'sns' ||
|
|
38
|
+
service === 'sqs') {
|
|
39
|
+
return ['', resourceString];
|
|
40
|
+
}
|
|
41
|
+
if (resourceString.startsWith('/')) {
|
|
42
|
+
resourceString = resourceString.slice(1);
|
|
43
|
+
}
|
|
44
|
+
const slashIndex = resourceString.indexOf('/');
|
|
45
|
+
const colonIndex = resourceString.indexOf(':');
|
|
46
|
+
let splitIndex = slashIndex;
|
|
47
|
+
if (slashIndex != -1 && colonIndex != -1) {
|
|
48
|
+
splitIndex = Math.min(slashIndex, colonIndex) + 1;
|
|
49
|
+
}
|
|
50
|
+
else if (slashIndex == -1 && colonIndex == -1) {
|
|
51
|
+
splitIndex = resourceString.length + 1;
|
|
52
|
+
}
|
|
53
|
+
else if (colonIndex == -1) {
|
|
54
|
+
splitIndex = slashIndex + 1;
|
|
55
|
+
}
|
|
56
|
+
else if (slashIndex == -1) {
|
|
57
|
+
splitIndex = colonIndex + 1;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
throw new Error(`Unable to split resource ${resourceString}`);
|
|
61
|
+
}
|
|
62
|
+
return [resourceString.slice(0, splitIndex - 1), resourceString.slice(splitIndex)];
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=arn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arn.js","sourceRoot":"","sources":["../../../src/util/arn.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAYlF;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,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AA;IAC3B,IAAI,UAAU,IAAI,CAAC,CAAC,IAAI,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC;QACzC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,UAAU,CAAC,GAAG,CAAC,CAAA;IACnD,CAAC;SAAM,IAAI,UAAU,IAAI,CAAC,CAAC,IAAI,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC;QAChD,UAAU,GAAG,cAAc,CAAC,MAAM,GAAG,CAAC,CAAA;IACxC,CAAC;SAAM,IAAI,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC;QAC5B,UAAU,GAAG,UAAU,GAAG,CAAC,CAAA;IAC7B,CAAC;SAAM,IAAI,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC;QAC5B,UAAU,GAAG,UAAU,GAAG,CAAC,CAAA;IAC7B,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,4BAA4B,cAAc,EAAE,CAAC,CAAA;IAC/D,CAAC;IAED,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAA;AACpF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloud-copilot/iam-lens",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Visibility in IAM in and across AWS accounts",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aws",
|
|
@@ -105,5 +105,10 @@
|
|
|
105
105
|
}
|
|
106
106
|
]
|
|
107
107
|
]
|
|
108
|
+
},
|
|
109
|
+
"dependencies": {
|
|
110
|
+
"@cloud-copilot/iam-collect": "^0.1.63",
|
|
111
|
+
"@cloud-copilot/iam-policy": "^0.1.24",
|
|
112
|
+
"@cloud-copilot/iam-simulate": "^0.1.35"
|
|
108
113
|
}
|
|
109
114
|
}
|