Skip to content

Commit 745f168

Browse files
committed
Merge branch 'alpha' into feature/CG-1072
2 parents 0ddf442 + 447b324 commit 745f168

File tree

11 files changed

+114
-44
lines changed

11 files changed

+114
-44
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# [0.79.0-alpha.8](https://github.com/cloudgraphdev/cloudgraph-provider-aws/compare/0.79.0-alpha.7...0.79.0-alpha.8) (2022-04-11)
2+
3+
4+
### Bug Fixes
5+
6+
* Added iamRole connection to kinesisFirehose service ([dc17214](https://github.com/cloudgraphdev/cloudgraph-provider-aws/commit/dc1721403a6d86aa1d7a00542dff237011514654))
7+
8+
# [0.79.0-alpha.7](https://github.com/cloudgraphdev/cloudgraph-provider-aws/compare/0.79.0-alpha.6...0.79.0-alpha.7) (2022-04-11)
9+
10+
11+
### Bug Fixes
12+
13+
* Added iamRole to lambda service ([ae6177d](https://github.com/cloudgraphdev/cloudgraph-provider-aws/commit/ae6177de995975ab5194c5d2fcc8aaf98ec8d06d))
14+
115
# [0.79.0-alpha.6](https://github.com/cloudgraphdev/cloudgraph-provider-aws/compare/0.79.0-alpha.5...0.79.0-alpha.6) (2022-04-11)
216

317

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Use the CloudGraph AWS Provider to scan and normalize cloud infrastructure using the [AWS SDK](https://github.com/aws/aws-sdk-js)
44

55
<!-- toc -->
6+
67
- [Docs](#install)
78
- [Install](#install)
89
- [Authentication](#authentication)
@@ -13,9 +14,10 @@ Use the CloudGraph AWS Provider to scan and normalize cloud infrastructure using
1314

1415
# Docs
1516

16-
[CloudGraph Readme](https://github.com/cloudgraphdev/cli)
17+
[CloudGraph Readme](https://github.com/cloudgraphdev/cli)
1718

1819
💻 [Full CloudGraph Documentation Including AWS Examples](https://docs.cloudgraph.dev)
20+
1921
# Install
2022

2123
Install the aws provider in CloudGraph
@@ -122,14 +124,14 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
122124
| iamServerCertificate | |
123125
| iamUser | iamGroup |
124126
| iamPolicy | iamRole, iamGroup |
125-
| iamRole | appSync, codebuild, configurationRecorder, ec2, iamInstanceProfile, iamPolicy, eksCluster, ecsService, flowLog, glueJob, managedAirflow, sageMakerNotebookInstance, systemsManagerInstance guardDutyDetector |
127+
| iamRole | appSync, codebuild, configurationRecorder, ec2, iamInstanceProfile, iamPolicy, eksCluster, ecsService, flowLog, glueJob, kinesisFirehose, lambda, managedAirflow, sageMakerNotebookInstance, systemsManagerInstance guardDutyDetector |
126128
| iamGroup | iamUser, iamPolicy |
127129
| igw | vpc |
128130
| iot | |
129-
| kinesisFirehose | kinesisStream, s3 |
131+
| kinesisFirehose | iamRole, kinesisStream, s3 |
130132
| kinesisStream | kinesisFirehose |
131133
| kms | cloudtrail, cloudwatchLog, codebuild, ecsCluster, dmsReplicationInstance, efs, eksCluster, elastiCacheReplicationGroup, elasticSearchDomain, emrCluster, lambda, redshiftCluster, rdsClusterSnapshot, sageMakerNotebookInstance, secretsManager, sns |
132-
| lambda | appSync, cognitoUserPool, kms, secretsManager, securityGroup, subnet, vpc |
134+
| lambda | appSync, cognitoUserPool, iamRole, kms, secretsManager, securityGroup, subnet, vpc |
133135
| managedAirflow | iamRole, securityGroups, subnet, s3 |
134136
| nacl | vpc |
135137
| natGateway | networkInterface, subnet, vpc |
@@ -157,7 +159,6 @@ CloudGraph AWS Provider will ask you what regions you would like to crawl and wi
157159
| transitGateway | routeTable, transitGatewayAttachment, vpnConnection |
158160
| transitGatewayAttachment | routeTable, transitGateway, vpc, vpnConnection |
159161
| vpc | alb, codebuild, dmsReplicationInstance, ec2, eip, elb, ecsService, efsMountTarget, eksCluster igw, elastiCacheCluster, elasticSearchDomain, lambda, nacl, natGateway, networkInterface, rdsClusterSnapshot, rdsDbInstance, redshiftCluster, route53HostedZone, routeTable, subnet, flowLog, vpnGateway, transitGatewayAttachment |
160-
| vpnConnection | customerGateway, transitGateway, transitGatewayAttachment, vpnGateway |
161-
| vpnGateway | vpc, vpnConnection |
162-
| wafV2WebAcl | appSync |
163-
162+
| vpnConnection | customerGateway, transitGateway, transitGatewayAttachment, vpnGateway |
163+
| vpnGateway | vpc, vpnConnection |
164+
| wafV2WebAcl | appSync |

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.79.0-alpha.6",
3+
"version": "0.79.0-alpha.8",
44
"description": "cloud-graph provider plugin for AWS used to fetch AWS cloud data.",
55
"publishConfig": {
66
"registry": "https://registry.npmjs.org/",

src/services/iamRole/connections.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,12 @@ export default ({
170170
/**
171171
* Find any guardDutyDetector related data
172172
*/
173-
const detectors = data.find(
174-
({ name }) => name === services.guardDutyDetector
175-
)
173+
const detectors = data.find(({ name }) => name === services.guardDutyDetector)
176174
if (detectors?.data?.[region]) {
177175
const dataAtRegion: RawAwsGuardDutyDetector[] = detectors.data[
178176
region
179177
].filter(
180-
({ ServiceRole }: RawAwsGuardDutyDetector) =>
181-
ServiceRole === role.Arn
178+
({ ServiceRole }: RawAwsGuardDutyDetector) => ServiceRole === role.Arn
182179
)
183180
for (const detector of dataAtRegion) {
184181
connections.push({
@@ -189,19 +186,17 @@ export default ({
189186
})
190187
}
191188
}
192-
/**
189+
/**
193190
* Find any systemsManagerInstance related data
194191
*/
195-
const systemsManagerInstances = data.find(
192+
const systemsManagerInstances = data.find(
196193
({ name }) => name === services.systemsManagerInstance
197194
)
198195
if (systemsManagerInstances?.data?.[region]) {
199-
const dataAtRegion: RawAwsSystemsManagerInstance[] = systemsManagerInstances.data[
200-
region
201-
].filter(
202-
({ IamRole }: RawAwsSystemsManagerInstance) =>
203-
IamRole === role.Arn
204-
)
196+
const dataAtRegion: RawAwsSystemsManagerInstance[] =
197+
systemsManagerInstances.data[region].filter(
198+
({ IamRole }: RawAwsSystemsManagerInstance) => IamRole === role.Arn
199+
)
205200
for (const instance of dataAtRegion) {
206201
connections.push({
207202
id: instance.InstanceId,
@@ -215,15 +210,14 @@ export default ({
215210
/**
216211
* Find any sageMakerNotebookInstance related data
217212
*/
218-
const notebooks = data.find(
213+
const notebooks = data.find(
219214
({ name }) => name === services.sageMakerNotebookInstance
220215
)
221216
if (notebooks?.data?.[region]) {
222217
const dataAtRegion: RawAwsSageMakerNotebookInstance[] = notebooks.data[
223218
region
224219
].filter(
225-
({ RoleArn }: RawAwsSageMakerNotebookInstance) =>
226-
RoleArn === role.Arn
220+
({ RoleArn }: RawAwsSageMakerNotebookInstance) => RoleArn === role.Arn
227221
)
228222
for (const notebook of dataAtRegion) {
229223
connections.push({

src/services/iamRole/schema.graphql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ type awsIamRole implements awsBaseService @key(fields: "id") {
2626
ec2Instances: [awsEc2] @hasInverse(field: iamRole)
2727
cognitoUserPools: [awsCognitoUserPool] @hasInverse(field: iamRole)
2828
appSync: [awsAppSync] @hasInverse(field: iamRoles)
29+
lambda: [awsLambda] @hasInverse(field: iamRole)
30+
kinesisFirehose: [awsKinesisFirehose] @hasInverse(field: iamRole)
2931
}

src/services/kinesisFirehose/connections.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { TagMap } from '../../types'
88
import services from '../../enums/services'
99
import { RawAwsS3 } from '../s3/data'
1010
import { s3BucketArn } from '../../utils/generateArns'
11+
import { globalRegionName } from '../../enums/regions'
12+
import { RawAwsIamRole } from '../iamRole/data'
1113

1214
/**
1315
* Kinesis Firehose
@@ -26,7 +28,11 @@ export default ({
2628
region: string
2729
}): { [key: string]: ServiceConnection[] } => {
2830
const connections: ServiceConnection[] = []
29-
const { DeliveryStreamARN: id, Destinations: destinations = [] } = firehose
31+
const {
32+
DeliveryStreamARN: id,
33+
Destinations: destinations = [],
34+
Source = {},
35+
} = firehose
3036

3137
const kinesisStreamSourceARN =
3238
firehose.Source?.KinesisStreamSourceDescription?.KinesisStreamARN
@@ -63,10 +69,8 @@ export default ({
6369

6470
if (!isEmpty(destinations)) {
6571
destinations.map((destination: DestinationDescription) => {
66-
const {
67-
ExtendedS3DestinationDescription,
68-
S3DestinationDescription,
69-
} = destination
72+
const { ExtendedS3DestinationDescription, S3DestinationDescription } =
73+
destination
7074
const s3DestinationDescription =
7175
ExtendedS3DestinationDescription || S3DestinationDescription
7276
if (s3DestinationDescription) {
@@ -94,6 +98,32 @@ export default ({
9498
})
9599
}
96100

101+
/**
102+
* Find related IAM Roles
103+
*/
104+
const roles: { name: string; data: { [property: string]: any[] } } =
105+
data.find(({ name }) => name === services.iamRole)
106+
if (
107+
roles?.data?.[globalRegionName] &&
108+
Source?.KinesisStreamSourceDescription?.RoleARN
109+
) {
110+
const dataAtRegion: RawAwsIamRole[] = roles.data[globalRegionName].filter(
111+
role => role.Arn === Source.KinesisStreamSourceDescription.RoleARN
112+
)
113+
if (!isEmpty(dataAtRegion)) {
114+
for (const instance of dataAtRegion) {
115+
const { Arn: roleId } = instance
116+
117+
connections.push({
118+
id: roleId,
119+
resourceType: services.iamRole,
120+
relation: 'child',
121+
field: 'iamRole',
122+
})
123+
}
124+
}
125+
}
126+
97127
const kinesisFirehoseResult = {
98128
[id]: connections,
99129
}

src/services/kinesisFirehose/schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#TODO: add iam role connection
21
type awsKinesisFirehose implements awsBaseService @key(fields: "arn") {
32
name: String @search(by: [hash, regexp])
43
deliveryStreamStatus: String @search(by: [hash, regexp])
@@ -12,6 +11,7 @@ type awsKinesisFirehose implements awsBaseService @key(fields: "arn") {
1211
source: awsKinesisFirehoseSource
1312
kinesisStream: [awsKinesisStream] @hasInverse(field: kinesisFirehose)
1413
s3: [awsS3] @hasInverse(field: kinesisFirehose)
14+
iamRole: [awsIamRole] @hasInverse(field: kinesisFirehose)
1515
tags: [awsRawTag]
1616
}
1717

src/services/lambda/connections.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { SecurityGroup } from 'aws-sdk/clients/ec2'
77

88
import services from '../../enums/services'
99
import { RawAwsSubnet } from '../subnet/data'
10+
import { RawAwsIamRole } from '../iamRole/data'
11+
import { globalRegionName } from '../../enums/regions'
1012

1113
export default ({
1214
service: lambda,
@@ -22,6 +24,7 @@ export default ({
2224
const {
2325
KMSKeyArn,
2426
FunctionArn: id,
27+
Role,
2528
VpcConfig: { SecurityGroupIds: sgIds = [], SubnetIds: subnetIds = [] } = {},
2629
} = lambda
2730
const connections: ServiceConnection[] = []
@@ -83,7 +86,7 @@ export default ({
8386
if (!isEmpty(subnetsInRegion)) {
8487
for (const subnet of subnetsInRegion) {
8588
connections.push({
86-
id:subnet.SubnetId,
89+
id: subnet.SubnetId,
8790
resourceType: services.subnet,
8891
relation: 'child',
8992
field: 'subnet',
@@ -92,6 +95,30 @@ export default ({
9295
}
9396
}
9497

98+
/**
99+
* Find IAM Role
100+
* related to this lambda function
101+
*/
102+
const iamRoles: {
103+
name: string
104+
data: { [property: string]: RawAwsIamRole[] }
105+
} = data.find(({ name }) => name === services.iamRole)
106+
if (iamRoles?.data?.[globalRegionName]) {
107+
const iamRolesInRegion: RawAwsIamRole[] = iamRoles.data[
108+
globalRegionName
109+
].filter(({ Arn }: RawAwsIamRole) => Arn === Role)
110+
if (!isEmpty(iamRolesInRegion)) {
111+
for (const role of iamRolesInRegion) {
112+
connections.push({
113+
id: role.Arn,
114+
resourceType: services.iamRole,
115+
relation: 'child',
116+
field: 'iamRole',
117+
})
118+
}
119+
}
120+
}
121+
95122
const lambdaResult = {
96123
[id]: connections,
97124
}

src/services/lambda/format.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
import isEmpty from 'lodash/isEmpty'
22
import t from '../../properties/translations'
33
import { AwsLambda } from '../../types/generated'
4-
import { formatTagsFromMap } from '../../utils/format'
4+
import { formatTagsFromMap, formatIamJsonPolicy } from '../../utils/format'
55
import { RawAwsLambdaFunction } from './data'
6-
import { formatIamJsonPolicy } from '../../utils/format'
76

87
/**
98
* Lambda
109
*/
1110
export default ({
1211
service: rawData,
1312
account,
14-
region
13+
region,
1514
}: {
1615
service: RawAwsLambdaFunction
1716
account: string
@@ -33,10 +32,7 @@ export default ({
3332
Version: version,
3433
reservedConcurrentExecutions: rawReservedConcurrentExecutions,
3534
VpcConfig: vpcConfig,
36-
PolicyData: {
37-
Policy: policy = '',
38-
RevisionId: policyRevisionId = ''
39-
}
35+
PolicyData: { Policy: policy = '', RevisionId: policyRevisionId = '' },
4036
} = rawData
4137
const environmentVariables = []
4238
const secretNames = [t.pass, t.secret, t.private, t.cert]
@@ -53,7 +49,11 @@ export default ({
5349
}
5450
})
5551

56-
environmentVariables.push({ id: `${key}:${desiredValue}`, key, value: desiredValue })
52+
environmentVariables.push({
53+
id: `${key}:${desiredValue}`,
54+
key,
55+
value: desiredValue,
56+
})
5757
})
5858
}
5959
}
@@ -65,7 +65,7 @@ export default ({
6565
const formattedVpcConfig = {
6666
vpcId: vpcConfig?.VpcId,
6767
subnetIds: vpcConfig?.SubnetIds,
68-
securityGroupIds: vpcConfig?.SecurityGroupIds
68+
securityGroupIds: vpcConfig?.SecurityGroupIds,
6969
}
7070

7171
return {
@@ -79,7 +79,6 @@ export default ({
7979
lastModified,
8080
memorySize,
8181
reservedConcurrentExecutions,
82-
role: handler,
8382
runtime,
8483
sourceCodeSize: `${codeSize * 0.001} Kb`,
8584
timeout,

src/services/lambda/schema.graphql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ type awsLambda implements awsBaseService @key(fields: "arn") {
55
lastModified: String @search(by: [hash, regexp])
66
memorySize: Int @search
77
reservedConcurrentExecutions: Int @search
8-
role: String @search(by: [hash, regexp]) # TODO: add iamRole connection here
98
runtime: String @search(by: [hash, regexp])
109
sourceCodeSize: String @search(by: [hash, regexp])
1110
timeout: Int @search
@@ -23,6 +22,7 @@ type awsLambda implements awsBaseService @key(fields: "arn") {
2322
cognitoUserPools: [awsCognitoUserPool] @hasInverse(field: lambdas)
2423
appSync: [awsAppSync] @hasInverse(field: lambda)
2524
secretsManager: [awsSecretsManager] @hasInverse(field: lambda)
25+
iamRole: [awsIamRole] @hasInverse(field: lambda)
2626
}
2727

2828
type awsLambdaEnvironmentVariable

0 commit comments

Comments
 (0)