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

The generated request resources give EMR's session type the
aws:ResourceTag/ and elasticmapreduce:ResourceTag/ keys, but
EmrService.storedTags answered clusters, Studios and notebook executions
and nothing for a session's ARN, so a condition on a session's tags saw
none. It now reads the session stored under the id the ARN ends in, in
the account the ARN names, in place, matched on the whole ARN, giving
the tags it started with.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-18 12:21:41 -04:00
1 parent 0842636ed9
commit 5548bb78eb
6 files changed
+97 -11

No files matched your search

@@ -23,8 +23,8 @@ import java.util.Optional;
* connections and API destinations; Application Auto Scaling, for its scalable targets and their tags; Redshift
* Data, for the Redshift Serverless workgroups it runs statements on and the targets of its sessions; Payment
* Cryptography, for the key an alias names and the tags of a key; EMR, for the clusters of its instance groups and a
* tag call's resource and the tags of a cluster; IAM Identity Center, for the accounts its permission sets are
* provisioned to and the tags of an instance,
* tag call's resource and the tags of a cluster or a session; IAM Identity Center, for the accounts its permission
* sets are provisioned to and the tags of an instance,
* a permission set, an application or a trusted token issuer; Resource Explorer, for its default view and the tags
* of an index or a view; OAM and RAM, for the sinks, invitations and shares of other accounts they act on, OAM for
* the tags of a sink or a link, and RAM for the tags of a resource share;
@@ -135,6 +135,8 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
private static final String SERVICE = "emr";
// The resource of a cluster's ARN, before its id.
static final String CLUSTER_RESOURCE = "cluster/";
/** What follows a cluster's ARN in the ARN of one of its sessions, the session's id following. */
static final String SESSION_SEGMENT = "/session/";
// The reason of a cluster a failed bootstrap action ended, as Terraform reported a real one's
// (hashicorp/terraform-provider-aws#4378) and the Management Guide's VPC errors page quotes it.
private static final String BOOTSTRAP_ACTION_FAILED =
@@ -777,7 +779,7 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
long sequence = sessions.stream().mapToLong(EmrSession::getSequence).max().orElse(0) + 1;
EmrSession session = EmrSessions.start(cluster, request, id,
regionResolver.buildArn("elasticmapreduce", regionOf(cluster),
"cluster/" + cluster.getId() + "/session/" + id),
CLUSTER_RESOURCE + cluster.getId() + SESSION_SEGMENT + id),
regionResolver.getAccountId(), now(), sequence, parameters);
session.setContainerSession(runsSessionServers());
sessionStore.put(id, session);
@@ -1833,10 +1835,10 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
}
/**
* The tags held on the cluster, Studio or notebook execution stored under {@code arn}, in the account it names,
* read in place: the cluster of that id in the ARN's Region, or one recorded with no Region, as the tag handlers
* find it, or the Studio or execution of that id in the ARN's Region; empty for an ARN naming nothing stored or
* naming anything else.
* The tags held on the cluster, session, Studio or notebook execution stored under {@code arn}, in the account it
* names, read in place: the cluster of that id in the ARN's Region, or one recorded with no Region, as the tag
* handlers find it, the session of that id recording that ARN, the tags it started with, or the Studio or execution
* of that id in the ARN's Region; empty for an ARN naming nothing stored or naming anything else.
*/
@Override
public Map<String, String> storedTags(String arn) {
@@ -1851,6 +1853,14 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
if (resource.startsWith(EmrNotebookExecutionService.EXECUTION_RESOURCE)) {
return notebookExecutions != null ? notebookExecutions.get().storedTags(arn) : Map.of();
}
int session = resource.startsWith(CLUSTER_RESOURCE) ? resource.indexOf(SESSION_SEGMENT) : -1;
if (session > 0) {
return AccountAwareStorageBackend.readInAccount(sessionStore, parsed.accountId(),
resource.substring(session + SESSION_SEGMENT.length()))
.filter(stored -> arn.equals(stored.getArn()))
.map(stored -> heldTags(stored.getTags()))
.orElse(Map.of());
}
String clusterId = resourceIdOf(parsed, CLUSTER_RESOURCE);
if (clusterId == null || !arn.equals(AwsArnUtils.Arn.of("elasticmapreduce", parsed.region(),
parsed.accountId(), resource).toString())) {