EKS node remote access has no source security groups

When enabling remote access to an EKS node group, also restrict the security groups allowed to connect.

Description

When an EKS managed node group specifies only ec2_ssh_key, Linux SSH port 22 or Windows RDP port 3389 is open to every IPv4 address.

Potential impact

Any host with a route to the node can attempt to use its management port. Internet reachability depends on the node’s address, routes and security groups.

Remediation

If direct access is needed, set remote_access.source_security_group_ids to the groups attached to your management hosts and test a connection. Otherwise omit remote_access. If switching to Session Manager, prepare its agent, IAM permissions and network path first.

Examples

Supply the referenced resources, an existing EC2 key pair and scaling_config. Updating remote access replaces the node group. To keep the source running during migration, define a separate replacement with its own Terraform resource and node group name.

Before

hcl
resource "aws_eks_node_group" "example" {
  cluster_name    = aws_eks_cluster.example.name
  node_group_name = "example"
  node_role_arn   = aws_iam_role.example.arn
  subnet_ids      = aws_subnet.example[*].id

  remote_access {
    ec2_ssh_key = "my-rsa-key"
  }
}

After

hcl
resource "aws_eks_node_group" "example" {
  cluster_name    = aws_eks_cluster.example.name
  node_group_name = "example"
  node_role_arn   = aws_iam_role.example.arn
  subnet_ids      = aws_subnet.example[*].id

  remote_access {
    ec2_ssh_key                = "my-rsa-key"
    source_security_group_ids = [aws_security_group.management.id]
  }
}

References