Skip to content

Commit 1247797

Browse files
committed
Merge branch 'alpha' into feature/CG-1063
2 parents 613a679 + bb27a44 commit 1247797

22 files changed

Lines changed: 533 additions & 137 deletions

File tree

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
# [0.79.0-alpha.22](https://github.com/cloudgraphdev/cloudgraph-provider-aws/compare/0.79.0-alpha.21...0.79.0-alpha.22) (2022-04-14)
2+
3+
4+
### Bug Fixes
5+
6+
* **elasticSearchDomain:** add cloudwatchLogs, cognitoIdentityPool, cognitoUserPool, iamRole connections ([694d298](https://github.com/cloudgraphdev/cloudgraph-provider-aws/commit/694d298af419a8f18f55ccebb5fc21b06574c930))
7+
8+
# [0.79.0-alpha.21](https://github.com/cloudgraphdev/cloudgraph-provider-aws/compare/0.79.0-alpha.20...0.79.0-alpha.21) (2022-04-14)
9+
10+
11+
### Bug Fixes
12+
13+
* Created iamRole connection for emrCluster ([80a39e1](https://github.com/cloudgraphdev/cloudgraph-provider-aws/commit/80a39e19046ad46a2897f667171b271b5a1f9cc7))
14+
15+
# [0.79.0-alpha.20](https://github.com/cloudgraphdev/cloudgraph-provider-aws/compare/0.79.0-alpha.19...0.79.0-alpha.20) (2022-04-14)
16+
17+
18+
### Features
19+
20+
* **cognitoIdentityPool:** add iamRole/iamOpenIdConnectProvider/iamSamlProvider connections, generate arn ([3ba9610](https://github.com/cloudgraphdev/cloudgraph-provider-aws/commit/3ba9610af535f9b84f229ce6abcfcf1e43664d45))
21+
122
# [0.79.0-alpha.19](https://github.com/cloudgraphdev/cloudgraph-provider-aws/compare/0.79.0-alpha.18...0.79.0-alpha.19) (2022-04-13)
223

324

README.md

Lines changed: 94 additions & 94 deletions
Large diffs are not rendered by default.

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

src/services/cloudwatchLogs/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type awsCloudwatchLog @key(fields: "arn") {
1414
cloudwatch: [awsCloudwatch] @hasInverse(field: cloudwatchLog)
1515
cloudtrail: [awsCloudtrail] @hasInverse(field: cloudwatchLog)
1616
ecsCluster: [awsEcsCluster] @hasInverse(field: cloudwatchLog)
17+
elasticSearchDomains: [awsElasticSearchDomain] @hasInverse(field: cloudwatchLogs)
1718
rdsDbInstance: [awsRdsDbInstance] @hasInverse(field: cloudwatchLogs)
1819
managedAirflows: [awsManagedAirflow] @hasInverse(field: cloudwatchLogs)
1920
}
Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,104 @@
1-
// TODO Add Optional IAM saml provider
1+
import { ServiceConnection } from '@cloudgraph/sdk'
2+
import { isEmpty } from 'lodash'
3+
import services from '../../enums/services'
4+
import { RawAwsCognitoIdentityPool } from './data'
5+
import { RawAwsIamRole } from '../iamRole/data'
6+
import { globalRegionName } from '../../enums/regions'
7+
8+
/**
9+
* Cognito Identity Pool
10+
*/
11+
12+
export default ({
13+
service: identityPool,
14+
data,
15+
region,
16+
}: {
17+
data: { name: string; data: { [property: string]: any[] } }[]
18+
service: RawAwsCognitoIdentityPool
19+
region: string
20+
}): { [key: string]: ServiceConnection[] } => {
21+
const connections: ServiceConnection[] = []
22+
23+
const {
24+
IdentityPoolId: id,
25+
identityPoolRoles,
26+
SamlProviderARNs = [],
27+
OpenIdConnectProviderARNs = [],
28+
} = identityPool
29+
30+
/**
31+
* Find related IAM Roles
32+
*/
33+
const roles: { name: string; data: { [property: string]: any[] } } =
34+
data.find(({ name }) => name === services.iamRole)
35+
36+
const iamRoleArns = Object.values(identityPoolRoles?.Roles || {})
37+
38+
if (roles?.data?.[globalRegionName]) {
39+
const dataAtRegion: RawAwsIamRole[] = roles.data[globalRegionName].filter(role =>
40+
iamRoleArns.includes(role.Arn)
41+
)
42+
if (!isEmpty(dataAtRegion)) {
43+
for (const instance of dataAtRegion) {
44+
const { Arn: arn }: RawAwsIamRole = instance
45+
46+
connections.push({
47+
id: arn,
48+
resourceType: services.iamRole,
49+
relation: 'child',
50+
field: 'iamRoles',
51+
})
52+
}
53+
}
54+
}
55+
56+
/**
57+
* Find iamSamlProvider
58+
* related to this cognito identity pool
59+
*/
60+
const iamSamlProviders = data.find(({ name }) => name === services.iamSamlProvider)
61+
if (iamSamlProviders?.data?.[region]) {
62+
const dataInRegion = iamSamlProviders.data[region].filter(provider =>
63+
SamlProviderARNs.includes(provider.arn)
64+
)
65+
66+
if (!isEmpty(dataInRegion)) {
67+
for (const provider of dataInRegion) {
68+
connections.push({
69+
id: provider.KeyId,
70+
resourceType: services.iamSamlProvider,
71+
relation: 'child',
72+
field: 'iamSamlProviders',
73+
})
74+
}
75+
}
76+
}
77+
78+
/**
79+
* Find iamOpenIdConnectProvider
80+
* related to this cognito identity pool
81+
*/
82+
const iamOpenIdConnectProviders = data.find(({ name }) => name === services.iamOpenIdConnectProvider)
83+
if (iamOpenIdConnectProviders?.data?.[region]) {
84+
const dataInRegion = iamOpenIdConnectProviders.data[region].filter(provider =>
85+
OpenIdConnectProviderARNs.includes(provider.arn)
86+
)
87+
88+
if (!isEmpty(dataInRegion)) {
89+
for (const provider of dataInRegion) {
90+
connections.push({
91+
id: provider.KeyId,
92+
resourceType: services.iamOpenIdConnectProvider,
93+
relation: 'child',
94+
field: 'iamOpenIdConnectProviders',
95+
})
96+
}
97+
}
98+
}
99+
100+
const identityPoolResult = {
101+
[id]: connections,
102+
}
103+
return identityPoolResult
104+
}

src/services/cognitoIdentityPool/data.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import COGID, {
22
IdentityPool,
33
IdentityPoolShortDescription,
4+
GetIdentityPoolRolesResponse,
45
} from 'aws-sdk/clients/cognitoidentity'
56
import { Config } from 'aws-sdk/lib/config'
67

@@ -25,6 +26,7 @@ const MAX_RESULTS = 60
2526

2627
export interface RawAwsCognitoIdentityPool
2728
extends Omit<IdentityPool, 'IdentityPoolTags'> {
29+
identityPoolRoles: GetIdentityPoolRolesResponse
2830
region: string
2931
Tags: TagMap
3032
}
@@ -91,6 +93,27 @@ const describeIdentityPool = async ({
9193
return null
9294
}
9395

96+
const getIdentityPoolRoles = async ({
97+
cogId,
98+
IdentityPoolId,
99+
}: {
100+
cogId: COGID
101+
IdentityPoolId: string
102+
}): Promise<GetIdentityPoolRolesResponse> => {
103+
try {
104+
return await cogId
105+
.getIdentityPoolRoles({ IdentityPoolId })
106+
.promise()
107+
108+
} catch (err) {
109+
errorLog.generateAwsErrorLog({
110+
functionName: 'cognitoIdentityPool:getIdentityPoolRoles',
111+
err,
112+
})
113+
}
114+
return null
115+
}
116+
94117
const listIdentityPoolData = async ({
95118
cogId,
96119
region,
@@ -106,8 +129,13 @@ const listIdentityPoolData = async ({
106129
cogId,
107130
IdentityPoolId: identityPoolId.IdentityPoolId,
108131
})
132+
const identityPoolRoles = await getIdentityPoolRoles({
133+
cogId,
134+
IdentityPoolId: identityPoolId.IdentityPoolId,
135+
})
109136
identityPoolData.push({
110137
...identityPool,
138+
identityPoolRoles,
111139
region,
112140
})
113141
}

src/services/cognitoIdentityPool/format.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { IdentityProviders } from 'aws-sdk/clients/cognitoidentity';
2-
import cuid from 'cuid';
1+
import { IdentityProviders } from 'aws-sdk/clients/cognitoidentity'
2+
import cuid from 'cuid'
33
import t from '../../properties/translations'
4-
5-
import { AwsCognitoIdentityPool, AwsSupportedLoginProvider } from '../../types/generated';
6-
import { formatTagsFromMap } from '../../utils/format';
7-
import { RawAwsCognitoIdentityPool } from './data';
4+
import { AwsCognitoIdentityPool, AwsSupportedLoginProvider } from '../../types/generated'
5+
import { formatTagsFromMap } from '../../utils/format'
6+
import { RawAwsCognitoIdentityPool } from './data'
7+
import {
8+
cognitoIdentityPoolArn,
9+
} from '../../utils/generateArns'
810

911
/**
1012
* Cognito Identity Pool
@@ -53,9 +55,12 @@ export default ({
5355
serverSideTokenCheck: serverSideTokenCheck? t.yes : t.no,
5456
})) || []
5557

58+
const arn = cognitoIdentityPoolArn({ region, account, identityPoolId })
59+
5660
const identityPool = {
5761
id: identityPoolId,
5862
accountId: account,
63+
arn,
5964
identityPoolName,
6065
allowUnauthenticatedIdentities: allowUnauthenticatedIdentities? t.yes : t.no,
6166
allowClassicFlow: allowClassicFlow? t.yes : t.no,

src/services/cognitoIdentityPool/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { Service } from '@cloudgraph/sdk';
22
import BaseService from '../base';
33
import format from './format';
44
import getData from './data';
5-
// import getConnections from './connections'
5+
import getConnections from './connections'
66
import mutation from './mutation';
77

88
export default class AwsCognitoIdentityPool extends BaseService implements Service {
99
format = format.bind(this);
1010

1111
getData = getData.bind(this);
1212

13-
// getConnections = getConnections.bind(this)
13+
getConnections = getConnections.bind(this)
1414

1515
mutation = mutation;
1616
}

src/services/cognitoIdentityPool/schema.graphql

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type awsCognitoIdentityProviders
2222

2323
type awsCognitoIdentityPool @key(fields: "id") {
2424
id: String! @id @search(by: [hash])
25+
arn: String! @search(by: [hash])
2526
accountId: String! @search(by: [hash])
2627
region: String @search(by: [hash, regexp])
2728
identityPoolName: String @search(by: [hash, regexp])
@@ -33,8 +34,8 @@ type awsCognitoIdentityPool @key(fields: "id") {
3334
cognitoIdentityProviders: [awsCognitoIdentityProviders]
3435
samlProviderARNs: [String] @search
3536
tags: [awsRawTag]
37+
elasticSearchDomains: [awsElasticSearchDomain] @hasInverse(field: cognitoIdentityPool)
38+
iamRoles: [awsIamRole] @hasInverse(field: awsCognitoIdentityPool)
39+
iamOpenIdConnectProviders: [awsIamOpenIdConnectProvider] @hasInverse(field: awsCognitoIdentityPool)
40+
iamSamlProviders: [awsIamSamlProvider] @hasInverse(field: awsCognitoIdentityPool)
3641
}
37-
38-
# TODO: add an arn for identity pool see here: https://docs.aws.amazon.com/cognito/latest/developerguide/security_iam_service-with-iam.html
39-
#TODO: add connections to iamSamlProvider and iamOpenIdConnectProvider
40-
#TODO: try to add connection to iam role using getIdentityPoolRoles

src/services/cognitoUserPool/schema.graphql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,5 @@ type awsCognitoUserPool implements awsBaseService @key(fields: "id") {
124124
kms: [awsKms] @hasInverse(field: cognitoUserPools)
125125
ses: [awsSes] @hasInverse(field: cognitoUserPools)
126126
iamRole: [awsIamRole] @hasInverse(field: cognitoUserPools)
127-
}
127+
elasticSearchDomains: [awsElasticSearchDomain] @hasInverse(field: cognitoUserPool)
128+
}

0 commit comments

Comments
 (0)