-
Notifications
You must be signed in to change notification settings - Fork 12
/
template.yml
214 lines (206 loc) · 7.5 KB
/
template.yml
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
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
---
AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Description: Automated AWS Organizations configuration for security operations
Parameters:
Regions:
Type: CommaDelimitedList
Description: Regions to enable for Security Hub and GuardDuty (leave blank for all regions)
Default: "us-east-1"
ExecutionRoleName:
Type: String
Description: Execution IAM role name
Default: AWSControlTowerExecution
AdministratorAccountName:
Type: String
Description: "Security operations AWS account name (Audit Manager, SecurityHub, GuardDuty, Macie, S3 Storage Lens and Firewall Manager)"
Default: Audit
ExecutionCount:
Type: Number
Description: Increment this value to re-execute the OrganizationSetup custom resource
Default: 1
SigningProfileVersionArn:
Type: String
Description: Code Signing Profile Version ARN
EnableAIOptOutPolicy:
Type: String
Description: Opt-out of AI-services improvement
Default: "false"
AllowedValues:
- "true"
- "false"
Resources:
OrganizationSetupFunctionLogGroup:
Type: "AWS::Logs::LogGroup"
UpdateReplacePolicy: Delete
DeletionPolicy: Delete
Metadata:
cfn_nag:
rules_to_suppress:
- id: W84
reason: "Ignore KMS key"
Properties:
LogGroupName: !Sub "/aws/lambda/${OrganizationSetupFunction}"
RetentionInDays: 3
OrganizationSetupFunctionRole:
Type: "AWS::IAM::Role"
Metadata:
cfn_nag:
rules_to_suppress:
- id: W11
reason: "Ignore wildcard in resource policy"
- id: W76
reason: "Ignore large policy"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
Effect: Allow
Principal:
Service: !Sub "lambda.${AWS::URLSuffix}"
Action: "sts:AssumeRole"
Description: !Sub "DO NOT DELETE - Used by Lambda. Created by CloudFormation ${AWS::StackId}"
Policies:
- PolicyName: OrganizationSetupFunctionPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: OrganizationsAccess
Effect: Allow
Action:
- "organizations:AttachPolicy"
- "organizations:CreatePolicy"
- "organizations:DescribeAccount"
- "organizations:DescribeEffectivePolicy"
- "organizations:DescribeOrganization"
- "organizations:DescribeOrganizationalUnit"
- "organizations:EnableAWSServiceAccess"
- "organizations:EnableAllFeatures"
- "organizations:EnablePolicyType"
- "organizations:ListAccounts"
- "organizations:ListAWSServiceAccessForOrganization"
- "organizations:ListDelegatedAdministrators"
- "organizations:ListPolicies"
- "organizations:ListRoots"
- "organizations:RegisterDelegatedAdministrator"
Resource: "*"
- Effect: Allow
Action: "access-analyzer:CreateAnalyzer"
Resource: !Sub "arn:${AWS::Partition}:access-analyzer:*:${AWS::AccountId}:analyzer/*"
- Effect: Allow
Action: "iam:GetRole"
Resource: !Sub "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/*"
- Effect: Allow
Action:
- "cloudformation:ActivateOrganizationsAccess"
- "detective:EnableOrganizationAdminAccount"
- "ec2:DescribeRegions"
- "fms:AssociateAdminAccount"
- "guardduty:EnableOrganizationAdminAccount"
- "inspector2:Enable"
- "inspector2:EnableDelegatedAdminAccount"
- "macie2:EnableMacie"
- "macie2:EnableOrganizationAdminAccount"
- "ram:EnableSharingWithAwsOrganization"
- "securityhub:EnableOrganizationAdminAccount"
- "servicecatalog:EnableAWSOrganizationsAccess"
- "securitylake:RegisterDataLakeDelegatedAdministrator"
Resource: "*"
- Effect: Allow
Action: "iam:CreateServiceLinkedRole"
Resource: "*"
- Effect: Allow
Action: "sts:AssumeRole"
Resource: !Sub "arn:${AWS::Partition}:iam::*:role/AWSControlTowerExecution"
Tags:
- Key: "aws-cloudformation:stack-name"
Value: !Ref "AWS::StackName"
- Key: "aws-cloudformation:stack-id"
Value: !Ref "AWS::StackId"
- Key: "aws-cloudformation:logical-id"
Value: OrganizationSetupFunctionRole
- Key: GITHUB_ORG
Value: "aws-samples"
- Key: GITHUB_REPO
Value: aws-control-tower-org-setup-sample
CloudWatchLogsPolicy:
Type: "AWS::IAM::Policy"
Properties:
PolicyName: CloudWatchLogs
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Action:
- "logs:CreateLogStream"
- "logs:PutLogEvents"
Resource: !GetAtt OrganizationSetupFunctionLogGroup.Arn
Roles:
- !Ref OrganizationSetupFunctionRole
CodeSigningConfig:
Type: "AWS::Lambda::CodeSigningConfig"
Properties:
Description: OrganizationSetup Code Signing
AllowedPublishers:
SigningProfileVersionArns:
- !Ref SigningProfileVersionArn
CodeSigningPolicies:
UntrustedArtifactOnDeployment: Enforce
OrganizationSetupFunction:
Type: "AWS::Serverless::Function"
Metadata:
cfn_nag:
rules_to_suppress:
- id: W58
reason: "Ignore CloudWatch Logs write"
- id: W89
reason: "Ignore VPC"
Properties:
Architectures:
- arm64
CodeSigningConfigArn: !Ref CodeSigningConfig
CodeUri: src/
Description: DO NOT DELETE - Organization Setup Function
Environment:
Variables:
ADMINISTRATOR_ACCOUNT_NAME: !Ref AdministratorAccountName
ENABLE_AI_OPTOUT_POLICY: !Ref EnableAIOptOutPolicy
EXECUTION_ROLE_NAME: !Ref ExecutionRoleName
LOG_LEVEL: INFO
REGIONS: !Join [",", !Ref Regions]
PRIMARY_REGION: !Ref "AWS::Region"
Events:
EventBridgeEvent:
Type: EventBridgeRule
Properties:
InputPath: "$.detail"
Pattern:
source:
- "aws.controltower"
"detail-type":
- "AWS Service Event via CloudTrail"
detail:
eventName:
- SetupLandingZone
serviceEventDetails:
setupLandingZoneStatus:
state:
- SUCCEEDED
Handler: org_setup.lambda_handler.handler
MemorySize: 256 # megabytes
PropagateTags: true
ReservedConcurrentExecutions: 1
Role: !GetAtt OrganizationSetupFunctionRole.Arn
Runtime: python3.12
Tags:
GITHUB_ORG: aws-samples
GITHUB_REPO: aws-control-tower-org-setup-sample
Timeout: 600 # 10 minutes
OrganizationSetup:
Type: "Custom::OrganizationSetup"
DependsOn: CloudWatchLogsPolicy
Properties:
ServiceToken: !GetAtt OrganizationSetupFunction.Arn
ExecutionCount: !Ref ExecutionCount