Skip to content

Commit efa9e34

Browse files
authored
feat: Updated query of security_groups_with_access_to_unauthorized_ports (#13855)
A change was made because duplicate rows were inserted into the aws_policy_results table. Additionally, the IP condition should be combined with port conditions using parentheses for proper logical grouping.
1 parent 6834ee9 commit efa9e34

1 file changed

Lines changed: 31 additions & 17 deletions

File tree

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
-- uses view which uses aws_security_group_ingress_rules.sql query
22
insert into aws_policy_results
3+
WITH IndividualRuleStatus AS (
4+
SELECT
5+
account_id,
6+
id as resource_id,
7+
case when
8+
(ip = '0.0.0.0/0' OR ip = '::/0')
9+
AND ((from_port IS NULL AND to_port IS NULL) -- all prots
10+
OR from_port IS DISTINCT FROM 80
11+
OR to_port IS DISTINCT FROM 80
12+
OR from_port IS DISTINCT FROM 443
13+
OR to_port IS DISTINCT FROM 443
14+
OR to_port IS DISTINCT FROM 443)
15+
then 'fail'
16+
else 'pass'
17+
end as status
18+
FROM view_aws_security_group_ingress_rules
19+
)
20+
321
SELECT
4-
:'execution_time' as execution_time,
5-
:'framework' as framework,
6-
:'check_id' as check_id,
7-
'Aggregates rules of security groups with ports and IPs including ipv6' as title,
8-
account_id,
9-
id as resource_id,
10-
case when
11-
(ip = '0.0.0.0/0' OR ip = '::/0')
12-
AND (from_port IS NULL AND to_port IS NULL) -- all prots
13-
OR from_port IS DISTINCT FROM 80
14-
OR to_port IS DISTINCT FROM 80
15-
OR from_port IS DISTINCT FROM 443
16-
OR to_port IS DISTINCT FROM 443
17-
then 'fail'
18-
else 'pass'
19-
end
20-
FROM view_aws_security_group_ingress_rules
22+
:'execution_time' as execution_time,
23+
:'framework' as framework,
24+
:'check_id' as check_id,
25+
'Aggregates rules of security groups with ports and IPs including ipv6' as title,
26+
account_id,
27+
resource_id,
28+
CASE
29+
WHEN SUM(CASE WHEN status = 'fail' THEN 1 ELSE 0 END) > 0 THEN 'fail'
30+
ELSE 'pass'
31+
END as status
32+
FROM IndividualRuleStatus
33+
GROUP BY account_id, resource_id
34+

0 commit comments

Comments
 (0)