@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,454 @@
|
|
|
1
|
+
import { splitArnParts } from '../util/arn.js';
|
|
2
|
+
// export interface IamCollectClient {
|
|
3
|
+
// /**
|
|
4
|
+
// * Does an account exist in the store?
|
|
5
|
+
// *
|
|
6
|
+
// * @param accountId the id of the account to check
|
|
7
|
+
// * @returns true if the account exists, false otherwise
|
|
8
|
+
// */
|
|
9
|
+
// accountExists: (accountId: string) => Promise<boolean>
|
|
10
|
+
// /**
|
|
11
|
+
// * Does a principal exist in the store?
|
|
12
|
+
// *
|
|
13
|
+
// * @param principalArn the arn of the principal to check
|
|
14
|
+
// * @returns true if the principal exists, false otherwise
|
|
15
|
+
// */
|
|
16
|
+
// principalExists: (principalArn: string) => Promise<boolean>
|
|
17
|
+
// /**
|
|
18
|
+
// * Get the org id for an account
|
|
19
|
+
// */
|
|
20
|
+
// getOrgIdForAccount: (accountId: string) => Promise<string | undefined>
|
|
21
|
+
// /**
|
|
22
|
+
// * Get the SCPs for an account and only the account
|
|
23
|
+
// *
|
|
24
|
+
// * @param accountId the id of the account to get the policies for
|
|
25
|
+
// * @returns the policies for the account
|
|
26
|
+
// */
|
|
27
|
+
// getScpsForAccount: (accountId: string) => Promise<OrgPolicy[]>
|
|
28
|
+
// /**
|
|
29
|
+
// * Get the SCP Hierarchy for an account. The first element is the root, the last element is the account itself.
|
|
30
|
+
// *
|
|
31
|
+
// * @param accountId the id of the account to get the policies for
|
|
32
|
+
// * @returns the policies for the account
|
|
33
|
+
// */
|
|
34
|
+
// getScpHierarchyForAccount(accountId: string): Promise<SimulationOrgPolicies[]>
|
|
35
|
+
// /**
|
|
36
|
+
// * Get the RCPs for an account
|
|
37
|
+
// *
|
|
38
|
+
// * @param accountId the account id to get the policies for
|
|
39
|
+
// * @returns the policies for the account
|
|
40
|
+
// */
|
|
41
|
+
// getRcpsForAccount: (accountId: string) => Promise<OrgPolicy[]>
|
|
42
|
+
// getRcpHierarchyForAccount(accountId: string): Promise<SimulationOrgPolicies[]>
|
|
43
|
+
// /**
|
|
44
|
+
// * Get the SCPs for an org unit
|
|
45
|
+
// *
|
|
46
|
+
// * @param orgUnitId the id of the org unit to get the policies for
|
|
47
|
+
// * @returns the policies for the org unit
|
|
48
|
+
// */
|
|
49
|
+
// getScpsForOrgUnit: (orgId: string, orgUnitId: string) => Promise<OrgPolicy[]>
|
|
50
|
+
// /**
|
|
51
|
+
// * Get the RCPs for an org unit
|
|
52
|
+
// *
|
|
53
|
+
// * @param orgUnitId
|
|
54
|
+
// * @returns
|
|
55
|
+
// */
|
|
56
|
+
// getRcpsForOrgUnit: (orgId: string, orgUnitId: string) => Promise<OrgPolicy[]>
|
|
57
|
+
// getAccountIdForBucket: (bucketName: string) => Promise<string | undefined>
|
|
58
|
+
// getAccountIdForRestApi: (apiArn: string) => Promise<string | undefined>
|
|
59
|
+
// getManagedPoliciesForUser(userArn: string): Promise<ManagedPolicy[]>
|
|
60
|
+
// }
|
|
61
|
+
export class IamCollectClient {
|
|
62
|
+
constructor(storageClient) {
|
|
63
|
+
this.storageClient = storageClient;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Checks if an account exists in the store.
|
|
67
|
+
* @param accountId The ID of the account to check.
|
|
68
|
+
* @returns True if the account exists, false otherwise.
|
|
69
|
+
*/
|
|
70
|
+
async accountExists(accountId) {
|
|
71
|
+
const accounts = await this.storageClient.listAccountIds();
|
|
72
|
+
return accounts.includes(accountId);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Checks if a principal exists in the store.
|
|
76
|
+
* @param principalArn The ARN of the principal to check.
|
|
77
|
+
* @returns True if the principal exists, false otherwise.
|
|
78
|
+
*/
|
|
79
|
+
async principalExists(principalArn) {
|
|
80
|
+
const accountId = splitArnParts(principalArn).accountId;
|
|
81
|
+
const principalData = await this.storageClient.getResourceMetadata(accountId, principalArn, 'metadata');
|
|
82
|
+
return !!principalData;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Gets the SCP Hierarchy for an account. The first element is the root, the last element is the account itself.
|
|
86
|
+
* @param accountId The ID of the account to get the SCP Hierarchy for.
|
|
87
|
+
* @returns The SCP Hierarchy for the account.
|
|
88
|
+
*/
|
|
89
|
+
async getScpHierarchyForAccount(accountId) {
|
|
90
|
+
return this.getOrgPolicyHierarchyForAccount(accountId, 'scps');
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Gets the policy hierarchy for an account for a given policy type.
|
|
94
|
+
* @param accountId The ID of the account.
|
|
95
|
+
* @param policyType The type of policy ('scps' or 'rcps').
|
|
96
|
+
* @returns The policy hierarchy for the account.
|
|
97
|
+
*/
|
|
98
|
+
async getOrgPolicyHierarchyForAccount(accountId, policyType) {
|
|
99
|
+
const orgId = await this.getOrgIdForAccount(accountId);
|
|
100
|
+
if (!orgId) {
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
// SCPs and RCPs do not apply to the root account
|
|
104
|
+
const orgMetadata = await this.getOrganizationMetadata(orgId);
|
|
105
|
+
if (orgMetadata.rootAccountId === accountId) {
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
const policyHierarchy = [];
|
|
109
|
+
const orgHierarchy = await this.getOrgUnitHierarchyForAccount(accountId);
|
|
110
|
+
for (const ouId of orgHierarchy) {
|
|
111
|
+
const policies = await this.getOrgPoliciesForOrgUnit(orgId, ouId, policyType);
|
|
112
|
+
policyHierarchy.push({
|
|
113
|
+
orgIdentifier: ouId,
|
|
114
|
+
policies: policies.map((p) => ({
|
|
115
|
+
name: p.arn,
|
|
116
|
+
policy: p.policy
|
|
117
|
+
}))
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
const accountPolicies = await this.getOrgPoliciesForAccount(accountId, policyType);
|
|
121
|
+
policyHierarchy.push({
|
|
122
|
+
orgIdentifier: accountId,
|
|
123
|
+
policies: accountPolicies.map((p) => ({
|
|
124
|
+
name: p.arn,
|
|
125
|
+
policy: p.policy
|
|
126
|
+
}))
|
|
127
|
+
});
|
|
128
|
+
return policyHierarchy;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Gets the OUs for an account. The first element is the root,
|
|
132
|
+
* the last element is the parent OU of the account.
|
|
133
|
+
* @param accountId The ID of the account to get the OUs for.
|
|
134
|
+
* @returns The OUs for the account.
|
|
135
|
+
*/
|
|
136
|
+
async getOrgUnitHierarchyForAccount(accountId) {
|
|
137
|
+
const orgId = await this.getOrgIdForAccount(accountId);
|
|
138
|
+
if (!orgId) {
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
141
|
+
const ouIds = [];
|
|
142
|
+
let ouId = await this.getOrgUnitIdForAccount(accountId);
|
|
143
|
+
ouIds.push(ouId);
|
|
144
|
+
while (ouId) {
|
|
145
|
+
const parentOuId = await this.getParentOrgUnitIdForOrgUnit(orgId, ouId);
|
|
146
|
+
if (parentOuId) {
|
|
147
|
+
ouIds.unshift(parentOuId);
|
|
148
|
+
}
|
|
149
|
+
ouId = parentOuId;
|
|
150
|
+
}
|
|
151
|
+
return ouIds;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Gets the org unit ID for an account.
|
|
155
|
+
* @param accountId The ID of the account.
|
|
156
|
+
* @returns The org unit ID for the account, or undefined if not found.
|
|
157
|
+
*/
|
|
158
|
+
async getOrgUnitIdForAccount(accountId) {
|
|
159
|
+
const orgId = await this.getOrgIdForAccount(accountId);
|
|
160
|
+
if (!orgId) {
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
const accounts = await this.getAccountDataForOrg(orgId);
|
|
164
|
+
return accounts[accountId].ou;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Gets the parent org unit ID for a given org unit.
|
|
168
|
+
* @param orgId The ID of the organization.
|
|
169
|
+
* @param ouId The ID of the org unit.
|
|
170
|
+
* @returns The parent org unit ID, or undefined if not found.
|
|
171
|
+
*/
|
|
172
|
+
async getParentOrgUnitIdForOrgUnit(orgId, ouId) {
|
|
173
|
+
const ouData = await this.getOrgUnitsDataForOrg(orgId);
|
|
174
|
+
const ou = ouData[ouId];
|
|
175
|
+
return ou.parent;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Gets the SCPs for an account.
|
|
179
|
+
* @param accountId The ID of the account.
|
|
180
|
+
* @returns The SCPs for the account.
|
|
181
|
+
*/
|
|
182
|
+
async getScpsForAccount(accountId) {
|
|
183
|
+
return this.getOrgPoliciesForAccount(accountId, 'scps');
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Gets the org policies for an account for a given policy type.
|
|
187
|
+
* @param accountId The ID of the account.
|
|
188
|
+
* @param policyType The type of policy ('scps' or 'rcps').
|
|
189
|
+
* @returns The org policies for the account.
|
|
190
|
+
*/
|
|
191
|
+
async getOrgPoliciesForAccount(accountId, policyType) {
|
|
192
|
+
const orgId = await this.getOrgIdForAccount(accountId);
|
|
193
|
+
if (!orgId) {
|
|
194
|
+
return [];
|
|
195
|
+
}
|
|
196
|
+
const accounts = await this.getAccountDataForOrg(orgId);
|
|
197
|
+
const orgInformation = accounts[accountId];
|
|
198
|
+
const policyArns = orgInformation[policyType];
|
|
199
|
+
const policies = [];
|
|
200
|
+
for (const policyArn of policyArns) {
|
|
201
|
+
const policyInfo = await this.getOrgPolicy(orgId, policyType, policyArn);
|
|
202
|
+
policies.push(policyInfo);
|
|
203
|
+
}
|
|
204
|
+
return policies;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Gets the account data for an organization.
|
|
208
|
+
* @param orgId The ID of the organization.
|
|
209
|
+
* @returns The account data for the organization.
|
|
210
|
+
*/
|
|
211
|
+
async getAccountDataForOrg(orgId) {
|
|
212
|
+
return this.storageClient.getOrganizationMetadata(orgId, 'accounts');
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Gets the org units data for an organization.
|
|
216
|
+
* @param orgId The ID of the organization.
|
|
217
|
+
* @returns The org units data for the organization.
|
|
218
|
+
*/
|
|
219
|
+
async getOrgUnitsDataForOrg(orgId) {
|
|
220
|
+
return this.storageClient.getOrganizationMetadata(orgId, 'ous');
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Gets a specific org policy.
|
|
224
|
+
* @param orgId The ID of the organization.
|
|
225
|
+
* @param policyType The type of policy ('scps' or 'rcps').
|
|
226
|
+
* @param policyArn The ARN of the policy.
|
|
227
|
+
* @returns The org policy.
|
|
228
|
+
*/
|
|
229
|
+
async getOrgPolicy(orgId, policyType, policyArn) {
|
|
230
|
+
const policyId = policyArn.split('/').at(-1);
|
|
231
|
+
const policyData = await this.storageClient.getOrganizationPolicyMetadata(orgId, policyType, policyId, 'metadata');
|
|
232
|
+
const policyDocument = await this.storageClient.getOrganizationPolicyMetadata(orgId, policyType, policyId, 'policy');
|
|
233
|
+
return {
|
|
234
|
+
arn: policyData.arn,
|
|
235
|
+
name: policyData.name,
|
|
236
|
+
policy: policyDocument
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Gets the RCPs for an account.
|
|
241
|
+
* @param accountId The ID of the account.
|
|
242
|
+
* @returns The RCPs for the account.
|
|
243
|
+
*/
|
|
244
|
+
async getRcpsForAccount(accountId) {
|
|
245
|
+
return this.getOrgPoliciesForAccount(accountId, 'rcps');
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Gets the RCP hierarchy for an account.
|
|
249
|
+
* @param accountId The ID of the account.
|
|
250
|
+
* @returns The RCP hierarchy for the account.
|
|
251
|
+
*/
|
|
252
|
+
async getRcpHierarchyForAccount(accountId) {
|
|
253
|
+
return this.getOrgPolicyHierarchyForAccount(accountId, 'rcps');
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Gets the SCPs for an org unit.
|
|
257
|
+
* @param orgId The ID of the organization.
|
|
258
|
+
* @param orgUnitId The ID of the org unit.
|
|
259
|
+
* @returns The SCPs for the org unit.
|
|
260
|
+
*/
|
|
261
|
+
async getScpsForOrgUnit(orgId, orgUnitId) {
|
|
262
|
+
return this.getOrgPoliciesForOrgUnit(orgId, orgUnitId, 'scps');
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Gets the org policies for an org unit for a given policy type.
|
|
266
|
+
* @param orgId The ID of the organization.
|
|
267
|
+
* @param orgUnitId The ID of the org unit.
|
|
268
|
+
* @param policyType The type of policy ('scps' or 'rcps').
|
|
269
|
+
* @returns The org policies for the org unit.
|
|
270
|
+
*/
|
|
271
|
+
async getOrgPoliciesForOrgUnit(orgId, orgUnitId, policyType) {
|
|
272
|
+
const orgUnitInformation = await this.getOrgUnitsDataForOrg(orgId);
|
|
273
|
+
const orgUnit = orgUnitInformation[orgUnitId];
|
|
274
|
+
const orgPolicies = orgUnit[policyType];
|
|
275
|
+
const policies = [];
|
|
276
|
+
for (const policyArn of orgPolicies) {
|
|
277
|
+
const policyInfo = await this.getOrgPolicy(orgId, policyType, policyArn);
|
|
278
|
+
policies.push(policyInfo);
|
|
279
|
+
}
|
|
280
|
+
return policies;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Gets the RCPs for an org unit.
|
|
284
|
+
* @param orgId The ID of the organization.
|
|
285
|
+
* @param orgUnitId The ID of the org unit.
|
|
286
|
+
* @returns The RCPs for the org unit.
|
|
287
|
+
*/
|
|
288
|
+
async getRcpsForOrgUnit(orgId, orgUnitId) {
|
|
289
|
+
return this.getOrgPoliciesForOrgUnit(orgId, orgUnitId, 'rcps');
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Gets the org ID for an account.
|
|
293
|
+
* @param accountId The ID of the account.
|
|
294
|
+
* @returns The org ID for the account, or undefined if not found.
|
|
295
|
+
*/
|
|
296
|
+
async getOrgIdForAccount(accountId) {
|
|
297
|
+
const index = await this.storageClient.getIndex('accounts-to-orgs', {});
|
|
298
|
+
const accountToOrgMap = index.data;
|
|
299
|
+
return accountToOrgMap[accountId];
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Gets the account ID for a given S3 bucket name.
|
|
303
|
+
* @param bucketName The name of the bucket.
|
|
304
|
+
* @returns The account ID for the bucket, or undefined if not found.
|
|
305
|
+
*/
|
|
306
|
+
async getAccountIdForBucket(bucketName) {
|
|
307
|
+
const index = await this.storageClient.getIndex('buckets-to-accounts', {});
|
|
308
|
+
const bucketToAccountMap = index.data;
|
|
309
|
+
return bucketToAccountMap[bucketName]?.accountId;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Gets the account ID for a given API Gateway ARN.
|
|
313
|
+
* @param apiArn The ARN of the API Gateway.
|
|
314
|
+
* @returns The account ID for the API Gateway, or undefined if not found.
|
|
315
|
+
*/
|
|
316
|
+
async getAccountIdForRestApi(apiArn) {
|
|
317
|
+
const index = await this.storageClient.getIndex('apigateways-to-accounts', {});
|
|
318
|
+
const bucketToAccountMap = index.data;
|
|
319
|
+
return bucketToAccountMap[apiArn];
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Gets the managed policies attached to a user.
|
|
323
|
+
* @param userArn The ARN of the user.
|
|
324
|
+
* @returns The managed policies for the user.
|
|
325
|
+
*/
|
|
326
|
+
async getManagedPoliciesForUser(userArn) {
|
|
327
|
+
const accountId = splitArnParts(userArn).accountId;
|
|
328
|
+
const managedPolicies = await this.storageClient.getResourceMetadata(accountId, userArn, 'managed-policies', []);
|
|
329
|
+
const results = [];
|
|
330
|
+
for (const policyArn of managedPolicies) {
|
|
331
|
+
results.push(await this.getManagedPolicy(accountId, policyArn));
|
|
332
|
+
}
|
|
333
|
+
return results;
|
|
334
|
+
}
|
|
335
|
+
async getManagedPolicy(accountId, policyArn) {
|
|
336
|
+
const policyMetadata = await this.storageClient.getResourceMetadata(accountId, policyArn, 'metadata');
|
|
337
|
+
const policyDocument = await this.storageClient.getResourceMetadata(accountId, policyArn, 'policy');
|
|
338
|
+
return {
|
|
339
|
+
arn: policyMetadata.arn,
|
|
340
|
+
name: policyMetadata.name,
|
|
341
|
+
policy: policyDocument
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Gets the inline policies attached to a user.
|
|
346
|
+
* @param userArn The ARN of the user.
|
|
347
|
+
* @returns The inline policies for the user.
|
|
348
|
+
*/
|
|
349
|
+
async getInlinePoliciesForUser(userArn) {
|
|
350
|
+
const accountId = splitArnParts(userArn).accountId;
|
|
351
|
+
const inlinePolicies = await this.storageClient.getResourceMetadata(accountId, userArn, 'inline-policies', []);
|
|
352
|
+
return inlinePolicies.map((p) => ({
|
|
353
|
+
name: p.PolicyName,
|
|
354
|
+
policy: p.PolicyDocument
|
|
355
|
+
}));
|
|
356
|
+
}
|
|
357
|
+
async getIamUserMetadata(userArn) {
|
|
358
|
+
const accountId = splitArnParts(userArn).accountId;
|
|
359
|
+
// The permissions boundary is stored as a policy ARN on the user resource metadata
|
|
360
|
+
return this.storageClient.getResourceMetadata(accountId, userArn, 'metadata');
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Gets the permissions boundary policy attached to a user, if any.
|
|
364
|
+
*
|
|
365
|
+
* @param userArn The ARN of the user.
|
|
366
|
+
* @returns The permissions boundary policy as an OrgPolicy, or undefined if none is set.
|
|
367
|
+
*/
|
|
368
|
+
async getPermissionsBoundaryForUser(userArn) {
|
|
369
|
+
const accountId = splitArnParts(userArn).accountId;
|
|
370
|
+
// The permissions boundary is stored as a policy ARN on the user resource metadata
|
|
371
|
+
const userMetadata = await this.getIamUserMetadata(userArn);
|
|
372
|
+
if (!userMetadata) {
|
|
373
|
+
return undefined;
|
|
374
|
+
}
|
|
375
|
+
const permissionsBoundaryArn = userMetadata.permissionBoundary;
|
|
376
|
+
if (!permissionsBoundaryArn) {
|
|
377
|
+
return undefined;
|
|
378
|
+
}
|
|
379
|
+
return this.getManagedPolicy(accountId, permissionsBoundaryArn);
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Gets the group ARNs that the user is a member of.
|
|
383
|
+
* @param userArn The ARN of the user.
|
|
384
|
+
* @returns An array of group ARNs the user belongs to.
|
|
385
|
+
*/
|
|
386
|
+
async getGroupsForUser(userArn) {
|
|
387
|
+
const accountId = splitArnParts(userArn).accountId;
|
|
388
|
+
const groups = await this.storageClient.getResourceMetadata(accountId, userArn, 'groups', []);
|
|
389
|
+
return groups;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Gets the managed policies attached to a group.
|
|
393
|
+
*
|
|
394
|
+
* @param groupArn The ARN of the group.
|
|
395
|
+
* @returns The managed policies for the group.
|
|
396
|
+
*/
|
|
397
|
+
async getManagedPoliciesForGroup(groupArn) {
|
|
398
|
+
const accountId = splitArnParts(groupArn).accountId;
|
|
399
|
+
const managedPolicies = await this.storageClient.getResourceMetadata(accountId, groupArn, 'managed-policies', []);
|
|
400
|
+
const results = [];
|
|
401
|
+
for (const policyArn of managedPolicies) {
|
|
402
|
+
results.push(await this.getManagedPolicy(accountId, policyArn));
|
|
403
|
+
}
|
|
404
|
+
return results;
|
|
405
|
+
}
|
|
406
|
+
async getInlinePoliciesForGroup(groupArn) {
|
|
407
|
+
const accountId = splitArnParts(groupArn).accountId;
|
|
408
|
+
const inlinePolicies = await this.storageClient.getResourceMetadata(accountId, groupArn, 'inline-policies', []);
|
|
409
|
+
return inlinePolicies.map((p) => ({
|
|
410
|
+
name: p.PolicyName,
|
|
411
|
+
policy: p.PolicyDocument
|
|
412
|
+
}));
|
|
413
|
+
}
|
|
414
|
+
async getManagedPoliciesForRole(roleArn) {
|
|
415
|
+
const accountId = splitArnParts(roleArn).accountId;
|
|
416
|
+
const managedPolicies = await this.storageClient.getResourceMetadata(accountId, roleArn, 'managed-policies', []);
|
|
417
|
+
const results = [];
|
|
418
|
+
for (const policyArn of managedPolicies) {
|
|
419
|
+
results.push(await this.getManagedPolicy(accountId, policyArn));
|
|
420
|
+
}
|
|
421
|
+
return results;
|
|
422
|
+
}
|
|
423
|
+
async getInlinePoliciesForRole(roleArn) {
|
|
424
|
+
const accountId = splitArnParts(roleArn).accountId;
|
|
425
|
+
const inlinePolicies = await this.storageClient.getResourceMetadata(accountId, roleArn, 'inline-policies', []);
|
|
426
|
+
return inlinePolicies.map((p) => ({
|
|
427
|
+
name: p.PolicyName,
|
|
428
|
+
policy: p.PolicyDocument
|
|
429
|
+
}));
|
|
430
|
+
}
|
|
431
|
+
async getPermissionsBoundaryForRole(roleArn) {
|
|
432
|
+
const accountId = splitArnParts(roleArn).accountId;
|
|
433
|
+
// The permissions boundary is stored as a policy ARN on the user resource metadata
|
|
434
|
+
const roleMetadata = await this.getIamUserMetadata(roleArn);
|
|
435
|
+
if (!roleMetadata) {
|
|
436
|
+
return undefined;
|
|
437
|
+
}
|
|
438
|
+
const permissionsBoundaryArn = roleMetadata.permissionBoundary;
|
|
439
|
+
if (!permissionsBoundaryArn) {
|
|
440
|
+
return undefined;
|
|
441
|
+
}
|
|
442
|
+
return this.getManagedPolicy(accountId, permissionsBoundaryArn);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Get the metadata for an organization.
|
|
446
|
+
*
|
|
447
|
+
* @param organizationId the id of the organization
|
|
448
|
+
* @returns the metadata for the organization
|
|
449
|
+
*/
|
|
450
|
+
async getOrganizationMetadata(organizationId) {
|
|
451
|
+
return this.storageClient.getOrganizationMetadata(organizationId, 'metadata');
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/collect/client.ts"],"names":[],"mappings":"AACA,O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 -0,0 +1,18 @@
|
|
|
1
|
+
import { TopLevelConfig } from '@cloud-copilot/iam-collect';
|
|
2
|
+
import { IamCollectClient } from './client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Load IAM collect configs from the specified paths.
|
|
5
|
+
*
|
|
6
|
+
* @param configPaths the paths to the config files
|
|
7
|
+
* @returns the top-level configs
|
|
8
|
+
*/
|
|
9
|
+
export declare function loadCollectConfigs(configPaths: string[]): Promise<TopLevelConfig[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Get a collect client for the specified partition using the provided configs.
|
|
12
|
+
*
|
|
13
|
+
* @param configs the top-level configs to use for storage
|
|
14
|
+
* @param partition which partition to use (aws, aws-cn, aws-us-gov)
|
|
15
|
+
* @returns the iam-collect client to use for retrieving IAM resources
|
|
16
|
+
*/
|
|
17
|
+
export declare function getCollectClient(configs: TopLevelConfig[], partition: string): IamCollectClient;
|
|
18
|
+
//# sourceMappingURL=collect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collect.d.ts","sourceRoot":"","sources":["../../../src/collect/collect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAwC,MAAM,4BAA4B,CAAA;AACjG,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAE9C;;;;;GAKG;AACH,wBAAsB,kBAAkB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAEzF;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,gBAAgB,CAE/F"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createStorageClient, loadConfigFiles } from '@cloud-copilot/iam-collect';
|
|
2
|
+
import { IamCollectClient } from './client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Load IAM collect configs from the specified paths.
|
|
5
|
+
*
|
|
6
|
+
* @param configPaths the paths to the config files
|
|
7
|
+
* @returns the top-level configs
|
|
8
|
+
*/
|
|
9
|
+
export async function loadCollectConfigs(configPaths) {
|
|
10
|
+
return loadConfigFiles(configPaths);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get a collect client for the specified partition using the provided configs.
|
|
14
|
+
*
|
|
15
|
+
* @param configs the top-level configs to use for storage
|
|
16
|
+
* @param partition which partition to use (aws, aws-cn, aws-us-gov)
|
|
17
|
+
* @returns the iam-collect client to use for retrieving IAM resources
|
|
18
|
+
*/
|
|
19
|
+
export function getCollectClient(configs, partition) {
|
|
20
|
+
return new IamCollectClient(createStorageClient(configs, partition));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=collect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collect.js","sourceRoot":"","sources":["../../../src/collect/collect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,mBAAmB,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAA;AACjG,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAE9C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,WAAqB;IAC5D,OAAO,eAAe,CAAC,WAAW,CAAC,CAAA;AACrC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAyB,EAAE,SAAiB;IAC3E,OAAO,IAAI,gBAAgB,CAAC,mBAAmB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC,CAAA;AACtE,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AwsIamStore } from '@cloud-copilot/iam-collect';
|
|
2
|
+
import { IamCollectClient } from './collect/client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Check if a principal exists in the specified AWS IAM store.
|
|
5
|
+
*/
|
|
6
|
+
export declare function principalExists(storageClient: AwsIamStore, principalArn: string): Promise<boolean>;
|
|
7
|
+
/**
|
|
8
|
+
* Get all the IAM policies for a user, including managed and inline policies, permission boundaries, and group policies.
|
|
9
|
+
*
|
|
10
|
+
* @param collectClient the IAM collect client to use for retrieving policies
|
|
11
|
+
* @param principalArn the ARN of the user to get policies for
|
|
12
|
+
* @returns an object containing the managed policies, inline policies, permission boundary, and group policies
|
|
13
|
+
*/
|
|
14
|
+
export declare function getAllPoliciesForUser(collectClient: IamCollectClient, principalArn: string): Promise<{
|
|
15
|
+
scps: import("./collect/client.js").SimulationOrgPolicies[];
|
|
16
|
+
rcps: import("./collect/client.js").SimulationOrgPolicies[];
|
|
17
|
+
managedPolicies: import("./collect/client.js").ManagedPolicy[];
|
|
18
|
+
inlinePolicies: import("./collect/client.js").InlinePolicy[];
|
|
19
|
+
permissionBoundary: import("./collect/client.js").ManagedPolicy | undefined;
|
|
20
|
+
groupPolicies: {
|
|
21
|
+
group: string;
|
|
22
|
+
managedPolices: import("./collect/client.js").ManagedPolicy[];
|
|
23
|
+
inlinePolicies: import("./collect/client.js").InlinePolicy[];
|
|
24
|
+
}[];
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Get all the IAM policies for a role, including managed and inline policies and permission boundaries.
|
|
28
|
+
*
|
|
29
|
+
* @param collectClient the IAM collect client to use for retrieving policies
|
|
30
|
+
* @param principalArn the ARN of the role to get policies for
|
|
31
|
+
* @returns an object containing the managed policies, inline policies, and permission boundary
|
|
32
|
+
*/
|
|
33
|
+
export declare function getAllPoliciesForRole(collectClient: IamCollectClient, principalArn: string): Promise<{
|
|
34
|
+
scps: import("./collect/client.js").SimulationOrgPolicies[];
|
|
35
|
+
rcps: import("./collect/client.js").SimulationOrgPolicies[];
|
|
36
|
+
managedPolices: import("./collect/client.js").ManagedPolicy[];
|
|
37
|
+
inlinePolicies: import("./collect/client.js").InlinePolicy[];
|
|
38
|
+
permissionBoundary: import("./collect/client.js").ManagedPolicy | undefined;
|
|
39
|
+
}>;
|
|
40
|
+
//# sourceMappingURL=principals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"principals.d.ts","sourceRoot":"","sources":["../../src/principals.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAGtD;;GAEG;AACH,wBAAsB,eAAe,CACnC,aAAa,EAAE,WAAW,EAC1B,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,OAAO,CAAC,CAIlB;AAOD;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAAC,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM;;;;;;;;;;;GA2BhG;AAED;;;;;;GAMG;AACH,wBAAsB,qBAAqB,CAAC,aAAa,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM;;;;;;GAgBhG"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { splitArnParts } from './util/arn.js';
|
|
2
|
+
/**
|
|
3
|
+
* Check if a principal exists in the specified AWS IAM store.
|
|
4
|
+
*/
|
|
5
|
+
export async function principalExists(storageClient, principalArn) {
|
|
6
|
+
const accountId = splitArnParts(principalArn).accountId;
|
|
7
|
+
const principalData = await storageClient.getResourceMetadata(accountId, principalArn, 'metadata');
|
|
8
|
+
return !!principalData;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Get all the IAM policies for a user, including managed and inline policies, permission boundaries, and group policies.
|
|
12
|
+
*
|
|
13
|
+
* @param collectClient the IAM collect client to use for retrieving policies
|
|
14
|
+
* @param principalArn the ARN of the user to get policies for
|
|
15
|
+
* @returns an object containing the managed policies, inline policies, permission boundary, and group policies
|
|
16
|
+
*/
|
|
17
|
+
export async function getAllPoliciesForUser(collectClient, principalArn) {
|
|
18
|
+
const accountId = splitArnParts(principalArn).accountId;
|
|
19
|
+
const managedPolicies = await collectClient.getManagedPoliciesForUser(principalArn);
|
|
20
|
+
const inlinePolicies = await collectClient.getInlinePoliciesForUser(principalArn);
|
|
21
|
+
const permissionBoundary = await collectClient.getPermissionsBoundaryForUser(principalArn);
|
|
22
|
+
const groups = await collectClient.getGroupsForUser(principalArn);
|
|
23
|
+
const scps = await collectClient.getScpHierarchyForAccount(accountId);
|
|
24
|
+
const rcps = await collectClient.getRcpHierarchyForAccount(accountId);
|
|
25
|
+
const groupPolicies = [];
|
|
26
|
+
for (const group of groups) {
|
|
27
|
+
const groupManagedPolicies = await collectClient.getManagedPoliciesForGroup(group);
|
|
28
|
+
const groupInlinePolicies = await collectClient.getInlinePoliciesForGroup(group);
|
|
29
|
+
groupPolicies.push({
|
|
30
|
+
group,
|
|
31
|
+
managedPolices: groupManagedPolicies,
|
|
32
|
+
inlinePolicies: groupInlinePolicies
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
scps,
|
|
37
|
+
rcps,
|
|
38
|
+
managedPolicies,
|
|
39
|
+
inlinePolicies,
|
|
40
|
+
permissionBoundary,
|
|
41
|
+
groupPolicies
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get all the IAM policies for a role, including managed and inline policies and permission boundaries.
|
|
46
|
+
*
|
|
47
|
+
* @param collectClient the IAM collect client to use for retrieving policies
|
|
48
|
+
* @param principalArn the ARN of the role to get policies for
|
|
49
|
+
* @returns an object containing the managed policies, inline policies, and permission boundary
|
|
50
|
+
*/
|
|
51
|
+
export async function getAllPoliciesForRole(collectClient, principalArn) {
|
|
52
|
+
const accountId = splitArnParts(principalArn).accountId;
|
|
53
|
+
const managedPolices = await collectClient.getManagedPoliciesForRole(principalArn);
|
|
54
|
+
const inlinePolicies = await collectClient.getInlinePoliciesForRole(principalArn);
|
|
55
|
+
const permissionBoundary = await collectClient.getPermissionsBoundaryForRole(principalArn);
|
|
56
|
+
const scps = await collectClient.getScpHierarchyForAccount(accountId);
|
|
57
|
+
const rcps = await collectClient.getRcpHierarchyForAccount(accountId);
|
|
58
|
+
return {
|
|
59
|
+
scps,
|
|
60
|
+
rcps,
|
|
61
|
+
managedPolices,
|
|
62
|
+
inlinePolicies,
|
|
63
|
+
permissionBoundary
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=principals.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"principals.js","sourceRoot":"","sources":["../../src/principals.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAE7C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,aAA0B,EAC1B,YAAoB;IAEpB,MAAM,SAAS,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC,SAAU,CAAA;IACxD,MAAM,aAAa,GAAG,MAAM,aAAa,CAAC,mBAAmB,CAAC,SAAS,EAAE,YAAY,EAAE,UAAU,CAAC,CAAA;IAClG,OAAO,CAAC,CAAC,aAAa,CAAA;AACxB,CAAC;AAOD;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,aAA+B,EAAE,YAAoB;IAC/F,MAAM,SAAS,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC,SAAU,CAAA;IAExD,MAAM,eAAe,GAAG,MAAM,aAAa,CAAC,yBAAyB,CAAC,YAAY,CAAC,CAAA;IACnF,MAAM,cAAc,GAAG,MAAM,aAAa,CAAC,wBAAwB,CAAC,YAAY,CAAC,CAAA;IACjF,MAAM,kBAAkB,GAAG,MAAM,aAAa,CAAC,6BAA6B,CAAC,YAAY,CAAC,CAAA;IAC1F,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAA;IACjE,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAA;IACrE,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAA;IACrE,MAAM,aAAa,GAAG,EAAE,CAAA;IACxB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,oBAAoB,GAAG,MAAM,aAAa,CAAC,0BAA0B,CAAC,KAAK,CAAC,CAAA;QAClF,MAAM,mBAAmB,GAAG,MAAM,aAAa,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAA;QAChF,aAAa,CAAC,IAAI,CAAC;YACjB,KAAK;YACL,cAAc,EAAE,oBAAoB;YACpC,cAAc,EAAE,mBAAmB;SACpC,CAAC,CAAA;IACJ,CAAC;IACD,OAAO;QACL,IAAI;QACJ,IAAI;QACJ,eAAe;QACf,cAAc;QACd,kBAAkB;QAClB,aAAa;KACd,CAAA;AACH,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,aAA+B,EAAE,YAAoB;IAC/F,MAAM,SAAS,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC,SAAU,CAAA;IAExD,MAAM,cAAc,GAAG,MAAM,aAAa,CAAC,yBAAyB,CAAC,YAAY,CAAC,CAAA;IAClF,MAAM,cAAc,GAAG,MAAM,aAAa,CAAC,wBAAwB,CAAC,YAAY,CAAC,CAAA;IACjF,MAAM,kBAAkB,GAAG,MAAM,aAAa,CAAC,6BAA6B,CAAC,YAAY,CAAC,CAAA;IAC1F,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAA;IACrE,MAAM,IAAI,GAAG,MAAM,aAAa,CAAC,yBAAyB,CAAC,SAAS,CAAC,CAAA;IAErE,OAAO;QACL,IAAI;QACJ,IAAI;QACJ,cAAc;QACd,cAAc;QACd,kBAAkB;KACnB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Simulation } from '@cloud-copilot/iam-simulate';
|
|
2
|
+
import { IamCollectClient } from './collect/client.js';
|
|
3
|
+
/**
|
|
4
|
+
* Get the account ID for a given resource ARN. Lookup index if necessary to find the account ID.
|
|
5
|
+
*
|
|
6
|
+
* @param collectClient the IAM collect client to use for retrieving the account ID
|
|
7
|
+
* @param resourceArn the ARN of the resource to get the account ID for
|
|
8
|
+
* @returns the account ID for the specified resource, or undefined if not found
|
|
9
|
+
*/
|
|
10
|
+
export declare function getAccountIdForResource(collectClient: IamCollectClient, resourceArn: string): Promise<string | undefined>;
|
|
11
|
+
/**
|
|
12
|
+
* Get the resource control policies (RCPs) for a given resource ARN.
|
|
13
|
+
*
|
|
14
|
+
* @param collectClient the IAM collect client to use for retrieving RCPs
|
|
15
|
+
* @param resourceArn the ARN of the resource to get RCPs for
|
|
16
|
+
* @returns an array of resource control policies for the specified resource
|
|
17
|
+
*/
|
|
18
|
+
export declare function getRcpsForResource(collectClient: IamCollectClient, resourceArn: string): Promise<Simulation['resourceControlPolicies']>;
|
|
19
|
+
//# sourceMappingURL=resources.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.d.ts","sourceRoot":"","sources":["../../src/resources.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAA;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAGtD;;;;;;GAMG;AACH,wBAAsB,uBAAuB,CAC3C,aAAa,EAAE,gBAAgB,EAC/B,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAc7B;AAED;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,aAAa,EAAE,gBAAgB,EAC/B,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAC,CAMhD"}
|