-
Notifications
You must be signed in to change notification settings - Fork 17
/
cloudcheckr-controltower-integration.template.yaml
266 lines (266 loc) · 8.59 KB
/
cloudcheckr-controltower-integration.template.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
AWSTemplateFormatVersion: 2010-09-09
Description: CloudCheckr ControlTower Integration.
Parameters:
LambdaBucket:
Type: String
MinLength: '1'
AllowedPattern: '[a-zA-Z0-9-.]*'
Description: The prefix of the S3 bucket containing the Lambda package and templates.
Default: cc-public-resources
LambdaPath:
Type: String
MinLength: '1'
Description: The path to the lambda package file within the bucket.
Default: packages/cc_ct_integration_1.0.0.zip
StackSetName:
Type: String
MinLength: '1'
Description: Name for the StackSet to create stack instances in new accounts.
Default: 'CloudCheckr-ControlTower-StackSet'
StackSetTemplateUrl:
Type: String
MinLength: '1'
Description: S3 URL of the CloudFormation template for new accounts. Change the region name suffix on the URL to the Control Tower supported region you are deploying into.
Default: 'https://cc-public-resources-us-east-1.s3.amazonaws.com/templates/cc_aws_cfn_iam_stack.template.json'
ExternalAccount:
Type: String
MinLength: '12'
MaxLength: '12'
Description: CloudCheckr Account ID for cross-account trust.
Default: '352813966189'
SnsTopicName:
Type: String
MinLength: '3'
Description: SNS Topic to which the Lambda will push notifications in case of failure or important notifications.
Default: CloudCheckr-Control-Tower-Integration-Topic
ApiClientId:
Type: String
NoEcho: false
MinLength: '36'
MaxLength: '36'
Description: CloudCheckr API Client ID.
ApiClientSecret:
Type: String
NoEcho: true
MinLength: '32'
Description: CloudCheckr API Client Secret.
ApiClientEndpoint:
Type: String
Description: CloudCheckr API Endpoint to use.
Default: US
AllowedValues:
- US
- AU
- EU
ApiClientRegionGroup:
Type: String
Description: CloudCheckr API Region Group for Accounts Credentials Setup.
Default: Commercial
AllowedValues:
- Commercial
Metadata:
'AWS::CloudFormation::Interface':
ParameterGroups:
- Label:
default: Integration Configuration
Parameters:
- ApiClientId
- ApiClientSecret
- ApiClientEndpoint
- ApiClientRegionGroup
- Label:
default: Cloud Formation and StackSets Information
Parameters:
- LambdaBucket
- LambdaPath
- SnsTopicName
- ExternalAccount
- StackSetName
- StackSetTemplateUrl
Resources:
CreateAccountLifeCycleRule:
Type: 'AWS::Events::Rule'
Properties:
Description: Life Cycle for CreateManagedAccount
EventPattern:
source:
- aws.controltower
detail-type:
- AWS Service Event via CloudTrail
detail:
eventSource:
- controltower.amazonaws.com
eventName:
- CreateManagedAccount
userAgent:
- AWS Internal
State: ENABLED
Targets:
- Arn: !GetAtt
- CloudCheckrLifeCycleLambda
- Arn
Id: CreateAccountLifeCycle
CreateAccountLifeCycleRulePermission:
Type: 'AWS::Lambda::Permission'
Properties:
FunctionName: !Ref CloudCheckrLifeCycleLambda
Action: 'lambda:InvokeFunction'
Principal: events.amazonaws.com
SourceArn: !GetAtt
- CreateAccountLifeCycleRule
- Arn
SnsTopic:
Type : AWS::SNS::Topic
Properties:
TopicName: !Ref SnsTopicName
DisplayName: !Ref SnsTopicName
Credentials:
Type: 'AWS::SecretsManager::Secret'
Properties:
Description: CloudCheckr API Credentials
Name: "CloudCheckrApiCredentialsSecret"
SecretString: !Join
- ''
- - '{"ApiClientId":"'
- !Ref ApiClientId
- '","ApiClientSecret":"'
- !Ref ApiClientSecret
- '","ApiClientEndpoint":"'
- !Ref ApiClientEndpoint
- '","ApiClientRegionGroup":"'
- !Ref ApiClientRegionGroup
- '"}'
KmsKeyId: !GetAtt CloudCheckrControlTowerKMSKey.Arn
DependsOn:
- CloudCheckrControlTowerKMSKey
CloudCheckrLifeCycleLambda:
Type: 'AWS::Lambda::Function'
Properties:
FunctionName: "CloudCheckr-ControlTower-Integration-LifeCycle"
Description: Function to handle Control Tower LifeCycle
Handler: >-
Lambda.ControlTowerIntegration::Lambda.ControlTowerIntegration.Function::FunctionHandler
Role: !GetAtt
- CloudCheckrLifeCycleLambdaRole
- Arn
Code:
S3Bucket: !Join ['-', [!Ref LambdaBucket, !Ref 'AWS::Region']]
S3Key: !Ref LambdaPath
Runtime: dotnetcore3.1
MemorySize: 128
Timeout: 300
Environment:
Variables:
STACKSET_NAME: !Ref StackSetName
STACKSET_URL: !Ref StackSetTemplateUrl
EXTERNAL_ACCOUNT: !Ref ExternalAccount
SECRETS_ARN: !Ref Credentials
TOPIC_ARN: !Ref SnsTopic
DependsOn:
- Credentials
- SnsTopic
CloudCheckrControlTowerKMSKey:
Type: 'AWS::KMS::Key'
Properties:
Description: KMS Key used to encrypt/decrypt the CloudCheckr-ControlTower Integration Credentials
EnableKeyRotation: true
KeyPolicy:
Version: '2012-10-17'
Statement:
- Sid: KMSAdminOperations
Effect: Allow
Principal:
AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:root'
Action:
- kms:*
Resource: '*'
- Sid: KMSOperations
Effect: Allow
Principal:
AWS: !Sub '${AWS::AccountId}'
Action:
- kms:Encrypt
- kms:Decrypt
- kms:ReEncrypt*
- kms:GenerateDataKey*
- kms:CreateGrant
- kms:DescribeKey
Resource: '*'
Condition:
StringEquals:
kms:ViaService: !Sub 'secretsmanager.${AWS::Region}.amazonaws.com'
kms:CallerAccount: !Sub '${AWS::AccountId}'
CloudCheckrControlTowerKMSAlias:
Type: 'AWS::KMS::Alias'
Properties:
AliasName: !Sub 'alias/${AWS::StackName}'
TargetKeyId:
Ref: CloudCheckrControlTowerKMSKey
CloudCheckrLifeCycleLambdaRole:
Type: 'AWS::IAM::Role'
Properties:
Description: Role used by Lambda for life cycle / new account creation
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
Policies:
- PolicyName: LambaPolicy
PolicyDocument:
Version: 2012-10-17
Statement:
- Sid: STSAssumeRole
Effect: Allow
Action:
- sts:AssumeRole
Resource:
- 'arn:aws:iam::*:role/AWSControlTowerExecution'
- Sid: IAMOperations
Effect: Allow
Action:
- iam:PassRole
Resource:
- !Sub 'arn:aws:iam::${AWS::AccountId}:role/service-role/AWSControlTowerStackSetRole'
- Sid: S3Operations
Effect: Allow
Action:
- 's3:GetObject'
Resource:
- !Join ['',['arn:aws:s3:::', !Ref LambdaBucket ,'*']]
- Sid: SecretsManagerOperations
Effect: Allow
Action:
- 'secretsmanager:GetSecretValue'
Resource:
- !Ref Credentials
- Sid: CloudFormationOperations
Effect: Allow
Action:
- 'cloudformation:CreateStackInstances'
- 'cloudformation:DescribeStackInstance'
- 'cloudformation:DescribeStackSetOperation'
- 'cloudformation:CreateStackSet'
- 'cloudformation:DescribeStackSet'
Resource:
- !Join ['',['arn:aws:cloudformation:', !Ref 'AWS::Region', ':', !Ref 'AWS::AccountId', ':stackset/', !Ref StackSetName, ':*']]
- Sid: SnsOperations
Effect: Allow
Action:
- 'sns:Publish'
Resource:
- !Ref SnsTopic
- Sid: KMSOperations
Effect: Allow
Action:
- 'kms:GenerateDataKey'
- 'kms:Decrypt'
Resource:
- !GetAtt CloudCheckrControlTowerKMSKey.Arn