mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(scheduler): give resource-tag conditions the tags of the schedule group a request names (#8517)
The generated request resources give Scheduler's schedule-group type aws:ResourceTag/ keys, but SchedulerService did not answer storedTags, so a condition on a schedule group's tags saw none. SchedulerService.storedTags now reads the one group entry in the account and Region the ARN names and gives its tags, matched on the whole ARN, reading only; a group stored before storage was account-aware is read in place for the default account, and the default group has none until a request stores it. Tagging and untagging now put a new tag map in place of the group's, taking turns on the group, and the field is volatile, so the lookup, and the existing tag listing, always copies one whole set nothing changes after.
This commit is contained in:
1 parent
73f2c348b6
commit
bca36ce5b5
6 files changed
+114
-11
No files matched your search
@@ -167,6 +167,26 @@ class IamRestRouteEnforcementIntegrationTest {
|
||||
.body(containsString("Invalid resource ARN"));
|
||||
}
|
||||
|
||||
/** A resource-tag condition reads the tags Scheduler holds on the schedule group a request names. */
|
||||
@Test
|
||||
void aResourceTagConditionReadsTheTagsOfTheScheduleGroup() {
|
||||
String tagged = "route-tagged-" + suffix();
|
||||
String untagged = "route-untagged-" + suffix();
|
||||
for (String[] group : new String[][] {{tagged, "{\"Tags\":[{\"Key\":\"team\",\"Value\":\"data\"}]}"},
|
||||
{untagged, "{}"}}) {
|
||||
given().header("Authorization", auth(ADMIN, "scheduler")).contentType("application/json").body(group[1])
|
||||
.post("/schedule-groups/" + group[0]).then().statusCode(200);
|
||||
cleanup.register(() -> given().header("Authorization", auth(ADMIN, "scheduler"))
|
||||
.delete("/schedule-groups/" + group[0]).then().statusCode(200));
|
||||
}
|
||||
String user = user("route-scheduler-tag-condition");
|
||||
|
||||
policy(user, "{\"Effect\":\"Allow\",\"Action\":\"scheduler:GetScheduleGroup\",\"Resource\":\"*\","
|
||||
+ "\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
|
||||
as(user, "scheduler").get("/schedule-groups/" + tagged).then().statusCode(200);
|
||||
refused(as(user, "scheduler").get("/schedule-groups/" + untagged).then(), "scheduler:GetScheduleGroup");
|
||||
}
|
||||
|
||||
@Test
|
||||
void postTagsIsCheckedAgainstTheArnItsBodyNames() {
|
||||
// POST /tags tags the ARN its body names: one named in the query does not move the check.
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.floci.aws.services.scheduler;
|
||||
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.scheduler.model.DeadLetterConfig;
|
||||
import io.floci.aws.services.scheduler.model.FlexibleTimeWindow;
|
||||
@@ -46,6 +47,51 @@ class SchedulerServiceTest {
|
||||
return req;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tagging and untagging put a new map in place of the group's, never changing the one a tag lookup may be
|
||||
* copying, so a lookup during either reads one whole set.
|
||||
*/
|
||||
@Test
|
||||
void taggingReplacesTheGroupsTagsAndLeavesTheOldSetWhole() {
|
||||
ScheduleGroup group = service.createScheduleGroup("tags", Map.of("team", "data"), REGION);
|
||||
Map<String, String> before = group.getTags();
|
||||
|
||||
service.tagScheduleGroup("tags", REGION, Map.of("owner", "alice"));
|
||||
Map<String, String> tagged = service.getScheduleGroup("tags", REGION).getTags();
|
||||
service.untagScheduleGroup("tags", REGION, List.of("team"));
|
||||
|
||||
assertEquals(Map.of("team", "data"), before);
|
||||
assertEquals(Map.of("team", "data", "owner", "alice"), tagged);
|
||||
assertEquals(Map.of("owner", "alice"), service.getScheduleGroup("tags", REGION).getTags());
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags IAM gives a resource-tag condition: the schedule group's, read on its whole ARN in the account and
|
||||
* Region it names, a pre-multi-account entry of the default account in place; none for anything else, the default
|
||||
* group before a request stores it among them.
|
||||
*/
|
||||
@Test
|
||||
void storedTagsReadsTheScheduleGroupItsArnNames() {
|
||||
InMemoryStorage<String, ScheduleGroup> raw = new InMemoryStorage<>();
|
||||
SchedulerService accounts = new SchedulerService(new AccountAwareStorageBackend<>(raw, null, "000000000000"),
|
||||
new InMemoryStorage<>(), new RegionResolver(REGION, "000000000000"));
|
||||
ScheduleGroup group = accounts.createScheduleGroup("tagged", Map.of("team", "data"), REGION);
|
||||
|
||||
assertEquals(Map.of("team", "data"), accounts.storedTags(group.getArn()));
|
||||
assertEquals(Map.of(), accounts.storedTags(group.getArn().replace(":000000000000:", ":111122223333:")));
|
||||
assertEquals(Map.of(), accounts.storedTags(group.getArn().replace(REGION, "eu-west-1")));
|
||||
String schedule = group.getArn().replace("schedule-group/tagged", "schedule/tagged/s");
|
||||
assertEquals(Map.of(), accounts.storedTags(schedule));
|
||||
assertEquals(Map.of(), accounts.storedTags(accounts.findDefault("schedule-group", REGION).orElseThrow()));
|
||||
|
||||
String legacyArn = group.getArn().replace("tagged", "legacy");
|
||||
ScheduleGroup legacy = new ScheduleGroup("legacy", legacyArn, "ACTIVE", Instant.now(), Instant.now());
|
||||
legacy.getTags().put("team", "old");
|
||||
raw.put("group:" + REGION + ":legacy", legacy);
|
||||
assertEquals(Map.of("team", "old"), accounts.storedTags(legacyArn));
|
||||
assertTrue(raw.get("group:" + REGION + ":legacy").isPresent());
|
||||
}
|
||||
@Test
|
||||
void getOrCreateDefaultGroup() {
|
||||
ScheduleGroup group = service.getOrCreateDefaultGroup(REGION);
|
||||
|
||||
Reference in new issue
Block a user