-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror-iam.yml
190 lines (189 loc) · 5.69 KB
/
error-iam.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
---
AWSTemplateFormatVersion: '2010-09-09'
Description: MU IAM roles for an environment
Parameters:
Namespace:
Type: String
Description: Namespace for stack prefixes
EnvironmentName:
Type: String
Description: Name of environment used for resource namespace
Provider:
Type: String
Description: Provider type for services
Default: "ecs"
AllowedValues:
- "ecs"
- "ecs-fargate"
- "eks"
- "eks-fargate"
- "ec2"
Conditions:
IsEcsService:
"Fn::Equals":
- !Ref Provider
- 'ecs'
IsEcsFargateService:
"Fn::Equals":
- !Ref Provider
- 'ecs-fargate'
IsEksService:
"Fn::Equals":
- !Ref Provider
- 'eks'
IsEksFargateService:
"Fn::Equals":
- !Ref Provider
- 'eks-fargate'
HasEksServiceRole:
"Fn::Or":
- !Condition IsEksService
- !Condition IsEksFargateService
HasEC2InstanceProfile:
"Fn::Or":
- !Condition IsEksService
- !Condition IsEcsService
Resources:
EksServiceRole:
Type: AWS::IAM::Role
Condition: HasEksServiceRole
Properties:
RoleName: !Sub ${Namespace}-environment-${EnvironmentName}-eks-service-${AWS::Region}
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- eks.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
ManagedPolicyArns:
- !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonEKSServicePolicy
- !Sub arn:${AWS::Partition}:iam::aws:policy/AmazonEKSClusterPolicy
EC2InstanceProfile:
Type: AWS::IAM::InstanceProfile
Condition: HasEC2InstanceProfile
Properties:
Path: "/"
Roles:
- !Ref EC2Role
EC2Role:
Type: AWS::IAM::Role
Condition: HasEC2InstanceProfile
Properties:
RoleName: !Sub ${Namespace}-environment-${EnvironmentName}-instance-${AWS::Region}
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- sts:AssumeRole
Path: "/"
ManagedPolicyArns:
Fn::If:
- IsEksService
- - Fn::Sub: arn:${AWS::Partition}:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
- Fn::Sub: arn:${AWS::Partition}:iam::aws:policy/AmazonEKSWorkerNodePolicy
- Fn::Sub: arn:${AWS::Partition}:iam::aws:policy/AmazonEKS_CNI_Policy
- - Fn::Sub: arn:${AWS::Partition}:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly
Policies:
- Fn::If:
- IsEcsService
- PolicyName: ecs-service
PolicyDocument:
Statement:
- Effect: Allow
Action:
- ecs:RegisterContainerInstance
- ecs:DeregisterContainerInstance
- ecs:SubmitContainerStateChange
- ecs:SubmitTaskStateChange
Resource: !Sub arn:${AWS::Partition}:ecs:${AWS::Region}:${AWS::AccountId}:cluster/${Namespace}-environment-${EnvironmentName}
- Effect: Allow
Action:
- ecs:StartTelemetrySession
- ecs:Poll
Resource: "*"
Condition:
ArnEquals:
"ecs:cluster": !Sub arn:${AWS::Partition}:ecs:${AWS::Region}:${AWS::AccountId}:cluster/${Namespace}-environment-${EnvironmentName}
- Effect: Allow
Action:
- ecs:StartTask
Resource: "*"
Condition:
ArnEquals:
"ecs:cluster": !Sub arn:${AWS::Partition}:ecs:${AWS::Region}:${AWS::AccountId}:cluster/${Namespace}-environment-${EnvironmentName}
- Effect: Allow
Action:
- ecs:DiscoverPollEndpoint
Resource: "*"
- !Ref AWS::NoValue
- PolicyName: env-common
PolicyDocument:
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
- logs:DescribeLogGroups
- logs:DescribeLogStreams
Resource: '*'
- Effect: Allow
Action:
- ssm:DescribeAssociation
- ssm:GetDocument
- ssm:GetManifest
- ssm:ListAssociations
- ssm:ListInstanceAssociations
- ssm:PutInventory
- ssm:PutComplianceItems
- ssm:PutConfigurePackageResult
- ssm:UpdateAssociationStatus
- ssm:UpdateInstanceAssociationStatus
- ssm:UpdateInstanceInformation
Resource: "*"
- Effect: Allow
Action:
- ssmmessages:CreateControlChannel
- ssmmessages:CreateDataChannel
- ssmmessages:OpenControlChannel
- ssmmessages:OpenDataChannel
Resource: "*"
- Effect: Allow
Action:
- ec2messages:AcknowledgeMessage
- ec2messages:DeleteMessage
- ec2messages:FailMessage
- ec2messages:GetEndpoint
- ec2messages:GetMessages
- ec2messages:SendReply
Resource: "*"
WaitHandle:
Type: "AWS::CloudFormation::WaitConditionHandle"
Outputs:
EC2InstanceProfileArn:
Description: Instance profile for container instances
Value:
Fn::If:
- HasEC2InstanceProfile
- !GetAtt EC2InstanceProfile.Arn
- ''
EC2RoleArn:
Description: IAM Role for container instances
Value:
Fn::If:
- HasEC2InstanceProfile
- !GetAtt EC2Role.Arn
- ''
EksServiceRoleArn:
Description: IAM role ARN for EKS clusters
Value:
Fn::If:
- HasEksServiceRole
- !GetAtt EksServiceRole.Arn
- ''