Security group exposes SSH too broadly

Restrict SSH to required management paths to reduce external login attempts and the risk of server compromise.

Description

On servers that need SSH, limit TCP 22 to the actual management network, VPN or bastion. Include only addresses used for administration, even in a private range.

Potential impact

External clients can attempt to sign in when addressing, routes and the host firewall permit access. Stolen keys or weak authentication can then expose the server.

Remediation

Remove broad rules covering TCP 22 from all attached groups. Check SSH authentication and updates. If switching to Session Manager, first verify its agent, IAM permissions and network path.

Examples

Supply the actual VPC ID. To change rules on an existing group, keep its group description and list every required inbound rule. The module removes unlisted rules by default.

Before

yaml
- name: Configure the SSH security group
  amazon.aws.ec2_group:
    name: example
    description: ssh-open security group
    vpc_id: vpc-12345
    rules:
      - proto: tcp
        from_port: 22
        to_port: 22
        cidr_ip: 79.32.0.0/12

The first rule admits TCP 22 from the broad public range 79.32.0.0/12.

After

yaml
- name: Configure the SSH security group
  amazon.aws.ec2_group:
    name: example
    description: ssh-restricted security group
    vpc_id: vpc-12345
    rules:
      - proto: tcp
        from_port: 22
        to_port: 22
        cidr_ip: 10.0.10.0/24

Replace 10.0.10.0/24 with the actual management source. On a server using the group, verify that a new SSH connection succeeds from that source and is blocked from an unapproved one.

References