EKS Public Endpoint Unrestricted
eks-public-endpoint-unrestricted
What this rule checks
Detects EKS clusters with the API endpoint reachable from 0.0.0.0/0 or only via the public network.
How to fix it
- 1Enable EndpointPrivateAccess for in-VPC node communication
- 2Restrict PublicAccessCidrs to known administrative IP ranges
import { aws_ec2 as ec2, aws_eks as eks, aws_iam as iam } from 'aws-cdk-lib';
const vpc = new ec2.Vpc(this, 'Vpc', { maxAzs: 2 });
const role = new iam.Role(this, 'EksRole', { assumedBy: new iam.ServicePrincipal('eks.amazonaws.com') });
new eks.CfnCluster(this, 'Cluster', {
roleArn: role.roleArn,
resourcesVpcConfig: {
subnetIds: vpc.publicSubnets.map((s) => s.subnetId),
endpointPublicAccess: true,
endpointPrivateAccess: false,
publicAccessCidrs: ['0.0.0.0/0'],
},
});import { aws_ec2 as ec2, aws_eks as eks, aws_iam as iam } from 'aws-cdk-lib';
const vpc = new ec2.Vpc(this, 'Vpc', { maxAzs: 2 });
const role = new iam.Role(this, 'EksRole', { assumedBy: new iam.ServicePrincipal('eks.amazonaws.com') });
new eks.CfnCluster(this, 'Cluster', {
roleArn: role.roleArn,
resourcesVpcConfig: {
subnetIds: vpc.privateSubnets.map((s) => s.subnetId),
endpointPublicAccess: true,
endpointPrivateAccess: true,
publicAccessCidrs: ['203.0.113.0/24'],
},
});CDK Insights pinpoints the exact file and line in your CDK source for every finding, so you can jump straight to the fix.
Affected resource types
AWS::EKS::ClusterIntentional? Suppress this finding
Sometimes a flag is deliberate β a genuinely public endpoint, say. You can dismiss eks-public-endpoint-unrestricted and the reason is kept in the report, not silently hidden.
In .cdk-insights.json:
{
"ignoreRules": [
{ "id": "eks-public-endpoint-unrestricted", "reason": "Why this is intentional" }
]
}Or inline in your CDK code:
Validations.of(scope).acknowledge({
id: 'cdk-insights::eks-public-endpoint-unrestricted',
reason: 'Why this is intentional',
});Use the rule ID eks-public-endpoint-unrestricted shown above β not the CDK-* ID from SARIF / GitHub code scanning. To dismiss every finding on one construct instead, use ignorePaths. Suppression docs β
Catch this in your stack
$ npx cdk-insights scanCDK Insights runs this and 118+ other rules locally against your synthesised CDK app β free, no account, your code never leaves your machine.