/
ebs.sp
383 lines (356 loc) · 12.9 KB
/
ebs.sp
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
locals {
conformance_pack_ebs_common_tags = merge(local.aws_compliance_common_tags, {
service = "AWS/EBS"
})
}
control "ebs_snapshot_not_publicly_restorable" {
title = "EBS snapshots should not be publicly restorable"
description = "Manage access to the AWS Cloud by ensuring EBS snapshots are not publicly restorable."
query = query.ebs_snapshot_not_publicly_restorable
tags = merge(local.conformance_pack_ebs_common_tags, {
cis_controls_v8_ig1 = "true"
cisa_cyber_essentials = "true"
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gxp_21_cfr_part_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_4 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
pci_dss_v321 = "true"
rbi_cyber_security = "true"
soc_2 = "true"
})
}
control "ebs_volume_encryption_at_rest_enabled" {
title = "EBS volume encryption at rest should be enabled"
description = "Because sensitive data can exist and to help protect data at rest, ensure encryption is enabled for your AWS Elastic Block Store (AWS EBS) volumes."
query = query.ebs_volume_encryption_at_rest_enabled
tags = merge(local.conformance_pack_ebs_common_tags, {
fedramp_moderate_rev_4 = "true"
gdpr = "true"
nist_800_53_rev_5 = "true"
rbi_cyber_security = "true"
})
}
control "ebs_attached_volume_encryption_enabled" {
title = "Attached EBS volumes should have encryption enabled"
description = "Because sensitive data can exist and to help protect data at rest, ensure encryption is enabled for your AWS Elastic Block Store (AWS EBS) volumes."
query = query.ebs_attached_volume_encryption_enabled
tags = merge(local.conformance_pack_ebs_common_tags, {
audit_manager_control_tower = "true"
cis_controls_v8_ig1 = "true"
cisa_cyber_essentials = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gdpr = "true"
gxp_21_cfr_part_11 = "true"
gxp_eu_annex_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_4 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
pci_dss_v321 = "true"
rbi_cyber_security = "true"
soc_2 = "true"
})
}
control "ebs_volume_in_backup_plan" {
title = "EBS volumes should be in a backup plan"
description = "To help with data back-up processes, ensure your AWS Elastic Block Store (AWS EBS) volumes are a part of an AWS Backup plan."
query = query.ebs_volume_in_backup_plan
tags = merge(local.conformance_pack_ebs_common_tags, {
cis_controls_v8_ig1 = "true"
cisa_cyber_essentials = "true"
ffiec = "true"
gxp_21_cfr_part_11 = "true"
gxp_eu_annex_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_4 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
pci_dss_v321 = "true"
rbi_cyber_security = "true"
soc_2 = "true"
})
}
control "ebs_attached_volume_delete_on_termination_enabled" {
title = "Attached EBS volumes should have delete on termination enabled"
description = "This rule ensures that AWS Elastic Block Store volumes that are attached to AWS Elastic Compute Cloud (AWS EC2) instances are marked for deletion when an instance is terminated."
query = query.ebs_attached_volume_delete_on_termination_enabled
tags = merge(local.conformance_pack_ebs_common_tags, {
fedramp_moderate_rev_4 = "true"
ffiec = "true"
nist_800_53_rev_4 = "true"
})
}
control "ebs_volume_protected_by_backup_plan" {
title = "EBS volumes should be protected by a backup plan"
description = "Ensure that AWS Elastic Block Store (AWS EBS) volumes are protected by a backup plan. The rule is non-compliant if the AWS EBS volume is not covered by a backup plan."
query = query.ebs_volume_protected_by_backup_plan
tags = merge(local.conformance_pack_ebs_common_tags, {
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gxp_21_cfr_part_11 = "true"
gxp_eu_annex_11 = "true"
hipaa_final_omnibus_security_rule_2013 = "true"
hipaa_security_rule_2003 = "true"
nist_800_171_rev_2 = "true"
nist_csf = "true"
pci_dss_v321 = "true"
soc_2 = "true"
})
}
control "ebs_volume_unused" {
title = "EBS volumes should be attached to EC2 instances"
description = "Checks if EBS volumes are attached to EC2 instances."
query = query.ebs_volume_unused
tags = merge(local.conformance_pack_ebs_common_tags, {
audit_manager_control_tower = "true"
cis_controls_v8_ig1 = "true"
cisa_cyber_essentials = "true"
fedramp_low_rev_4 = "true"
fedramp_moderate_rev_4 = "true"
ffiec = "true"
gxp_21_cfr_part_11 = "true"
nist_800_171_rev_2 = "true"
nist_800_53_rev_5 = "true"
nist_csf = "true"
})
}
control "ebs_snapshot_encryption_enabled" {
title = "EBS snapshots should be encrypted"
description = "Ensure that EBS snapshots are encrypted. This rule is non-compliant if the EBS snapshot is not encrypted."
query = query.ebs_snapshot_encryption_enabled
tags = local.conformance_pack_ebs_common_tags
}
control "ebs_volume_snapshot_exists" {
title = "EBS volume snapshots should exist"
description = "Ensure that EBS volume snapshots exist. This rule is non-compliant if the EBS volume does not have any snapshot."
query = query.ebs_volume_snapshot_exists
tags = local.conformance_pack_ebs_common_tags
}
query "ebs_snapshot_not_publicly_restorable" {
sql = <<-EOQ
select
'arn:' || partition || ':ec2:' || region || ':' || account_id || ':snapshot/' || snapshot_id as resource,
case
when create_volume_permissions @> '[{"Group": "all", "UserId": null}]' then 'alarm'
else 'ok'
end as status,
case
when create_volume_permissions @> '[{"Group": "all", "UserId": null}]' then title || ' is publicly restorable.'
else title || ' is not publicly restorable.'
end as reason
${local.tag_dimensions_sql}
${local.common_dimensions_sql}
from
aws_ebs_snapshot;
EOQ
}
query "ebs_volume_encryption_at_rest_enabled" {
sql = <<-EOQ
select
arn as resource,
case
when encrypted then 'ok'
else 'alarm'
end as status,
case
when encrypted then volume_id || ' encrypted.'
else volume_id || ' not encrypted.'
end as reason
${local.tag_dimensions_sql}
${local.common_dimensions_sql}
from
aws_ebs_volume;
EOQ
}
query "ebs_attached_volume_encryption_enabled" {
sql = <<-EOQ
select
arn as resource,
case
when state != 'in-use' then 'skip'
when encrypted then 'ok'
else 'alarm'
end as status,
case
when state != 'in-use' then volume_id || ' not attached.'
when encrypted then volume_id || ' encrypted.'
else volume_id || ' not encrypted.'
end as reason
${local.tag_dimensions_sql}
${local.common_dimensions_sql}
from
aws_ebs_volume;
EOQ
}
query "ebs_volume_in_backup_plan" {
sql = <<-EOQ
with mapped_with_id as (
select
jsonb_agg(elems) as mapped_ids
from
aws_backup_selection,
jsonb_array_elements(resources) as elems
group by backup_plan_id
),
mapped_with_tags as (
select
jsonb_agg(elems ->> 'ConditionKey') as mapped_tags
from
aws_backup_selection,
jsonb_array_elements(list_of_tags) as elems
group by backup_plan_id
),
backed_up_volume as (
select
v.volume_id
from
aws_ebs_volume as v
join mapped_with_id as t on t.mapped_ids ?| array[v.arn]
union
select
v.volume_id
from
aws_ebs_volume as v
join mapped_with_tags as t on t.mapped_tags ?| array(select jsonb_object_keys(tags))
)
select
v.arn as resource,
case
when b.volume_id is null then 'alarm'
else 'ok'
end as status,
case
when b.volume_id is null then v.title || ' not in backup plan.'
else v.title || ' in backup plan.'
end as reason
${local.tag_dimensions_sql}
${replace(local.common_dimensions_qualifier_sql, "__QUALIFIER__", "v.")}
from
aws_ebs_volume as v
left join backed_up_volume as b on v.volume_id = b.volume_id;
EOQ
}
query "ebs_attached_volume_delete_on_termination_enabled" {
sql = <<-EOQ
select
arn as resource,
case
when state != 'in-use' then 'skip'
when attachment ->> 'DeleteOnTermination' = 'true' then 'ok'
else 'alarm'
end as status,
case
when state != 'in-use' then title || ' not attached to EC2 instance.'
when attachment ->> 'DeleteOnTermination' = 'true' then title || ' attached to ' || (attachment ->> 'InstanceId') || ', delete on termination enabled.'
else title || ' attached to ' || (attachment ->> 'InstanceId') || ', delete on termination disabled.'
end as reason
${local.tag_dimensions_sql}
${local.common_dimensions_sql}
from
aws_ebs_volume
left join jsonb_array_elements(attachments) as attachment on true;
EOQ
}
query "ebs_volume_protected_by_backup_plan" {
sql = <<-EOQ
with backup_protected_volume as (
select
resource_arn as arn
from
aws_backup_protected_resource as b
where
resource_type = 'EBS'
)
select
v.arn as resource,
case
when b.arn is not null then 'ok'
else 'alarm'
end as status,
case
when b.arn is not null then v.title || ' is protected by backup plan.'
else v.title || ' is not protected by backup plan.'
end as reason
${local.tag_dimensions_sql}
${replace(local.common_dimensions_qualifier_sql, "__QUALIFIER__", "v.")}
from
aws_ebs_volume as v
left join backup_protected_volume as b on v.arn = b.arn;
EOQ
}
query "ebs_volume_unused" {
sql = <<-EOQ
select
arn as resource,
case
when state = 'in-use' then 'ok'
else 'alarm'
end as status,
case
when state = 'in-use' then title || ' attached to EC2 instance.'
else title || ' not attached to EC2 instance.'
end as reason
${local.tag_dimensions_sql}
${local.common_dimensions_sql}
from
aws_ebs_volume;
EOQ
}
query "ebs_snapshot_encryption_enabled" {
sql = <<-EOQ
select
arn as resource,
case
when encrypted then 'ok'
else 'alarm'
end as status,
case
when encrypted then title || ' encryption enabled.'
else title || ' encryption disabled.'
end as reason
${local.tag_dimensions_sql}
${local.common_dimensions_sql}
from
aws_ebs_snapshot;
EOQ
}
query "ebs_volume_snapshot_exists" {
sql = <<-EOQ
with volume_with_snapshots as (
select
volume_id,
count(*) as snap_count
from
aws_ebs_snapshot
group by
volume_id
)
select
v.arn as resource,
case
when s.volume_id is not null then 'ok'
else 'alarm'
end as status,
case
when s.volume_id is not null then v.title || ' has ' || s.snap_count || ' snapshot(s).'
else v.title || ' does not have snapshot.'
end as reason
${local.tag_dimensions_sql}
${local.common_dimensions_sql}
from
aws_ebs_volume as v
left join volume_with_snapshots as s on s.volume_id = v.volume_id;
EOQ
}