diff --git a/docs/services/iam.md b/docs/services/iam.md
index becced166c..df5e28815f 100644
--- a/docs/services/iam.md
+++ b/docs/services/iam.md
@@ -3201,8 +3201,8 @@ floci populates:
snapshot schedules, event subscriptions and integrations, SSM for its parameters, documents and associations,
EMR for its clusters, CloudFront for every resource it tags, by its ARN, IAM Identity Center for its instances,
permission sets, applications and trusted token issuers, OAM for its sinks and links, RAM for its resource shares,
- Payment Cryptography for its keys, and Resource Explorer for its indexes and views. Tag keys differing only in
- case are one condition key holding every value.
+ Payment Cryptography for its keys, Resource Explorer for its indexes and views, and Application Auto Scaling for
+ its scalable targets. Tag keys differing only in case are one condition key holding every value.
- EC2 resource keys such as a network interface's `ec2:Vpc`, `ec2:Subnet`, `ec2:AvailabilityZone` and
`ec2:NetworkInterfaceID`: for every action on a resource EC2 holds, the members of the resource the
key names, an ARN for a key the Service Reference types as one. `resourceKeys` in
diff --git a/src/main/java/io/floci/aws/core/common/StoredResourceArns.java b/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
index 92ab38ae78..1ebad35bac 100644
--- a/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
+++ b/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
@@ -20,11 +20,11 @@ import java.util.Optional;
* points at.
*
*
Implemented by the service that owns such resources or whose requests name them (EventBridge, for its
- * connections and API destinations; Application Auto Scaling, for its scalable targets; 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,
+ * 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,
* 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;
diff --git a/src/main/java/io/floci/aws/services/applicationautoscaling/ApplicationAutoScalingService.java b/src/main/java/io/floci/aws/services/applicationautoscaling/ApplicationAutoScalingService.java
index 937fc8291e..9189d4883e 100644
--- a/src/main/java/io/floci/aws/services/applicationautoscaling/ApplicationAutoScalingService.java
+++ b/src/main/java/io/floci/aws/services/applicationautoscaling/ApplicationAutoScalingService.java
@@ -1,6 +1,7 @@
package io.floci.aws.services.applicationautoscaling;
import com.fasterxml.jackson.core.type.TypeReference;
+import io.floci.aws.core.common.AwsArnUtils;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.PaginatedResult;
import io.floci.aws.core.common.Pagination;
@@ -38,6 +39,7 @@ import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -1004,6 +1006,42 @@ public class ApplicationAutoScalingService implements StoredResourceArns {
return findTarget(region, names.get(0), names.get(1), names.get(2)).map(ScalableTarget::getScalableTargetArn);
}
+ /**
+ * The tags held on the scalable target whose ARN is {@code arn}, read in place where its handlers find it: among
+ * the targets of the account and Region the ARN names, a pre-multi-account one of the default account included,
+ * matched on the whole ARN. Tagging stores a copy of the target, so the read is of one whole set. Empty for an ARN
+ * naming no target.
+ */
+ @Override
+ public Map storedTags(String arn) {
+ if (!AwsArnUtils.isArnFor(arn, "application-autoscaling")) {
+ return Map.of();
+ }
+ AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
+ String account = parsed.accountId();
+ if (account.isEmpty()) {
+ return Map.of();
+ }
+ String prefix = parsed.region() + "::";
+ List held;
+ if (targets instanceof AccountAwareStorageBackend aware) {
+ String scoped = AccountAwareStorageBackend.rawKey(account, prefix);
+ boolean legacyToo = account.equals(aware.defaultAccountId());
+ held = aware.scanRaw(key -> key.startsWith(scoped)
+ || (legacyToo && !AccountAwareStorageBackend.hasAccountPrefix(key) && key.startsWith(prefix)));
+ } else {
+ held = targets.scan(key -> key.startsWith(prefix));
+ }
+ Map tags = new LinkedHashMap<>();
+ held.stream().filter(target -> arn.equals(target.getScalableTargetArn())).findFirst()
+ .ifPresent(target -> target.getTags().forEach((key, value) -> {
+ if (key != null && value != null) {
+ tags.put(key, value);
+ }
+ }));
+ return tags;
+ }
+
/**
* Looked up by {@link ScalingPolicyAlarmActionHandler} when an alarm's AlarmActions references
* a scaling-policy ARN, and by the CloudFormation provisioner, whose physical id for a policy
diff --git a/src/main/java/io/floci/aws/services/applicationautoscaling/model/ScalableTarget.java b/src/main/java/io/floci/aws/services/applicationautoscaling/model/ScalableTarget.java
index d39bf0b4e7..4303942e13 100644
--- a/src/main/java/io/floci/aws/services/applicationautoscaling/model/ScalableTarget.java
+++ b/src/main/java/io/floci/aws/services/applicationautoscaling/model/ScalableTarget.java
@@ -29,7 +29,7 @@ public class ScalableTarget {
private String scalableTargetArn;
private double creationTime;
private SuspendedState suspendedState = new SuspendedState();
- private Map tags = new HashMap<>();
+ private volatile Map tags = new HashMap<>();
public ScalableTarget() {}
diff --git a/src/test/java/io/floci/aws/services/applicationautoscaling/ApplicationAutoScalingServiceTest.java b/src/test/java/io/floci/aws/services/applicationautoscaling/ApplicationAutoScalingServiceTest.java
index 4837e80820..b302c619ce 100644
--- a/src/test/java/io/floci/aws/services/applicationautoscaling/ApplicationAutoScalingServiceTest.java
+++ b/src/test/java/io/floci/aws/services/applicationautoscaling/ApplicationAutoScalingServiceTest.java
@@ -3,6 +3,7 @@ package io.floci.aws.services.applicationautoscaling;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.PaginatedResult;
import io.floci.aws.core.common.RegionResolver;
+import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.InMemoryStorage;
import io.floci.aws.services.applicationautoscaling.model.PredefinedMetricSpecification;
import io.floci.aws.services.applicationautoscaling.model.ScalableTarget;
@@ -79,6 +80,48 @@ class ApplicationAutoScalingServiceTest {
null, null, Map.of("Environment", "dev"), REGION);
}
+ /**
+ * IAM's tag lookup reads the tags held on the scalable target whose ARN it is given, in that ARN's Region, as
+ * tagging and an update's tags leave them; nothing for another Region's ARN or an unknown target's.
+ */
+ @Test
+ void storedTagsAreTheTagsOfTheScalableTargetTheArnNames() {
+ String arn = register().getScalableTargetArn();
+ service.tagResource(arn, Map.of("team", "data"), REGION);
+ service.untagResource(arn, List.of("Environment"), REGION);
+
+ assertEquals(Map.of("team", "data"), service.storedTags(arn));
+ assertEquals(Map.of(), service.storedTags(arn.replace(":" + REGION + ":", ":eu-west-1:")));
+ assertEquals(Map.of(), service.storedTags(arn + "0"));
+ assertEquals(Map.of(), service.storedTags("arn:aws:s3:::bucket"));
+ }
+
+ /**
+ * A target stored before storage was account-aware is read in place for the default account, its ECS resource id
+ * slashes and all, and never migrated; another account's ARN reads nothing.
+ */
+ @Test
+ void storedTagsReadsAPreMultiAccountTargetOfTheDefaultAccountInPlace() {
+ InMemoryStorage raw = new InMemoryStorage<>();
+ ApplicationAutoScalingService legacy = new ApplicationAutoScalingService(
+ new AccountAwareStorageBackend<>(raw, null, "000000000000"), new InMemoryStorage<>(),
+ new InMemoryStorage<>(), new InMemoryStorage<>(), new RegionResolver(REGION, "000000000000"),
+ cloudWatch, mock(EcsCapacityAdjuster.class));
+ String arn = "arn:aws:application-autoscaling:" + REGION + ":000000000000:scalable-target/0123456789abcdef";
+ ScalableTarget target = new ScalableTarget();
+ target.setServiceNamespace(NAMESPACE);
+ target.setResourceId(RESOURCE_ID);
+ target.setScalableDimension(DIMENSION);
+ target.setScalableTargetArn(arn);
+ target.setTags(Map.of("team", "data"));
+ String key = REGION + "::" + NAMESPACE + "::" + DIMENSION + "::" + RESOURCE_ID;
+ raw.put(key, target);
+
+ assertEquals(Map.of("team", "data"), legacy.storedTags(arn));
+ assertEquals(Map.of(), legacy.storedTags(arn.replace(":000000000000:", ":111122223333:")));
+ assertTrue(raw.get(key).isPresent());
+ }
+
private TargetTrackingConfiguration targetTracking(double value, String metricType, String resourceLabel) {
TargetTrackingConfiguration config = new TargetTrackingConfiguration();
config.setTargetValue(value);
diff --git a/src/test/java/io/floci/aws/services/iam/IamRequestResourceEnforcementIntegrationTest.java b/src/test/java/io/floci/aws/services/iam/IamRequestResourceEnforcementIntegrationTest.java
index 2c63616237..75cba98777 100644
--- a/src/test/java/io/floci/aws/services/iam/IamRequestResourceEnforcementIntegrationTest.java
+++ b/src/test/java/io/floci/aws/services/iam/IamRequestResourceEnforcementIntegrationTest.java
@@ -1589,6 +1589,31 @@ class IamRequestResourceEnforcementIntegrationTest {
}
}
+ /**
+ * An {@code aws:ResourceTag} condition reads the tags Application Auto Scaling holds on the scalable target a
+ * request names, so an allow on one team's tag lets the caller list that team's target's tags and not another's.
+ */
+ @Test
+ void anApplicationAutoScalingResourceTagConditionReadsTheTagsOfTheScalableTarget() {
+ String tagged = taggedScalableTarget("data");
+ String other = taggedScalableTarget("web");
+
+ User user = user("res-target-tags");
+ user.policy("{\"Effect\":\"Allow\",\"Action\":\"application-autoscaling:ListTagsForResource\","
+ + "\"Resource\":\"*\",\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
+ scaling(user, "ListTagsForResource", "{\"ResourceARN\":\"" + tagged + "\"}").statusCode(200);
+ refusedJson(scaling(user, "ListTagsForResource", "{\"ResourceARN\":\"" + other + "\"}"),
+ "application-autoscaling:ListTagsForResource");
+ }
+
+ /** A scalable target the admin registers and tags with the team; its ARN. */
+ private String taggedScalableTarget(String team) {
+ String arn = registerScalableTarget(scalableTarget("service/res-" + suffix() + "/web"));
+ adminJson("application-autoscaling", "AnyScaleFrontendService.TagResource").body("{\"ResourceARN\":\"" + arn
+ + "\",\"Tags\":{\"team\":\"" + team + "\"}}").post("/").then().statusCode(200);
+ return arn;
+ }
+
/** The members naming an ECS service's desired count as a scalable target, an open JSON object. */
private static String scalableTarget(String resourceId) {
return "{\"ServiceNamespace\":\"ecs\",\"ResourceId\":\"" + resourceId + "\","