Public access enabled for an EKS cluster

Review the need for public EKS API access and use a private management path when public access is unnecessary.

Description

Decide where administrators and nodes should reach the EKS Kubernetes API. Its public endpoint accepts connections from permitted CIDRs. Switching to private access preserves the cluster’s authentication methods, including IAM, and Kubernetes authorization.

Potential impact

A broad public CIDR lets networks outside your management environment attempt to connect to the API.

Remediation

For private-only access, enable endpoint_private_access = true first. From the nodes in the VPC and your connected management network, verify that the endpoint resolves to a private IP and that routes and security groups allow the API connection. Then set endpoint_public_access = false. If you keep public access, allow only approved outbound CIDRs.

Examples

Supply the referenced cluster IAM role and both subnets.

Before

hcl
resource "aws_eks_cluster" "example" {
  name     = "example"
  role_arn = aws_iam_role.example.arn

  vpc_config {
    subnet_ids             = [aws_subnet.example1.id, aws_subnet.example2.id]
    endpoint_public_access = true
  }
}

After

hcl
resource "aws_eks_cluster" "example" {
  name     = "example"
  role_arn = aws_iam_role.example.arn

  vpc_config {
    subnet_ids             = [aws_subnet.example1.id, aws_subnet.example2.id]
    endpoint_public_access = false
    endpoint_private_access = true
  }
}

References