Skip to content

Commit 5993fb7

Browse files
committed
Merge branch 'alpha' into feature/CG-1192
2 parents e02c6cb + f3030c2 commit 5993fb7

17 files changed

Lines changed: 271 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# [0.81.0-alpha.1](https://github.com/cloudgraphdev/cloudgraph-provider-aws/compare/0.80.0...0.81.0-alpha.1) (2022-05-04)
2+
3+
4+
### Features
5+
6+
* Add AWS IAM Access analyzer service ([cc3ae64](https://github.com/cloudgraphdev/cloudgraph-provider-aws/commit/cc3ae64366e60f915ec1f4194ebc7cccf9969576))
7+
18
# [0.80.0](https://github.com/cloudgraphdev/cloudgraph-provider-aws/compare/0.79.0...0.80.0) (2022-05-02)
29

310

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
119119
| glueJob | iamRole |
120120
| glueRegistry | |
121121
| guardDutyDetector | iamRole |
122+
| iamAccessAnalyzer | |
122123
| iamInstanceProfile | ec2, iamRole |
123124
| iamPasswordPolicy | |
124125
| iamSamlProvider | cognitoIdentityPool |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cloudgraph/cg-provider-aws",
3-
"version": "0.80.0",
3+
"version": "0.81.0-alpha.1",
44
"description": "cloud-graph provider plugin for AWS used to fetch AWS cloud data.",
55
"publishConfig": {
66
"registry": "https://registry.npmjs.org/",

src/enums/schemasMap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export default {
5656
[services.emrCluster]: 'awsEmrCluster',
5757
[services.emrInstance]: 'awsEmrInstance',
5858
[services.emrStep]: 'awsEmrStep',
59+
[services.iamAccessAnalyzer]: 'awsIamAccessAnalyzer',
5960
[services.iamGroup]: 'awsIamGroup',
6061
[services.iamOpenIdConnectProvider]: 'awsIamOpenIdConnectProvider',
6162
[services.iamPasswordPolicy]: 'awsIamPasswordPolicy',

src/enums/serviceAliases.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default {
3838
[services.glueJob]: 'glueJobs',
3939
[services.glueRegistry]: 'glueRegistries',
4040
[services.guardDutyDetector]: 'guardDutyDetectors',
41+
[services.iamAccessAnalyzer]: 'iamAccessAnalyzers',
4142
[services.iamGroup]: 'iamGroups',
4243
[services.iamOpenIdConnectProvider]: 'iamOpenIdConnectProviders',
4344
[services.iamPasswordPolicy]: 'iamPasswordPolicies',

src/enums/serviceMap.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import SES from '../services/ses'
5858
import SQS from '../services/sqs'
5959
import VPC from '../services/vpc'
6060
import ECR from '../services/ecr'
61+
import IamAccessAnalyzer from '../services/iamAccessAnalyzer'
6162
import IamGroup from '../services/iamGroup'
6263
import IamUser from '../services/iamUser'
6364
import IamRole from '../services/iamRole'
@@ -175,6 +176,7 @@ export default {
175176
[services.s3]: S3,
176177
[services.secretsManager]: SecretsManager,
177178
[services.ses]: SES,
179+
[services.iamAccessAnalyzer]: IamAccessAnalyzer,
178180
[services.iamUser]: IamUser,
179181
[services.iamGroup]: IamGroup,
180182
[services.iamRole]: IamRole,

src/enums/services.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export default {
5050
emrCluster: 'emrCluster',
5151
emrInstance: 'emrInstance',
5252
emrStep: 'emrStep',
53+
iamAccessAnalyzer: 'iamAccessAnalyzer',
5354
iamUser: 'iamUser',
5455
iamGroup: 'iamGroup',
5556
iamRole: 'iamRole',

src/properties/logger.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,4 +668,8 @@ export default {
668668
* Configuration Recorder Status
669669
*/
670670
fetchedConfigurationRecorderStatus: (num: number): string => `Fetched ${num} Configuration Recorder Status`,
671+
/**
672+
* Access Analyzers
673+
*/
674+
fetchedaccessAnalyzers: (num: number): string => `Found ${num} Access Analyzers`,
671675
}

src/services/account/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ type awsAccount implements awsOptionalService @key(fields: "id") {
5151
glueJobs: [awsGlueJob]
5252
glueRegistries: [awsGlueRegistry]
5353
guardDutyDetectors: [awsGuardDutyDetector]
54+
iamAccessAnalyzers: [awsIamAccessAnalyzer]
5455
iamGroups: [awsIamGroup]
5556
iamOpenIdConnectProviders: [awsIamOpenIdConnectProvider]
5657
iamPasswordPolicies: [awsIamPasswordPolicy]
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import CloudGraph from '@cloudgraph/sdk'
2+
import groupBy from 'lodash/groupBy'
3+
import isEmpty from 'lodash/isEmpty'
4+
import AccessAnalyzer, {
5+
ListAnalyzersRequest,
6+
ListAnalyzersResponse,
7+
AnalyzerSummary,
8+
AnalyzersList,
9+
} from 'aws-sdk/clients/accessanalyzer'
10+
11+
import { Config } from 'aws-sdk/lib/config'
12+
import { AWSError } from 'aws-sdk/lib/error'
13+
import awsLoggerText from '../../properties/logger'
14+
import { initTestEndpoint } from '../../utils'
15+
import AwsErrorLog from '../../utils/errorLog'
16+
import { TagMap } from '../../types'
17+
18+
const lt = { ...awsLoggerText }
19+
const { logger } = CloudGraph
20+
const serviceName = 'IAM Access Analyzer'
21+
const errorLog = new AwsErrorLog(serviceName)
22+
const endpoint = initTestEndpoint(serviceName)
23+
24+
const listAnalyzersData = async ({
25+
accessAnalyzer,
26+
region,
27+
nextToken: NextToken = '',
28+
}: {
29+
accessAnalyzer: AccessAnalyzer
30+
region: string
31+
nextToken?: string
32+
}): Promise<(AnalyzerSummary & { region: string })[]> =>
33+
new Promise<(AnalyzerSummary & { region: string })[]>(resolve => {
34+
let analyzerSummarytData: (AnalyzerSummary & {
35+
region: string
36+
})[] = []
37+
38+
const analyzersList: AnalyzersList = []
39+
let args: ListAnalyzersRequest = {}
40+
41+
if (NextToken) {
42+
args = { ...args, nextToken: NextToken }
43+
}
44+
45+
accessAnalyzer.listAnalyzers(
46+
args,
47+
(err: AWSError, data: ListAnalyzersResponse) => {
48+
if (err) {
49+
errorLog.generateAwsErrorLog({
50+
functionName: 'accessAnalyzer:listAnalyzers',
51+
err,
52+
})
53+
}
54+
55+
if (!isEmpty(data)) {
56+
const { nextToken, analyzers: analyzersData = [] } = data
57+
58+
analyzersList.push(...analyzersData)
59+
60+
logger.debug(lt.fetchedaccessAnalyzers(analyzersList.length))
61+
62+
if (nextToken) {
63+
listAnalyzersData({ accessAnalyzer, region, nextToken })
64+
}
65+
66+
analyzerSummarytData = analyzersList.map(analyzer => ({
67+
...analyzer,
68+
region,
69+
}))
70+
}
71+
72+
resolve(analyzerSummarytData)
73+
}
74+
)
75+
})
76+
77+
/**
78+
* IAM Access Analyzer
79+
*/
80+
81+
export interface RawAwsAnalyzerSummary extends Omit<AnalyzerSummary, 'Tags'> {
82+
region: string
83+
Tags?: TagMap
84+
}
85+
86+
export default async ({
87+
regions,
88+
config,
89+
}: {
90+
regions: string
91+
config: Config
92+
}): Promise<{
93+
[region: string]: RawAwsAnalyzerSummary[]
94+
}> =>
95+
new Promise(async resolve => {
96+
const analyzerSummaryResult: RawAwsAnalyzerSummary[] = []
97+
98+
const regionPromises = regions.split(',').map(region => {
99+
const accessAnalyzer = new AccessAnalyzer({ ...config, region, endpoint })
100+
101+
return new Promise<void>(async resolveAnalyzerSummaryData => {
102+
const analyzerSummaryData = await listAnalyzersData({
103+
accessAnalyzer,
104+
region,
105+
})
106+
107+
if (!isEmpty(analyzerSummaryData)) {
108+
for (const analyzer of analyzerSummaryData) {
109+
analyzerSummaryResult.push({
110+
...analyzer,
111+
region,
112+
Tags: analyzer.tags || {}
113+
})
114+
}
115+
}
116+
117+
resolveAnalyzerSummaryData()
118+
})
119+
})
120+
121+
await Promise.all(regionPromises)
122+
errorLog.reset()
123+
124+
resolve(groupBy(analyzerSummaryResult, 'region'))
125+
})

0 commit comments

Comments
 (0)