mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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:
1 parent
a06be2d292
commit
5b2c46f358
10 files changed
+538
-41
No files matched your search
@@ -214,7 +214,7 @@ public class EksAccessEntryService {
|
||||
&& tags.equals(previous.tags())) {
|
||||
return previous;
|
||||
}
|
||||
throw invalid("clientRequestToken was already used with different parameters");
|
||||
throw invalid(EksAddonService.TOKEN_REUSED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import io.floci.aws.services.eks.model.CreatePodIdentityAssociationRequest;
|
||||
import io.floci.aws.services.eks.model.PodIdentityAssociation;
|
||||
import io.floci.aws.services.eks.model.Update;
|
||||
import io.floci.aws.services.eks.model.UpdateAddonRequest;
|
||||
import io.floci.aws.services.eks.model.UpdateClusterConfigRequest;
|
||||
import io.floci.aws.services.eks.model.UpdateParam;
|
||||
import io.floci.aws.services.iam.IamService;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
@@ -43,6 +44,8 @@ import java.util.function.UnaryOperator;
|
||||
@ApplicationScoped
|
||||
public class EksAddonService {
|
||||
|
||||
static final String TOKEN_REUSED = "clientRequestToken was already used with different parameters";
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(EksAddonService.class);
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
private static final int DEFAULT_PAGE_SIZE = 100;
|
||||
@@ -85,7 +88,11 @@ public class EksAddonService {
|
||||
public record StoredAddon(Addon addon, String clientRequestToken) {}
|
||||
|
||||
@RegisterForReflection
|
||||
public record StoredUpdate(Update update, String addonName) {}
|
||||
public record StoredUpdate(Update update, String addonName, UpdateClusterConfigRequest request) {
|
||||
public StoredUpdate(Update update, String addonName) {
|
||||
this(update, addonName, null);
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
public record AddonNamesPage(List<String> addons, String nextToken) {}
|
||||
@@ -114,8 +121,7 @@ public class EksAddonService {
|
||||
if (parametersMatch(stored.addon(), request)) {
|
||||
return stored.addon();
|
||||
}
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"clientRequestToken was already used with different parameters", 400);
|
||||
throw new AwsException("InvalidParameterException", TOKEN_REUSED, 400);
|
||||
}
|
||||
throw new AwsException("ResourceInUseException", "Addon already exists: " + addonName, 409);
|
||||
}
|
||||
@@ -301,16 +307,7 @@ public class EksAddonService {
|
||||
storage.put(storageKey, new StoredAddon(updatedAddon, token));
|
||||
LOG.infov("Updated EKS addon {0} on cluster {1}", addonName, cluster.getName());
|
||||
|
||||
Update update = new Update(
|
||||
UUID.randomUUID().toString(),
|
||||
"Successful",
|
||||
"AddonUpdate",
|
||||
params,
|
||||
now,
|
||||
List.of()
|
||||
);
|
||||
updatesStorage.put(prefix(cluster) + update.id(), new StoredUpdate(update, addonName));
|
||||
return update;
|
||||
return recordUpdate(cluster, "AddonUpdate", params, addonName);
|
||||
}
|
||||
|
||||
public synchronized Addon delete(Cluster cluster, String addonName, boolean preserve) {
|
||||
@@ -377,10 +374,35 @@ public class EksAddonService {
|
||||
}
|
||||
}
|
||||
|
||||
/** Stores an update that always completes at once; {@code addonName} is null for one made to the cluster. */
|
||||
public Update recordUpdate(Cluster cluster, String type, List<UpdateParam> params, String addonName) {
|
||||
return recordUpdate(cluster, type, params, addonName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* As above, keeping the UpdateClusterConfig {@code request} that made the update, so a repeat of its
|
||||
* {@code clientRequestToken} finds it again.
|
||||
*/
|
||||
public Update recordUpdate(Cluster cluster, String type, List<UpdateParam> params, String addonName,
|
||||
UpdateClusterConfigRequest request) {
|
||||
Update update = new Update(UUID.randomUUID().toString(), "Successful", type, params,
|
||||
EpochSeconds.fromInstant(Instant.now()), List.of());
|
||||
updatesStorage.put(prefix(cluster) + update.id(), new StoredUpdate(update, addonName, request));
|
||||
return update;
|
||||
}
|
||||
|
||||
/** The update an earlier UpdateClusterConfig with this {@code clientRequestToken} made, with its request. */
|
||||
public Optional<StoredUpdate> findConfigUpdateByToken(Cluster cluster, String token) {
|
||||
String p = prefix(cluster);
|
||||
return updatesStorage.scan(k -> k.startsWith(p)).stream()
|
||||
.filter(stored -> stored.request() != null && token.equals(stored.request().clientRequestToken()))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public Update describeUpdate(Cluster cluster, String updateId, String addonName) {
|
||||
StoredUpdate stored = storedUpdate(cluster, updateId);
|
||||
if (addonName != null && !addonName.isBlank()
|
||||
&& stored.addonName() != null && !stored.addonName().equalsIgnoreCase(addonName.trim())) {
|
||||
&& (stored.addonName() == null || !stored.addonName().equalsIgnoreCase(addonName.trim()))) {
|
||||
throw new AwsException("ResourceNotFoundException",
|
||||
"No update: " + updateId + " found for addon: " + addonName, 404);
|
||||
}
|
||||
@@ -534,7 +556,7 @@ public class EksAddonService {
|
||||
.toString();
|
||||
}
|
||||
|
||||
private static void requireActiveCluster(Cluster cluster) {
|
||||
static void requireActiveCluster(Cluster cluster) {
|
||||
if (cluster == null) {
|
||||
throw new AwsException("ResourceNotFoundException", "Cluster not found", 404);
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ import io.floci.aws.services.eks.model.Nodegroup;
|
||||
import io.floci.aws.services.eks.model.PodIdentityAssociation;
|
||||
import io.floci.aws.services.eks.model.Update;
|
||||
import io.floci.aws.services.eks.model.UpdateAddonRequest;
|
||||
import io.floci.aws.services.eks.model.UpdateClusterConfigRequest;
|
||||
import io.floci.aws.services.eks.model.UpdatePodIdentityAssociationRequest;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.Consumes;
|
||||
@@ -37,6 +38,7 @@ import jakarta.ws.rs.core.Response;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* EKS REST-JSON controller.
|
||||
@@ -59,6 +61,10 @@ public class EksController {
|
||||
+ "aws(?::|%3[aA])cluster-access-policy(?:/|%2[fF])[^/]+";
|
||||
|
||||
|
||||
private static final List<String> UPDATE_CONFIG_FAMILIES = List.of("resourcesVpcConfig", "logging", "accessConfig");
|
||||
private static final Set<String> UPDATE_CONFIG_MEMBERS =
|
||||
Set.of("name", "clientRequestToken", "resourcesVpcConfig", "logging", "accessConfig");
|
||||
|
||||
private final EksService eksService;
|
||||
private final EksAccessEntryService accessEntries;
|
||||
private final EksPodIdentityAssociationService podIdentityAssociations;
|
||||
@@ -343,6 +349,35 @@ public class EksController {
|
||||
return Response.ok(Map.of("update", update)).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* The body is checked against its botocore shape as {@link #createCluster} checks its own. A member floci does
|
||||
* not apply is refused rather than dropped. The service applies every family the request names; this endpoint
|
||||
* refuses more than one, as EKS does.
|
||||
*/
|
||||
@POST
|
||||
@Path("/clusters/{name}/update-config")
|
||||
public Response updateClusterConfig(@PathParam("name") String name, JsonNode body) {
|
||||
UpdateClusterConfigRequest request = null;
|
||||
if (body != null) {
|
||||
EksRequestShapes.check("UpdateClusterConfig", body);
|
||||
for (String member : (Iterable<String>) body::fieldNames) {
|
||||
if (!UPDATE_CONFIG_MEMBERS.contains(member)) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"Floci does not support updating " + member + " through UpdateClusterConfig yet", 400);
|
||||
}
|
||||
}
|
||||
if (UPDATE_CONFIG_FAMILIES.stream().filter(body::has).count() > 1) {
|
||||
throw new AwsException("InvalidParameterException", "Only one type of update can be allowed.", 400);
|
||||
}
|
||||
try {
|
||||
request = objectMapper.treeToValue(body, UpdateClusterConfigRequest.class);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("SerializationException", e.getOriginalMessage(), 400);
|
||||
}
|
||||
}
|
||||
return Response.ok(Map.of("update", eksService.updateClusterConfig(name, request).get(0))).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/clusters/{name}/updates/{updateId}")
|
||||
public Response describeUpdate(@PathParam("name") String name,
|
||||
|
||||
@@ -111,7 +111,7 @@ public class EksPodIdentityAssociationService {
|
||||
&& tags.equals(previous.tags())) {
|
||||
return previous;
|
||||
}
|
||||
throw invalid("clientRequestToken was already used with different parameters");
|
||||
throw invalid(EksAddonService.TOKEN_REUSED);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,7 +190,7 @@ public class EksPodIdentityAssociationService {
|
||||
if (matches) {
|
||||
return current;
|
||||
}
|
||||
throw invalid("clientRequestToken was already used with different parameters");
|
||||
throw invalid(EksAddonService.TOKEN_REUSED);
|
||||
}
|
||||
|
||||
String newRoleArn = current.roleArn();
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package io.floci.aws.services.eks;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.floci.aws.config.EmulatorConfig;
|
||||
import io.floci.aws.core.common.AvailabilityZoneIds;
|
||||
import io.floci.aws.core.common.AwsArnUtils;
|
||||
@@ -52,6 +54,9 @@ 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.services.eks.model.UpdateParam;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
@@ -89,10 +94,11 @@ import java.util.stream.Collectors;
|
||||
public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaunchListener {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(EksService.class);
|
||||
private static final ObjectMapper MAPPER = new ObjectMapper();
|
||||
|
||||
private record UserDataClaim(String userData, CompletableFuture<UserDataPipeline.ExecutionResult> future) {}
|
||||
|
||||
private static final List<String> ALL_LOG_TYPES = List.of(
|
||||
public static final List<String> ALL_LOG_TYPES = List.of(
|
||||
"api", "audit", "authenticator", "controllerManager", "scheduler"
|
||||
);
|
||||
|
||||
@@ -796,7 +802,7 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
AccessConfig requestedAccess = request.getAccessConfig();
|
||||
String authenticationMode = requestedAccess == null || requestedAccess.authenticationMode() == null
|
||||
? "CONFIG_MAP" : requestedAccess.authenticationMode();
|
||||
if (!Set.of("CONFIG_MAP", "API_AND_CONFIG_MAP", "API").contains(authenticationMode)) {
|
||||
if (!AUTHENTICATION_MODE_RANK.containsKey(authenticationMode)) {
|
||||
throw new AwsException("InvalidParameterException", "Invalid authenticationMode", 400);
|
||||
}
|
||||
validateAutoMode(request.getComputeConfig(), request.getStorageConfig(), request.getKubernetesNetworkConfig());
|
||||
@@ -1028,6 +1034,206 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
}
|
||||
}
|
||||
|
||||
static final List<String> DEFAULT_PUBLIC_ACCESS_CIDRS = List.of("0.0.0.0/0");
|
||||
|
||||
private static final Map<String, Integer> AUTHENTICATION_MODE_RANK =
|
||||
Map.of("CONFIG_MAP", 0, "API_AND_CONFIG_MAP", 1, "API", 2);
|
||||
|
||||
/**
|
||||
* UpdateClusterConfig for {@code resourcesVpcConfig} endpoint access, {@code logging} and
|
||||
* {@code accessConfig.authenticationMode}. AWS accepts more members and lets the subnets and security
|
||||
* groups change; floci applies these three families and refuses a different subnet or security group list.
|
||||
* Each family the request names is stored as its own {@link Update} and all are returned in order. The
|
||||
* REST endpoint refuses a request naming more than one family, as EKS does, so it returns the only one. The
|
||||
* request is kept with the first update, and a repeat of its {@code clientRequestToken} returns that update.
|
||||
* The cluster is written through the delete-safe writer, so a concurrent delete is not undone.
|
||||
*/
|
||||
public synchronized List<Update> updateClusterConfig(String name, UpdateClusterConfigRequest request) {
|
||||
Cluster cluster = requireClusterInRequestRegion(name);
|
||||
EksAddonService.requireActiveCluster(cluster);
|
||||
if (request == null || (request.resourcesVpcConfig() == null && request.logging() == null
|
||||
&& request.accessConfig() == null)) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"UpdateClusterConfig supports resourcesVpcConfig, logging and accessConfig only", 400);
|
||||
}
|
||||
String token = request.clientRequestToken();
|
||||
if (token != null && !token.isBlank()) {
|
||||
Optional<EksAddonService.StoredUpdate> previous = addons.findConfigUpdateByToken(cluster, token);
|
||||
if (previous.isPresent()) {
|
||||
if (updateParametersMatch(previous.get().request(), request)) {
|
||||
return List.of(previous.get().update());
|
||||
}
|
||||
throw new AwsException("InvalidParameterException", EksAddonService.TOKEN_REUSED, 400);
|
||||
}
|
||||
}
|
||||
// Validated whole before anything is written, so a refused request changes nothing.
|
||||
ResourcesVpcConfig vpc = cluster.getResourcesVpcConfig();
|
||||
ResourcesVpcConfig requestedVpc = request.resourcesVpcConfig();
|
||||
Boolean storedPublic = vpc == null || vpc.getEndpointPublicAccess() == null ? Boolean.TRUE : vpc.getEndpointPublicAccess();
|
||||
Boolean storedPrivate = vpc == null || vpc.getEndpointPrivateAccess() == null ? Boolean.FALSE : vpc.getEndpointPrivateAccess();
|
||||
List<String> storedCidrs = vpc == null || vpc.getPublicAccessCidrs() == null
|
||||
? DEFAULT_PUBLIC_ACCESS_CIDRS : vpc.getPublicAccessCidrs();
|
||||
Boolean publicAccess = storedPublic;
|
||||
Boolean privateAccess = storedPrivate;
|
||||
List<String> cidrs = storedCidrs;
|
||||
if (requestedVpc != null) {
|
||||
requireSameMembers("subnetIds", requestedVpc.getSubnetIds(), vpc == null ? null : vpc.getSubnetIds());
|
||||
requireSameMembers("securityGroupIds", requestedVpc.getSecurityGroupIds(),
|
||||
vpc == null ? null : vpc.getSecurityGroupIds());
|
||||
publicAccess = requestedVpc.getEndpointPublicAccess() != null
|
||||
? requestedVpc.getEndpointPublicAccess() : publicAccess;
|
||||
privateAccess = requestedVpc.getEndpointPrivateAccess() != null
|
||||
? requestedVpc.getEndpointPrivateAccess() : privateAccess;
|
||||
// The stored cluster's ipFamily, as CreateCluster checks the same list against the requested one.
|
||||
KubernetesNetworkConfig stored = cluster.getKubernetesNetworkConfig();
|
||||
requireValidPublicAccessCidrs(requestedVpc.getPublicAccessCidrs(),
|
||||
stored == null || stored.getIpFamily() == null ? "ipv4" : stored.getIpFamily());
|
||||
cidrs = requestedVpc.getPublicAccessCidrs() != null ? requestedVpc.getPublicAccessCidrs() : cidrs;
|
||||
requireEndpointChange(vpc != null, storedPublic, storedPrivate, storedCidrs, publicAccess, privateAccess, cidrs);
|
||||
}
|
||||
Logging logging = request.logging() == null || request.logging().getClusterLogging() == null
|
||||
? null : buildLogging(mergedLogging(cluster.getLogging(), request.logging()));
|
||||
if (logging != null && enabledLogTypes(logging).equals(enabledLogTypes(cluster.getLogging()))) {
|
||||
throw new AwsException("InvalidParameterException", "No changes needed for the logging config provided", 400);
|
||||
}
|
||||
String mode = cluster.getAccessConfig() == null || cluster.getAccessConfig().authenticationMode() == null
|
||||
? "CONFIG_MAP" : cluster.getAccessConfig().authenticationMode();
|
||||
String requestedMode = request.accessConfig() == null ? null : request.accessConfig().authenticationMode();
|
||||
if (requestedMode != null) {
|
||||
requireForwardAuthenticationMode(mode, requestedMode);
|
||||
}
|
||||
|
||||
Boolean finalPublicAccess = publicAccess;
|
||||
Boolean finalPrivateAccess = privateAccess;
|
||||
List<String> finalCidrs = cidrs;
|
||||
List<Update> updates = new ArrayList<>();
|
||||
String accountId = regionResolver.getAccountId();
|
||||
boolean[] saved = {false};
|
||||
saveClusterIfNotDeleting(accountId, clusterKey(cluster), current -> {
|
||||
saved[0] = true;
|
||||
ResourcesVpcConfig currentVpc = current.getResourcesVpcConfig();
|
||||
if (requestedVpc != null && currentVpc != null) {
|
||||
currentVpc.setEndpointPublicAccess(finalPublicAccess);
|
||||
currentVpc.setEndpointPrivateAccess(finalPrivateAccess);
|
||||
currentVpc.setPublicAccessCidrs(finalCidrs);
|
||||
List<UpdateParam> params = new ArrayList<>();
|
||||
params.add(new UpdateParam("EndpointPublicAccess", String.valueOf(finalPublicAccess)));
|
||||
params.add(new UpdateParam("EndpointPrivateAccess", String.valueOf(finalPrivateAccess)));
|
||||
if (requestedVpc.getPublicAccessCidrs() != null) {
|
||||
params.add(new UpdateParam("PublicAccessCidrs", json(finalCidrs)));
|
||||
}
|
||||
updates.add(addons.recordUpdate(current, "EndpointAccessUpdate", params, null, updates.isEmpty() ? request : null));
|
||||
}
|
||||
if (logging != null) {
|
||||
current.setLogging(logging);
|
||||
updates.add(addons.recordUpdate(current, "LoggingUpdate",
|
||||
List.of(new UpdateParam("ClusterLogging", json(logging))), null,
|
||||
updates.isEmpty() ? request : null));
|
||||
}
|
||||
if (requestedMode != null) {
|
||||
current.setAccessConfig(new AccessConfig(requestedMode,
|
||||
current.getAccessConfig() == null ? null : current.getAccessConfig().bootstrapClusterCreatorAdminPermissions()));
|
||||
updates.add(addons.recordUpdate(current, "AccessConfigUpdate",
|
||||
List.of(new UpdateParam("AuthenticationMode", requestedMode)), null,
|
||||
updates.isEmpty() ? request : null));
|
||||
}
|
||||
});
|
||||
if (!saved[0]) {
|
||||
throw new AwsException("ResourceNotFoundException", "No cluster found for name: " + name, 404);
|
||||
}
|
||||
if (updates.isEmpty()) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"UpdateClusterConfig supports resourcesVpcConfig, logging and accessConfig.authenticationMode only", 400);
|
||||
}
|
||||
LOG.infov("Updated the configuration of EKS cluster {0}: {1}", cluster.getName(),
|
||||
updates.stream().map(Update::type).toList());
|
||||
return updates;
|
||||
}
|
||||
|
||||
private static boolean updateParametersMatch(UpdateClusterConfigRequest existing, UpdateClusterConfigRequest request) {
|
||||
if (existing == null) {
|
||||
return false;
|
||||
}
|
||||
ResourcesVpcConfig a = existing.resourcesVpcConfig();
|
||||
ResourcesVpcConfig b = request.resourcesVpcConfig();
|
||||
boolean sameVpc = a == null || b == null ? a == b
|
||||
: Objects.equals(a.getSubnetIds(), b.getSubnetIds())
|
||||
&& Objects.equals(a.getSecurityGroupIds(), b.getSecurityGroupIds())
|
||||
&& Objects.equals(a.getEndpointPublicAccess(), b.getEndpointPublicAccess())
|
||||
&& Objects.equals(a.getEndpointPrivateAccess(), b.getEndpointPrivateAccess())
|
||||
&& Objects.equals(a.getPublicAccessCidrs(), b.getPublicAccessCidrs());
|
||||
return sameVpc && Objects.equals(existing.logging(), request.logging())
|
||||
&& Objects.equals(existing.accessConfig(), request.accessConfig());
|
||||
}
|
||||
|
||||
/** The cluster's current settings with the request applied on top, in the shape createCluster validates. */
|
||||
private static Logging mergedLogging(Logging current, Logging requested) {
|
||||
List<LogSetup> merged = new ArrayList<>();
|
||||
if (current != null && current.getClusterLogging() != null) {
|
||||
merged.addAll(current.getClusterLogging());
|
||||
}
|
||||
merged.addAll(requested.getClusterLogging());
|
||||
return new Logging(merged);
|
||||
}
|
||||
|
||||
private static String json(Object value) {
|
||||
try {
|
||||
return MAPPER.writeValueAsString(value);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new AwsException("InternalFailure", "Could not serialize the update parameter", 500);
|
||||
}
|
||||
}
|
||||
|
||||
/** The log types a {@link Logging} setting enables; empty for a null setting. */
|
||||
public static Set<String> enabledLogTypes(Logging logging) {
|
||||
Set<String> enabled = new HashSet<>();
|
||||
if (logging != null && logging.getClusterLogging() != null) {
|
||||
for (LogSetup setup : logging.getClusterLogging()) {
|
||||
if (setup != null && setup.getTypes() != null && Boolean.TRUE.equals(setup.getEnabled())) {
|
||||
enabled.addAll(setup.getTypes());
|
||||
}
|
||||
}
|
||||
}
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/** EKS refuses an endpoint update that leaves both endpoints off or changes nothing. */
|
||||
private static void requireEndpointChange(boolean stored, Boolean storedPublic, Boolean storedPrivate,
|
||||
List<String> storedCidrs, Boolean publicAccess, Boolean privateAccess,
|
||||
List<String> cidrs) {
|
||||
if (Boolean.FALSE.equals(publicAccess) && Boolean.FALSE.equals(privateAccess)) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"You must enable private access to disable public access", 400);
|
||||
}
|
||||
if (stored && publicAccess.equals(storedPublic) && privateAccess.equals(storedPrivate)
|
||||
&& new HashSet<>(cidrs).equals(new HashSet<>(storedCidrs))) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"Cluster is already at the desired configuration with endpointPrivateAccess: " + privateAccess
|
||||
+ " , endpointPublicAccess: " + publicAccess
|
||||
+ ", and Public Endpoint Restrictions: [" + String.join(",", cidrs) + "]", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireSameMembers(String member, List<String> requested, List<String> current) {
|
||||
if (requested != null && !new HashSet<>(requested).equals(new HashSet<>(current == null ? List.of() : current))) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"Floci does not support changing " + member + " through UpdateClusterConfig", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireForwardAuthenticationMode(String current, String requested) {
|
||||
Integer to = AUTHENTICATION_MODE_RANK.get(requested);
|
||||
if (to == null) {
|
||||
throw new AwsException("InvalidParameterException", "Invalid authenticationMode", 400);
|
||||
}
|
||||
Integer from = AUTHENTICATION_MODE_RANK.get(current);
|
||||
// EKS moves the mode one step forward only: CONFIG_MAP, API_AND_CONFIG_MAP, API.
|
||||
if (from == null || to != from + 1) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"Unsupported authentication mode update from " + current + " to " + requested, 400);
|
||||
}
|
||||
}
|
||||
|
||||
/** The cluster {@code name} in the request's Region. */
|
||||
public Cluster describeCluster(String name) {
|
||||
Cluster cluster = storage.get(requestClusterKey(name))
|
||||
@@ -1741,6 +1947,25 @@ public class EksService implements TagHandler, ResourceProvider, Ec2InstanceLaun
|
||||
return vpcId;
|
||||
}
|
||||
|
||||
/** The public access CIDR checks CreateCluster and UpdateClusterConfig share. */
|
||||
private static void requireValidPublicAccessCidrs(List<String> cidrs, String ipFamily) {
|
||||
if (cidrs == null) {
|
||||
return;
|
||||
}
|
||||
for (String cidr : cidrs) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private ResourcesVpcConfig buildVpcConfigResponse(ResourcesVpcConfig request, String resolvedVpcId,
|
||||
String ipFamily) {
|
||||
ResourcesVpcConfig response = new ResourcesVpcConfig();
|
||||
@@ -1757,29 +1982,16 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
requireValidPublicAccessCidrs(request.getPublicAccessCidrs(), ipFamily);
|
||||
response.setPublicAccessCidrs(
|
||||
request.getPublicAccessCidrs() != null ? request.getPublicAccessCidrs() : List.of("0.0.0.0/0"));
|
||||
request.getPublicAccessCidrs() != null ? request.getPublicAccessCidrs() : DEFAULT_PUBLIC_ACCESS_CIDRS);
|
||||
} else {
|
||||
response.setSubnetIds(List.of());
|
||||
response.setSecurityGroupIds(List.of());
|
||||
response.setVpcId("");
|
||||
response.setEndpointPublicAccess(Boolean.TRUE);
|
||||
response.setEndpointPrivateAccess(Boolean.FALSE);
|
||||
response.setPublicAccessCidrs(List.of("0.0.0.0/0"));
|
||||
response.setPublicAccessCidrs(DEFAULT_PUBLIC_ACCESS_CIDRS);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package io.floci.aws.services.eks.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/**
|
||||
* The members of UpdateClusterConfig that floci applies. The REST controller refuses any other member.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public record UpdateClusterConfigRequest(
|
||||
ResourcesVpcConfig resourcesVpcConfig,
|
||||
Logging logging,
|
||||
AccessConfig accessConfig,
|
||||
String clientRequestToken
|
||||
) {}
|
||||
Reference in new issue
Block a user