11-- uses view which uses aws_security_group_ingress_rules.sql query
22insert into aws_policy_results
3- select
4- :' execution_time' as execution_time,
5- :' framework' as framework,
6- :' check_id' as check_id,
7- ' Security groups should not allow unrestricted access to ports with high risk' as title,
8- account_id,
3+ WITH IndividualRuleStatus AS (
4+ SELECT
5+ account_id,
96 id as resource_id,
10- case when
7+ case when
118 (ip = ' 0.0.0.0/0' or ip = ' ::/0' )
129 and ((from_port is null and to_port is null ) -- all ports
1310 or 20 between from_port and to_port
@@ -36,5 +33,20 @@ select
3633 or 9300 between from_port and to_port)
3734 then ' fail'
3835 else ' pass'
39- end
40- from view_aws_security_group_ingress_rules
36+ end as status
37+ FROM view_aws_security_group_ingress_rules
38+ )
39+
40+ SELECT
41+ :' execution_time' as execution_time,
42+ :' framework' as framework,
43+ :' check_id' as check_id,
44+ ' Aggregates rules of security groups with ports and IPs including ipv6' as title,
45+ account_id,
46+ resource_id,
47+ CASE
48+ WHEN SUM (CASE WHEN status = ' fail' THEN 1 ELSE 0 END) > 0 THEN ' fail'
49+ ELSE ' pass'
50+ END as status
51+ FROM IndividualRuleStatus
52+ GROUP BY account_id, resource_id
0 commit comments