Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(eks): accept IAM authentication tokens for the authenticator's token lifetime (#4186)

Simone Primarosa7eafd2f7067e
diff --git a/docs/services/eks.md b/docs/services/eks.md
index 3c0a25479a..06165990c1 100644
--- a/docs/services/eks.md
+++ b/docs/services/eks.md
@@ -315,7 +315,7 @@ aws eks update-kubeconfig --name my-cluster
kubectl get nodes
```
-`aws eks update-kubeconfig` wires `aws eks get-token` into the kubeconfig as an exec credential. The bearer token contains a SigV4-presigned STS `GetCallerIdentity` request. Floci validates its signature and 60-second presign expiry, then verifies the signed `x-k8s-aws-id` header against the cluster-specific `/_floci/eks/clusters/<cluster-name>/token-webhook` endpoint before resolving the caller identity. Instance-profile sessions require an EC2_LINUX access entry as described above; non-worker callers retain the `system:masters` mapping (bound to `cluster-admin`). No `aws-iam-authenticator` is required.
+`aws eks update-kubeconfig` wires `aws eks get-token` into the kubeconfig as an exec credential. The bearer token contains a SigV4-presigned STS `GetCallerIdentity` request. Floci validates its signature and 15-minute token lifetime matching `aws-iam-authenticator` rather than the presigned expiry, then verifies the signed `x-k8s-aws-id` header against the cluster-specific `/_floci/eks/clusters/<cluster-name>/token-webhook` endpoint before resolving the caller identity. Instance-profile sessions require an EC2_LINUX access entry as described above; non-worker callers retain the `system:masters` mapping (bound to `cluster-admin`). No `aws-iam-authenticator` is required.
Create an IAM access key before using EKS authentication. The public local-development pairs `test`/`test` and `floci`/`floci` are deliberately rejected because the webhook grants cluster-admin access.
diff --git a/src/main/java/io/github/hectorvent/floci/services/eks/EksTokenValidator.java b/src/main/java/io/github/hectorvent/floci/services/eks/EksTokenValidator.java
index 3bc2f47fc5..b9346412dd 100644
--- a/src/main/java/io/github/hectorvent/floci/services/eks/EksTokenValidator.java
+++ b/src/main/java/io/github/hectorvent/floci/services/eks/EksTokenValidator.java
@@ -35,7 +35,8 @@ class EksTokenValidator {
private static final String EMPTY_PAYLOAD_SHA256 =
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
private static final String REQUIRED_SIGNED_HEADERS = "host;x-k8s-aws-id";
- private static final int MAX_PRESIGN_EXPIRY_SECONDS = 60;
+ private static final Duration TOKEN_LIFETIME = Duration.ofMinutes(15);
+ private static final int MAX_PRESIGN_EXPIRY_SECONDS = (int) TOKEN_LIFETIME.toSeconds();
private static final int MAX_TOKEN_LENGTH = 4096;
private static final Duration MAX_FUTURE_SKEW = Duration.ofMinutes(5);
private static final DateTimeFormatter DATETIME_FORMAT =
@@ -155,11 +156,11 @@ class EksTokenValidator {
private boolean isCurrent(Instant signedAt, String expiryText) {
int expirySeconds = Integer.parseInt(expiryText);
- if (expirySeconds <= 0 || expirySeconds > MAX_PRESIGN_EXPIRY_SECONDS) {
+ if (expirySeconds < 0 || expirySeconds > MAX_PRESIGN_EXPIRY_SECONDS) {
return false;
}
Instant now = clock.instant();
- return !signedAt.isAfter(now.plus(MAX_FUTURE_SKEW)) && !now.isAfter(signedAt.plusSeconds(expirySeconds));
+ return !signedAt.isAfter(now.plus(MAX_FUTURE_SKEW)) && !now.isAfter(signedAt.plus(TOKEN_LIFETIME));
}
private String secretKey(String accessKeyId, String sessionToken) {
diff --git a/src/test/java/io/github/hectorvent/floci/services/eks/EksTokenValidatorTest.java b/src/test/java/io/github/hectorvent/floci/services/eks/EksTokenValidatorTest.java
index 6cf3ee2ba2..da17ef1c84 100644
--- a/src/test/java/io/github/hectorvent/floci/services/eks/EksTokenValidatorTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/eks/EksTokenValidatorTest.java
@@ -57,18 +57,64 @@ class EksTokenValidatorTest {
assertFalse(validator.validate(token, CLUSTER_NAME));
}
+ @Test
+ void validateAcceptsPresignedTokenAfterSixtySecondsWithinTokenLifetime() throws Exception {
+ Instant signedAt = Instant.parse("2026-09-01T22:00:00Z");
+ Instant evaluationTime = signedAt.plusSeconds(600);
+ EksTokenValidator validator = validator(Clock.fixed(evaluationTime, ZoneOffset.UTC));
+ String token = token(CLUSTER_NAME, signedAt, 60);
+
+ assertTrue(validator.validate(token, CLUSTER_NAME));
+ }
+
+ @Test
+ void validateAcceptsPresignedTokenAtTokenLifetimeBoundary() throws Exception {
+ Instant signedAt = Instant.parse("2026-09-01T22:00:00Z");
+ Instant evaluationTime = signedAt.plusSeconds(900);
+ EksTokenValidator validator = validator(Clock.fixed(evaluationTime, ZoneOffset.UTC));
+ String token = token(CLUSTER_NAME, signedAt, 60);
+
+ assertTrue(validator.validate(token, CLUSTER_NAME));
+ }
+
@Test
void validateRejectsExpiredToken() throws Exception {
+ Instant signedAt = Instant.parse("2026-09-01T22:00:00Z");
+ Instant evaluationTime = signedAt.plusSeconds(901);
+ EksTokenValidator validator = validator(Clock.fixed(evaluationTime, ZoneOffset.UTC));
+ String token = token(CLUSTER_NAME, signedAt, 60);
+
+ assertFalse(validator.validate(token, CLUSTER_NAME));
+ }
+
+ @Test
+ void validateAcceptsTokenWithLongerExpiryWithinAuthenticatorBound() throws Exception {
+ EksTokenValidator validator = validator();
+ String token = token(CLUSTER_NAME, Instant.now(), 900);
+
+ assertTrue(validator.validate(token, CLUSTER_NAME));
+ }
+
+ @Test
+ void validateAcceptsTokenWithZeroExpiryParameter() throws Exception {
+ EksTokenValidator validator = validator();
+ String token = token(CLUSTER_NAME, Instant.now(), 0);
+
+ assertTrue(validator.validate(token, CLUSTER_NAME));
+ }
+
+ @Test
+ void validateRejectsTokenWithExpiryExceedingAuthenticatorBound() throws Exception {
EksTokenValidator validator = validator();
- String token = token(CLUSTER_NAME, Instant.now().minusSeconds(61), 60);
+ String token = token(CLUSTER_NAME, Instant.now(), 901);
assertFalse(validator.validate(token, CLUSTER_NAME));
}
@Test
- void validateRejectsTokenWithAStretchedExpiry() throws Exception {
+ void validateRejectsTokenWithNegativeExpiry() throws Exception {
EksTokenValidator validator = validator();
- String token = token(CLUSTER_NAME, Instant.now(), 61);
+ String token = token(CLUSTER_NAME, Instant.now(), -1);
assertFalse(validator.validate(token, CLUSTER_NAME));
}