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

The generated request resources give EMR on EKS's virtualCluster,
jobRun, managedEndpoint, jobTemplate and securityConfiguration types the
aws:ResourceTag/ key, but no service answered the emr-containers
namespace's stored tags, so a condition on their tags saw none.
EmrContainersService now answers it: storedTags reads the resource
stored under its ARN in the store its kind names, in the request's
account, where the handlers read, in place, and matches the ARN it
records. Every write already stores a new copy, so no lock change.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-18 10:49:52 -04:00
1 parent 81c5ecf777
commit 7b750b8455
5 files changed
+134 -6

No files matched your search

@@ -52,9 +52,10 @@ import java.util.Optional;
* the tags of a budget or a budget action; AWS FIS, for the tags of an experiment template, an experiment or an action;
* CodePipeline, for the tags of a pipeline, a webhook or a custom action type; DataSync, for the tags of an agent, a
* location or a task; Global Accelerator, for the tags of an accelerator, a listener or an endpoint group; EMR
* Serverless, for the tags of an application, a job run or a session); looked up lazily by {@code ResourceArnBuilder}
* and {@code IamConditionContextResolver} through {@code Instance<StoredResourceArns>} for the namespace a request or
* an ARN is of, so IAM never depends on that service directly.</p>
* Serverless, for the tags of an application, a job run or a session; EMR on EKS, for the tags of a virtual cluster, a
* job run, a managed endpoint, a job template or a security configuration); looked up lazily by
* {@code ResourceArnBuilder} and {@code IamConditionContextResolver} through {@code Instance<StoredResourceArns>} for
* the namespace a request or an ARN is of, so IAM never depends on that service directly.</p>
*
* <p>Each answer is a lookup of what the service holds, asked for by an entry of the generated table ({@code find},
* {@code through}, a default, {@code forwarded}, a type's {@code resourceTagKeys}): never a fact about what an operation acts on, which the table alone
@@ -16,6 +16,7 @@ import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.common.RequestContext;
import io.floci.aws.core.common.Resettable;
import io.floci.aws.core.common.SmithyValidationErrors;
import io.floci.aws.core.common.StoredResourceArns;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.eks.EksService;
@@ -54,7 +55,7 @@ import java.util.regex.Pattern;
* starts with {@code _} are Floci's own and never leave the service.
*/
@ApplicationScoped
public class EmrContainersService implements Resettable {
public class EmrContainersService implements Resettable, StoredResourceArns {
static final String SERVICE = "emr-containers";
static final String VIRTUAL_CLUSTERS = "/virtualclusters/";
@@ -592,6 +593,55 @@ public class EmrContainersService implements Resettable {
target.storage().put(resourceArn, updated);
}
@Override
public String namespace() {
return "emr-containers";
}
/** A request names each resource by the id its ARN ends in: nothing to find. */
@Override
public Optional<String> find(String type, List<String> names, String region) {
return Optional.empty();
}
/**
* The tags of the virtual cluster, job run, managed endpoint, job template or security configuration whose ARN is
* {@code arn}, in the request's account, where the handlers read: an ARN of another account names none. Each is
* stored under its ARN, so it is read in place under the ARN itself, a resource stored before storage was
* account-aware included, and matched on the ARN it records. Every write stores a new copy of the resource, so
* the read is of one whole set.
*/
@Override
public Map<String, String> storedTags(String arn) {
if (!AwsArnUtils.isArnFor(arn, "emr-containers")) {
return Map.of();
}
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
AccountAwareStorageBackend<ObjectNode> store = storeOf(parsed.resource());
if (store == null || !parsed.accountId().equals(regionResolver.getAccountId())) {
return Map.of();
}
return AccountAwareStorageBackend.readInAccount(store, parsed.accountId(), arn)
.filter(resource -> arn.equals(resource.path("arn").textValue()))
.map(EmrContainersService::tagMap)
.orElse(Map.of());
}
/** The store holding the kind of resource an ARN's resource part names, or null for none of them. */
private AccountAwareStorageBackend<ObjectNode> storeOf(String resource) {
Matcher nested = NESTED_ARN.matcher(resource);
if (nested.matches()) {
return "jobruns".equals(nested.group(2)) ? jobRuns : endpoints;
}
if (VIRTUAL_CLUSTER_ARN.matcher(resource).matches()) {
return virtualClusters;
}
if (resource.startsWith(JOB_TEMPLATES)) {
return jobTemplates;
}
return resource.startsWith(SECURITY_CONFIGURATIONS) ? securityConfigurations : null;
}
@Override
public synchronized void clear() {
virtualClusters.clear();