fix(eks): store and return encryptionConfig and logging on clusters (#4007)

* fix(eks): store and return encryptionConfig and logging on clusters

* docs(eks): retain access policies in unsupported features list
This commit is contained in:
Simone Primarosa authored and GitHub committed 2026-09-20 12:40:42 -04:00
1 parent a793776c1a
commit aede31c99c
10 files changed
+815 -4

No files matched your search

@@ -19,16 +19,20 @@ import io.github.hectorvent.floci.services.eks.model.Cluster;
import io.github.hectorvent.floci.services.eks.model.AccessConfig;
import io.github.hectorvent.floci.services.eks.model.ClusterIdentity;
import io.github.hectorvent.floci.services.eks.model.ClusterStatus;
import io.github.hectorvent.floci.services.eks.model.OidcIdentity;
import io.github.hectorvent.floci.services.eks.model.CreateClusterRequest;
import io.github.hectorvent.floci.services.eks.model.CreateFargateProfileRequest;
import io.github.hectorvent.floci.services.eks.model.CreateNodeGroupRequest;
import io.github.hectorvent.floci.services.eks.model.EncryptionConfig;
import io.github.hectorvent.floci.services.eks.model.FargateProfile;
import io.github.hectorvent.floci.services.eks.model.FargateProfileStatus;
import io.github.hectorvent.floci.services.eks.model.KubernetesNetworkConfig;
import io.github.hectorvent.floci.services.eks.model.LogSetup;
import io.github.hectorvent.floci.services.eks.model.Logging;
import io.github.hectorvent.floci.services.eks.model.Nodegroup;
import io.github.hectorvent.floci.services.eks.model.NodegroupScalingConfig;
import io.github.hectorvent.floci.services.eks.model.NodegroupStatus;
import io.github.hectorvent.floci.services.eks.model.OidcIdentity;
import io.github.hectorvent.floci.services.eks.model.Provider;
import io.github.hectorvent.floci.services.eks.model.ResourcesVpcConfig;
import com.fasterxml.jackson.core.type.TypeReference;
import jakarta.annotation.PostConstruct;
@@ -40,8 +44,10 @@ import org.jboss.logging.Logger;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.HexFormat;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -61,6 +67,10 @@ public class EksService implements TagHandler, ResourceProvider {
private static final Logger LOG = Logger.getLogger(EksService.class);
private static final List<String> ALL_LOG_TYPES = List.of(
"api", "audit", "authenticator", "controllerManager", "scheduler"
);
/** The AWS charset for EKS cluster names. It admits no dot, which the Docker-name account
* qualifier relies on — see EksClusterManager#accountQualifiedName. */
static final String CLUSTER_NAME_REGEX = "[0-9A-Za-z][A-Za-z0-9\\-_]*";
@@ -104,6 +114,7 @@ public class EksService implements TagHandler, ResourceProvider {
public void init() {
backfillOidcIdentities();
backfillClusterSecurityGroups();
backfillLogging();
if (!config.services().eks().mock()) {
restorePersistedClusters();
startReadinessPoller();
@@ -323,6 +334,23 @@ public class EksService implements TagHandler, ResourceProvider {
}
}
void backfillLogging() {
for (AccountAwareStorageBackend.AccountEntry<Cluster> entry : allClusterEntries()) {
Cluster cluster = entry.value();
if (cluster.getLogging() != null) {
continue;
}
String accountId = entry.accountId();
if (cluster.getAccountId() == null) {
cluster.setAccountId(accountId);
}
cluster.setLogging(defaultLogging());
putClusterForAccount(accountId, cluster);
LOG.infov("Backfilled default logging for existing EKS cluster {0} in account {1}",
cluster.getName(), accountId);
}
}
private String resolveClusterRegion(Cluster cluster) {
if (cluster.getArn() != null && !cluster.getArn().isBlank()) {
try {
@@ -408,6 +436,8 @@ public class EksService implements TagHandler, ResourceProvider {
}
cluster.setResourcesVpcConfig(vpcConfig);
cluster.setKubernetesNetworkConfig(buildNetworkConfig(request.getKubernetesNetworkConfig()));
cluster.setLogging(buildLogging(request.getLogging()));
cluster.setEncryptionConfig(buildEncryptionConfig(request.getEncryptionConfig()));
cluster.setStatus(ClusterStatus.CREATING);
cluster.setTags(request.getTags() != null ? new HashMap<>(request.getTags()) : new HashMap<>());
cluster.setPlatformVersion("eks.1");
@@ -467,9 +497,13 @@ public class EksService implements TagHandler, ResourceProvider {
}
public Cluster describeCluster(String name) {
return storage.get(name)
Cluster cluster = storage.get(name)
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
"No cluster found for name: " + name, 404));
if (cluster.getLogging() == null) {
cluster.setLogging(defaultLogging());
}
return cluster;
}
public List<String> listClusters() {
@@ -783,6 +817,81 @@ public class EksService implements TagHandler, ResourceProvider {
return config;
}
static Logging defaultLogging() {
return new Logging(List.of(new LogSetup(new ArrayList<>(ALL_LOG_TYPES), false)));
}
private Logging buildLogging(Logging requestedLogging) {
if (requestedLogging == null || requestedLogging.getClusterLogging() == null
|| requestedLogging.getClusterLogging().isEmpty()) {
return defaultLogging();
}
Set<String> enabledTypes = new LinkedHashSet<>();
Set<String> specifiedTypes = new HashSet<>();
for (LogSetup setup : requestedLogging.getClusterLogging()) {
if (setup == null || setup.getTypes() == null) {
continue;
}
for (String type : setup.getTypes()) {
if (!ALL_LOG_TYPES.contains(type)) {
throw new AwsException("InvalidParameterException",
"'" + type + "' is not a valid log type", 400);
}
specifiedTypes.add(type);
if (Boolean.TRUE.equals(setup.getEnabled())) {
enabledTypes.add(type);
} else {
enabledTypes.remove(type);
}
}
}
if (specifiedTypes.isEmpty()) {
return defaultLogging();
}
List<String> enabledList = ALL_LOG_TYPES.stream()
.filter(enabledTypes::contains)
.collect(Collectors.toList());
List<String> disabledList = ALL_LOG_TYPES.stream()
.filter(t -> !enabledTypes.contains(t))
.collect(Collectors.toList());
List<LogSetup> entries = new ArrayList<>();
if (!enabledList.isEmpty()) {
entries.add(new LogSetup(enabledList, true));
}
if (!disabledList.isEmpty()) {
entries.add(new LogSetup(disabledList, false));
}
return new Logging(entries);
}
private List<EncryptionConfig> buildEncryptionConfig(List<EncryptionConfig> requestedConfigs) {
if (requestedConfigs == null || requestedConfigs.isEmpty()) {
return null;
}
if (requestedConfigs.size() > 1) {
throw new AwsException("InvalidParameterException",
"Only one encryption configuration is allowed", 400);
}
EncryptionConfig config = requestedConfigs.getFirst();
if (config == null || config.getResources() == null || config.getResources().isEmpty()
|| !List.of("secrets").equals(config.getResources())) {
throw new AwsException("InvalidParameterException",
"Invalid k8s resource and provider for encryption", 400);
}
if (config.getProvider() == null || config.getProvider().getKeyArn() == null
|| config.getProvider().getKeyArn().isBlank()) {
throw new AwsException("InvalidParameterException",
"Invalid k8s resource and provider for encryption", 400);
}
return List.of(new EncryptionConfig(List.of("secrets"), new Provider(config.getProvider().getKeyArn())));
}
private String nodeGroupKey(String clusterName, String nodegroupName) {
return clusterName + "/" + nodegroupName;
}
@@ -3,10 +3,12 @@ package io.github.hectorvent.floci.services.eks.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.time.Instant;
import java.util.List;
import java.util.Map;
@RegisterForReflection
@@ -38,6 +40,13 @@ public class Cluster {
@JsonProperty("kubernetesNetworkConfig")
private KubernetesNetworkConfig kubernetesNetworkConfig;
@JsonProperty("logging")
private Logging logging;
@JsonProperty("encryptionConfig")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<EncryptionConfig> encryptionConfig;
@JsonProperty("status")
private ClusterStatus status;
@@ -131,6 +140,12 @@ public class Cluster {
public int getHostPort() { return hostPort; }
public void setHostPort(int hostPort) { this.hostPort = hostPort; }
public Logging getLogging() { return logging; }
public void setLogging(Logging logging) { this.logging = logging; }
public List<EncryptionConfig> getEncryptionConfig() { return encryptionConfig; }
public void setEncryptionConfig(List<EncryptionConfig> encryptionConfig) { this.encryptionConfig = encryptionConfig; }
public String getDockerName() { return dockerName; }
public void setDockerName(String dockerName) { this.dockerName = dockerName; }
}
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.List;
import java.util.Map;
@RegisterForReflection
@@ -25,6 +26,12 @@ public class CreateClusterRequest {
@JsonProperty("kubernetesNetworkConfig")
private KubernetesNetworkConfig kubernetesNetworkConfig;
@JsonProperty("encryptionConfig")
private List<EncryptionConfig> encryptionConfig;
@JsonProperty("logging")
private Logging logging;
@JsonProperty("tags")
private Map<String, String> tags;
@@ -56,6 +63,12 @@ public class CreateClusterRequest {
public Map<String, String> getTags() { return tags; }
public void setTags(Map<String, String> tags) { this.tags = tags; }
public List<EncryptionConfig> getEncryptionConfig() { return encryptionConfig; }
public void setEncryptionConfig(List<EncryptionConfig> encryptionConfig) { this.encryptionConfig = encryptionConfig; }
public Logging getLogging() { return logging; }
public void setLogging(Logging logging) { this.logging = logging; }
public String getClientRequestToken() { return clientRequestToken; }
public void setClientRequestToken(String clientRequestToken) { this.clientRequestToken = clientRequestToken; }
}
@@ -0,0 +1,59 @@
package io.github.hectorvent.floci.services.eks.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.List;
import java.util.Objects;
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
public class EncryptionConfig {
@JsonProperty("resources")
private List<String> resources;
@JsonProperty("provider")
private Provider provider;
public EncryptionConfig() {}
public EncryptionConfig(List<String> resources, Provider provider) {
this.resources = resources;
this.provider = provider;
}
public List<String> getResources() {
return resources;
}
public void setResources(List<String> resources) {
this.resources = resources;
}
public Provider getProvider() {
return provider;
}
public void setProvider(Provider provider) {
this.provider = provider;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
EncryptionConfig that = (EncryptionConfig) o;
return Objects.equals(resources, that.resources) && Objects.equals(provider, that.provider);
}
@Override
public int hashCode() {
return Objects.hash(resources, provider);
}
}
@@ -0,0 +1,59 @@
package io.github.hectorvent.floci.services.eks.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.List;
import java.util.Objects;
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
public class LogSetup {
@JsonProperty("types")
private List<String> types;
@JsonProperty("enabled")
private Boolean enabled;
public LogSetup() {}
public LogSetup(List<String> types, Boolean enabled) {
this.types = types;
this.enabled = enabled;
}
public List<String> getTypes() {
return types;
}
public void setTypes(List<String> types) {
this.types = types;
}
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
LogSetup logSetup = (LogSetup) o;
return Objects.equals(types, logSetup.types) && Objects.equals(enabled, logSetup.enabled);
}
@Override
public int hashCode() {
return Objects.hash(types, enabled);
}
}
@@ -0,0 +1,47 @@
package io.github.hectorvent.floci.services.eks.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.List;
import java.util.Objects;
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
public class Logging {
@JsonProperty("clusterLogging")
private List<LogSetup> clusterLogging;
public Logging() {}
public Logging(List<LogSetup> clusterLogging) {
this.clusterLogging = clusterLogging;
}
public List<LogSetup> getClusterLogging() {
return clusterLogging;
}
public void setClusterLogging(List<LogSetup> clusterLogging) {
this.clusterLogging = clusterLogging;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Logging logging = (Logging) o;
return Objects.equals(clusterLogging, logging.clusterLogging);
}
@Override
public int hashCode() {
return Objects.hash(clusterLogging);
}
}
@@ -0,0 +1,46 @@
package io.github.hectorvent.floci.services.eks.model;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.util.Objects;
@RegisterForReflection
@JsonIgnoreProperties(ignoreUnknown = true)
public class Provider {
@JsonProperty("keyArn")
private String keyArn;
public Provider() {}
public Provider(String keyArn) {
this.keyArn = keyArn;
}
public String getKeyArn() {
return keyArn;
}
public void setKeyArn(String keyArn) {
this.keyArn = keyArn;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Provider provider = (Provider) o;
return Objects.equals(keyArn, provider.keyArn);
}
@Override
public int hashCode() {
return Objects.hash(keyArn);
}
}