Light, fluffy, and always free - The AWS Local Emulator alternative
fix(eks): preserve worker webhook scope in the URL path (#3849)
luisetercfdec637c27c5
diff --git a/docs/services/eks.md b/docs/services/eks.mdindex 4d42f65bf8..fc9de75cb4 100644--- a/docs/services/eks.md+++ b/docs/services/eks.md@@ -46,7 +46,9 @@ running EC2 instance, and attached instance profile. Missing/deleted entries, rerevoked sessions and terminated instances are rejected without falling back to administrator access.The existing k3s webhook cache can retain a successful authentication for up to 30 seconds.-New cluster webhook configurations carry the target account, region and creation timestamp.+New cluster webhook configurations carry the target account, region and creation timestamp in the URL path.+Kubernetes client-go replaces server URL query parameters when sending TokenReview requests, so+worker scope must not depend on those parameters.Recreate older local clusters before using worker authentication; a legacy unscoped webhookrejects instance credentials. Obtain fresh IMDS credentials after upgrading so the sessionincludes the stable role ID.diff --git a/src/main/java/io/github/hectorvent/floci/services/eks/EksClusterManager.java b/src/main/java/io/github/hectorvent/floci/services/eks/EksClusterManager.javaindex 153a3a5d9f..7a2ba7bd14 100644--- a/src/main/java/io/github/hectorvent/floci/services/eks/EksClusterManager.java+++ b/src/main/java/io/github/hectorvent/floci/services/eks/EksClusterManager.java@@ -700,8 +700,9 @@ public class EksClusterManager {}static String webhookPath(Cluster cluster) {- return webhookPath(cluster.getName()) + "?accountId=" + cluster.getAccountId()- + "®ion=" + cluster.getArn().split(":", 6)[3] + "&createdAt=" + cluster.getCreatedAt();+ // client-go replaces a server URL query when constructing its TokenReview request.+ return webhookPath(cluster.getName()) + "/scope/" + cluster.getAccountId()+ + "/" + cluster.getArn().split(":", 6)[3] + "/" + cluster.getCreatedAt();}static String webhookPath(String clusterName) {diff --git a/src/main/java/io/github/hectorvent/floci/services/eks/EksTokenWebhookController.java b/src/main/java/io/github/hectorvent/floci/services/eks/EksTokenWebhookController.javaindex 2d6ead6026..00f2f991e7 100644--- a/src/main/java/io/github/hectorvent/floci/services/eks/EksTokenWebhookController.java+++ b/src/main/java/io/github/hectorvent/floci/services/eks/EksTokenWebhookController.java@@ -24,6 +24,11 @@ import java.util.Optional;* the request signature, expiration, and signed cluster ID before resolving worker access entries.* Non-worker credentials retain the legacy cluster-admin compatibility behavior.*+ * <p>New clusters use {@code token-webhook/scope/{accountId}/{region}/{createdAt}}, keeping+ * scope in the path because Kubernetes client-go replaces URL query parameters. The base+ * {@code token-webhook} route retains query-parameter scope for legacy compatibility;+ * unscoped requests cannot authenticate workers.+ ** <p>This is Floci plumbing under the {@code _floci/...} namespace, not an AWS API.*/@ApplicationScoped@@ -42,6 +47,16 @@ public class EksTokenWebhookController {this.authentication = authentication;}+ @POST+ @Path("scope/{accountId}/{region}/{createdAt}")+ public Response reviewScoped(@PathParam("clusterName") String clusterName,+ @PathParam("accountId") String accountId,+ @PathParam("region") String region,+ @PathParam("createdAt") String createdAt,+ Map<String, Object> tokenReview) {+ return review(clusterName, accountId, region, createdAt, tokenReview);+ }+@POSTpublic Response review(@PathParam("clusterName") String clusterName, @QueryParam("accountId") String accountId,@QueryParam("region") String region, @QueryParam("createdAt") String createdAt,diff --git a/src/test/java/io/github/hectorvent/floci/services/ec2/EksWorkerAuthenticationIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/ec2/EksWorkerAuthenticationIntegrationTest.javaindex f74410ef65..a5eaed306e 100644--- a/src/test/java/io/github/hectorvent/floci/services/ec2/EksWorkerAuthenticationIntegrationTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/ec2/EksWorkerAuthenticationIntegrationTest.java@@ -74,7 +74,28 @@ class EksWorkerAuthenticationIntegrationTest {given().queryParam("accountId", "999999999999").queryParam("region", "us-east-1").queryParam("createdAt", incarnation).contentType("application/json").body(review).post(path).then().statusCode(200).body("status.authenticated", equalTo(false));+ String scopedPath = path + "/scope/" + account + "/us-east-1/" + incarnation;+ // No scope query parameters: client-go replaces the webhook server URL query.+ given().contentType("application/json").body(review).post(scopedPath).then().statusCode(200)+ .body("status.authenticated", equalTo(true))+ .body("status.user.username", equalTo("system:node:" + instance.getPrivateDnsName()))+ .body("status.user.groups", contains("system:bootstrappers", "system:nodes"));+ // Query values cannot override the scoped route's cluster identity.+ given().queryParam("accountId", "999999999999").queryParam("region", "us-west-2")+ .queryParam("createdAt", "2000-01-01T00:00:00Z")+ .contentType("application/json").body(review).post(scopedPath).then().statusCode(200)+ .body("status.authenticated", equalTo(true));+ for (String invalidPath : new String[]{+ path,+ path + "/scope/999999999999/us-east-1/" + incarnation,+ path + "/scope/" + account + "/us-west-2/" + incarnation,+ path + "/scope/" + account + "/us-east-1/2000-01-01T00:00:00Z"}) {+ given().contentType("application/json").body(review).post(invalidPath).then().statusCode(200)+ .body("status.authenticated", equalTo(false));+ }credentials.unregister(instance);+ given().contentType("application/json").body(review).post(scopedPath).then().statusCode(200)+ .body("status.authenticated", equalTo(false));given().queryParam("accountId", account).queryParam("region", "us-east-1").queryParam("createdAt", incarnation).contentType("application/json").body(review).post(path).then().statusCode(200).body("status.authenticated", equalTo(false));diff --git a/src/test/java/io/github/hectorvent/floci/services/eks/EksClusterManagerTest.java b/src/test/java/io/github/hectorvent/floci/services/eks/EksClusterManagerTest.javaindex 34fc86efe0..7916feb4db 100644--- a/src/test/java/io/github/hectorvent/floci/services/eks/EksClusterManagerTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/eks/EksClusterManagerTest.java@@ -67,8 +67,8 @@ class EksClusterManagerTest {cluster.setAccountId("123456789012");cluster.setArn("arn:aws:eks:us-west-2:123456789012:cluster/demo");cluster.setCreatedAt(Instant.parse("2026-09-17T00:00:00Z"));- assertEquals("/_floci/eks/clusters/demo/token-webhook?accountId=123456789012"- + "®ion=us-west-2&createdAt=2026-09-17T00:00:00Z", EksClusterManager.webhookPath(cluster));+ assertEquals("/_floci/eks/clusters/demo/token-webhook/scope/123456789012"+ + "/us-west-2/2026-09-17T00:00:00Z", EksClusterManager.webhookPath(cluster));}@Test