This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
/
application-account-initial-setup.yaml
322 lines (306 loc) · 10.7 KB
/
application-account-initial-setup.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
#
# Copyright 2017-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
#
AWSTemplateFormatVersion: '2010-09-09'
Description: Initialize the Compliance-as-Code oversight in this Application Account
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Compliance-as-Code Engine Configuration
Parameters:
- MainRegion
- ComplianceAccountId
- ConfigAndComplianceAuditRoleName
- CentralizedS3BucketConfigFullName
- Label:
default: (Advanced User Only) Deployment options
Parameters:
- DeployAWSConfig
- ForceDeploymentRoleInMainRegionOnly
- RuleFrequency
- LambdaFunctionName
- EngineComplianceRule
Parameters:
CentralizedS3BucketConfigFullName:
ConstraintDescription: Enter DNS-compliant name
Description: (Only if DeployAWSConfig is set to "true") Bucket name where Config logs are centrally stored. It is located in the Compliance Account.
Default: centralized-config-112233445566
MaxLength: 63
MinLength: 10
Type: String
ComplianceAccountId:
ConstraintDescription: 12 digits, no dashes
Description: Account ID of the Compliance Account. The compliance-as-code engine must be installed in this account first.
Default: "112233445566"
MaxLength: 12
MinLength: 12
Type: String
ConfigAndComplianceAuditRoleName:
Description: (Only if DeployAWSConfig is set to "true") Role Name of the Compliance Account Cross Account Role
Default: AWSConfigAndComplianceAuditRole-DO-NOT-DELETE
Type: String
MainRegion:
Description: Region which is designated as main Region in your Compliance Account.
Default: us-west-2
AllowedValues:
- us-east-1
- us-east-2
- us-west-1
- us-west-2
- ap-south-1
- ap-northeast-1
- ap-northeast-2
- ap-southeast-1
- ap-southeast-2
- ca-central-1
- eu-central-1
- eu-west-1
- eu-west-2
- eu-west-3
- sa-east-1
AllowedPattern: ^.{0,14}$
ConstraintDescription: Select one AWS Region only.
Type: String
EngineComplianceRule:
Description: Rule name which review the state of this deployment
Default: COMPLIANCE_RULESET_LATEST_INSTALLED
Type: String
RuleFrequency:
Description: Frequency to verify the compliance of this deployment
AllowedValues:
- One_Hour
- Three_Hours
- Six_Hours
- Twelve_Hours
- TwentyFour_Hours
Default: One_Hour
Type: String
LambdaFunctionName:
Description: Lambda name in the Compliance Account
Default: RDK-Rule-Function-COMPLIANCERULESETLATESTINSTALLED
Type: String
DeployAWSConfig:
Description: Set to "true" to configure AWS Config. If set to "false", you must give the compliance account to assume the AWS Config service Role, and as well permissions to deploy CloudFormation templates and control Config.
Default: true
AllowedValues:
- true
- false
Type: String
ForceDeploymentRoleInMainRegionOnly:
Description: Set to "force" to deploy the ConfigAndComplianceAuditRoleName. This options only works in the main Region.
Default: default
AllowedValues:
- default
- force
Type: String
Conditions:
IsMainRegion: !Equals [ !Ref 'AWS::Region', !Ref MainRegion ]
NotMainRegion: !Not [!Equals [!Ref 'AWS::Region', !Ref MainRegion ]]
SetConfig: !Equals [ !Ref DeployAWSConfig, 'true']
NoSetConfig: !Equals [ !Ref DeployAWSConfig, 'false']
ForceDeployRole: !Equals [ !Ref ForceDeploymentRoleInMainRegionOnly, 'force']
SetConfigMain: !And
- !Condition IsMainRegion
- !Condition SetConfig
SetConfigNotMain: !And
- !Condition NotMainRegion
- !Condition SetConfig
NoSetConfigMain: !And
- !Condition IsMainRegion
- !Condition NoSetConfig
NoSetConfigNotMain: !And
- !Condition NotMainRegion
- !Condition NoSetConfig
ForceDeployRoleMain: !And
- !Condition IsMainRegion
- !Condition ForceDeployRole
DeployRole: !Or
- !Condition SetConfigMain
- !Condition ForceDeployRoleMain
Resources:
MainConfigurationRecorder:
Condition: SetConfigMain
Type: AWS::Config::ConfigurationRecorder
Properties:
RecordingGroup:
AllSupported: true
IncludeGlobalResourceTypes: true
RoleARN: !Join ["", ["arn:aws:iam::", !Ref 'AWS::AccountId', ":role/service-role/", !Ref ConfigAndComplianceAuditRoleName]]
DependsOn:
- AWSConfigAndComplianceRole
- ConfigS3WritePolicy
NotMainConfigurationRecorder:
Condition: SetConfigNotMain
Type: AWS::Config::ConfigurationRecorder
Properties:
RecordingGroup:
AllSupported: true
IncludeGlobalResourceTypes: false
RoleARN: !Join ["", ["arn:aws:iam::", !Ref 'AWS::AccountId', ":role/service-role/", !Ref ConfigAndComplianceAuditRoleName]]
MainDeliveryChannel:
Condition: SetConfigMain
Type: AWS::Config::DeliveryChannel
Properties:
ConfigSnapshotDeliveryProperties:
DeliveryFrequency: TwentyFour_Hours
S3BucketName: !Ref CentralizedS3BucketConfigFullName
DependsOn:
- ConfigS3WritePolicy
NotMainDeliveryChannel:
Condition: SetConfigNotMain
Type: AWS::Config::DeliveryChannel
Properties:
ConfigSnapshotDeliveryProperties:
DeliveryFrequency: TwentyFour_Hours
S3BucketName: !Ref CentralizedS3BucketConfigFullName
AggregationAuthorization:
Condition: SetConfig
Type: "AWS::Config::AggregationAuthorization"
Properties:
AuthorizedAccountId: !Ref ComplianceAccountId
AuthorizedAwsRegion: !Ref 'AWS::Region'
AWSConfigAndComplianceRole:
Condition: DeployRole
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Action:
- sts:AssumeRole
Principal:
Service: config.amazonaws.com
- Effect: Allow
Action:
- sts:AssumeRole
Principal:
AWS: !Ref ComplianceAccountId
Version: '2012-10-17'
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AWSConfigRole'
- 'arn:aws:iam::aws:policy/ReadOnlyAccess'
Path: /service-role/
RoleName: !Ref ConfigAndComplianceAuditRoleName
ConfigS3WritePolicy:
Condition: DeployRole
Type: 'AWS::IAM::Policy'
Properties:
Roles:
- !Ref ConfigAndComplianceAuditRoleName
PolicyName: !Join
- '-'
- - ConfigS3Write
- !Ref 'AWS::AccountId'
- !Ref 'AWS::Region'
PolicyDocument:
Statement:
- Action:
- s3:PutObject
Effect: Allow
Resource:
- !Join [ "", [ "arn:aws:s3:::", !Ref CentralizedS3BucketConfigFullName, "/AWSLogs/", !Ref 'AWS::AccountId', "/*"] ]
Sid: !Join ["", ["ConfigS3Write", !Ref 'AWS::AccountId'] ]
Version: "2012-10-17"
DependsOn:
- AWSConfigAndComplianceRole
ConfigDeployPolicy:
Condition: DeployRole
Type: 'AWS::IAM::Policy'
Properties:
Roles:
- !Ref ConfigAndComplianceAuditRoleName
PolicyName: !Join
- '-'
- - ConfigDeploy
- !Ref 'AWS::AccountId'
- !Ref 'AWS::Region'
PolicyDocument:
Statement:
- Action:
- cloudformation:*
Effect: Allow
Resource:
- !Join [ "", [ "arn:aws:cloudformation:*:", !Ref 'AWS::AccountId', ":stack/Compliance-Engine-Benchmark-DO-NOT-DELETE*" ]]
Sid: !Join ["", ["ConfigDeployCfn", !Ref 'AWS::AccountId'] ]
- Action:
- config:*
Effect: Allow
Resource: "*"
Sid: !Join ["", ["ConfigAccess", !Ref 'AWS::AccountId'] ]
Version: "2012-10-17"
DependsOn:
- AWSConfigAndComplianceRole
MainCaCReporter:
Condition: SetConfigMain
Type: AWS::Config::ConfigRule
Properties:
ConfigRuleName: !Ref EngineComplianceRule
Description: Check that the latest Compliance-as-code template is installed in this account.
Source:
Owner: CUSTOM_LAMBDA
SourceIdentifier: !Join [ ":", [ 'arn:aws:lambda', !Ref "AWS::Region", !Ref ComplianceAccountId, 'function', !Ref LambdaFunctionName ] ]
SourceDetails:
-
EventSource: "aws.config"
MaximumExecutionFrequency: !Ref RuleFrequency
MessageType: ScheduledNotification
DependsOn:
- MainConfigurationRecorder
- MainDeliveryChannel
MainCaCReporterNotConfig:
Condition: NoSetConfigMain
Type: AWS::Config::ConfigRule
Properties:
ConfigRuleName: !Ref EngineComplianceRule
Description: Check that the latest Compliance-as-code template is installed in this account.
Source:
Owner: CUSTOM_LAMBDA
SourceIdentifier: !Join [ ":", [ 'arn:aws:lambda', !Ref "AWS::Region", !Ref ComplianceAccountId, 'function', !Ref LambdaFunctionName ] ]
SourceDetails:
-
EventSource: "aws.config"
MaximumExecutionFrequency: !Ref RuleFrequency
MessageType: ScheduledNotification
NotMainCaCReporter:
Condition: SetConfigNotMain
Type: AWS::Config::ConfigRule
Properties:
ConfigRuleName: !Ref EngineComplianceRule
Description: Check that the latest template for the RuleSet is installed in this account.
Source:
Owner: CUSTOM_LAMBDA
SourceIdentifier: !Join [ ":", [ 'arn:aws:lambda', !Ref "AWS::Region", !Ref ComplianceAccountId, 'function', !Ref LambdaFunctionName ] ]
SourceDetails:
-
EventSource: "aws.config"
MaximumExecutionFrequency: !Ref RuleFrequency
MessageType: ScheduledNotification
DependsOn:
- NotMainConfigurationRecorder
- NotMainDeliveryChannel
NotMainCaCReporterNotConfig:
Condition: NoSetConfigNotMain
Type: AWS::Config::ConfigRule
Properties:
ConfigRuleName: !Ref EngineComplianceRule
Description: Check that the latest template for the RuleSet is installed in this account.
Source:
Owner: CUSTOM_LAMBDA
SourceIdentifier: !Join [ ":", [ 'arn:aws:lambda', !Ref "AWS::Region", !Ref ComplianceAccountId, 'function', !Ref LambdaFunctionName ] ]
SourceDetails:
-
EventSource: "aws.config"
MaximumExecutionFrequency: !Ref RuleFrequency
MessageType: ScheduledNotification