fix(emr): give resource-tag conditions the tags of the cluster a request names (#8698)

The generated request resources give EMR's cluster type the
aws:ResourceTag/ and elasticmapreduce:ResourceTag/ keys, but EmrService
answered no tags, so a condition on a cluster's tags saw none.
EmrService.storedTags now reads the cluster stored under the ARN's id
in the account it names, in place, in the ARN's Region or recorded with
none, as the tag handlers find it, the ARN matched whole. AddTags and
RemoveTags now put a new map in place of the held one under the
service's lock instead of editing it in place, and the field is
volatile.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-16 22:42:22 -04:00
1 parent 1d581eb131
commit 3313a5a9f0
6 files changed
+103 -9

No files matched your search

@@ -73,6 +73,36 @@ class EmrServiceTest {
assertEquals(List.of(cluster.getClusterArn()), service.through("ResourceId", cluster.getId(), "eu-west-1"));
}
/**
* A resource-tag condition reads the tags of the cluster the ARN names, in its account and Region, or of one stored
* with no Region, as the tag handlers find it; tagging puts a new map in place of the held one.
*/
@Test
void storedTagsAreTheTagsOfTheClusterTheArnNamesAndTaggingPutsANewMap() {
EmrServiceFixture fixture = new EmrServiceFixture(0, 0, 0);
EmrService service = fixture.service;
EmrCluster cluster = service.runJobFlow(cluster("tagged", true), REGION);
String arn = cluster.getClusterArn();
String elsewhere = arn.replace(":" + REGION + ":", ":eu-west-1:");
service.addTags(cluster.getId(), Map.of("team", "data"));
AccountAwareStorageBackend<EmrCluster> clusters = fixture.storage.create("emr", "emr-clusters.json",
new TypeReference<Map<String, EmrCluster>>() {});
Map<String, String> held = clusters.get(cluster.getId()).orElseThrow().getTags();
service.addTags(cluster.getId(), Map.of("env", "prod"));
assertEquals(Map.of("team", "data"), held);
assertEquals(Map.of("team", "data", "env", "prod"), service.storedTags(arn));
assertEquals(Map.of(), service.storedTags(elsewhere));
assertEquals(Map.of(), service.storedTags(arn + "/session/s-1"));
assertEquals(Map.of(), service.storedTags(arn.replace("arn:aws:", "arn:aws-cn:")));
EmrCluster regionless = clusters.get(cluster.getId()).orElseThrow();
regionless.setRegion(null);
clusters.put(cluster.getId(), regionless);
assertEquals(Map.of("team", "data", "env", "prod"), service.storedTags(elsewhere));
}
@Test
void aClusterIsStartingThenBootstrappingUntilItIsReady() {
EmrServiceFixture fixture = new EmrServiceFixture(10, 0, 0);
@@ -1732,6 +1732,31 @@ class IamRequestResourceEnforcementIntegrationTest {
"elasticmapreduce:AddTags");
}
/**
* An {@code aws:ResourceTag} condition reads the tags EMR holds on the cluster a request names, so an allow on one
* team's tag lets the caller describe that team's cluster and not another's.
*/
@Test
void anEmrResourceTagConditionReadsTheTagsOfTheCluster() {
String tagged = emrClusterId(emrCluster("res-emr-tag"), "data");
String other = emrClusterId(emrCluster("res-emr-tag"), "web");
User user = user("res-emr-tags");
user.policy("{\"Effect\":\"Allow\",\"Action\":\"elasticmapreduce:DescribeCluster\",\"Resource\":\"*\","
+ "\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
emr(user, "DescribeCluster", "{\"ClusterId\":\"" + tagged + "\"}").statusCode(200);
refusedJson(emr(user, "DescribeCluster", "{\"ClusterId\":\"" + other + "\"}"),
"elasticmapreduce:DescribeCluster");
}
/** The id of the cluster {@code arn} names, tagged with the team by an administrator. */
private static String emrClusterId(String arn, String team) {
String id = arn.substring(arn.lastIndexOf('/') + 1);
adminJson("elasticmapreduce", "ElasticMapReduce.AddTags").body("{\"ResourceId\":\"" + id
+ "\",\"Tags\":[{\"Key\":\"team\",\"Value\":\"" + team + "\"}]}").post("/").then().statusCode(200);
return id;
}
/**
* A Rekognition stream processor is checked on the ARN its {@code Name} gives, and a moderation analysis on the
* custom model whose ARN its {@code ProjectVersion} gives. Floci serves no stream processor and no custom model,