feat(eks): support per-cluster kubelet and API server arguments (#4772)

* feat(eks): support per-cluster kubelet and API server arguments

* fix(eks): prevent security group leak and reject authorization-mode override

* refactor(eks): classify authorization-mode as refused argument

* fix(eks): strip modifier suffixes before collision validation
This commit is contained in:
Simone Primarosa authored and GitHub committed 2026-10-02 11:16:31 -04:00
1 parent 044c700d68
commit 86c06247e3
9 files changed
+895 -2

No files matched your search

+62
View File
@@ -179,6 +179,68 @@ Floci tags the cluster security group with the standard AWS system tags:
- **Backfill**: Existing persisted clusters that were created before this feature receive an auto-generated cluster security group during startup backfill if their VPC is present.
- **Rules**: In accordance with AWS EKS behavior, the cluster security group includes a self-referencing inbound rule allowing all traffic from members of the same security group to enable control plane and node communication, a self-referencing outbound rule for Elastic Fabric Adapter (EFA) traffic, and the standard EC2 outbound rule.
## Custom control-plane and node arguments (emulator affordance)
Floci allows callers to pass custom flags to k3s server components when creating an EKS cluster via resource tags. This is an emulator affordance with no direct AWS equivalent, intended for testing configurations that require custom kubelet or control plane flags in local environments.
### Tag formats
Custom arguments are supplied as tags in `CreateCluster`:
- Prefixed flag tag: `floci:kubelet-arg:<flag>=<value>` or `floci:kubelet-arg:<flag>` with tag value set to `<value>` (for example, `floci:kubelet-arg:max-pods` = `250`).
- Plural tag: `floci:kubelet-args` with tag value set to a JSON array of flag strings (for example, `["max-pods=250", "image-gc-high-threshold-percent=80"]`) or newline-separated lines.
- Singular tag: `floci:kubelet-arg` with tag value set to `<flag>=<value>`.
The supported component prefixes correspond to k3s server argument flags:
- `kubelet` (`--kubelet-arg`): worker node kubelet settings.
- `kube-apiserver` or `apiserver` (`--kube-apiserver-arg`): Kubernetes API server settings.
- `kube-controller-manager` or `controller-manager` (`--kube-controller-manager-arg`): controller manager settings.
- `kube-scheduler` or `scheduler` (`--kube-scheduler-arg`): scheduler settings.
- `kube-cloud-controller-manager` (`--kube-cloud-controller-manager-arg`): cloud controller manager settings.
### Common examples
- **Kubelet capacity**: `floci:kubelet-arg:max-pods=250` raises the pod ceiling on the local node.
- **Kubelet garbage collection**: `floci:kubelet-args` = `["image-gc-high-threshold-percent=70", "image-gc-low-threshold-percent=50"]`.
- **API server feature gates**: `floci:kube-apiserver-arg:feature-gates=CSIStorageCapacity=true`.
- **Controller manager single-node tuning**: `floci:kube-controller-manager-arg:leader-elect=false`.
### Collision rules and Floci-managed arguments
Floci manages a specific set of flags required for container networking, IAM authentication, audit logging, and topology emulation. Passing a conflicting value or modifier (such as `+=` or `-=`) for any of these flags causes `CreateCluster` to reject the request with `InvalidParameterException` (HTTP 400).
Floci manages the following 16 flags:
- Kubelet:
- `provider-id`: manages EC2 worker node identity.
- `node-labels`: manages topology zones and instance types.
- `system-reserved`: manages memory and CPU reservations.
- `kube-reserved`: manages kubelet resource allocations.
- `eviction-hard`: manages memory pressure thresholds.
- API server:
- `authentication-token-webhook-config-file`: manages worker IAM authentication.
- `authentication-token-webhook-version`: token webhook protocol version.
- `authentication-token-webhook-cache-ttl`: webhook cache duration.
- `service-account-issuer`: IRSA OIDC discovery issuer URL.
- `service-account-key-file`: IRSA public signing key.
- `service-account-signing-key-file`: IRSA private signing key.
- `audit-policy-file`: EKS control plane audit policy.
- `audit-log-path`: audit log destination.
- `audit-log-maxage`: audit log retention days.
- `audit-log-maxbackup`: audit log file rotation count.
- `audit-log-maxsize`: audit log rotation size.
### Refused arguments
The following flags are refused outright because they conflict with the k3s embedded SQLite (kine) engine or bypass API server RBAC authorization:
- `storage-backend`
- `etcd-servers`
- `authorization-mode`
### Error handling and tag stripping
- **Malformed arguments**: If an argument tag is blank, contains control characters, or cannot be parsed, Floci logs a warning and proceeds with cluster creation.
- **Tag privacy and immutability**: All `floci:*` tags are stripped from public responses and are not returned by `DescribeCluster` or `ListTagsForResource`. Modification via `TagResource` after creation is rejected with `ValidationException`.
## Encryption and logging configuration
EKS clusters support configuring KMS envelope encryption for secrets and control plane logging export.
@@ -0,0 +1,324 @@
package io.github.hectorvent.floci.services.eks;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.ReservedTags;
import org.jboss.logging.Logger;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
/**
* Handles caller-supplied k3s arguments configured via reserved tags on cluster creation.
* Supported components include kubelet, kube-apiserver, kube-controller-manager, and kube-scheduler.
*/
public final class EksClusterArgs {
private static final Logger LOG = Logger.getLogger(EksClusterArgs.class);
private static final ObjectMapper MAPPER = new ObjectMapper();
public enum Component {
KUBELET("--kubelet-arg="),
KUBE_APISERVER("--kube-apiserver-arg="),
KUBE_CONTROLLER_MANAGER("--kube-controller-manager-arg="),
KUBE_SCHEDULER("--kube-scheduler-arg="),
KUBE_CLOUD_CONTROLLER_MANAGER("--kube-cloud-controller-manager-arg=");
private final String flagPrefix;
Component(String flagPrefix) {
this.flagPrefix = flagPrefix;
}
public String flagPrefix() {
return flagPrefix;
}
}
private record ComponentTagMapping(Component component, String name) {}
private static final List<ComponentTagMapping> MAPPINGS = List.of(
new ComponentTagMapping(Component.KUBELET, "kubelet"),
new ComponentTagMapping(Component.KUBE_APISERVER, "kube-apiserver"),
new ComponentTagMapping(Component.KUBE_APISERVER, "apiserver"),
new ComponentTagMapping(Component.KUBE_CONTROLLER_MANAGER, "kube-controller-manager"),
new ComponentTagMapping(Component.KUBE_CONTROLLER_MANAGER, "controller-manager"),
new ComponentTagMapping(Component.KUBE_SCHEDULER, "kube-scheduler"),
new ComponentTagMapping(Component.KUBE_SCHEDULER, "scheduler"),
new ComponentTagMapping(Component.KUBE_CLOUD_CONTROLLER_MANAGER, "kube-cloud-controller-manager")
);
/**
* Arguments Floci sets for kubelet to manage node identity, topology and node capacity budget.
* Normalized without hyphens for case/hyphen-insensitive collision matching.
*/
static final Set<String> FLOCI_MANAGED_KUBELET_FLAGS = Set.of(
"providerid",
"nodelabels",
"systemreserved",
"kubereserved",
"evictionhard"
);
/**
* Arguments Floci sets for kube-apiserver for IAM token webhook authentication, IRSA signing,
* and audit logging. Normalized without hyphens.
*/
static final Set<String> FLOCI_MANAGED_APISERVER_FLAGS = Set.of(
"authenticationtokenwebhookconfigfile",
"authenticationtokenwebhookversion",
"authenticationtokenwebhookcachettl",
"serviceaccountissuer",
"serviceaccountkeyfile",
"serviceaccountsigningkeyfile",
"auditpolicyfile",
"auditlogpath",
"auditlogmaxage",
"auditlogmaxbackup",
"auditlogmaxsize"
);
/**
* Flags refused outright because they conflict with the k3s embedded SQLite (kine) engine
* or bypass API server RBAC authorization.
*/
static final Set<String> REFUSED_APISERVER_FLAGS = Set.of(
"storagebackend",
"etcdservers",
"authorizationmode"
);
private static final TypeReference<List<String>> STRING_LIST_TYPE = new TypeReference<>() {};
private EksClusterArgs() {
}
public static class CollisionException extends IllegalArgumentException {
public CollisionException(String message) {
super(message);
}
}
/**
* Parses and validates cluster arguments supplied in tags, returning a list of k3s argument flags.
* Malformed entries log a warning and are skipped so the cluster still starts.
* Collisions with Floci-managed arguments throw {@link CollisionException}.
*/
public static List<String> parseAndValidateClusterArgs(Map<String, String> tags, String clusterName) {
if (tags == null || tags.isEmpty()) {
return Collections.emptyList();
}
List<String> result = new ArrayList<>();
for (Map.Entry<String, String> entry : tags.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (key == null || !key.startsWith(ReservedTags.RESERVED_PREFIX)) {
continue;
}
ParsedTag parsedTag = matchComponent(key);
if (parsedTag == null) {
continue;
}
try {
List<String> rawFlags = extractRawFlags(parsedTag, key, value);
for (String rawFlag : rawFlags) {
if (rawFlag == null || rawFlag.isBlank()) {
LOG.warnv("Malformed EKS cluster argument {0}={1} for cluster {2}: empty argument flag",
key, value, clusterName);
continue;
}
if (hasControlCharacters(rawFlag)) {
LOG.warnv("Malformed EKS cluster argument {0}={1} for cluster {2}: argument contains control characters",
key, value, clusterName);
continue;
}
String normalized = normalizeFlag(parsedTag.component(), rawFlag);
validateCollision(parsedTag.component(), normalized);
result.add(parsedTag.component().flagPrefix() + normalized);
}
} catch (CollisionException e) {
// Collisions and refused arguments must be propagated to reject the request
throw e;
} catch (Exception e) {
LOG.warnv("Malformed EKS cluster argument {0}={1} for cluster {2}: {3}",
key, value, clusterName, e.getMessage());
}
}
return result;
}
/**
* Validates a list of already-assembled server arguments to guarantee no Floci-managed or
* refused argument collides.
*/
public static void validateClusterArgs(List<String> serverArgs) {
if (serverArgs == null || serverArgs.isEmpty()) {
return;
}
for (String arg : serverArgs) {
if (arg == null || arg.isBlank()) {
continue;
}
for (Component component : Component.values()) {
if (arg.startsWith(component.flagPrefix())) {
String flag = arg.substring(component.flagPrefix().length());
validateCollision(component, flag);
break;
}
}
}
}
private record ParsedTag(Component component, TagKind kind, String prefixMatched) {}
private enum TagKind {
PREFIXED,
SINGLE,
PLURAL
}
static ParsedTag matchComponent(String key) {
for (ComponentTagMapping m : MAPPINGS) {
String prefix = ReservedTags.RESERVED_PREFIX + m.name() + "-arg:";
if (key.startsWith(prefix)) {
return new ParsedTag(m.component(), TagKind.PREFIXED, prefix);
}
String single = ReservedTags.RESERVED_PREFIX + m.name() + "-arg";
if (key.equals(single)) {
return new ParsedTag(m.component(), TagKind.SINGLE, single);
}
String plural = ReservedTags.RESERVED_PREFIX + m.name() + "-args";
if (key.equals(plural)) {
return new ParsedTag(m.component(), TagKind.PLURAL, plural);
}
}
return null;
}
private static List<String> extractRawFlags(ParsedTag parsedTag, String key, String value) throws Exception {
List<String> flags = new ArrayList<>();
switch (parsedTag.kind()) {
case PREFIXED -> {
String flagSuffix = key.substring(parsedTag.prefixMatched().length()).trim();
if (flagSuffix.isBlank()) {
if (value == null || value.isBlank()) {
throw new IllegalArgumentException("flag name is blank");
}
flags.add(value.trim());
} else if (flagSuffix.contains("=")) {
flags.add(flagSuffix);
} else if (value != null && !value.isBlank() && !"true".equalsIgnoreCase(value.trim())) {
flags.add(flagSuffix + "=" + value.trim());
} else {
flags.add(flagSuffix);
}
}
case SINGLE -> {
if (value == null || value.isBlank()) {
throw new IllegalArgumentException("tag value is blank");
}
flags.add(value.trim());
}
case PLURAL -> {
if (value == null || value.isBlank()) {
throw new IllegalArgumentException("tag value is blank");
}
String trimmedValue = value.trim();
if (trimmedValue.startsWith("[")) {
List<String> list = MAPPER.readValue(trimmedValue, STRING_LIST_TYPE);
if (list != null) {
for (String item : list) {
if (item != null && !item.isBlank()) {
flags.add(item.trim());
}
}
}
} else if (trimmedValue.contains("\n")) {
for (String line : trimmedValue.split("\n")) {
String lineTrimmed = line.trim();
if (!lineTrimmed.isBlank()) {
flags.add(lineTrimmed);
}
}
} else if (trimmedValue.contains(",") && !trimmedValue.contains("=")) {
for (String item : trimmedValue.split(",")) {
String itemTrimmed = item.trim();
if (!itemTrimmed.isBlank()) {
flags.add(itemTrimmed);
}
}
} else {
flags.add(trimmedValue);
}
}
}
return flags;
}
private static String normalizeFlag(Component component, String rawFlag) {
String flag = rawFlag.trim();
if (flag.startsWith(component.flagPrefix())) {
flag = flag.substring(component.flagPrefix().length()).trim();
}
while (flag.startsWith("-")) {
flag = flag.substring(1).trim();
}
return flag;
}
private static void validateCollision(Component component, String flag) {
String rawName = extractFlagName(flag);
String flagName = rawName.replace("-", "").toLowerCase(Locale.ROOT);
if (component == Component.KUBELET) {
if (FLOCI_MANAGED_KUBELET_FLAGS.contains(flagName)) {
throw new CollisionException("Cluster argument '" + rawName
+ "' collides with Floci-managed kubelet argument. "
+ "Floci manages this argument for cluster operation and it cannot be overridden.");
}
} else if (component == Component.KUBE_APISERVER) {
if (FLOCI_MANAGED_APISERVER_FLAGS.contains(flagName)) {
throw new CollisionException("Cluster argument '" + rawName
+ "' collides with Floci-managed kube-apiserver argument. "
+ "Floci manages this argument for cluster operation and it cannot be overridden.");
}
if (REFUSED_APISERVER_FLAGS.contains(flagName)) {
throw new CollisionException("Cluster argument '" + rawName
+ "' is refused outright and cannot be configured.");
}
}
}
private static String extractFlagName(String flag) {
int eqIndex = flag.indexOf('=');
String name = (eqIndex >= 0) ? flag.substring(0, eqIndex).trim() : flag.trim();
while (name.startsWith("-")) {
name = name.substring(1).trim();
}
while (name.endsWith("+") || name.endsWith("-")) {
name = name.substring(0, name.length() - 1).trim();
}
return name;
}
private static boolean hasControlCharacters(String s) {
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (Character.isISOControl(c) && c != '\t' && c != '\n' && c != '\r') {
return true;
}
}
return false;
}
}
@@ -531,6 +531,11 @@ public class EksClusterManager
}
}
List<String> callerArgs = resolveCallerArgs(cluster);
if (!callerArgs.isEmpty()) {
serverArgs.addAll(callerArgs);
}
if (config.services().eks().disableCni()) {
// A container's /sys mount defaults to private propagation, which breaks
// Cilium's BPF filesystem mount ("mounted on /sys but it is not a shared or
@@ -1243,6 +1248,29 @@ public class EksClusterManager
return wrappedCmd;
}
/**
* Resolves caller-supplied k3s arguments configured on the cluster or in its creation tags.
*/
List<String> resolveCallerArgs(Cluster cluster) {
if (cluster == null) {
return List.of();
}
List<String> result = new ArrayList<>();
if (cluster.getClusterArgs() != null && !cluster.getClusterArgs().isEmpty()) {
EksClusterArgs.validateClusterArgs(cluster.getClusterArgs());
result.addAll(cluster.getClusterArgs());
}
if (cluster.getTags() != null && !cluster.getTags().isEmpty()) {
List<String> fromTags = EksClusterArgs.parseAndValidateClusterArgs(cluster.getTags(), cluster.getName());
for (String arg : fromTags) {
if (!result.contains(arg)) {
result.add(arg);
}
}
}
return result;
}
/**
* Resolves the public {@code describe-cluster} endpoint. Returns the container DNS name only when
* Floci runs in a container and {@code endpoint-mode=network}; otherwise the host-reachable
@@ -92,12 +92,13 @@ public class EksController {
* causes Jackson to omit the property due to @JsonInclude(NON_DEFAULT).
*/
private Cluster toClusterResponse(Cluster cluster) {
if (cluster == null || (!cluster.isExplicitVersion() && cluster.getNodeInstanceType() == null)) {
if (cluster == null || (!cluster.isExplicitVersion() && cluster.getNodeInstanceType() == null && cluster.getClusterArgs() == null)) {
return cluster;
}
Cluster response = cluster.copy();
response.setExplicitVersion(false);
response.setNodeInstanceType(null);
response.setClusterArgs(null);
return response;
}
@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.RequestScopes;
import io.github.hectorvent.floci.core.common.ReservedTags;
import io.github.hectorvent.floci.core.common.TagHandler;
import io.github.hectorvent.floci.core.common.docker.UserDataPipeline;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
@@ -539,6 +540,18 @@ public class EksService implements TagHandler, ResourceProvider {
}
cluster.setRoleArn(request.getRoleArn());
List<String> clusterArgs;
try {
clusterArgs = EksClusterArgs.parseAndValidateClusterArgs(request.getTags(), name);
} catch (IllegalArgumentException e) {
throw new AwsException("InvalidParameterException", e.getMessage(), 400);
}
if (!clusterArgs.isEmpty()) {
cluster.setClusterArgs(clusterArgs);
}
cluster.setTags(request.getTags() != null ? ReservedTags.stripReservedTags(request.getTags()) : new HashMap<>());
ResourcesVpcConfig vpcConfig = buildVpcConfigResponse(request.getResourcesVpcConfig(), resolvedVpcId);
SecurityGroup clusterSg = null;
if (ec2Service != null && !vpcConfig.getVpcId().isBlank()) {
@@ -560,7 +573,6 @@ public class EksService implements TagHandler, ResourceProvider {
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");
cluster.setCertificateAuthority(new CertificateAuthority(""));
@@ -998,6 +1010,7 @@ public class EksService implements TagHandler, ResourceProvider {
@Override
public void tagResource(String region, String resourceArn, Map<String, String> tags) {
ReservedTags.rejectReservedTagsOnUpdate(tags);
String clusterName = extractClusterName(resourceArn);
Cluster cluster = storage.get(clusterName)
.orElseThrow(() -> new AwsException("ResourceNotFoundException",
@@ -8,6 +8,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import io.quarkus.runtime.annotations.RegisterForReflection;
import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -101,6 +102,14 @@ public class Cluster {
@JsonInclude(JsonInclude.Include.NON_NULL)
private String nodeInstanceType;
/**
* Caller-supplied k3s arguments passed at creation via reserved floci tags.
* Internal persisted metadata omitted from AWS API responses.
*/
@JsonProperty("clusterArgs")
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<String> clusterArgs;
private AccessConfig accessConfig;
public AccessConfig getAccessConfig() { return accessConfig; }
@@ -153,6 +162,9 @@ public class Cluster {
public String getNodeInstanceType() { return nodeInstanceType; }
public void setNodeInstanceType(String nodeInstanceType) { this.nodeInstanceType = nodeInstanceType; }
public List<String> getClusterArgs() { return clusterArgs; }
public void setClusterArgs(List<String> clusterArgs) { this.clusterArgs = clusterArgs; }
public String getAccountId() { return accountId; }
public void setAccountId(String accountId) { this.accountId = accountId; }
@@ -202,6 +214,7 @@ public class Cluster {
c.explicitVersion = this.explicitVersion;
c.dockerName = this.dockerName;
c.nodeInstanceType = this.nodeInstanceType;
c.clusterArgs = this.clusterArgs != null ? new ArrayList<>(this.clusterArgs) : null;
c.accessConfig = this.accessConfig;
return c;
}
@@ -0,0 +1,223 @@
package io.github.hectorvent.floci.services.eks;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
class EksClusterArgsTest {
@Test
void parsePrefixedKubeletArgWithKeyEqualsValue() {
Map<String, String> tags = Map.of("floci:kubelet-arg:max-pods=250", "true");
List<String> args = EksClusterArgs.parseAndValidateClusterArgs(tags, "demo");
assertEquals(List.of("--kubelet-arg=max-pods=250"), args);
}
@Test
void parsePrefixedKubeletArgWithKeyValue() {
Map<String, String> tags = Map.of("floci:kubelet-arg:max-pods", "250");
List<String> args = EksClusterArgs.parseAndValidateClusterArgs(tags, "demo");
assertEquals(List.of("--kubelet-arg=max-pods=250"), args);
}
@Test
void parseSingularKubeApiserverArg() {
Map<String, String> tags = Map.of("floci:kube-apiserver-arg", "feature-gates=CSIStorageCapacity=true");
List<String> args = EksClusterArgs.parseAndValidateClusterArgs(tags, "demo");
assertEquals(List.of("--kube-apiserver-arg=feature-gates=CSIStorageCapacity=true"), args);
}
@Test
void parsePluralJsonArrayArgs() {
Map<String, String> tags = Map.of(
"floci:kubelet-args", "[\"max-pods=250\", \"image-gc-high-threshold-percent=80\"]"
);
List<String> args = EksClusterArgs.parseAndValidateClusterArgs(tags, "demo");
assertEquals(List.of(
"--kubelet-arg=max-pods=250",
"--kubelet-arg=image-gc-high-threshold-percent=80"
), args);
}
@Test
void parsePluralNewlineSeparatedArgs() {
Map<String, String> tags = Map.of(
"floci:kubelet-args", "max-pods=250\nimage-gc-high-threshold-percent=80"
);
List<String> args = EksClusterArgs.parseAndValidateClusterArgs(tags, "demo");
assertEquals(List.of(
"--kubelet-arg=max-pods=250",
"--kubelet-arg=image-gc-high-threshold-percent=80"
), args);
}
@Test
void stripsRedundantPrefixesAndDashes() {
Map<String, String> tags = Map.of(
"floci:kubelet-arg:--max-pods=250", "true",
"floci:kube-apiserver-arg", "--kube-apiserver-arg=feature-gates=Test=true"
);
List<String> args = EksClusterArgs.parseAndValidateClusterArgs(tags, "demo");
assertTrue(args.contains("--kubelet-arg=max-pods=250"));
assertTrue(args.contains("--kube-apiserver-arg=feature-gates=Test=true"));
}
@Test
void supportsAllK3sComponents() {
Map<String, String> tags = Map.of(
"floci:kubelet-arg:max-pods=250", "true",
"floci:kube-apiserver-arg:runtime-config=batch/v1=true", "true",
"floci:kube-controller-manager-arg:leader-elect=false", "true",
"floci:kube-scheduler-arg:leader-elect=false", "true",
"floci:kube-cloud-controller-manager-arg:cloud-provider=aws", "true"
);
List<String> args = EksClusterArgs.parseAndValidateClusterArgs(tags, "demo");
assertTrue(args.contains("--kubelet-arg=max-pods=250"));
assertTrue(args.contains("--kube-apiserver-arg=runtime-config=batch/v1=true"));
assertTrue(args.contains("--kube-controller-manager-arg=leader-elect=false"));
assertTrue(args.contains("--kube-scheduler-arg=leader-elect=false"));
assertTrue(args.contains("--kube-cloud-controller-manager-arg=cloud-provider=aws"));
}
@Test
void supportsShortComponentAliases() {
Map<String, String> tags = Map.of(
"floci:apiserver-arg:runtime-config=batch/v1=true", "true",
"floci:controller-manager-arg:leader-elect=false", "true",
"floci:scheduler-arg:leader-elect=false", "true"
);
List<String> args = EksClusterArgs.parseAndValidateClusterArgs(tags, "demo");
assertTrue(args.contains("--kube-apiserver-arg=runtime-config=batch/v1=true"));
assertTrue(args.contains("--kube-controller-manager-arg=leader-elect=false"));
assertTrue(args.contains("--kube-scheduler-arg=leader-elect=false"));
}
@Test
void preservesModifierSuffixOnValidArguments() {
Map<String, String> tags = Map.of(
"floci:kubelet-arg:max-pods+=10", "true",
"floci:kube-apiserver-arg:feature-gates+=CSIStorageCapacity=true", "true"
);
List<String> args = EksClusterArgs.parseAndValidateClusterArgs(tags, "demo");
assertTrue(args.contains("--kubelet-arg=max-pods+=10"));
assertTrue(args.contains("--kube-apiserver-arg=feature-gates+=CSIStorageCapacity=true"));
}
@ParameterizedTest
@ValueSource(strings = {
"provider-id",
"node-labels",
"system-reserved",
"kube-reserved",
"eviction-hard",
"--provider-id=custom-id",
"providerId=custom-id",
"node-labels=topology.kubernetes.io/zone=custom",
"provider-id+=aws:///custom-id",
"node-labels-=zone=custom"
})
void rejectsCollidingKubeletArguments(String collidingFlag) {
Map<String, String> tags = Map.of("floci:kubelet-arg:" + collidingFlag, "true");
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
() -> EksClusterArgs.parseAndValidateClusterArgs(tags, "demo"));
assertNotNull(e.getMessage());
assertTrue(e.getMessage().contains("collides with Floci-managed kubelet argument"));
}
@ParameterizedTest
@ValueSource(strings = {
"authentication-token-webhook-config-file",
"authentication-token-webhook-version",
"authentication-token-webhook-cache-ttl",
"service-account-issuer",
"service-account-key-file",
"service-account-signing-key-file",
"audit-policy-file",
"audit-log-path",
"audit-log-maxage",
"audit-log-maxbackup",
"audit-log-maxsize",
"--service-account-issuer=https://override.example.com",
"auditPolicyFile=/custom/path",
"audit-policy-file+=/custom/path",
"audit-policy-file-=/custom/path"
})
void rejectsCollidingKubeApiserverArguments(String collidingFlag) {
Map<String, String> tags = Map.of("floci:kube-apiserver-arg:" + collidingFlag, "true");
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
() -> EksClusterArgs.parseAndValidateClusterArgs(tags, "demo"));
assertNotNull(e.getMessage());
assertTrue(e.getMessage().contains("collides with Floci-managed kube-apiserver argument"));
}
@ParameterizedTest
@ValueSource(strings = {
"storage-backend",
"etcd-servers",
"authorization-mode",
"authorization-mode=AlwaysAllow",
"authorization-mode+=AlwaysAllow",
"authorization-mode-=AlwaysAllow",
"authorization-mode+",
"storage-backend=etcd3",
"storage-backend+=etcd3",
"etcd-servers=https://127.0.0.1:2379"
})
void rejectsRefusedApiserverArguments(String refusedFlag) {
Map<String, String> tags = Map.of("floci:kube-apiserver-arg:" + refusedFlag, "true");
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
() -> EksClusterArgs.parseAndValidateClusterArgs(tags, "demo"));
assertNotNull(e.getMessage());
assertTrue(e.getMessage().contains("is refused outright"));
}
@Test
void malformedInputLogsWarningAndContinuesWithoutThrowing() {
// Empty flag name
Map<String, String> tags = Map.of(
"floci:kubelet-arg:", "",
"floci:kubelet-arg:max-pods=250", "true"
);
List<String> args = EksClusterArgs.parseAndValidateClusterArgs(tags, "demo");
assertEquals(List.of("--kubelet-arg=max-pods=250"), args);
}
@Test
void controlCharactersLogWarningAndAreSkipped() {
Map<String, String> tags = Map.of(
"floci:kubelet-arg:bad\u0000flag=1", "true",
"floci:kubelet-arg:max-pods=250", "true"
);
List<String> args = EksClusterArgs.parseAndValidateClusterArgs(tags, "demo");
assertEquals(List.of("--kubelet-arg=max-pods=250"), args);
}
@Test
void unparseableJsonArrayLogsWarningAndIsSkipped() {
Map<String, String> tags = Map.of(
"floci:kubelet-args", "[not-valid-json",
"floci:kubelet-arg:max-pods=250", "true"
);
List<String> args = EksClusterArgs.parseAndValidateClusterArgs(tags, "demo");
assertEquals(List.of("--kubelet-arg=max-pods=250"), args);
}
@Test
void nonReservedTagsAreIgnored() {
Map<String, String> tags = Map.of(
"Environment", "production",
"Team", "core",
"floci:kubelet-arg:max-pods=250", "true"
);
List<String> args = EksClusterArgs.parseAndValidateClusterArgs(tags, "demo");
assertEquals(List.of("--kubelet-arg=max-pods=250"), args);
}
}
@@ -2748,4 +2748,143 @@ class EksClusterManagerTest {
assertTrue(policy.contains("/version"));
}
}
@Nested
class ClusterArgsPassthrough {
private ContainerBuilder containerBuilder;
private ContainerBuilder.Builder builder;
private ContainerLifecycleManager lifecycleManager;
private EksClusterManager manager;
@BeforeEach
void setUp() {
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
EmulatorConfig.ServicesConfig services = Mockito.mock(EmulatorConfig.ServicesConfig.class);
EmulatorConfig.EksServiceConfig eks = Mockito.mock(EmulatorConfig.EksServiceConfig.class);
when(config.services()).thenReturn(services);
when(services.eks()).thenReturn(eks);
when(eks.defaultImage()).thenReturn("rancher/k3s:v1.30.0-k3s1");
when(eks.apiServerBasePort()).thenReturn(6440);
when(eks.apiServerMaxPort()).thenReturn(6499);
when(eks.dockerNetwork()).thenReturn(Optional.empty());
when(eks.disableCni()).thenReturn(false);
when(eks.iamAuthWebhook()).thenReturn(false);
when(eks.ecrRegistryMirror()).thenReturn(false);
lifecycleManager = Mockito.mock(ContainerLifecycleManager.class);
when(lifecycleManager.create(any())).thenReturn("container-id");
when(lifecycleManager.startCreated(any(), any())).thenReturn(
new ContainerInfo("container-id", Map.of()));
containerBuilder = Mockito.mock(ContainerBuilder.class);
builder = Mockito.mock(ContainerBuilder.Builder.class, Mockito.RETURNS_SELF);
when(containerBuilder.newContainer(anyString())).thenReturn(builder);
when(builder.build()).thenReturn(Mockito.mock(ContainerSpec.class));
RegionResolver regionResolver = Mockito.mock(RegionResolver.class);
when(regionResolver.getAccountId()).thenReturn("000000000000");
when(regionResolver.getDefaultRegion()).thenReturn("us-east-1");
when(regionResolver.buildGlobalArn(anyString(), anyString(), anyString())).thenAnswer(invocation ->
"arn:aws:" + invocation.getArgument(0) + "::" + invocation.getArgument(1) + ":" + invocation.getArgument(2));
manager = new EksClusterManager(containerBuilder, lifecycleManager,
Mockito.mock(ContainerDetector.class), Mockito.mock(PortAllocator.class),
Mockito.mock(DockerHostResolver.class), Mockito.mock(EcrRegistryManager.class),
config, regionResolver);
}
@Test
void callerArgsAppearAlongsideFlociArgs() {
Cluster cluster = new Cluster();
cluster.setName("my-cluster");
cluster.setClusterArgs(List.of(
"--kubelet-arg=max-pods=250",
"--kube-apiserver-arg=feature-gates=CSIStorageCapacity=true"
));
manager.startCluster(cluster);
@SuppressWarnings("unchecked")
ArgumentCaptor<List<String>> cmdCaptor = ArgumentCaptor.forClass(List.class);
verify(builder).withCmd(cmdCaptor.capture());
List<String> cmd = cmdCaptor.getValue();
assertTrue(cmd.contains("server"));
assertTrue(cmd.contains("--kubelet-arg=max-pods=250"));
assertTrue(cmd.contains("--kube-apiserver-arg=feature-gates=CSIStorageCapacity=true"));
}
@Test
void twoClustersWithDifferentArgsGetTheirOwn() {
Cluster cluster1 = new Cluster();
cluster1.setName("cluster-one");
cluster1.setClusterArgs(List.of("--kubelet-arg=max-pods=250"));
Cluster cluster2 = new Cluster();
cluster2.setName("cluster-two");
cluster2.setClusterArgs(List.of("--kubelet-arg=max-pods=500"));
manager.startCluster(cluster1);
manager.startCluster(cluster2);
@SuppressWarnings("unchecked")
ArgumentCaptor<List<String>> cmdCaptor = ArgumentCaptor.forClass(List.class);
verify(builder, Mockito.times(2)).withCmd(cmdCaptor.capture());
List<List<String>> allCmds = cmdCaptor.getAllValues();
List<String> cmd1 = allCmds.get(0);
List<String> cmd2 = allCmds.get(1);
assertTrue(cmd1.contains("--kubelet-arg=max-pods=250"));
assertFalse(cmd1.contains("--kubelet-arg=max-pods=500"));
assertTrue(cmd2.contains("--kubelet-arg=max-pods=500"));
assertFalse(cmd2.contains("--kubelet-arg=max-pods=250"));
}
@Test
void clusterWithoutCustomArgsProducesExactExistingArguments() {
Cluster clusterWithNoArgs = new Cluster();
clusterWithNoArgs.setName("plain-cluster");
manager.startCluster(clusterWithNoArgs);
@SuppressWarnings("unchecked")
ArgumentCaptor<List<String>> cmdCaptor = ArgumentCaptor.forClass(List.class);
verify(builder).withCmd(cmdCaptor.capture());
List<String> cmd = cmdCaptor.getValue();
assertFalse(cmd.stream().anyMatch(a -> a.contains("max-pods")));
}
@Test
void collisionThrowsExpectedException() {
Cluster cluster = new Cluster();
cluster.setName("colliding-cluster");
cluster.setClusterArgs(List.of("--kubelet-arg=provider-id=custom-id"));
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
() -> manager.startCluster(cluster));
assertTrue(e.getMessage().contains("collides with Floci-managed kubelet argument"));
}
@Test
void malformedInputLogsWarningAndStartsCluster() {
Cluster cluster = new Cluster();
cluster.setName("malformed-cluster");
cluster.setTags(Map.of(
"floci:kubelet-arg:", "",
"floci:kubelet-arg:max-pods=250", "true"
));
assertDoesNotThrow(() -> manager.startCluster(cluster));
@SuppressWarnings("unchecked")
ArgumentCaptor<List<String>> cmdCaptor = ArgumentCaptor.forClass(List.class);
verify(builder).withCmd(cmdCaptor.capture());
List<String> cmd = cmdCaptor.getValue();
assertTrue(cmd.contains("--kubelet-arg=max-pods=250"));
}
}
}
@@ -2495,4 +2495,94 @@ class EksServiceTest {
new EksOidcService(storageFactory, new ObjectMapper()), mock(EksAccessEntryService.class),
mock(EksPodIdentityAssociationService.class));
}
@Test
void createClusterWithClusterArgsExtractsArgsAndStripsReservedTags() {
CreateClusterRequest req = createTestClusterRequest("args-cluster");
req.setTags(Map.of(
"floci:kubelet-arg:max-pods=250", "true",
"floci:kube-apiserver-arg:runtime-config=batch/v1=true", "true",
"env", "production"
));
Cluster created = eksService.createCluster(req);
assertNotNull(created.getClusterArgs());
assertEquals(2, created.getClusterArgs().size());
assertTrue(created.getClusterArgs().contains("--kubelet-arg=max-pods=250"));
assertTrue(created.getClusterArgs().contains("--kube-apiserver-arg=runtime-config=batch/v1=true"));
// Reserved tags must be stripped from public tags
assertNotNull(created.getTags());
assertEquals(Map.of("env", "production"), created.getTags());
assertFalse(created.getTags().containsKey("floci:kubelet-arg:max-pods=250"));
Cluster described = eksService.describeCluster("args-cluster");
assertEquals(Map.of("env", "production"), described.getTags());
assertEquals(created.getClusterArgs(), described.getClusterArgs());
}
@Test
void createClusterWithCollidingArgThrowsInvalidParameterException() {
CreateClusterRequest req = createTestClusterRequest("colliding-cluster");
req.setTags(Map.of("floci:kubelet-arg:provider-id", "my-id"));
AwsException ex = assertThrows(AwsException.class, () -> eksService.createCluster(req));
assertEquals("InvalidParameterException", ex.getErrorCode());
assertEquals(400, ex.getHttpStatus());
assertTrue(ex.getMessage().contains("collides with Floci-managed kubelet argument"));
}
@Test
void createClusterWithCollidingArgDoesNotLeakSecurityGroup() {
Ec2Service ec2 = realEc2Service();
ec2.ensureDefaultResources("us-east-1");
String vpcId = ec2.createVpc("us-east-1", "172.31.0.0/16", false).getVpcId();
String subnetId = ec2.createSubnet("us-east-1", vpcId, "172.31.1.0/24", "us-east-1a").getSubnetId();
EksService service = new EksService(storageFactory, testConfig(), regionResolver, null, ec2,
new EksOidcService(storageFactory, new ObjectMapper()), mock(EksAccessEntryService.class),
mock(EksPodIdentityAssociationService.class));
CreateClusterRequest req = createTestClusterRequest("colliding-sg-leak");
ResourcesVpcConfig vpcConfig = new ResourcesVpcConfig();
vpcConfig.setSubnetIds(List.of(subnetId));
req.setResourcesVpcConfig(vpcConfig);
req.setTags(Map.of("floci:kubelet-arg:provider-id", "my-id"));
AwsException ex = assertThrows(AwsException.class, () -> service.createCluster(req));
assertEquals("InvalidParameterException", ex.getErrorCode());
List<SecurityGroup> allSgs = ec2.describeSecurityGroups("us-east-1", List.of(), List.of(), Map.of());
boolean leaked = allSgs.stream().anyMatch(sg -> sg.getGroupName().startsWith("eks-cluster-sg-colliding-sg-leak-"));
assertFalse(leaked, "Cluster security group should not be created when argument validation fails");
}
@Test
void tagResourceWithReservedTagThrowsValidationException() {
createTestCluster("tag-resource-cluster");
Cluster cluster = eksService.describeCluster("tag-resource-cluster");
AwsException ex = assertThrows(AwsException.class, () ->
eksService.tagResource(cluster.getArn(), Map.of("floci:kubelet-arg:max-pods=250", "true")));
assertEquals("ValidationException", ex.getErrorCode());
assertEquals(400, ex.getHttpStatus());
}
@Test
void clusterArgsSurviveRestart(@TempDir Path directory) {
EksService before = persistentEksService(directory);
before.init();
CreateClusterRequest req = createTestClusterRequest("restart-args-cluster");
req.setTags(Map.of("floci:kubelet-arg:max-pods=250", "true", "owner", "ops"));
Cluster created = before.createCluster(req);
assertEquals(List.of("--kubelet-arg=max-pods=250"), created.getClusterArgs());
EksService after = persistentEksService(directory);
after.init();
Cluster described = after.describeCluster("restart-args-cluster");
assertEquals(List.of("--kubelet-arg=max-pods=250"), described.getClusterArgs());
assertEquals(Map.of("owner", "ops"), described.getTags());
}
}