feat(eks): apply UpdateClusterConfig for endpoint access, logging and authentication mode (#8769)

Floci now implements UpdateClusterConfig for endpoint public and private access, publicAccessCidrs, logging and authentication mode, each stored as an update DescribeUpdate returns. As on EKS, one request names one family, the authentication mode moves one step forward (CONFIG_MAP, API_AND_CONFIG_MAP, API), turning both endpoints off or sending an endpoint or logging update that changes nothing is refused with EKS's messages, and a repeated clientRequestToken returns the first update. A different subnet or security group list, and any other member, the Auto Mode ones included, are refused. DescribeUpdate with an addonName no longer answers a cluster update.
This commit is contained in:
Oleksandr Nikolaichuk authored and GitHub committed 2026-11-19 11:18:04 -04:00
1 parent a06be2d292
commit 5b2c46f358
10 files changed
+538 -41

No files matched your search

@@ -1,10 +1,15 @@
package io.floci.aws.services.eks;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsInAnyOrder;
@@ -12,7 +17,9 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.startsWith;
@QuarkusTest
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@@ -215,4 +222,141 @@ class EksEncryptionLoggingIntegrationTest {
.then().statusCode(200)
.body("cluster", not(hasKey("explicitVersion")));
}
private static final String ROLE_ARN = "arn:aws:iam::000000000000:role/eks-role";
private static final String LOGGING_AUDIT_ON =
"\"logging\":{\"clusterLogging\":[{\"types\":[\"audit\"],\"enabled\":true}]}";
private static String createClusterFrom(String name, String extraMembers) {
given().contentType(JSON)
.body("{\"name\":\"" + name + "\",\"roleArn\":\"" + ROLE_ARN + "\"" + extraMembers + "}")
.when().post("/clusters").then().statusCode(200);
return name;
}
private static void deleteCluster(String name) {
given().when().delete("/clusters/" + name);
}
@Test
void updateConfigReturnsALoggingUpdateThatDescribeUpdateFinds() {
String name = createClusterFrom("it-update-config-cluster", "");
try {
String id = given().contentType(JSON)
.body("{" + LOGGING_AUDIT_ON + "}")
.when().post("/clusters/" + name + "/update-config")
.then().statusCode(200)
.body("update.type", equalTo("LoggingUpdate"))
.body("update.id", notNullValue())
.extract().path("update.id");
given().contentType(JSON)
.when().get("/clusters/" + name + "/updates/" + id)
.then().statusCode(200)
.body("update.id", equalTo(id))
.body("update.type", equalTo("LoggingUpdate"));
} finally {
deleteCluster(name);
}
}
@ParameterizedTest
@CsvSource(delimiter = '|', nullValues = "null", value = {
// two update families in one request
"{\"logging\":{\"clusterLogging\":[{\"types\":[\"audit\"],\"enabled\":true}]},"
+ "\"accessConfig\":{\"authenticationMode\":\"API_AND_CONFIG_MAP\"}}"
+ "|400|InvalidParameterException|Only one type of update can be allowed.",
"{\"resourcesVpcConfig\":{\"endpointPublicAccess\":true},"
+ "\"logging\":{\"clusterLogging\":[{\"types\":[\"audit\"],\"enabled\":true}]}}"
+ "|400|InvalidParameterException|Only one type of update can be allowed.",
// a number where the model has a boolean, as createCluster refuses it
"{\"resourcesVpcConfig\":{\"endpointPublicAccess\":1}}|400|SerializationException|null",
// members UpdateClusterConfig does not support here
"{\"kubernetesNetworkConfig\":{\"ipFamily\":\"ipv4\"}}|400|InvalidParameterException|null",
"{\"deletionProtection\":true}|400|InvalidParameterException|null",
"{\"deletionProtection\":true,\"logging\":{\"clusterLogging\":[{\"types\":[\"audit\"],\"enabled\":true}]}}"
+ "|400|InvalidParameterException|null",
// accessConfig: unknown mode, and a move from API_AND_CONFIG_MAP back to CONFIG_MAP
"{\"accessConfig\":{\"authenticationMode\":\"BOGUS\"}}|400|InvalidParameterException|null",
"{\"accessConfig\":{\"authenticationMode\":\"CONFIG_MAP\"}}|400|InvalidParameterException|null"
})
void updateConfigRefusesWhatAwsRefuses(String body, int status, String type, String message) {
String name = createClusterFrom("it-update-refuse-" + UUID.randomUUID(),
",\"accessConfig\":{\"authenticationMode\":\"API_AND_CONFIG_MAP\"}");
try {
ValidatableResponse response = given().contentType(JSON)
.body(body)
.when().post("/clusters/" + name + "/update-config")
.then().statusCode(status).body("__type", equalTo(type));
if (message != null) {
response.body("message", equalTo(message));
}
} finally {
deleteCluster(name);
}
}
@Test
void updateConfigWithTheSameClientRequestTokenReturnsTheSameUpdate() {
String name = createClusterFrom("it-update-idempotent-" + UUID.randomUUID(), "");
try {
String body = "{\"clientRequestToken\":\"token-1\"," + LOGGING_AUDIT_ON + "}";
String first = given().contentType(JSON).body(body)
.when().post("/clusters/" + name + "/update-config")
.then().statusCode(200).extract().path("update.id");
given().contentType(JSON).body(body)
.when().post("/clusters/" + name + "/update-config")
.then().statusCode(200).body("update.id", equalTo(first));
given().contentType(JSON)
.when().get("/clusters/" + name + "/updates/" + first)
.then().statusCode(200).body("update.id", equalTo(first));
} finally {
deleteCluster(name);
}
}
@Test
void updateConfigRecordsCidrsAsJsonRefusesNoOpsAndScopesDescribeUpdateToTheCluster() {
String name = createClusterFrom("it-update-noop-" + UUID.randomUUID(), "");
try {
String cidrs = "\"publicAccessCidrs\":[\"203.0.113.5/32\"]";
given().contentType(JSON)
.body("{\"resourcesVpcConfig\":{\"endpointPublicAccess\":true," + cidrs + "}}")
.when().post("/clusters/" + name + "/update-config")
.then().statusCode(200)
.body("update.type", equalTo("EndpointAccessUpdate"))
.body("update.params.find { it.type == 'PublicAccessCidrs' }.value",
equalTo("[\"203.0.113.5/32\"]"));
String loggingId = given().contentType(JSON).body("{" + LOGGING_AUDIT_ON + "}")
.when().post("/clusters/" + name + "/update-config")
.then().statusCode(200).extract().path("update.id");
Object before = given().when().get("/clusters/" + name).then().statusCode(200).extract().path("cluster");
// both endpoints off
given().contentType(JSON)
.body("{\"resourcesVpcConfig\":{\"endpointPublicAccess\":false,\"endpointPrivateAccess\":false}}")
.when().post("/clusters/" + name + "/update-config")
.then().statusCode(400).body("__type", equalTo("InvalidParameterException"));
// the stored flags and CIDRs again
given().contentType(JSON)
.body("{\"resourcesVpcConfig\":{\"endpointPublicAccess\":true,"
+ "\"endpointPrivateAccess\":false," + cidrs + "}}")
.when().post("/clusters/" + name + "/update-config")
.then().statusCode(400).body("__type", equalTo("InvalidParameterException"))
.body("message", startsWith("Cluster is already at the desired configuration"));
// api logs are already off
given().contentType(JSON)
.body("{\"logging\":{\"clusterLogging\":[{\"types\":[\"api\"],\"enabled\":false}]}}")
.when().post("/clusters/" + name + "/update-config")
.then().statusCode(400).body("__type", equalTo("InvalidParameterException"))
.body("message", equalTo("No changes needed for the logging config provided"));
given().when().get("/clusters/" + name).then().statusCode(200).body("cluster", equalTo(before));
given().contentType(JSON)
.when().get("/clusters/" + name + "/updates/" + loggingId + "?addonName=vpc-cni")
.then().statusCode(404).body("__type", equalTo("ResourceNotFoundException"))
.body("message", equalTo("No update: " + loggingId + " found for addon: vpc-cni"));
} finally {
deleteCluster(name);
}
}
}
@@ -26,6 +26,7 @@ import io.floci.aws.services.ec2.model.SecurityGroup;
import io.floci.aws.services.ec2.model.Tag;
import io.floci.aws.services.ec2.model.Vpc;
import io.floci.aws.services.ec2.portforward.Ec2PortForwardManager;
import io.floci.aws.services.eks.model.AccessConfig;
import io.floci.aws.services.eks.model.BlockStorage;
import io.floci.aws.services.eks.model.Cluster;
import io.floci.aws.services.eks.model.ClusterIdentity;
@@ -49,6 +50,8 @@ import io.floci.aws.services.eks.model.OidcIdentity;
import io.floci.aws.services.eks.model.Provider;
import io.floci.aws.services.eks.model.ResourcesVpcConfig;
import io.floci.aws.services.eks.model.StorageConfig;
import io.floci.aws.services.eks.model.Update;
import io.floci.aws.services.eks.model.UpdateClusterConfigRequest;
import io.floci.aws.testing.ThreadStates;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -918,6 +921,69 @@ class EksServiceTest {
assertTrue(eksService.listClusters().isEmpty());
}
@Test
void updateClusterConfigRefusesBadPublicAccessCidrsOnAnIpv4ClusterAndChangesNothing() {
EksAddonService addons = mock(EksAddonService.class);
Update recorded = new Update("u", "Successful", "EndpointAccessUpdate", List.of(), 0, List.of());
when(addons.recordUpdate(any(), anyString(), any(), any(), any())).thenReturn(recorded);
EksService service = new EksService(storageFactory, testConfig(), regionResolver, null, ec2Service,
new EksOidcService(storageFactory, new ObjectMapper()), mock(EksAccessEntryService.class),
mock(EksPodIdentityAssociationService.class), addons);
CreateClusterRequest create = new CreateClusterRequest();
create.setName("cidr-cluster");
create.setRoleArn("arn:aws:iam::000000000000:role/eks-role");
service.createCluster(create);
for (String cidr : List.of("10.0.0.0/33", "::/0")) {
ResourcesVpcConfig vpc = new ResourcesVpcConfig();
vpc.setEndpointPublicAccess(false);
vpc.setPublicAccessCidrs(List.of(cidr));
AwsException e = assertThrows(AwsException.class, () -> service.updateClusterConfig(
"cidr-cluster", new UpdateClusterConfigRequest(vpc, null, null, null)), cidr);
assertEquals("InvalidParameterException", e.getErrorCode(), cidr);
ResourcesVpcConfig stored = service.describeCluster("cidr-cluster").getResourcesVpcConfig();
assertEquals(Boolean.TRUE, stored.getEndpointPublicAccess(), cidr);
assertEquals(List.of("0.0.0.0/0"), stored.getPublicAccessCidrs(), cidr);
}
verify(addons, never()).recordUpdate(any(), anyString(), any(), any(), any());
}
@Test
void updateClusterConfigMovesTheAuthenticationModeOneStepForwardOnly() {
EksAddonService addons = mock(EksAddonService.class);
Update recorded = new Update("u", "Successful", "AuthenticationModeUpdate", List.of(), 0, List.of());
when(addons.recordUpdate(any(), anyString(), any(), any(), any())).thenReturn(recorded);
EksService service = new EksService(storageFactory, testConfig(), regionResolver, null, ec2Service,
new EksOidcService(storageFactory, new ObjectMapper()), mock(EksAccessEntryService.class),
mock(EksPodIdentityAssociationService.class), addons);
List<String> modes = List.of("CONFIG_MAP", "API_AND_CONFIG_MAP", "API");
for (int from = 0; from < modes.size(); from++) {
for (int to = 0; to < modes.size(); to++) {
String pair = modes.get(from) + " to " + modes.get(to);
String name = "mode-" + from + "-" + to;
CreateClusterRequest create = new CreateClusterRequest();
create.setName(name);
create.setRoleArn("arn:aws:iam::000000000000:role/eks-role");
create.setAccessConfig(new AccessConfig(modes.get(from), null));
service.createCluster(create);
UpdateClusterConfigRequest request = new UpdateClusterConfigRequest(
null, null, new AccessConfig(modes.get(to), null), null);
if (to == from + 1) {
service.updateClusterConfig(name, request);
assertEquals(modes.get(to), service.describeCluster(name).getAccessConfig()
.authenticationMode(), pair);
} else {
AwsException e = assertThrows(AwsException.class,
() -> service.updateClusterConfig(name, request), pair);
assertEquals("InvalidParameterException", e.getErrorCode(), pair);
assertEquals("Unsupported authentication mode update from " + pair,
e.getMessage(), pair);
assertEquals(modes.get(from), service.describeCluster(name).getAccessConfig()
.authenticationMode(), pair);
}
}
}
}
@Test
void deleteClusterDeletesAddons() {
StorageFactory storageFactory = new StorageFactory(null, null) {