-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtemplate.yaml
232 lines (208 loc) · 7.64 KB
/
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
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals:
Function:
Runtime: python3.12
Handler: app.lambda_handler
Timeout: 900
Description:
This configures the SSO permissions of an account. Responds to an SNS message sent
from an AFT customisation to assign SSO permission sets to an account using custom
AFT data.
Parameters:
CloudAdministrationGroupName:
Type: String
Description: The name of the SSO Cloud Administration Group to be given
AWSAdministratorAccess to all accounts. Leave blank if you don't want
or have a cloud administration group which needs access to all accounts.
Default: 'your-cloud-administration-sso-group-name'
CloudAdministrationGroupPermissionSets:
Type: String
Description: The permission sets to be assigned the CloudAdministrationGroupName group.
Default: 'AWSAdministratorAccess,AWSReadOnlyAccess'
AFTManagementAccountId:
Type: String
Description: The name of the AFT Management account.
Default: "444455556666"
# ------------------------------------------------------------------------------
Resources:
###############################################################################
#
# The SNS queue to which AFT sends messages from each member account.
#
###############################################################################
AFTSSOAccountConfigurationTopic:
Type: 'AWS::SNS::Topic'
Properties:
TopicName: aft-sso-account-configuration-topic
AFTSSOAccountConfigurationTopicPolicy:
Type: 'AWS::SNS::TopicPolicy'
Properties:
PolicyDocument:
Version: '2012-10-17'
Statement:
-
Sid: CrossAccountAccess
Effect: Allow
Principal:
AWS: '*'
Resource: !Ref AFTSSOAccountConfigurationTopic
Action: 'sns:Publish'
Condition:
# "StringEquals":
# "aws:PrincipalOrgID": !Ref OrgId
"ArnLike":
"aws:PrincipalArn": "arn:aws:iam::*:role/AWSAFTExecution"
-
Sid: AllowUse
Effect: Allow
Principal:
AWS: !Sub '${AWS::AccountId}'
Resource: !Ref AFTSSOAccountConfigurationTopic
Action:
- sns:Subscribe
- sns:Receive
- sns:ListSubscriptionsByTopic
-
Sid: AllowAWSChatbot
Effect: Allow
Principal:
AWS: !Sub 'arn:aws:iam::${AWS::AccountId}:role/aws-service-role/management.chatbot.amazonaws.com/AWSServiceRoleForAWSChatbot'
Resource: !Ref AFTSSOAccountConfigurationTopic
Action:
- sns:Subscribe
- sns:Receive
Topics:
- !Ref AFTSSOAccountConfigurationTopic
###############################################################################
#
# The trigger function, listening for SNS messages and starting a Step Function
# execution for each SNS message received.
#
###############################################################################
TriggerFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/trigger/
Events:
CalledFromAFTEvent:
Type: SNS
Properties:
Topic: !Ref AFTSSOAccountConfigurationTopic
Region: !Sub '${AWS::Region}'
Environment:
Variables:
STATE_MACHINE_ARN: !Ref ConfigureSSOAccountPermissionsSM
Policies:
- Statement:
-
Effect: Allow
Action:
- states:StartExecution
Resource:
- !Ref ConfigureSSOAccountPermissionsSM
LambdaResourcePolicy:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !Ref TriggerFunction
Principal: sns.amazonaws.com
Action: lambda:InvokeFunction
SourceArn: !Ref AFTSSOAccountConfigurationTopic
###############################################################################
#
# The Step Functions state machine which performs the actual SSO permission
# set changes to the account.
#
###############################################################################
ConfigureSSOAccountPermissionsSM:
Type: AWS::Serverless::StateMachine
Properties:
DefinitionUri: statemachine/configure_sso_account_permissions.asl.yaml
DefinitionSubstitutions:
ConfigureSSOAccountPermissionsFunctionArn: !GetAtt ConfigureSSOAccountPermissionsFunction.Arn
Policies:
- LambdaInvokePolicy:
FunctionName: !Ref ConfigureSSOAccountPermissionsFunction
ConfigureSSOAccountPermissionsFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: functions/configure_sso_account_permissions/
Policies:
- Statement:
-
Sid: SSOPermissions
Effect: Allow
Action:
- sso:CreateAccountAssignment
- sso:DeleteAccountAssignment
- sso:DescribeAccountAssignmentCreationStatus
- sso:DescribePermissionSet
- sso:ListAccountAssignments
- sso:ListInstances
- sso:ListPermissionSets
- sso:ListPermissionSetsProvisionedToAccount
Resource: '*'
-
Sid: IdentityStorePermissions
Effect: Allow
Action:
- identitystore:DescribeGroup
- identitystore:DescribeUser
- identitystore:ListGroups
- identitystore:ListUsers
Resource: '*'
Environment:
Variables:
CLOUD_ADMINISTRATION_GROUP_NAME: !Ref CloudAdministrationGroupName
CLOUD_ADMINISTRATION_GROUP_PERMISSION_SETS: !Ref CloudAdministrationGroupPermissionSets
################################################################################
#
# Monitoring. For state machines, only the state machine itself should be
# monitored as it orchestrates the lambda functions which are expected to fail
# in certain circumstances without this constituting a processing failure.
#
# Lambdas not in state machines should be monitored individually.
#
################################################################################
ConfigureSSOAccountPermissionsSMAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: INFRA-ConfigureSSOAccountPermissionsSM-Failure-MEDIUM
AlarmDescription: The state machine ConfigureSSOAccountPermissionsSM failed.
ActionsEnabled: true
OKActions: []
AlarmActions: []
InsufficientDataActions: []
MetricName: ExecutionsFailed
Namespace: AWS/States
Statistic: Sum
Dimensions:
- Name: StateMachineArn
Value: !Ref ConfigureSSOAccountPermissionsSM
Period: 60
EvaluationPeriods: 1
DatapointsToAlarm: 1
Threshold: 1
ComparisonOperator: GreaterThanOrEqualToThreshold
TreatMissingData: notBreaching
AlarmTriggerFunction:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmName: INFRA-SSOAccountConfigurationTriggerFunction-HIGH
AlarmDescription: SSOAccountConfigurationTriggerFunction failed.
ActionsEnabled: true
OKActions: []
AlarmActions: []
InsufficientDataActions: []
MetricName: Errors
Namespace: AWS/Lambda
Statistic: Sum
Dimensions:
- Name: FunctionName
Value: !Ref TriggerFunction
Period: 60
EvaluationPeriods: 1
DatapointsToAlarm: 1
Threshold: 1
ComparisonOperator: GreaterThanOrEqualToThreshold
TreatMissingData: notBreaching