turbot/steampipe-mod-aws-compliance

Control: VPC security groups should restrict ingress access on ports 20, 21, 22, 3306, 3389, 4333 from 0.0.0.0/0

Description

Manage access to resources in the AWS Cloud by ensuring common ports are restricted on AWS Elastic Compute Cloud (AWS EC2) security groups.

Usage

Run the control in your terminal:

powerpipe control run aws_compliance.control.vpc_security_group_restrict_ingress_common_ports_all

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run aws_compliance.control.vpc_security_group_restrict_ingress_common_ports_all --share

SQL

This control uses a named query:

with ingress_ssh_rules as (
select
group_id,
count(*) as num_ssh_rules
from
aws_vpc_security_group_rule
where
type = 'ingress'
and cidr_ipv4 = '0.0.0.0/0'
and (
( ip_protocol = '-1'
and from_port is null
)
or (
from_port <= 22
and to_port >= 22
)
or (
from_port <= 3389
and to_port >= 3389
)
or (
from_port <= 21
and to_port >= 21
)
or (
from_port <= 20
and to_port >= 20
)
or (
from_port <= 3306
and to_port >= 3306
)
or (
from_port <= 4333
and to_port >= 4333
)
)
group by
group_id
)
select
arn as resource,
case
when ingress_ssh_rules.group_id is null then 'ok'
else 'alarm'
end as status,
case
when ingress_ssh_rules.group_id is null then sg.group_id || ' ingress restricted for ports 20, 21, 22, 3306, 3389, 4333 from 0.0.0.0/0.'
else sg.group_id || ' contains ' || ingress_ssh_rules.num_ssh_rules || ' ingress rule(s) allowing access on ports 20, 21, 22, 3306, 3389, 4333 from 0.0.0.0/0.'
end as reason
, region, account_id
from
aws_vpc_security_group as sg
left join ingress_ssh_rules on ingress_ssh_rules.group_id = sg.group_id;

Tags