diff --git a/docs/services/cloudformation.md b/docs/services/cloudformation.md index 537a731832..528e27ac43 100644 --- a/docs/services/cloudformation.md +++ b/docs/services/cloudformation.md @@ -219,7 +219,7 @@ cross-resource references. | ECR | `Repository` | | ECS | `Cluster`, `TaskDefinition`, `Service`, `CapacityProvider`, `ClusterCapacityProviderAssociations` | | EFS | `FileSystem` (metadata only, there is no NFS data plane), `MountTarget` (`SecurityGroups` update in place, every other property replaces), `AccessPoint` (`AccessPointTags` update in place, every other property replaces) | -| EKS | `Cluster` (created with `Name`, `Version`, `RoleArn`, `Tags`, `EncryptionConfig` and `KubernetesNetworkConfig.IpFamily` and `ServiceIpv4Cidr`, a replacement included; a change to `EncryptionConfig`, `IpFamily` or `ServiceIpv4Cidr` replaces the cluster with the new value applied; `ElasticLoadBalancing` and `ServiceIpv6Cidr` are accepted and ignored; updated in place for `Tags`, keeping tags added outside the stack; a change to `Name`, `RoleArn`, `EncryptionConfig`, `BootstrapSelfManagedAddons`, `OutpostConfig`, `AccessConfig.BootstrapClusterCreatorAdminPermissions`, `KubernetesNetworkConfig.IpFamily` or `KubernetesNetworkConfig.ServiceIpv4Cidr` replaces the cluster, as the registry marks them create-only, and deletes the old one once the update commits; a change to `Version` is accepted with a warning and not applied, as the emulator cannot upgrade a cluster in place), `Nodegroup` (created with `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets` and `Tags`; updated in place for `Tags`, keeping tags added outside the stack; a change to `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets`, `AmiType`, `CapacityType`, `DiskSize`, `InstanceTypes` or `RemoteAccess` replaces the nodegroup, as the registry marks them create-only, and deletes the old one once the update commits; `ScalingConfig`, `Labels`, `Taints`, `UpdateConfig`, `Version`, `ReleaseVersion`, `ForceUpdateEnabled`, `LaunchTemplate`, `NodeRepairConfig` and `WarmPoolConfig` are accepted and not applied, whether changed or dropped, with a warning, as the emulator cannot update a nodegroup in place) | +| EKS | `Cluster` (created with `Name`, `Version`, `RoleArn`, `Tags`, `EncryptionConfig`, `ResourcesVpcConfig`, `Logging`, `AccessConfig` and `KubernetesNetworkConfig.IpFamily` and `ServiceIpv4Cidr`, a replacement included; a change to `EncryptionConfig`, `IpFamily` or `ServiceIpv4Cidr` replaces the cluster with the new value applied; `ElasticLoadBalancing`, `ServiceIpv6Cidr` and `ResourcesVpcConfig.ControlPlaneEgressMode` are accepted and ignored; updated in place for `Tags`, keeping tags added outside the stack; a change to `Name`, `RoleArn`, `EncryptionConfig`, `BootstrapSelfManagedAddons`, `OutpostConfig`, `AccessConfig.BootstrapClusterCreatorAdminPermissions`, `KubernetesNetworkConfig.IpFamily` or `KubernetesNetworkConfig.ServiceIpv4Cidr` replaces the cluster, as the registry marks them create-only, and deletes the old one once the update commits; a change to `Version`, `ResourcesVpcConfig`, `Logging` or `AccessConfig` is accepted with a warning and not applied, as the emulator has no `UpdateClusterVersion` or `UpdateClusterConfig`), `Nodegroup` (created with `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets` and `Tags`; updated in place for `Tags`, keeping tags added outside the stack; a change to `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets`, `AmiType`, `CapacityType`, `DiskSize`, `InstanceTypes` or `RemoteAccess` replaces the nodegroup, as the registry marks them create-only, and deletes the old one once the update commits; `ScalingConfig`, `Labels`, `Taints`, `UpdateConfig`, `Version`, `ReleaseVersion`, `ForceUpdateEnabled`, `LaunchTemplate`, `NodeRepairConfig` and `WarmPoolConfig` are accepted and not applied, whether changed or dropped, with a warning, as the emulator cannot update a nodegroup in place) | | RDS | `DBInstance` (starts a real container), `DBCluster` (starts a real container), `DBSubnetGroup`, `DBParameterGroup`, `DBClusterParameterGroup`, `DBProxy`, `DBProxyTargetGroup` | | Aurora DSQL | `Cluster` | | ElastiCache | `CacheCluster` (starts a real container; modifying an existing cluster in place is not supported), `ReplicationGroup` (starts a real container; modifying an existing group in place is not supported), `SubnetGroup`, `User` (Tags are ignored), `UserGroup` (Tags are ignored), `ServerlessCache` (GetAtt uses the dotted Endpoint.* and ReaderEndpoint.* form) | diff --git a/src/main/java/io/floci/aws/services/cloudformation/provisioners/EksCfnProvisioner.java b/src/main/java/io/floci/aws/services/cloudformation/provisioners/EksCfnProvisioner.java index 197fa99836..bf74fe3808 100644 --- a/src/main/java/io/floci/aws/services/cloudformation/provisioners/EksCfnProvisioner.java +++ b/src/main/java/io/floci/aws/services/cloudformation/provisioners/EksCfnProvisioner.java @@ -10,6 +10,8 @@ import io.floci.aws.services.cloudformation.model.StackResource; import io.floci.aws.services.eks.EksService; import io.floci.aws.services.eks.model.Cluster; import io.floci.aws.services.eks.model.CreateClusterRequest; +import io.floci.aws.services.eks.model.LogSetup; +import io.floci.aws.services.eks.model.Logging; import io.floci.aws.services.eks.model.Nodegroup; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; @@ -40,7 +42,8 @@ public class EksCfnProvisioner implements CfnResourceProvisioner { /** Every attribute {@code publish} writes for a cluster. */ private static final List CLUSTER_ATTRIBUTES = - List.of("Arn", "Endpoint", "CertificateAuthorityData", "OpenIdConnectIssuerUrl"); + List.of("Arn", "Endpoint", "CertificateAuthorityData", "OpenIdConnectIssuerUrl", + "ClusterSecurityGroupId"); private static final ObjectMapper MAPPER = new ObjectMapper(); /** Every attribute {@code publishNodegroup} writes for a nodegroup. */ private static final List NODEGROUP_ATTRIBUTES = List.of("Id", "ClusterName", "NodegroupName", "Arn"); @@ -114,6 +117,9 @@ public class EksCfnProvisioner implements CfnResourceProvisioner { request.setEncryptionConfig(createSetting(props, "EncryptionConfig", ctx, new TypeReference<>() { })); request.setKubernetesNetworkConfig( createSetting(props, "KubernetesNetworkConfig", ctx, new TypeReference<>() { })); + request.setResourcesVpcConfig(createSetting(props, "ResourcesVpcConfig", ctx, new TypeReference<>() { })); + request.setAccessConfig(createSetting(props, "AccessConfig", ctx, new TypeReference<>() { })); + request.setLogging(logging(props, ctx)); Cluster created = eksService.createCluster(request); // The cluster this resource named before is gone or replaced; publish writes only what the // new one has, so its endpoint and certificate must not outlive it. @@ -132,15 +138,14 @@ public class EksCfnProvisioner implements CfnResourceProvisioner { } /** - * A create-only property in its API request shape, or null when the template leaves it out. The + * A property in its API request shape, or null when the template leaves it out. The * template value is read against the type the resource schema declares, so a value of another type * fails the resource with CloudFormation's wording. The request model has no ElasticLoadBalancing - * or ServiceIpv6Cidr member, so those members of KubernetesNetworkConfig are not read. + * or ServiceIpv6Cidr member of KubernetesNetworkConfig and no ControlPlaneEgressMode member of + * ResourcesVpcConfig, so those are not read. */ private static T createSetting(JsonNode props, String name, ProvisionContext ctx, TypeReference type) { - CfnPropertyTypes.Reader types = new CfnPropertyTypes.Reader(ctx.engine()); - JsonNode resolved = types.readProperty(CLUSTER, props, name); - types.finish(); + JsonNode resolved = readSetting(props, name, ctx); if (resolved == null) { return null; } @@ -153,12 +158,45 @@ public class EksCfnProvisioner implements CfnResourceProvisioner { } } + private static JsonNode readSetting(JsonNode props, String name, ProvisionContext ctx) { + CfnPropertyTypes.Reader types = new CfnPropertyTypes.Reader(ctx.engine()); + JsonNode resolved = types.readProperty(CLUSTER, props, name); + types.finish(); + return resolved; + } + + /** + * Logging in the API shape. The template lists the enabled types as + * {@code ClusterLogging.EnabledTypes[].Type}; the service disables every type not listed. + */ + private static Logging logging(JsonNode props, ProvisionContext ctx) { + JsonNode resolved = readSetting(props, "Logging", ctx); + if (resolved == null) { + return null; + } + List enabled = new ArrayList<>(); + JsonNode types = resolved.path("ClusterLogging").path("EnabledTypes"); + types.forEach(entry -> { + String type = entry.path("Type").asText(""); + if (type.isBlank()) { + throw new AwsException("ValidationError", + "AWS::EKS::Cluster Logging.ClusterLogging.EnabledTypes entry has no Type", 400); + } + enabled.add(type); + }); + return new Logging(List.of(new LogSetup(enabled, true))); + } + private void publish(StackResource r, Cluster cluster) { r.setPhysicalId(cluster.getName()); r.getAttributes().put("Arn", cluster.getArn()); if (cluster.getEndpoint() != null) { r.getAttributes().put("Endpoint", cluster.getEndpoint()); } + if (cluster.getResourcesVpcConfig() != null + && cluster.getResourcesVpcConfig().getClusterSecurityGroupId() != null) { + r.getAttributes().put("ClusterSecurityGroupId", cluster.getResourcesVpcConfig().getClusterSecurityGroupId()); + } if (cluster.getCertificateAuthority() != null && cluster.getCertificateAuthority().getData() != null) { r.getAttributes().put("CertificateAuthorityData", cluster.getCertificateAuthority().getData()); } diff --git a/src/main/java/io/floci/aws/services/eks/EksService.java b/src/main/java/io/floci/aws/services/eks/EksService.java index bf2c480b7c..6c806e1268 100644 --- a/src/main/java/io/floci/aws/services/eks/EksService.java +++ b/src/main/java/io/floci/aws/services/eks/EksService.java @@ -815,9 +815,14 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun } cluster.setTags(request.getTags() != null ? ReservedTags.stripReservedTags(request.getTags()) : new HashMap<>()); - // Refused before the cluster security group exists, so a bad ipFamily leaves nothing behind. - resolveIpFamily(request.getKubernetesNetworkConfig()); - ResourcesVpcConfig vpcConfig = buildVpcConfigResponse(request.getResourcesVpcConfig(), resolvedVpcId); + // The checks below run before the cluster security group is created, so a request they refuse + // leaves no group behind for a stack's VPC rollback to trip over. + String ipFamily = resolveIpFamily(request.getKubernetesNetworkConfig()); + ResourcesVpcConfig vpcConfig = buildVpcConfigResponse(request.getResourcesVpcConfig(), resolvedVpcId, ipFamily); + String vpcCidr = resolveClusterVpcCidr(region, vpcConfig.getVpcId()); + KubernetesNetworkConfig networkConfig = buildNetworkConfig(request.getKubernetesNetworkConfig(), vpcCidr); + Logging logging = buildLogging(request.getLogging()); + List encryptionConfig = buildEncryptionConfig(request.getEncryptionConfig()); SecurityGroup clusterSg = null; if (ec2Service != null && !vpcConfig.getVpcId().isBlank()) { try { @@ -832,11 +837,10 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun } } cluster.setResourcesVpcConfig(vpcConfig); - String vpcCidr = resolveClusterVpcCidr(region, vpcConfig.getVpcId()); - cluster.setKubernetesNetworkConfig(buildNetworkConfig(request.getKubernetesNetworkConfig(), vpcCidr)); + cluster.setKubernetesNetworkConfig(networkConfig); cluster.setPodCidr(EksClusterManager.DEFAULT_POD_CIDR); - cluster.setLogging(buildLogging(request.getLogging())); - cluster.setEncryptionConfig(buildEncryptionConfig(request.getEncryptionConfig())); + cluster.setLogging(logging); + cluster.setEncryptionConfig(encryptionConfig); cluster.setStatus(ClusterStatus.CREATING); cluster.setPlatformVersion("eks.1"); cluster.setCertificateAuthority(new CertificateAuthority("")); @@ -1684,17 +1688,25 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun } String vpcId = null; for (String subnetId : vpcConfig.getSubnetIds()) { + String subnetVpcId; try { - vpcId = ec2Service.requireSubnet(region, subnetId).getVpcId(); + subnetVpcId = ec2Service.requireSubnet(region, subnetId).getVpcId(); } catch (AwsException e) { throw new AwsException("InvalidParameterException", "Subnet ID '" + subnetId + "' does not exist", 400); } + if (vpcId != null && !vpcId.equals(subnetVpcId)) { + throw new AwsException("InvalidParameterException", + "Subnet ID '" + subnetId + "' is in VPC '" + subnetVpcId + + "', not in VPC '" + vpcId + "' of the other subnets", 400); + } + vpcId = subnetVpcId; } return vpcId; } - private ResourcesVpcConfig buildVpcConfigResponse(ResourcesVpcConfig request, String resolvedVpcId) { + private ResourcesVpcConfig buildVpcConfigResponse(ResourcesVpcConfig request, String resolvedVpcId, + String ipFamily) { ResourcesVpcConfig response = new ResourcesVpcConfig(); if (request != null) { response.setSubnetIds(request.getSubnetIds() != null ? request.getSubnetIds() : List.of()); @@ -1709,6 +1721,20 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun request.getEndpointPublicAccess() != null ? request.getEndpointPublicAccess() : Boolean.TRUE); response.setEndpointPrivateAccess( request.getEndpointPrivateAccess() != null ? request.getEndpointPrivateAccess() : Boolean.FALSE); + if (request.getPublicAccessCidrs() != null) { + for (String cidr : request.getPublicAccessCidrs()) { + if (!SecurityGroupPolicy.validCidr(cidr)) { + throw new AwsException("InvalidParameterException", + "The specified parameter resourcesVpcConfig.publicAccessCidrs is not valid: " + + cidr, 400); + } + if (cidr.contains(":") && !"ipv6".equals(ipFamily)) { + throw new AwsException("InvalidParameterException", + "The specified parameter resourcesVpcConfig.publicAccessCidrs is not valid: " + + cidr + ". IPv6 blocks cannot be added to IPv4 clusters.", 400); + } + } + } response.setPublicAccessCidrs( request.getPublicAccessCidrs() != null ? request.getPublicAccessCidrs() : List.of("0.0.0.0/0")); } else { diff --git a/src/test/java/io/floci/aws/services/cloudformation/CloudFormationEksIntegrationTest.java b/src/test/java/io/floci/aws/services/cloudformation/CloudFormationEksIntegrationTest.java index 5b954fb86e..77ea241564 100644 --- a/src/test/java/io/floci/aws/services/cloudformation/CloudFormationEksIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/cloudformation/CloudFormationEksIntegrationTest.java @@ -10,6 +10,7 @@ import software.amazon.awssdk.services.cloudformation.CloudFormationClient; import java.util.List; import java.util.Map; +import java.util.stream.Stream; import static io.floci.aws.services.cloudformation.CfnStackTestSupport.createUpdateChangeSet; import static io.floci.aws.services.cloudformation.CfnStackTestSupport.executeAndAwaitUpdate; @@ -20,6 +21,7 @@ import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * End-to-end check that CloudFormation provisions EKS resources for real (into EksService) rather @@ -232,13 +234,17 @@ class CloudFormationEksIntegrationTest { @Test void aBlankEncryptionConfigFailsTheClusterInsteadOfCreatingItUnencrypted() { - String stack = "cfn-eks-blank-" + Long.toString(System.nanoTime(), 36); - try (CloudFormationClient client = AwsTestClients.create( - CloudFormationClient.builder(), "test", Region.US_EAST_1)) { - CfnStackWaits.createStack(client, stack, subjectStack("", "", "AWS::EKS::Cluster", - ROLE + "\"EncryptionConfig\": \"\""), "ROLLBACK_COMPLETE"); - } finally { - CfnStackWaits.deleteStack(stack); + for (String blank : List.of("\"EncryptionConfig\": \"\"", + "\"Logging\": {\"ClusterLogging\": {\"EnabledTypes\": [{}]}}", + "\"Logging\": {\"ClusterLogging\": {\"EnabledTypes\": [{\"Type\": \"\"}]}}")) { + String stack = "cfn-eks-blank-" + Long.toString(System.nanoTime(), 36); + try (CloudFormationClient client = AwsTestClients.create( + CloudFormationClient.builder(), "test", Region.US_EAST_1)) { + CfnStackWaits.createStack(client, stack, subjectStack("", "", "AWS::EKS::Cluster", + ROLE + blank), "ROLLBACK_COMPLETE"); + } finally { + CfnStackWaits.deleteStack(stack); + } } } @@ -262,10 +268,62 @@ class CloudFormationEksIntegrationTest { } } + @Test + void aClusterHonoursItsVpcLoggingAndAccessSettings() { + String stack = "cfn-eks-cfg-" + Long.toString(System.nanoTime(), 36); + String template = "{\"Resources\": {" + + "\"Vpc\": {\"Type\": \"AWS::EC2::VPC\", \"Properties\": {\"CidrBlock\": \"10.7.0.0/16\"}}," + + subnet("SubA", "10.7.1.0/24", "us-east-1a") + subnet("SubB", "10.7.2.0/24", "us-east-1b") + + "\"Subject\": {\"Type\": \"AWS::EKS::Cluster\", \"Properties\": {" + ROLE + + vpcConfig("{\"Ref\": \"SubA\"}, {\"Ref\": \"SubB\"}") + ", " + SETTINGS + "}}}}"; + try (CloudFormationClient client = AwsTestClients.create( + CloudFormationClient.builder(), "test", Region.US_EAST_1)) { + CfnStackWaits.createStack(client, stack, template, "CREATE_COMPLETE"); + JsonPath cluster = given().get("/clusters/" + physicalId(client, stack, "Subject")).jsonPath(); + assertEquals(false, cluster.getBoolean("cluster.resourcesVpcConfig.endpointPublicAccess")); + assertEquals(true, cluster.getBoolean("cluster.resourcesVpcConfig.endpointPrivateAccess")); + assertEquals(Stream.of(physicalId(client, stack, "SubA"), physicalId(client, stack, "SubB")).sorted().toList(), + cluster.getList("cluster.resourcesVpcConfig.subnetIds").stream().sorted().toList()); + assertEquals(List.of("api", "audit"), cluster.getList( + "cluster.logging.clusterLogging.find { it.enabled == true }.types").stream().sorted().toList()); + assertEquals("API", cluster.getString("cluster.accessConfig.authenticationMode")); + } finally { + CfnStackWaits.deleteStack(stack); + } + } + + @Test + void aClusterNamingAMissingSubnetFailsTheStack() { + String stack = "cfn-eks-nosub-" + Long.toString(System.nanoTime(), 36); + String template = "{\"Resources\": {\"Subject\": {\"Type\": \"AWS::EKS::Cluster\", \"Properties\": {" + + ROLE + vpcConfig("\"subnet-0000000000000000f\"") + "}}}}"; + try (CloudFormationClient client = AwsTestClients.create( + CloudFormationClient.builder(), "test", Region.US_EAST_1)) { + client.createStack(request -> request.stackName(stack).templateBody(template)); + String status = CfnStackWaits.awaitTerminal(stack).status(); + assertTrue(List.of("CREATE_FAILED", "ROLLBACK_COMPLETE").contains(status), status); + } finally { + CfnStackWaits.deleteStack(stack); + } + } + private static final String ROLE = "\"RoleArn\": \"arn:aws:iam::000000000000:role/eks-set\", "; private static final String NETWORK = "\"KubernetesNetworkConfig\": {\"IpFamily\": \"ipv4\"," + " \"ServiceIpv4Cidr\": \"172.20.0.0/16\"}"; + private static final String SETTINGS = "\"Logging\": {\"ClusterLogging\": {\"EnabledTypes\": [" + + "{\"Type\": \"api\"}, {\"Type\": \"audit\"}]}}, \"AccessConfig\": {\"AuthenticationMode\": \"API\"}"; + + private static String subnet(String id, String cidr, String zone) { + return "\"" + id + "\": {\"Type\": \"AWS::EC2::Subnet\", \"Properties\": {\"VpcId\": {\"Ref\": \"Vpc\"}," + + " \"CidrBlock\": \"" + cidr + "\", \"AvailabilityZone\": \"" + zone + "\"}},"; + } + + private static String vpcConfig(String subnetIds) { + return "\"ResourcesVpcConfig\": {\"SubnetIds\": [" + subnetIds + "], \"EndpointPublicAccess\": false," + + " \"EndpointPrivateAccess\": true}"; + } + private static String cluster(String role, String team) { return subjectStack("", "", "AWS::EKS::Cluster", "\"RoleArn\": \"arn:aws:iam::000000000000:role/" + role + "\", \"Tags\": [{\"Key\": \"team\", \"Value\": \"" + team + "\"}]"); diff --git a/src/test/java/io/floci/aws/services/eks/EksServiceTest.java b/src/test/java/io/floci/aws/services/eks/EksServiceTest.java index 3ca67ef71f..e5235e2f70 100644 --- a/src/test/java/io/floci/aws/services/eks/EksServiceTest.java +++ b/src/test/java/io/floci/aws/services/eks/EksServiceTest.java @@ -60,6 +60,7 @@ import java.time.Duration; import java.util.ArrayList; import java.util.EnumSet; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; @@ -1795,18 +1796,57 @@ class EksServiceTest { && p.getUserIdGroupPairs().stream().anyMatch(u -> sgId.equals(u.getGroupId()))); assertTrue(hasSelfEgress, "Security group should have self-referencing outbound egress rule for EFA"); - int groupsBefore = ec2Service.describeSecurityGroups("us-east-1", List.of(), List.of(), Map.of()).size(); - KubernetesNetworkConfig badFamily = new KubernetesNetworkConfig(); - badFamily.setIpFamily("ipv5"); - CreateClusterRequest bad = new CreateClusterRequest(); - bad.setName("cluster-sg-bad-family"); - bad.setRoleArn("arn:aws:iam::000000000000:role/eks-role"); - bad.setResourcesVpcConfig(vpcConfig); - bad.setKubernetesNetworkConfig(badFamily); - assertEquals("InvalidParameterException", - assertThrows(AwsException.class, () -> service.createCluster(bad)).getErrorCode()); - assertEquals(groupsBefore, - ec2Service.describeSecurityGroups("us-east-1", List.of(), List.of(), Map.of()).size()); + String otherVpc = ec2Service.createVpc("us-east-1", "10.50.0.0/16", false).getVpcId(); + String otherSubnet = ec2Service.createSubnet("us-east-1", otherVpc, "10.50.1.0/24", "us-east-1b").getSubnetId(); + Map> rejected = new LinkedHashMap<>(); + rejected.put("ipFamily ipv5", r -> r.setKubernetesNetworkConfig(network("ipv5", null))); + rejected.put("service CIDR 8.8.8.0/24", r -> r.setKubernetesNetworkConfig(network("ipv4", "8.8.8.0/24"))); + rejected.put("unknown log type", r -> r.setLogging(new Logging(List.of(new LogSetup(List.of("bogus"), true))))); + rejected.put("subnets in two VPCs", r -> vpcConfig.setSubnetIds(List.of(subnetId, otherSubnet))); + rejected.put("public CIDR /33", r -> vpcConfig.setPublicAccessCidrs(List.of("10.0.0.0/33"))); + rejected.put("IPv6 public CIDR on ipv4", r -> vpcConfig.setPublicAccessCidrs(List.of("::/0"))); + int row = 0; + List failed = new ArrayList<>(); + for (Map.Entry> entry : rejected.entrySet()) { + vpcConfig.setSubnetIds(List.of(subnetId)); + vpcConfig.setPublicAccessCidrs(null); + CreateClusterRequest bad = new CreateClusterRequest(); + bad.setName("cluster-sg-bad-" + row++); + bad.setRoleArn("arn:aws:iam::000000000000:role/eks-role"); + bad.setResourcesVpcConfig(vpcConfig); + entry.getValue().accept(bad); + int groupsBefore = ec2Service.describeSecurityGroups("us-east-1", List.of(), List.of(), Map.of()).size(); + try { + service.createCluster(bad); + failed.add(entry.getKey() + ": accepted"); + } catch (AwsException e) { + boolean clean = groupsBefore + == ec2Service.describeSecurityGroups("us-east-1", List.of(), List.of(), Map.of()).size(); + if (!"InvalidParameterException".equals(e.getErrorCode()) || !clean) { + failed.add(entry.getKey() + ": " + e.getErrorCode() + (clean ? "" : ", security group left")); + } + } + } + vpcConfig.setSubnetIds(List.of(subnetId)); + vpcConfig.setPublicAccessCidrs(List.of("::/0")); + CreateClusterRequest v6 = new CreateClusterRequest(); + v6.setName("cluster-sg-ipv6"); + v6.setRoleArn("arn:aws:iam::000000000000:role/eks-role"); + v6.setResourcesVpcConfig(vpcConfig); + v6.setKubernetesNetworkConfig(network("ipv6", null)); + try { + service.createCluster(v6); + } catch (AwsException e) { + failed.add("ipv6 with ::/0: " + e.getErrorCode()); + } + assertEquals(List.of(), failed); + } + + private static KubernetesNetworkConfig network(String family, String serviceCidr) { + KubernetesNetworkConfig network = new KubernetesNetworkConfig(); + network.setIpFamily(family); + network.setServiceIpv4Cidr(serviceCidr); + return network; } @Test diff --git a/src/test/resources/cloudformation/getatt-attribute-gaps.tsv b/src/test/resources/cloudformation/getatt-attribute-gaps.tsv index 48516bced4..dd63e7fbdc 100644 --- a/src/test/resources/cloudformation/getatt-attribute-gaps.tsv +++ b/src/test/resources/cloudformation/getatt-attribute-gaps.tsv @@ -47,7 +47,6 @@ AWS::RedshiftServerless::Namespace Namespace the whole Namespace object has no s AWS::SQS::QueuePolicy Id schema gives no description; the policy has no backing entity to take an id from AWS::Transfer::Server As2ServiceManagedEgressIpAddresses AS2 managed egress IP allocation is not emulated by the Transfer management-plane service AWS::SecretsManager::Secret Id Fn::GetAtt Id on a secret is its ARN, which the provisioner already sets as the physical id and as Arn; closable, deferred to a follow-up PR to keep this one a pure move -AWS::EKS::Cluster ClusterSecurityGroupId not modeled: Floci does not create a cluster security group, so there is no id to publish AWS::EKS::Cluster EncryptionConfigKeyArn not modeled: Floci does not apply envelope encryption, so no KMS key arn is resolved AWS::EKS::Cluster Id not modeled: Floci identifies a cluster by its Name (the primary identifier and Ref), not a separate Id AWS::ElastiCache::CacheCluster ConfigurationEndpoint the whole object has no scalar GetAtt form; its members are set under the dotted ConfigurationEndpoint.* attributes, the form AWS GetAtt exposes (memcached only) diff --git a/src/test/resources/cloudformation/writable-property-gaps.tsv b/src/test/resources/cloudformation/writable-property-gaps.tsv index 84315ec7ea..299ad8d68e 100644 --- a/src/test/resources/cloudformation/writable-property-gaps.tsv +++ b/src/test/resources/cloudformation/writable-property-gaps.tsv @@ -290,7 +290,6 @@ AWS::ECS::TaskDefinition Tags accepted and ignored AWS::ECS::TaskDefinition TrustedExecutionConfiguration accepted and ignored AWS::EFS::FileSystem BypassPolicyLockoutSafetyCheck Floci's EFS service applies a file system policy without a lockout check, so there is nothing to bypass AWS::EFS::FileSystem ReplicationConfiguration not modeled: Floci has no EFS replication, so the destination file system is not created -AWS::EKS::Cluster AccessConfig accepted and ignored AWS::EKS::Cluster ActiveCertificateAuthorityId accepted and ignored AWS::EKS::Cluster BootstrapSelfManagedAddons accepted and ignored AWS::EKS::Cluster CertificateAuthority accepted and ignored @@ -301,10 +300,8 @@ AWS::EKS::Cluster Force accepted and ignored AWS::EKS::Cluster KubeApiServerConfig accepted and ignored AWS::EKS::Cluster KubeControllerManagerConfig accepted and ignored AWS::EKS::Cluster KubeSchedulerConfig accepted and ignored -AWS::EKS::Cluster Logging accepted and ignored AWS::EKS::Cluster OutpostConfig accepted and ignored AWS::EKS::Cluster RemoteNetworkConfig accepted and ignored -AWS::EKS::Cluster ResourcesVpcConfig accepted and ignored AWS::EKS::Cluster RollbackConfig accepted and ignored AWS::EKS::Cluster StorageConfig accepted and ignored AWS::EKS::Cluster UpgradePolicy accepted and ignored diff --git a/tools/docs/cfn_resource_types.yaml b/tools/docs/cfn_resource_types.yaml index 3b67436cf6..930315c52c 100644 --- a/tools/docs/cfn_resource_types.yaml +++ b/tools/docs/cfn_resource_types.yaml @@ -224,7 +224,7 @@ notes: AWS::CDK::Metadata: accepted; no-op AWS::Transfer::Server: 'management plane only; Ref returns the server ARN; Arn, ServerId and State attributes supported; AS2 managed egress IPs are not modeled; Domain replacement and IdentityProviderType changes are not supported' AWS::Transfer::User: 'management plane only; Ref returns the user ARN; Arn attribute supported; Policy and PosixProfile are not supported; a ServerId or UserName change replaces the user' - AWS::EKS::Cluster: 'created with `Name`, `Version`, `RoleArn`, `Tags`, `EncryptionConfig` and `KubernetesNetworkConfig.IpFamily` and `ServiceIpv4Cidr`, a replacement included; a change to `EncryptionConfig`, `IpFamily` or `ServiceIpv4Cidr` replaces the cluster with the new value applied; `ElasticLoadBalancing` and `ServiceIpv6Cidr` are accepted and ignored; updated in place for `Tags`, keeping tags added outside the stack; a change to `Name`, `RoleArn`, `EncryptionConfig`, `BootstrapSelfManagedAddons`, `OutpostConfig`, `AccessConfig.BootstrapClusterCreatorAdminPermissions`, `KubernetesNetworkConfig.IpFamily` or `KubernetesNetworkConfig.ServiceIpv4Cidr` replaces the cluster, as the registry marks them create-only, and deletes the old one once the update commits; a change to `Version` is accepted with a warning and not applied, as the emulator cannot upgrade a cluster in place' + AWS::EKS::Cluster: 'created with `Name`, `Version`, `RoleArn`, `Tags`, `EncryptionConfig`, `ResourcesVpcConfig`, `Logging`, `AccessConfig` and `KubernetesNetworkConfig.IpFamily` and `ServiceIpv4Cidr`, a replacement included; a change to `EncryptionConfig`, `IpFamily` or `ServiceIpv4Cidr` replaces the cluster with the new value applied; `ElasticLoadBalancing`, `ServiceIpv6Cidr` and `ResourcesVpcConfig.ControlPlaneEgressMode` are accepted and ignored; updated in place for `Tags`, keeping tags added outside the stack; a change to `Name`, `RoleArn`, `EncryptionConfig`, `BootstrapSelfManagedAddons`, `OutpostConfig`, `AccessConfig.BootstrapClusterCreatorAdminPermissions`, `KubernetesNetworkConfig.IpFamily` or `KubernetesNetworkConfig.ServiceIpv4Cidr` replaces the cluster, as the registry marks them create-only, and deletes the old one once the update commits; a change to `Version`, `ResourcesVpcConfig`, `Logging` or `AccessConfig` is accepted with a warning and not applied, as the emulator has no `UpdateClusterVersion` or `UpdateClusterConfig`' AWS::EKS::Nodegroup: 'created with `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets` and `Tags`; updated in place for `Tags`, keeping tags added outside the stack; a change to `ClusterName`, `NodegroupName`, `NodeRole`, `Subnets`, `AmiType`, `CapacityType`, `DiskSize`, `InstanceTypes` or `RemoteAccess` replaces the nodegroup, as the registry marks them create-only, and deletes the old one once the update commits; `ScalingConfig`, `Labels`, `Taints`, `UpdateConfig`, `Version`, `ReleaseVersion`, `ForceUpdateEnabled`, `LaunchTemplate`, `NodeRepairConfig` and `WarmPoolConfig` are accepted and not applied, whether changed or dropped, with a warning, as the emulator cannot update a nodegroup in place' AWS::IAM::User: 'template `LoginProfile` and `PermissionsBoundary` are ignored; an API-created login profile is removed on delete' AWS::KMS::Key: 'created with `Description`, `KeyPolicy`, `KeySpec`, `KeyUsage`, `Origin`, `MultiRegion`, `Enabled`, `EnableKeyRotation` and `Tags`; updated in place for `Description`, `KeyPolicy`, `Enabled`, `EnableKeyRotation` and `Tags`, keeping tags added outside the stack; a template that drops `Description`, `Enabled` or `EnableKeyRotation` clears the description, enables the key and turns rotation off, a dropped `KeyPolicy` keeps the current policy, and one the stack never declared keeps the value set outside it; a rotation change on a key that stays disabled fails, as AWS raises `DisabledException`; a change to `KeySpec`, `KeyUsage`, `Origin` or `MultiRegion` fails the update, as on AWS, and the stack rolls back'