Security group allows SSH from the entire internet

Limit SSH access to approved management networks.

Description

If SSH is required, allow TCP 22 only from the actual administrator, VPN or bastion addresses. Remove the ingress rule when direct SSH is unnecessary.

Potential impact

External clients can attempt sign-in when they have a route to the SSH listener. Check account authentication and key management as well.

Remediation

Check all attached groups for SSH grants from 0.0.0.0/0 or its IPv6 counterpart ::/0. Test a new SSH connection from the management path and confirm that an unapproved source is blocked.

Examples

In the first example, 0.0.0.0/0 also admits sources outside 192.120.0.0/16. Replace the second example’s 10.10.10.0/24 with your management range. For a rule-only change on an existing group, retain its original name and group-level description to avoid replacement.

Before

hcl
resource "aws_security_group" "example" {
  name        = "allow_tls"
  description = "SSH port open"

  ingress {
    description = "SSH port open"
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["192.120.0.0/16", "0.0.0.0/0"]
  }
}

After

hcl
resource "aws_security_group" "example" {
  ingress {
    description = "SSH from management network"
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["10.10.10.0/24"]
  }
}

References