Control: Ensure no security groups allow ingress from ::/0 to remote server administration ports
Description
Security groups provide stateful filtering of ingress and egress network traffic to AWS resources. It is recommended that no security group allows unrestricted ingress access to remote server administration ports, such as SSH to port 22 and RDP to port 3389.
Usage
Run the control in your terminal:
powerpipe control run aws_compliance.control.vpc_security_group_remote_administration_ipv6
Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run aws_compliance.control.vpc_security_group_remote_administration_ipv6 --share
SQL
This control uses a named query:
with bad_rules as ( select group_id, count(*) as num_bad_rules from aws_vpc_security_group_rule where type = 'ingress' and ( cidr_ipv6 = '::/0' ) and ( ( ip_protocol = '-1' -- all traffic and from_port is null ) or ( from_port <= 22 and to_port >= 22 ) or ( from_port <= 3389 and to_port >= 3389 ) ) group by group_id)select arn as resource, case when bad_rules.group_id is null then 'ok' else 'alarm' end as status, case when bad_rules.group_id is null then sg.group_id || ' does not allow ingress to port 22 or 3389 from ::/0.' else sg.group_id || ' contains ' || bad_rules.num_bad_rules || ' rule(s) that allow ingress to port 22 or 3389 from ::/0.' end as reason , sg.region, sg.account_idfrom aws_vpc_security_group as sg left join bad_rules on bad_rules.group_id = sg.group_id;