generated from cloudposse/terraform-example-module
-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathec2-policies.yaml
308 lines (298 loc) · 7.6 KB
/
ec2-policies.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
#
## WARNING AND HISTORICAL NOTE
#
# When the DenyEC2NonNitroInstances policy was first introduced, it was primarily intended
# to ensure that network traffic was encrypted in transit, which was seen to be a feature
# that all Nitro instances supported and all non-Nitro instances did not. However, this
# is not the case, as instance families such as `a1`, `t3`, and `t4g` are Nitro based but
# do not support network traffic encryption in transit.
#
# As such, the DenyEC2NonNitroInstances policy is no longer a reliable way to ensure that
# network traffic is encrypted in transit. It is recommended that you use the
# DenyEC2InstancesWithoutEncryptionInTransit policy (below) instead if that is your goal.
# This policy denies instance families that aren't based on the Nitro system as documented in the following document:
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html#ec2-nitro-instances
# The listing below *are* Nitro-based instances. Most are collected from the following CLI query:
# aws ec2 describe-instance-types \
# --filters Name=hypervisor,Values=nitro \
# --query "InstanceTypes[*].[InstanceType]" --output text | cut -f 1 -d. | sort | uniq
#
# However, that the command only lists instance types available in the default region. To be
# fully comprehensive, the command should be run in all regions where instances are launched.
# As a shortcut, we only run the command in us-east-1, us-west-2, and eu-north-1, as these
# regions combined appear to cover all instance types.
#
# In order to fit within the 5120-character limit for policies
# (See https://docs.aws.amazon.com/organizations/latest/userguide/org_troubleshoot_policies.html )
# only the instance family is checked, not the specific instance type. AWS support
# has confirmed that this is in fact correct, and spot checking has failed to
# find any instance families that have some sizes based on Nitro and some not.
#
- sid: "DenyEC2NonNitroInstances"
effect: "Deny"
actions:
- "ec2:RunInstances"
condition:
- test: "StringNotLike"
variable: "ec2:InstanceType"
values:
# updated 2024-04-11
- a1.*
- c5.*
- c5a.*
- c5ad.*
- c5d.*
- c5n.*
- c6a.*
- c6g.*
- c6gd.*
- c6gn.*
- c6i.*
- c6id.*
- c6in.*
- c7a.*
- c7g.*
- c7gd.*
- c7gn.*
- c7i.*
- d3.*
- d3en.*
- dl1.*
- dl2q.*
- g4ad.*
- g4dn.*
- g5.*
- g5g.*
- g6.*
- gr6.*
- hpc6a.*
- hpc6id.*
- hpc7a.*
- hpc7g.*
- i3en.*
- i4g.*
- i4i.*
- im4gn.*
- inf1.*
- inf2.*
- is4gen.*
- m5.*
- m5a.*
- m5ad.*
- m5d.*
- m5dn.*
- m5n.*
- m5zn.*
- m6a.*
- m6g.*
- m6gd.*
- m6i.*
- m6id.*
- m6idn.*
- m6in.*
- m7a.*
- m7g.*
- m7gd.*
- m7i.*
- m7i-flex.*
- p3dn.*
- p4d.*
- p5.*
- r5.*
- r5a.*
- r5ad.*
- r5b.*
- r5d.*
- r5dn.*
- r5n.*
- r6a.*
- r6g.*
- r6gd.*
- r6i.*
- r6id.*
- r6idn.*
- r6in.*
- r7a.*
- r7g.*
- r7gd.*
- r7i.*
- r7iz.*
- t3.*
- t3a.*
- t4g.*
- trn1.*
- trn1n.*
- u-12tb1.*
- u-18tb1.*
- u-24tb1.*
- u-3tb1.*
- u-6tb1.*
- u-9tb1.*
- vt1.*
- x2gd.*
- x2idn.*
- x2iedn.*
- x2iezn.*
- z1d.*
resources:
- "arn:aws:ec2:*:*:instance/*"
# This policy denies instance types that do not support Encryption-in-Transit as
# described in the following document:
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/data-protection.html#encryption-transit
# and enumerated by the following command (adapted from the command specified in the documentation):
#
# aws ec2 describe-instance-types \
# --filters Name=network-info.encryption-in-transit-supported,Values=true \
# --query "InstanceTypes[*].[InstanceType]" --output text | cut -f 1 -d. | sort | uniq
#
# Note that the command only lists instance types available in the default region. To be
# fully comprehensive, the command should be run in all regions where instances are launched.
# Since that is difficult, this policy is based on the official AWS documentation instead.
#
# In order to fit within the 5120-character limit for policies
# (See https://docs.aws.amazon.com/organizations/latest/userguide/org_troubleshoot_policies.html )
# only the instance family is checked, not the specific instance type. AWS support
# has confirmed that this is in fact correct, and spot checking has failed to
# find any instance families that have mixed support for encryption in transit based on size.
- sid: "DenyEC2InstancesWithoutEncryptionInTransit"
effect: "Deny"
actions:
- "ec2:RunInstances"
condition:
- test: "StringNotLike"
variable: "ec2:InstanceType"
values:
# updated 2024-04-11
- c5a.*
- c5ad.*
- c5n.*
- c6a.*
- c6gn.*
- c6i.*
- c6id.*
- c6in.*
- c7a.*
- c7g.*
- c7gd.*
- c7gn.*
- c7i.*
- d3.*
- d3en.*
- dl1.*
- dl2q.*
- g4ad.*
- g4dn.*
- g5.*
- g6.*
- gr6.*
- hpc6a.*
- hpc6id.*
- hpc7a.*
- hpc7g.*
- i3en.*
- i4g.*
- i4i.*
- im4gn.*
- inf1.*
- inf2.*
- is4gen.*
- m5dn.*
- m5n.*
- m5zn.*
- m6a.*
- m6i.*
- m6id.*
- m6idn.*
- m6in.*
- m7a.*
- m7g.*
- m7gd.*
- m7i.*
- m7i-flex.*
- p3dn.*
- p4d.*
- p4de.*
- p5.*
- r5dn.*
- r5n.*
- r6a.*
- r6i.*
- r6id.*
- r6idn.*
- r6in.*
- r7a.*
- r7g.*
- r7gd.*
- r7i.*
- r7iz.*
- trn1.*
- trn1n.*
- u-12tb1.*
- u-18tb1.*
- u-24tb1.*
- u-3tb1.*
- u-6tb1.*
- u-9tb1.*
- vt1.*
- x2idn.*
- x2iedn.*
- x2iezn.*
resources:
- "arn:aws:ec2:*:*:instance/*"
- sid: "DenyEC2PublicAMI"
effect: "Deny"
actions:
- "ec2:RunInstances"
condition:
- test: "Bool"
variable: "ec2:Public"
values:
- true
resources:
- "arn:aws:ec2:*::image/*"
- sid: "DenyEC2AssociatePublicIp"
effect: "Deny"
actions:
- "ec2:RunInstances"
condition:
- test: "Bool"
variable: "ec2:AssociatePublicIpAddress"
values:
- true
resources:
- "arn:aws:ec2:*:*:network-interface/*"
- sid: "DenyEC2WithNoIMDSv2"
effect: "Deny"
actions:
- "ec2:RunInstances"
condition:
- test: "StringNotEquals"
variable: "ec2:MetadataHttpTokens"
values:
- "required"
resources:
- "arn:aws:ec2:*:*:instance/*"
- sid: "DenyEC2ApiWithNoMFA"
effect: "Deny"
actions:
- "ec2:StopInstances"
- "ec2:TerminateInstances"
- "ec2:SendDiagnosticInterrupt"
condition:
- test: "BoolIfExists"
variable: "aws:MultiFactorAuthPresent"
values:
- false
resources:
- "*"
- sid: "RequireEBSEncryption"
effect: "Deny"
actions:
- "ec2:CreateVolume"
condition:
- test: "Bool"
variable: "ec2:Encrypted"
values:
- false
resources:
- "*"