diff --git a/docs/services/eks.md b/docs/services/eks.md index 138bd1d672..192524c052 100644 --- a/docs/services/eks.md +++ b/docs/services/eks.md @@ -89,7 +89,8 @@ Access entries use EKS storage and retain the IAM principal's stable ID internal ### EC2 Linux worker authentication IMDS instance-profile credentials authenticate through a matching `EC2_LINUX` entry as -`system:node:` with `system:bootstrappers` and `system:nodes` groups. +`system:node:`, or through an EKS Auto Mode node role's `EC2` entry as +`system:node:` (its `{{SessionName}}`), with `system:bootstrappers` and `system:nodes` groups. The webhook verifies the signed token, cluster account/region/incarnation, stored role ID, running EC2 instance, and attached instance profile. Missing/deleted entries, recreated roles, revoked sessions and terminated instances are rejected without falling back to administrator access. @@ -621,7 +622,7 @@ aws eks update-kubeconfig --name my-cluster kubectl get nodes ``` -`aws eks update-kubeconfig` wires `aws eks get-token` into the kubeconfig as an exec credential. The bearer token contains a SigV4-presigned STS `GetCallerIdentity` request. Floci validates its signature and 15-minute token lifetime matching `aws-iam-authenticator` rather than the presigned expiry, then verifies the signed `x-k8s-aws-id` header against the cluster-specific `/_floci/eks/clusters//token-webhook` endpoint before resolving the caller identity. Instance-profile sessions require an EC2_LINUX access entry as described above; non-worker callers retain the `system:masters` mapping (bound to `cluster-admin`). A long-term access key gets it only on clusters of its own account, so a default-account key is refused on another account's cluster; on the older unscoped webhook path only the default account's keys get it. No `aws-iam-authenticator` is required. +`aws eks update-kubeconfig` wires `aws eks get-token` into the kubeconfig as an exec credential. The bearer token contains a SigV4-presigned STS `GetCallerIdentity` request. Floci validates its signature and 15-minute token lifetime matching `aws-iam-authenticator` rather than the presigned expiry, then verifies the signed `x-k8s-aws-id` header against the cluster-specific `/_floci/eks/clusters//token-webhook` endpoint before resolving the caller identity. Instance-profile sessions require an EC2_LINUX or EC2 access entry as described above; non-worker callers retain the `system:masters` mapping (bound to `cluster-admin`). A long-term access key gets it only on clusters of its own account, so a default-account key is refused on another account's cluster; on the older unscoped webhook path only the default account's keys get it. No `aws-iam-authenticator` is required. Create an IAM access key before using EKS authentication. The public local-development pair `test`/`test` and the seeded deployer's key, whose secret `floci` is public whatever access key ID it was seeded under, are deliberately rejected because the webhook grants cluster-admin access. diff --git a/src/main/java/io/floci/aws/services/eks/EksAccessEntryService.java b/src/main/java/io/floci/aws/services/eks/EksAccessEntryService.java index 43ee29ffc9..69eab12700 100644 --- a/src/main/java/io/floci/aws/services/eks/EksAccessEntryService.java +++ b/src/main/java/io/floci/aws/services/eks/EksAccessEntryService.java @@ -296,7 +296,8 @@ public class EksAccessEntryService { Optional stored = entries instanceof AccountAwareStorageBackend aware ? aware.getForAccount(accountId, key) : entries.get(key); return stored.filter(value -> roleId != null && roleId.equals(value.principalId())) - .map(StoredEntry::entry).filter(entry -> "EC2_LINUX".equals(entry.type())); + .map(StoredEntry::entry) + .filter(entry -> "EC2_LINUX".equals(entry.type()) || AUTO_MODE_NODE_TYPE.equals(entry.type())); } public synchronized AccessEntry describe(Cluster cluster, String principal) { 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 61305c6595..b920931785 100644 --- a/src/main/java/io/floci/aws/services/eks/EksService.java +++ b/src/main/java/io/floci/aws/services/eks/EksService.java @@ -1023,6 +1023,7 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun cluster.setPlatformVersion("eks.1"); cluster.setCertificateAuthority(new CertificateAuthority("")); + boolean madeNodeEntry = false; try { String issuer = oidcService.newIssuerUrl(region); cluster.setIdentity(new ClusterIdentity(new OidcIdentity(issuer))); @@ -1044,9 +1045,24 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun } } - ensureAutoModeNodeEntry(cluster); - storage.put(clusterKey(region, name), cluster); + // The entry and the cluster appear together, under the lock a delete removes entries under, so no + // reader sees an Auto Mode cluster without its node's entry. + synchronized (clustersBeingDeleted) { + madeNodeEntry = true; + makeAutoModeNodeEntry(cluster); + storage.put(clusterKey(region, name), cluster); + } } catch (RuntimeException e) { + if (madeNodeEntry) { + // A create that failed once it began making the node's entry leaves none behind; the cluster is new. + // A cleanup that fails too is logged, so the security group still goes and the create's error stays. + try { + accessEntries.deleteClusterEntries(cluster); + } catch (RuntimeException cleanupEx) { + LOG.warnv("Failed to clean up the access entries of cluster {0} after its creation failed: {1}", + name, cleanupEx.getMessage()); + } + } if (clusterSg != null) { try { ec2Service.deleteSecurityGroup(region, clusterSg.getGroupId()); @@ -1199,6 +1215,12 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun Optional previous = addons.findConfigUpdateByToken(cluster, token); if (previous.isPresent()) { if (updateParametersMatch(previous.get().request(), request)) { + // A retry of a request that makes the node's entry finishes it, should the first attempt not have; + // a retry of any other update leaves the entries as they are. + if (request.changesAutoMode() || (request.accessConfig() != null + && request.accessConfig().authenticationMode() != null)) { + ensureAutoModeNodeEntry(cluster); + } return List.of(previous.get().update()); } throw new AwsException("InvalidParameterException", EksAddonService.TOKEN_REUSED, 400); @@ -1317,7 +1339,8 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun && !config.services().eks().mock() && clusterManager != null && cluster.getContainerId() != null) { replaceNodeForServiceLb(requireClusterInRequestRegion(name)); } - if (nextAutoMode != null && nextAutoMode.computeOn()) { + if ((nextAutoMode != null && nextAutoMode.computeOn()) || requestedMode != null) { + // Turning compute on, or moving off CONFIG_MAP while it is on, gives the node role its entry. ensureAutoModeNodeEntry(requireClusterInRequestRegion(name)); } LOG.infov("Updated the configuration of EKS cluster {0}: {1}", cluster.getName(), @@ -1374,6 +1397,20 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun * cluster's EKS Auto Mode compute capability is on (measured on AWS for CreateCluster). */ private void ensureAutoModeNodeEntry(Cluster cluster) { + ComputeConfig compute = cluster.getComputeConfig(); + if (accessEntries == null || compute == null || !Boolean.TRUE.equals(compute.enabled())) { + return; + } + // A cluster being deleted, or gone, gets no entry: its delete removes entries under this lock. + synchronized (clustersBeingDeleted) { + if (!isClusterDeleting(cluster.getAccountId(), cluster) + && findClusterForAccount(cluster.getAccountId(), clusterKey(cluster)).isPresent()) { + makeAutoModeNodeEntry(cluster); + } + } + } + + private void makeAutoModeNodeEntry(Cluster cluster) { ComputeConfig compute = cluster.getComputeConfig(); if (accessEntries != null && compute != null && Boolean.TRUE.equals(compute.enabled())) { accessEntries.ensureAutoModeNodeEntry(cluster, compute.nodeRoleArn()); @@ -1756,7 +1793,6 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun deleteClusterSecurityGroup(cluster); deleteNodeGroupAutoScalingGroups(cluster.getAccountId(), cluster); deleteAutoModeLoadBalancers(cluster); - accessEntries.deleteClusterEntries(cluster); if (podIdentityAssociations != null) { podIdentityAssociations.deleteClusterAssociations(cluster); } @@ -1767,6 +1803,9 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun deletedFargateArns.keys().stream().filter(key -> key.startsWith(deletedPrefix)) .toList().forEach(deletedFargateArns::delete); synchronized (clustersBeingDeleted) { + // Under the lock ensureAutoModeNodeEntry takes, so an entry it makes meanwhile goes too, and before + // the record, so a delete whose entry cleanup fails can be retried. + accessEntries.deleteClusterEntries(cluster); storage.delete(clusterKey(cluster)); clearAppliedClusterUserData(cluster, name); oidcService.deleteKey(clusterKey(cluster)); diff --git a/src/main/java/io/floci/aws/services/eks/EksWorkerAuthentication.java b/src/main/java/io/floci/aws/services/eks/EksWorkerAuthentication.java index 4704aef460..0e57cb074d 100644 --- a/src/main/java/io/floci/aws/services/eks/EksWorkerAuthentication.java +++ b/src/main/java/io/floci/aws/services/eks/EksWorkerAuthentication.java @@ -5,6 +5,7 @@ import io.floci.aws.core.common.AwsArnUtils; import io.floci.aws.core.common.AwsException; import io.floci.aws.services.ec2.Ec2Service; import io.floci.aws.services.ec2.model.Instance; +import io.floci.aws.services.eks.model.AccessEntry; import io.floci.aws.services.eks.model.Cluster; import io.floci.aws.services.iam.IamService; import io.floci.aws.services.iam.IamService.EksSessionIdentity; @@ -70,22 +71,30 @@ class EksWorkerAuthentication { if (role.isEmpty()) { return Optional.empty(); } + Optional entry; try { - if (entries.workerEntry(cluster.get(), account, identity.roleArn(), identity.roleId()).isEmpty()) { - return Optional.empty(); - } + entry = entries.workerEntry(cluster.get(), account, identity.roleArn(), identity.roleId()); } catch (AwsException rejected) { return Optional.empty(); } + if (entry.isEmpty()) { + return Optional.empty(); + } Optional instance = ec2.findInstanceForAccount(account, region, identity.instanceId()) .filter(value -> value.getState() != null && "running".equals(value.getState().getName())) .filter(value -> region.equals(value.getRegion())) .filter(value -> profileMatches(value, account, roleName)); - if (instance.isEmpty() || instance.get().getPrivateDnsName() == null - || instance.get().getPrivateDnsName().isBlank()) { + if (instance.isEmpty()) { return Optional.empty(); } - return Optional.of(Map.of("username", "system:node:" + instance.get().getPrivateDnsName(), + // An EC2_LINUX entry names the node by its private DNS name, an EKS Auto Mode node's EC2 entry by + // {{SessionName}}, which an instance profile's session is named for: the instance ID. + String node = EksAccessEntryService.AUTO_MODE_NODE_TYPE.equals(entry.get().type()) + ? identity.instanceId() : instance.get().getPrivateDnsName(); + if (node == null || node.isBlank()) { + return Optional.empty(); + } + return Optional.of(Map.of("username", "system:node:" + node, "uid", account + ":" + identity.roleId() + ":" + identity.instanceId(), "groups", List.of("system:bootstrappers", "system:nodes"))); } diff --git a/src/test/java/io/floci/aws/services/eks/EksAccessEntryIntegrationTest.java b/src/test/java/io/floci/aws/services/eks/EksAccessEntryIntegrationTest.java index d1cf5ed6b7..feffa13386 100644 --- a/src/test/java/io/floci/aws/services/eks/EksAccessEntryIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/eks/EksAccessEntryIntegrationTest.java @@ -223,10 +223,13 @@ class EksAccessEntryIntegrationTest { } } - /** EKS makes the node role's EC2 entry with AmazonEKSAutoNodePolicy when Auto Mode compute is on (measured). */ + /** + * EKS makes the node role's EC2 entry with AmazonEKSAutoNodePolicy when Auto Mode compute is on (measured): at + * create, when an update turns compute on, and when a cluster with compute on leaves CONFIG_MAP. + */ @ParameterizedTest - @ValueSource(booleans = {true, false}) - void anAutoModeClustersNodeRoleGetsItsEc2EntryWithTheAutoNodePolicy(boolean atCreate) { + @ValueSource(strings = {"create", "update", "authentication"}) + void anAutoModeClustersNodeRoleGetsItsEc2EntryWithTheAutoNodePolicy(String when) { String account = "357913579135"; String name = "auto-node-" + UUID.randomUUID().toString().substring(0, 8); String role = "node-" + name; @@ -237,15 +240,21 @@ class EksAccessEntryIntegrationTest { "kubernetesNetworkConfig":{"elasticLoadBalancing":{"enabled":true}}""".formatted(principal); createRole(account, role, "/"); try { + String mode = "authentication".equals(when) ? "CONFIG_MAP" : "API"; eks(account, REGION).body(""" - {"name":"%s","roleArn":"arn:aws:iam::%s:role/cluster","accessConfig":{"authenticationMode":"API"}%s}""" - .formatted(name, account, atCreate ? "," + autoMode : "")).post("/clusters").then().statusCode(200); - if (!atCreate) { + {"name":"%s","roleArn":"arn:aws:iam::%s:role/cluster","accessConfig":{"authenticationMode":"%s"}%s}""" + .formatted(name, account, mode, "update".equals(when) ? "" : "," + autoMode)) + .post("/clusters").then().statusCode(200); + if ("update".equals(when)) { eks(account, REGION).get("/clusters/" + name + "/access-entries").then().statusCode(200) .body("accessEntries", empty()); eks(account, REGION).body("{" + autoMode + "}").post("/clusters/" + name + "/update-config").then() .statusCode(200); } + if ("authentication".equals(when)) { + eks(account, REGION).body("{\"accessConfig\":{\"authenticationMode\":\"API_AND_CONFIG_MAP\"}}") + .post("/clusters/" + name + "/update-config").then().statusCode(200); + } String entryPath = "/clusters/" + name + "/access-entries/" + URLEncoder.encode(principal, StandardCharsets.UTF_8); eks(account, REGION).get("/clusters/" + name + "/access-entries").then().statusCode(200) 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 827dea870a..4561bf8b91 100644 --- a/src/test/java/io/floci/aws/services/eks/EksServiceTest.java +++ b/src/test/java/io/floci/aws/services/eks/EksServiceTest.java @@ -91,6 +91,7 @@ import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.*; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doThrow; @@ -459,6 +460,163 @@ class EksServiceTest { verify(clusterManager, times(2)).replaceNodeForServiceLb(running); } + /** An authentication change whose node entry failed makes it on the retry the client token returns. */ + @Test + void aRetriedAuthenticationChangeMakesTheNodeEntryTheFirstAttemptMissed() { + Cluster cluster = activeCluster(); + cluster.setAccessConfig(new AccessConfig("CONFIG_MAP", false)); + cluster.setComputeConfig(new ComputeConfig(true, List.of("general-purpose"), "arn:aws:iam::000000000000:role/node")); + EksAccessEntryService accessEntries = mock(EksAccessEntryService.class); + doThrow(new IllegalStateException("entry write failed")).doNothing() + .when(accessEntries).ensureAutoModeNodeEntry(any(), any()); + UpdateClusterConfigRequest request = new UpdateClusterConfigRequest(null, null, + new AccessConfig("API_AND_CONFIG_MAP", null), null, "retry-token"); + Update recorded = new Update("u", "Successful", "AccessConfigUpdate", List.of(), 0, List.of()); + EksAddonService addons = mock(EksAddonService.class); + when(addons.recordUpdate(any(), anyString(), any(), any(), any())).thenReturn(recorded); + when(addons.findConfigUpdateByToken(any(), eq("retry-token"))).thenReturn(Optional.empty()) + .thenReturn(Optional.of(new EksAddonService.StoredUpdate(recorded, null, request))); + EksService service = new EksService(fixedStorageFactory(clusterStoreWith(cluster)), testConfig(true), + new RegionResolver("us-east-1", "000000000000"), mock(EksClusterManager.class), null, + new EksOidcService(fixedStorageFactory(new InMemoryStorage()), + new ObjectMapper()), accessEntries, mock(EksPodIdentityAssociationService.class), addons); + + assertThrows(IllegalStateException.class, () -> service.updateClusterConfig("running-cluster", request)); + assertEquals(List.of(recorded), service.updateClusterConfig("running-cluster", request)); + + verify(accessEntries, times(2)).ensureAutoModeNodeEntry(cluster, "arn:aws:iam::000000000000:role/node"); + } + + /** A retry of an update that makes no node entry, such as a logging change, doesn't make one. */ + @Test + void aRetriedLoggingUpdateLeavesTheNodeEntriesAlone() { + Cluster cluster = activeCluster(); + cluster.setAccessConfig(new AccessConfig("API", false)); + cluster.setComputeConfig(new ComputeConfig(true, List.of("general-purpose"), "arn:aws:iam::000000000000:role/node")); + EksAccessEntryService accessEntries = mock(EksAccessEntryService.class); + UpdateClusterConfigRequest request = new UpdateClusterConfigRequest(null, new Logging(List.of()), null, null, + "logging-token"); + Update recorded = new Update("u", "Successful", "LoggingUpdate", List.of(), 0, List.of()); + EksAddonService addons = mock(EksAddonService.class); + when(addons.findConfigUpdateByToken(any(), eq("logging-token"))) + .thenReturn(Optional.of(new EksAddonService.StoredUpdate(recorded, null, request))); + EksService service = new EksService(fixedStorageFactory(clusterStoreWith(cluster)), testConfig(true), + new RegionResolver("us-east-1", "000000000000"), mock(EksClusterManager.class), null, + new EksOidcService(fixedStorageFactory(new InMemoryStorage()), + new ObjectMapper()), accessEntries, mock(EksPodIdentityAssociationService.class), addons); + + assertEquals(List.of(recorded), service.updateClusterConfig("running-cluster", request)); + + verify(accessEntries, never()).ensureAutoModeNodeEntry(any(), any()); + } + + @Test + void aCreateWhoseNodeEntryFailsStoresNoClusterAndLeavesNoEntry() { + EksAccessEntryService accessEntries = mock(EksAccessEntryService.class); + doThrow(new IllegalStateException("entry write failed")).when(accessEntries).ensureAutoModeNodeEntry(any(), any()); + EksService service = new EksService(storageFactory, testConfig(), regionResolver, null, ec2Service, + new EksOidcService(storageFactory, new ObjectMapper()), accessEntries, + mock(EksPodIdentityAssociationService.class)); + CreateClusterRequest request = new CreateClusterRequest(); + request.setName("auto-failing"); + request.setRoleArn("arn:aws:iam::000000000000:role/eks-role"); + request.setAccessConfig(new AccessConfig("API", false)); + request.setComputeConfig(new ComputeConfig(true, List.of("general-purpose"), "arn:aws:iam::000000000000:role/node")); + request.setStorageConfig(new StorageConfig(new BlockStorage(true))); + KubernetesNetworkConfig loadBalancing = new KubernetesNetworkConfig(); + loadBalancing.setElasticLoadBalancing(new ElasticLoadBalancing(true)); + request.setKubernetesNetworkConfig(loadBalancing); + + assertThrows(IllegalStateException.class, () -> service.createCluster(request)); + + assertThrows(AwsException.class, () -> service.describeCluster("auto-failing")); + verify(accessEntries).deleteClusterEntries(argThat(cluster -> "auto-failing".equals(cluster.getName()))); + } + + @Test + void aCreateWhoseEntryCleanupFailsTooKeepsTheCreatesError() { + EksAccessEntryService accessEntries = mock(EksAccessEntryService.class); + doThrow(new IllegalStateException("entry write failed")).when(accessEntries).ensureAutoModeNodeEntry(any(), any()); + doThrow(new IllegalStateException("entry cleanup failed")).when(accessEntries).deleteClusterEntries(any()); + EksService service = new EksService(storageFactory, testConfig(), regionResolver, null, ec2Service, + new EksOidcService(storageFactory, new ObjectMapper()), accessEntries, + mock(EksPodIdentityAssociationService.class)); + CreateClusterRequest request = new CreateClusterRequest(); + request.setName("auto-failing-twice"); + request.setRoleArn("arn:aws:iam::000000000000:role/eks-role"); + request.setAccessConfig(new AccessConfig("API", false)); + request.setComputeConfig(new ComputeConfig(true, List.of("general-purpose"), "arn:aws:iam::000000000000:role/node")); + request.setStorageConfig(new StorageConfig(new BlockStorage(true))); + KubernetesNetworkConfig loadBalancing = new KubernetesNetworkConfig(); + loadBalancing.setElasticLoadBalancing(new ElasticLoadBalancing(true)); + request.setKubernetesNetworkConfig(loadBalancing); + + IllegalStateException failure = assertThrows(IllegalStateException.class, () -> service.createCluster(request)); + + assertEquals("entry write failed", failure.getMessage()); + assertThrows(AwsException.class, () -> service.describeCluster("auto-failing-twice")); + } + + @Test + void aDeleteWhoseEntryCleanupFailsKeepsTheClusterForARetry() { + Cluster cluster = activeCluster(); + EksAccessEntryService accessEntries = mock(EksAccessEntryService.class); + doThrow(new IllegalStateException("entry delete failed")).doNothing() + .when(accessEntries).deleteClusterEntries(cluster); + EksService service = new EksService(fixedStorageFactory(clusterStoreWith(cluster)), testConfig(true), + new RegionResolver("us-east-1", "000000000000"), mock(EksClusterManager.class), null, + new EksOidcService(fixedStorageFactory(new InMemoryStorage()), + new ObjectMapper()), accessEntries); + + assertThrows(IllegalStateException.class, () -> service.deleteCluster("running-cluster")); + assertEquals("running-cluster", service.describeCluster("running-cluster").getName()); + + service.deleteCluster("running-cluster"); + assertThrows(AwsException.class, () -> service.describeCluster("running-cluster")); + } + + /** + * A delete that starts while an update is past its status check, and has removed the cluster's entries before + * the update makes the node's, leaves no entry to outlive the cluster. + */ + @Test + void anUpdateTurningComputeOnDuringADeleteMakesNoNodeEntry() { + StorageBackend rawClusters = new InMemoryStorage<>(); + AccountAwareStorageBackend clusterStore = new AccountAwareStorageBackend<>(rawClusters, null, "000000000000"); + Cluster cluster = new Cluster(); + cluster.setName("deleting"); + cluster.setArn("arn:aws:eks:us-east-1:000000000000:cluster/deleting"); + cluster.setStatus(ClusterStatus.ACTIVE); + cluster.setAccessConfig(new AccessConfig("API", false)); + cluster.setKubernetesNetworkConfig(new KubernetesNetworkConfig()); + cluster.setContainerId("k3s-deleting"); + clusterStore.putForAccount("000000000000", EksService.clusterKey("us-east-1", "deleting"), cluster); + EksAccessEntryService accessEntries = mock(EksAccessEntryService.class); + EksPodIdentityAssociationService podIdentity = mock(EksPodIdentityAssociationService.class); + EksAddonService addons = mock(EksAddonService.class); + when(addons.recordUpdate(any(), anyString(), any(), any(), any())) + .thenReturn(new Update("u", "Successful", "AutoModeUpdate", List.of(), 0, List.of())); + EksClusterManager clusterManager = mock(EksClusterManager.class); + // A delete begins (its first step marks the cluster DELETING) after the update stored the configuration and + // before it makes the node entry: the block storage the update turns on is applied to the node in between. + doAnswer(inv -> { + cluster.setStatus(ClusterStatus.DELETING); + return null; + }).when(clusterManager).applyBlockStorage(anyString(), any()); + EksService service = new EksService(fixedStorageFactory(clusterStore), testConfig(false), + new RegionResolver("us-east-1", "000000000000"), clusterManager, null, + new EksOidcService(fixedStorageFactory(new InMemoryStorage()), + new ObjectMapper()), accessEntries, podIdentity, addons); + KubernetesNetworkConfig loadBalancing = new KubernetesNetworkConfig(); + loadBalancing.setElasticLoadBalancing(new ElasticLoadBalancing(true)); + + service.updateClusterConfig("deleting", new UpdateClusterConfigRequest(null, null, null, null, null, + new ComputeConfig(true, List.of("general-purpose"), "arn:aws:iam::000000000000:role/node"), + new StorageConfig(new BlockStorage(true)), loadBalancing)); + + verify(accessEntries, never()).ensureAutoModeNodeEntry(any(), any()); + } + @Test void initRestoresPersistedClustersAfterARestart() { // A cluster restored from eks-clusters.json after a Floci/Docker restart (#2609) has no @@ -743,6 +901,14 @@ class EksServiceTest { return cluster; } + private AccountAwareStorageBackend clusterStoreWith(Cluster cluster) { + AccountAwareStorageBackend clusterStore = + new AccountAwareStorageBackend<>(new InMemoryStorage<>(), null, "000000000000"); + clusterStore.putForAccount("000000000000", EksService.clusterKey( + AwsArnUtils.regionOrDefault(cluster.getArn(), "us-east-1"), cluster.getName()), cluster); + return clusterStore; + } + private EksService serviceWithCluster(Cluster cluster, EksClusterManager clusterManager, boolean keepRunningOnShutdown) { return serviceWithCluster(cluster, clusterManager, keepRunningOnShutdown, null); diff --git a/src/test/java/io/floci/aws/services/eks/EksWorkerAuthenticationTest.java b/src/test/java/io/floci/aws/services/eks/EksWorkerAuthenticationTest.java index 2777e1aa6d..7365eef744 100644 --- a/src/test/java/io/floci/aws/services/eks/EksWorkerAuthenticationTest.java +++ b/src/test/java/io/floci/aws/services/eks/EksWorkerAuthenticationTest.java @@ -189,6 +189,19 @@ class EksWorkerAuthenticationTest { return auth.authenticate(verified, "demo", ACCOUNT, REGION, CREATED.toString()); } + /** An EKS Auto Mode node role's EC2 entry names the node by {{SessionName}}: the instance profile's, its ID. */ + @Test + void anAutoModeNodeRolesEc2EntryNamesTheNodeByItsSessionName() { + entries.delete(cluster, ROLE); + entries.ensureAutoModeNodeEntry(cluster, ROLE); + instance.setPrivateDnsName(null); + + Map user = auth.authenticate(verified, "demo", ACCOUNT, REGION, CREATED.toString()).orElseThrow(); + + assertEquals("system:node:i-worker", user.get("username")); + assertEquals(List.of("system:bootstrappers", "system:nodes"), user.get("groups")); + } + private void createEntry(String type) { entries.create(cluster, new CreateAccessEntryRequest(ROLE, type, null, null, null, null)); }