Skip to content

Commit ed14116

Browse files
Update queries to use non-deprecated columns, update ebs_encryption_by_default_enabled control and query name, fix VPC security group rule queries only checking for exact port matches instead of ranges (#835)
Co-authored-by: Cody Bruno <[email protected]>
1 parent 640d430 commit ed14116

File tree

47 files changed

+225
-200
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+225
-200
lines changed

all_controls/ec2.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
control.ec2_ami_not_older_than_90_days,
1313
control.ec2_ami_restrict_public_access,
1414
control.ec2_client_vpn_endpoint_client_connection_logging_enabled,
15-
control.ec2_ebs_default_encryption_enabled,
15+
control.ebs_encryption_by_default_enabled,
1616
control.ec2_instance_attached_ebs_volume_delete_on_termination_enabled,
1717
control.ec2_instance_detailed_monitoring_enabled,
1818
control.ec2_instance_ebs_optimized,

cis_controls_v8_ig1/cis_controls_v8_ig1_11.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
description = "Protect recovery data with equivalent controls to the original data. Reference encryption or data separation, based on requirements."
3737
children = [
3838
control.ebs_attached_volume_encryption_enabled,
39-
control.ec2_ebs_default_encryption_enabled,
39+
control.ebs_encryption_by_default_enabled,
4040
control.rds_db_instance_encryption_at_rest_enabled
4141
]
4242

cis_controls_v8_ig1/cis_controls_v8_ig1_4.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
control.cloudtrail_trail_logs_encrypted_with_kms_cmk,
3838
control.cloudtrail_trail_validation_enabled,
3939
control.ebs_attached_volume_encryption_enabled,
40-
control.ec2_ebs_default_encryption_enabled,
40+
control.ebs_encryption_by_default_enabled,
4141
control.ec2_instance_iam_profile_attached,
4242
control.iam_account_password_policy_strong_min_reuse_24,
4343
control.iam_group_user_role_no_inline_policies,

cis_v150/section_2.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
title = "2.2.1 Ensure EBS Volume Encryption is Enabled in all Regions"
139139
description = "Elastic Compute Cloud (EC2) supports encryption at rest when using the Elastic Block Store (EBS) service. While disabled by default, forcing encryption at EBS volume creation is supported."
140140
documentation = file("./cis_v150/docs/cis_v150_2_2_1.md")
141-
query = query.ebs_volume_encryption_at_rest_enabled
141+
query = query.ebs_encryption_by_default_enabled
142142

143143
tags = merge(local.cis_v150_2_2_common_tags, {
144144
cis_item_id = "2.2.1"

cis_v200/section_2.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
title = "2.2.1 Ensure EBS Volume Encryption is Enabled in all Regions"
124124
description = "Elastic Compute Cloud (EC2) supports encryption at rest when using the Elastic Block Store (EBS) service. While disabled by default, forcing encryption at EBS volume creation is supported."
125125
documentation = file("./cis_v200/docs/cis_v200_2_2_1.md")
126-
query = query.ebs_volume_encryption_at_rest_enabled
126+
query = query.ebs_encryption_by_default_enabled
127127

128128
tags = merge(local.cis_v200_2_2_common_tags, {
129129
cis_item_id = "2.2.1"

cis_v300/section_2.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
title = "2.2.1 Ensure EBS Volume Encryption is Enabled in all Regions"
124124
description = "Elastic Compute Cloud (EC2) supports encryption at rest when using the Elastic Block Store (EBS) service. While disabled by default, forcing encryption at EBS volume creation is supported."
125125
documentation = file("./cis_v300/docs/cis_v300_2_2_1.md")
126-
query = query.ebs_volume_encryption_at_rest_enabled
126+
query = query.ebs_encryption_by_default_enabled
127127

128128
tags = merge(local.cis_v300_2_2_common_tags, {
129129
cis_item_id = "2.2.1"

cisa_cyber_essentials/your_data.pp

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
control.cloudtrail_trail_logs_encrypted_with_kms_cmk,
2222
control.dynamodb_table_encrypted_with_kms,
2323
control.ebs_attached_volume_encryption_enabled,
24-
control.ec2_ebs_default_encryption_enabled,
24+
control.ebs_encryption_by_default_enabled,
2525
control.efs_file_system_encrypted_with_cmk,
2626
control.es_domain_encryption_at_rest_enabled,
2727
control.log_group_encryption_at_rest_enabled,
@@ -58,7 +58,7 @@
5858
control.dynamodb_table_encrypted_with_kms,
5959
control.ebs_attached_volume_encryption_enabled,
6060
control.ebs_snapshot_not_publicly_restorable,
61-
control.ec2_ebs_default_encryption_enabled,
61+
control.ebs_encryption_by_default_enabled,
6262
control.ec2_instance_in_vpc,
6363
control.ec2_instance_not_publicly_accessible,
6464
control.efs_file_system_encrypted_with_cmk,

cisa_cyber_essentials/your_systems.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
control.ebs_attached_volume_encryption_enabled,
6666
control.ebs_snapshot_not_publicly_restorable,
6767
control.ebs_volume_in_backup_plan,
68-
control.ec2_ebs_default_encryption_enabled,
68+
control.ebs_encryption_by_default_enabled,
6969
control.ec2_instance_ebs_optimized,
7070
control.ec2_instance_in_vpc,
7171
control.ec2_instance_not_publicly_accessible,

conformance_pack/ebs.pp

+44-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@
44
})
55
}
66

7+
control "ebs_encryption_by_default_enabled" {
8+
title = "EBS default encryption should be enabled"
9+
description = "To help protect data at rest, ensure that encryption is enabled for your AWS Elastic Block Store (AWS EBS) volumes."
10+
query = query.ebs_encryption_by_default_enabled
11+
12+
tags = merge(local.conformance_pack_ec2_common_tags, {
13+
cis_controls_v8_ig1 = "true"
14+
cisa_cyber_essentials = "true"
15+
ffiec = "true"
16+
gxp_21_cfr_part_11 = "true"
17+
gxp_eu_annex_11 = "true"
18+
hipaa_final_omnibus_security_rule_2013 = "true"
19+
hipaa_security_rule_2003 = "true"
20+
nist_800_171_rev_2 = "true"
21+
nist_800_53_rev_4 = "true"
22+
nist_800_53_rev_5 = "true"
23+
nist_csf = "true"
24+
pci_dss_v321 = "true"
25+
soc_2 = "true"
26+
})
27+
}
28+
729
control "ebs_snapshot_not_publicly_restorable" {
830
title = "EBS snapshots should not be publicly restorable"
931
description = "Manage access to the AWS Cloud by ensuring EBS snapshots are not publicly restorable."
@@ -163,6 +185,27 @@
163185
tags = local.conformance_pack_ebs_common_tags
164186
}
165187

188+
query "ebs_encryption_by_default_enabled" {
189+
sql = <<-EOQ
190+
select
191+
'arn:' || r.partition || '::' || r.region || ':' || r.account_id as resource,
192+
case
193+
when r.opt_in_status = 'not-opted-in' then 'skip'
194+
when not default_ebs_encryption_enabled then 'alarm'
195+
else 'ok'
196+
end as status,
197+
case
198+
when r.opt_in_status = 'not-opted-in' then r.region || ' region is disabled.'
199+
when not default_ebs_encryption_enabled then r.region || ' default EBS encryption disabled.'
200+
else r.region || ' default EBS encryption enabled.'
201+
end as reason
202+
${replace(local.common_dimensions_qualifier_sql, "__QUALIFIER__", "r.")}
203+
from
204+
aws_region as r
205+
left join aws_ec2_regional_settings as s on s.account_id = r.account_id and s.region = r.region;
206+
EOQ
207+
}
208+
166209
query "ebs_snapshot_not_publicly_restorable" {
167210
sql = <<-EOQ
168211
select
@@ -386,4 +429,4 @@
386429
aws_ebs_volume as v
387430
left join volume_with_snapshots as s on s.volume_id = v.volume_id;
388431
EOQ
389-
}
432+
}

conformance_pack/ec2.pp

+1-40
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,6 @@
2020
tags = local.conformance_pack_ec2_common_tags
2121
}
2222

23-
control "ec2_ebs_default_encryption_enabled" {
24-
title = "EBS default encryption should be enabled"
25-
description = "To help protect data at rest, ensure that encryption is enabled for your AWS Elastic Block Store (AWS EBS) volumes."
26-
query = query.ec2_ebs_default_encryption_enabled
27-
28-
tags = merge(local.conformance_pack_ec2_common_tags, {
29-
cis_controls_v8_ig1 = "true"
30-
cisa_cyber_essentials = "true"
31-
ffiec = "true"
32-
gxp_21_cfr_part_11 = "true"
33-
gxp_eu_annex_11 = "true"
34-
hipaa_final_omnibus_security_rule_2013 = "true"
35-
hipaa_security_rule_2003 = "true"
36-
nist_800_171_rev_2 = "true"
37-
nist_800_53_rev_4 = "true"
38-
nist_800_53_rev_5 = "true"
39-
nist_csf = "true"
40-
pci_dss_v321 = "true"
41-
soc_2 = "true"
42-
})
43-
}
4423

4524
control "ec2_instance_detailed_monitoring_enabled" {
4625
title = "EC2 instance detailed monitoring should be enabled"
@@ -512,24 +491,6 @@
512491
tags = local.conformance_pack_ec2_common_tags
513492
}
514493

515-
query "ec2_ebs_default_encryption_enabled" {
516-
sql = <<-EOQ
517-
select
518-
'arn:' || partition || '::' || region || ':' || account_id as resource,
519-
case
520-
when not default_ebs_encryption_enabled then 'alarm'
521-
else 'ok'
522-
end as status,
523-
case
524-
when not default_ebs_encryption_enabled then region || ' default EBS encryption disabled.'
525-
else region || ' default EBS encryption enabled.'
526-
end as reason
527-
${local.common_dimensions_sql}
528-
from
529-
aws_ec2_regional_settings;
530-
EOQ
531-
}
532-
533494
query "ec2_instance_detailed_monitoring_enabled" {
534495
sql = <<-EOQ
535496
select
@@ -2036,4 +1997,4 @@
20361997
from
20371998
aws_ec2_network_interface;
20381999
EOQ
2039-
}
2000+
}

conformance_pack/iam.pp

+27-7
Original file line numberDiff line numberDiff line change
@@ -1518,28 +1518,48 @@
15181518

15191519
query "iam_access_analyzer_enabled_without_findings" {
15201520
sql = <<-EOQ
1521+
with accessanalyzer_findings as (
1522+
select
1523+
a.status as status,
1524+
f.access_analyzer_arn as arn,
1525+
a.region,
1526+
a.account_id,
1527+
a.tags,
1528+
a.name,
1529+
count(*)
1530+
from
1531+
aws_accessanalyzer_analyzer as a
1532+
left join aws_accessanalyzer_finding as f on f.access_analyzer_arn = a.arn
1533+
group by
1534+
f.access_analyzer_arn,
1535+
a.status,
1536+
a.region,
1537+
a.account_id,
1538+
a.tags,
1539+
a.name
1540+
)
15211541
select
15221542
'arn:' || r.partition || '::' || r.region || ':' || r.account_id as resource,
15231543
case
15241544
-- Skip any regions that are disabled in the account.
15251545
when r.opt_in_status = 'not-opted-in' then 'skip'
1526-
when aa.status = 'ACTIVE' and aa.findings is null then 'ok'
1527-
when aa.status = 'ACTIVE' and jsonb_array_length(aa.findings) > 0 then 'alarm'
1528-
when aa.status = 'NOT_AVAILABLE' then 'alarm'
1546+
when f.status = 'ACTIVE' and f.arn is null then 'ok'
1547+
when f.status = 'ACTIVE' and f.arn is not null then 'alarm'
1548+
when f.status = 'NOT_AVAILABLE' then 'alarm'
15291549
else 'alarm'
15301550
end as status,
15311551
case
15321552
when r.opt_in_status = 'not-opted-in' then r.region || ' region is disabled.'
1533-
when aa.status = 'ACTIVE' and aa.findings is null then aa.name || ' does not have active findings in region ' || r.region || '.'
1534-
when aa.status = 'ACTIVE' and jsonb_array_length(aa.findings) > 0 then aa.name || ' has active findings in region ' || r.region || '.'
1535-
when aa.status = 'NOT_AVAILABLE' then aa.name || ' is not enabled in region ' || r.region || '.'
1553+
when f.status = 'ACTIVE' and f.arn is null then f.name || ' does not have active findings in region ' || r.region || '.'
1554+
when f.status = 'ACTIVE' and f.arn is not null then f.name || ' has active findings in region ' || r.region || '.'
1555+
when f.status = 'NOT_AVAILABLE' then f.name || ' is not enabled in region ' || r.region || '.'
15361556
else 'IAM Access Analyzer is not active in region ' || r.region || '.'
15371557
end as reason
15381558
${local.tag_dimensions_sql}
15391559
${replace(local.common_dimensions_qualifier_sql, "__QUALIFIER__", "r.")}
15401560
from
15411561
aws_region as r
1542-
left join aws_accessanalyzer_analyzer as aa on r.account_id = aa.account_id and r.region = aa.region;
1562+
left join accessanalyzer_findings as f on f.region = r.region and f.account_id = r.account_id;
15431563
EOQ
15441564
}
15451565

conformance_pack/ssm.pp

+9-8
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,22 @@
176176
query "ssm_document_prohibit_public_access" {
177177
sql = <<-EOQ
178178
select
179-
'arn:' || partition || ':ssm:' || region || ':' || account_id || ':document/' || name as resource,
179+
d.arn as resource,
180180
case
181-
when account_ids :: jsonb ? 'all' then 'alarm'
181+
when p.account_ids :: jsonb ? 'all' then 'alarm'
182182
else 'ok'
183183
end as status,
184184
case
185-
when account_ids :: jsonb ? 'all' then title || ' publicly accesible.'
186-
else title || ' not publicly accesible.'
185+
when p.account_ids :: jsonb ? 'all' then d.title || ' publicly accessible.'
186+
else d.title || ' not publicly accessible.'
187187
end as reason
188-
${local.tag_dimensions_sql}
189-
${local.common_dimensions_sql}
188+
${replace(local.tag_dimensions_qualifier_sql, "__QUALIFIER__", "d.")}
189+
${replace(local.common_dimensions_qualifier_sql, "__QUALIFIER__", "d.")}
190190
from
191-
aws_ssm_document
191+
aws_ssm_document as d
192+
left join aws_ssm_document_permission as p on p.document_name = d.name and p.region = d.region and p.account_id = d.account_id
192193
where
193-
owner_type = 'Self';
194+
d.owner_type = 'Self';
194195
EOQ
195196
}
196197

0 commit comments

Comments
 (0)