turbot/steampipe-mod-alicloud-compliance

Control: 3.2 Ensure that SSH access is restricted from the internet

Description

Security groups provide stateful filtering of ingress/egress network traffic to Alibaba Cloud resources. It is recommended that no security group allows unrestricted ingress access to port 22 or port 3389.

Remediation

From Console

  1. Logon to ECS Console.
  2. Go to Security Group.
  3. Find the Security Group you want to modify.
  4. Modify Source IP range to specific IP.
  5. Click Save.

Usage

Run the control in your terminal:

powerpipe control run alicloud_compliance.control.cis_v100_3_2

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run alicloud_compliance.control.cis_v100_3_2 --share

SQL

This control uses a named query:

with bad_groups as (
select
distinct arn
from
alicloud_ecs_security_group,
jsonb_array_elements(permissions) as p
where
p ->> 'Policy' = 'Accept'
and p ->> 'Direction' = 'ingress'
and p ->> 'SourceCidrIp' = '0.0.0.0/0'
and (
p ->> 'PortRange' in ('-1/-1', '22/22', '3389/3389')
or (
3389 between split_part(p ->> 'PortRange', '/', 1) :: int and split_part(p ->> 'PortRange', '/', 2) :: int
or 22 between split_part(p ->> 'PortRange', '/', 1) :: int and split_part(p ->> 'PortRange', '/', 2) :: int
)
)
)
select
a.arn as resource,
case
when b.arn is null then 'ok'
else 'alarm'
end as status,
case
when b.arn is null then a.security_group_id || ' does not allow ingress from 0.0.0.0/0 to port 22 or 3389.'
else a.security_group_id || ' allow ingress from 0.0.0.0/0 to port 22 or 3389.'
end as reason
, a.account_id as account_id, a.region as region
from
alicloud_ecs_security_group as a
left join bad_groups as b on a.arn = b.arn;

Tags