fix(emr): keep cluster operations in the cluster's region (#5097)

* fix(emr): keep cluster operations in the cluster's region

EMR looked a cluster up by id alone, so DescribeCluster, AddJobFlowSteps,
the instance group and fleet operations, policies, tags, TerminateJobFlows
and the cluster-wide setters acted on a cluster created in another region;
only ListClusters filtered by region. Every lookup now goes through one
region-aware findCluster: a cluster from another region reads as an unknown
id (InvalidRequestException), and terminate and the setters skip it, as they
skip an unknown id. A cluster recorded without a region stays reachable.

* test(emr): check a cluster-wide setter from another region leaves the cluster unchanged
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-10-05 00:36:51 -04:00
1 parent e22e24a810
commit 0e89ab962a
2 files changed
+87 -5

No files matched your search

@@ -0,0 +1,73 @@
package io.github.hectorvent.floci.services.emr;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.not;
/**
* Clusters are regional: a request signed for another region sees none of a cluster's operations
* work on it, as for an unknown id, and cannot terminate it.
*/
@QuarkusTest
class EmrClusterRegionIntegrationTest {
private static final String CT = "application/x-amz-json-1.1";
private static final String PREFIX = "ElasticMapReduce.";
private static final String HOME = "eu-west-1";
private static final String OTHER = "us-west-2";
@BeforeAll
static void configure() {
RestAssuredJsonUtils.configureAwsContentTypes();
}
private static Response call(String region, String action, String body) {
return given().contentType(CT)
.header("Authorization", "AWS4-HMAC-SHA256 Credential=AKID/20260215/" + region
+ "/elasticmapreduce/aws4_request, SignedHeaders=host, Signature=abc")
.header("X-Amz-Target", PREFIX + action)
.body(body).when().post("/");
}
@Test
void clusterOperationsStayInTheClustersRegion() {
String clusterId = call(HOME, "RunJobFlow",
"{\"Name\":\"region-emr\",\"ReleaseLabel\":\"emr-7.5.0\","
+ "\"Instances\":{\"KeepJobFlowAliveWhenNoSteps\":true,"
+ "\"InstanceGroups\":[{\"Name\":\"master\",\"InstanceRole\":\"MASTER\","
+ "\"InstanceType\":\"m5.xlarge\",\"InstanceCount\":1}]}}")
.then().statusCode(200)
.extract().path("JobFlowId");
String byId = "{\"ClusterId\":\"" + clusterId + "\"}";
call(OTHER, "DescribeCluster", byId)
.then().statusCode(400)
.body("__type", equalTo("InvalidRequestException"));
call(OTHER, "AddJobFlowSteps", "{\"JobFlowId\":\"" + clusterId + "\",\"Steps\":[{\"Name\":\"s\","
+ "\"HadoopJarStep\":{\"Jar\":\"command-runner.jar\",\"Args\":[\"echo\"]}}]}")
.then().statusCode(400)
.body("__type", equalTo("InvalidRequestException"));
call(OTHER, "ListClusters", "{}")
.then().statusCode(200)
.body("Clusters.Id", not(hasItem(clusterId)));
call(OTHER, "SetTerminationProtection",
"{\"JobFlowIds\":[\"" + clusterId + "\"],\"TerminationProtected\":true}")
.then().statusCode(200);
call(OTHER, "TerminateJobFlows", "{\"JobFlowIds\":[\"" + clusterId + "\"]}")
.then().statusCode(200);
call(HOME, "DescribeCluster", byId)
.then().statusCode(200)
.body("Cluster.Status.State", equalTo("WAITING"))
.body("Cluster.TerminationProtected", equalTo(false));
call(HOME, "TerminateJobFlows", "{\"JobFlowIds\":[\"" + clusterId + "\"]}")
.then().statusCode(200);
}
}