mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(eks): preserve worker webhook scope in the URL path (#3849)
* fix(eks): preserve worker webhook scope in the URL path * docs(eks): clarify scoped and legacy webhook routes
This commit is contained in:
1 parent
bd9700db0d
commit
fdec637c27
5 files changed
+44
-5
No files matched your search
@@ -46,7 +46,9 @@ running EC2 instance, and attached instance profile. Missing/deleted entries, re
|
||||
revoked 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 webhook
|
||||
rejects instance credentials. Obtain fresh IMDS credentials after upgrading so the session
|
||||
includes the stable role ID.
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@POST
|
||||
public Response review(@PathParam("clusterName") String clusterName, @QueryParam("accountId") String accountId,
|
||||
@QueryParam("region") String region, @QueryParam("createdAt") String createdAt,
|
||||
|
||||
+21
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user