mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(applicationautoscaling): give resource-tag conditions the tags of the target a request names (#8726)
The generated request resources give Application Auto Scaling's ScalableTarget type the aws:ResourceTag/ key, but its service answered no tags, so a condition on a scalable target's tags saw none. Its storedTags now reads the target whose ARN is the ARN, among the targets of the account and Region it names, a pre-multi-account one of the default account included, as the handlers find it. Tag changes already store a copy of the target under its lock; the tags field is now volatile.
This commit is contained in:
1 parent
151cb586f9
commit
65c6440b8f
6 files changed
+114
-8
No files matched your search
+43
@@ -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<String, ScalableTarget> 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);
|
||||
|
||||
+25
@@ -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 + "\","
|
||||
|
||||
Reference in new issue
Block a user