For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/terraform-aws-eks-cluster-has-public-access-cidrs.md.
A documentation index is available at /llms.txt.
Enabling the Amazon EKS public endpoint and allowing access from all IP addresses (0.0.0.0/0) exposes the Kubernetes cluster’s API server to the entire internet. This configuration creates a significant security risk, as it allows unauthorized parties to attempt authentication or exploit vulnerabilities in the API server from anywhere in the world. If left unaddressed, this could lead to unauthorized access, data breaches, or disruption of workloads orchestrated by the cluster. Limiting public access to trusted IP address ranges greatly reduces the attack surface and helps safeguard sensitive operations and cluster resources.
Compliant Code Examples
resource"aws_eks_cluster""negative1"{name="example"role_arn=aws_iam_role.example.arnvpc_config{subnet_ids=[aws_subnet.example1.id,aws_subnet.example2.id]endpoint_public_access=truepublic_access_cidrs=["1.1.1.1/1"]} # Ensure that IAM Role permissions are created before and deleted after EKS Cluster handling.
# Otherwise, EKS will not be able to properly delete EKS managed EC2 infrastructure such as Security Groups.
depends_on=[aws_iam_role_policy_attachment.example-AmazonEKSClusterPolicy,]}output"endpoint"{value=aws_eks_cluster.example.endpoint}output"kubeconfig-certificate-authority-data"{value=aws_eks_cluster.example.certificate_authority[0].data}
Non-Compliant Code Examples
resource"aws_eks_cluster""positive1"{name="example"role_arn=aws_iam_role.example.arnvpc_config{subnet_ids=[aws_subnet.example1.id,aws_subnet.example2.id]endpoint_public_access=truepublic_access_cidrs=["0.0.0.0/0"]} # Ensure that IAM Role permissions are created before and deleted after EKS Cluster handling.
# Otherwise, EKS will not be able to properly delete EKS managed EC2 infrastructure such as Security Groups.
depends_on=[aws_iam_role_policy_attachment.example-AmazonEKSClusterPolicy,]}output"endpoint"{value=aws_eks_cluster.example.endpoint}output"kubeconfig-certificate-authority-data"{value=aws_eks_cluster.example.certificate_authority[0].data}resource"aws_eks_cluster""positive2"{name="without_example"role_arn=aws_iam_role.example.arnvpc_config{subnet_ids=[aws_subnet.example1.id,aws_subnet.example2.id]endpoint_public_access=true} # Ensure that IAM Role permissions are created before and deleted after EKS Cluster handling.
# Otherwise, EKS will not be able to properly delete EKS managed EC2 infrastructure such as Security Groups.
depends_on=[aws_iam_role_policy_attachment.example-AmazonEKSClusterPolicy,]}
1
2
rulesets:- Terraform / AWS # Rules to enforce / AWS.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.