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

This commit is contained in:
Simone Primarosa authored and GitHub committed 2026-09-22 16:26:26 -04:00
1 parent b7a66d4aaf
commit 7eafd2f706
3 files changed
+55 -8

No files matched your search

+1 -1
View File
@@ -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.
@@ -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) {
@@ -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 {
EksTokenValidator validator = validator();
String token = token(CLUSTER_NAME, Instant.now().minusSeconds(61), 60);
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 validateRejectsTokenWithAStretchedExpiry() throws Exception {
void validateAcceptsTokenWithLongerExpiryWithinAuthenticatorBound() throws Exception {
EksTokenValidator validator = validator();
String token = token(CLUSTER_NAME, Instant.now(), 61);
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(), 901);
assertFalse(validator.validate(token, CLUSTER_NAME));
}
@Test
void validateRejectsTokenWithNegativeExpiry() throws Exception {
EksTokenValidator validator = validator();
String token = token(CLUSTER_NAME, Instant.now(), -1);
assertFalse(validator.validate(token, CLUSTER_NAME));
}