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:
Priamo Germosen authored and GitHub committed 2026-11-15 19:10:14 -04:00
1 parent 73f2c348b6
commit bca36ce5b5
6 files changed
+114 -11

No files matched your search

+2 -2
View File
@@ -3071,8 +3071,8 @@ floci populates:
its type (`aws:ResourceTag/`, `secretsmanager:ResourceTag/`), which `regen_iam_request_resources.py`
reads from the Service Reference for every namespace it reads, valued from the tags the type's service
holds on that resource (`StoredResourceArns.storedTags`); a service that holds none leaves them absent.
Secrets Manager answers for its secrets, and S3 Tables for its table buckets and tables. Tag keys differing
only in case are one condition key holding every value.
Secrets Manager answers for its secrets, S3 Tables for its table buckets and tables, and EventBridge
Scheduler for its schedule groups. 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
@@ -25,9 +25,9 @@ import java.util.Optional;
* the key an alias names; EMR, for the clusters of its instance groups; IAM Identity Center, for the accounts its
* permission sets are provisioned to; Resource Explorer, for its default view; OAM and RAM, for the sinks,
* invitations and shares of other accounts they act on; Secrets Manager, for the secret a name or an ARN names,
* random suffix included, and its tags; EventBridge Scheduler, for its default schedule group; CloudFormation, for
* the stack or the stack set a name names, whose id it minted; S3 Tables, for the table a request names by its table
* bucket, namespace and name, and the tags of a table bucket or a table); looked up lazily by
* random suffix included, and its tags; EventBridge Scheduler, for its default schedule group and its groups' tags;
* CloudFormation, for the stack or the stack set a name names, whose id it minted; S3 Tables, for the table a request
* names by its table bucket, namespace and name, and the tags of a table bucket or a table); 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>
*
@@ -25,6 +25,7 @@ import org.jboss.logging.Logger;
import java.time.DateTimeException;
import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@@ -41,6 +42,7 @@ public class SchedulerService implements StoredResourceArns {
"arn:(?:" + AwsArnUtils.PARTITION_REGEX + "):iam::\\d{12}:role/[\\w+=,.@/-]+");
private static final String ROLE_ARN_MODEL_PATTERN = "^arn:aws(-[a-z]+)?:iam::\\d{12}:role\\/[\\w+=,.@\\/-]+$"; // partition-literal: the Scheduler model's RoleArn pattern, quoted verbatim in the error message
private static final String DEFAULT_GROUP = "default";
private static final String GROUP_RESOURCE = "schedule-group/";
// ListScheduleGroups and ListSchedules model MaxResults as 1-100 and NextToken as 1-2048 chars.
private static final int MAX_PAGE_SIZE = 100;
private static final int MAX_TOKEN_LENGTH = 2048;
@@ -95,6 +97,31 @@ public class SchedulerService implements StoredResourceArns {
return "schedule-group".equals(type) ? Optional.of(buildGroupArn(region, DEFAULT_GROUP)) : Optional.empty();
}
/**
* The tags of the schedule group stored under {@code arn}, in the account and Region the ARN names, by key, which
* IAM gives a resource-tag condition; empty when there is none, the default group before a request stores it among
* them. Reads that one group's entry, a pre-multi-account one of the default account in place, and matches it on
* the whole ARN, leaving it as it is.
*/
@Override
public Map<String, String> storedTags(String arn) {
if (!AwsArnUtils.isArnFor(arn, "scheduler")) {
return Map.of();
}
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
if (!parsed.resource().startsWith(GROUP_RESOURCE)) {
return Map.of();
}
String key = groupKey(parsed.region(), parsed.resource().substring(GROUP_RESOURCE.length()));
String account = parsed.accountId();
Optional<ScheduleGroup> group = groupStore instanceof AccountAwareStorageBackend<ScheduleGroup> aware
? aware.getForAccount(account, key).or(() -> aware.getLegacyForAccount(account, key))
: groupStore.get(key);
return group.filter(stored -> arn.equals(stored.getArn()))
.<Map<String, String>>map(stored -> Map.copyOf(stored.getTags()))
.orElse(Map.of());
}
// ──────────────────────────── Schedule Groups ────────────────────────────
public ScheduleGroup getOrCreateDefaultGroup(String region) {
@@ -184,8 +211,14 @@ public class SchedulerService implements StoredResourceArns {
return;
}
ScheduleGroup group = getScheduleGroup(name, region);
group.getTags().putAll(tags);
group.setLastModificationDate(Instant.now());
// A new map in place of the old, never a change to the one a tag lookup may be copying (storedTags, the tag
// listing), so each reads one whole set; writers of the group take turns.
synchronized (group) {
Map<String, String> updated = new HashMap<>(group.getTags());
updated.putAll(tags);
group.setTags(updated);
group.setLastModificationDate(Instant.now());
}
groupStore.put(groupKey(region, group.getName()), group);
}
@@ -194,8 +227,12 @@ public class SchedulerService implements StoredResourceArns {
return;
}
ScheduleGroup group = getScheduleGroup(name, region);
tagKeys.forEach(group.getTags()::remove);
group.setLastModificationDate(Instant.now());
synchronized (group) {
Map<String, String> updated = new HashMap<>(group.getTags());
tagKeys.forEach(updated::remove);
group.setTags(updated);
group.setLastModificationDate(Instant.now());
}
groupStore.put(groupKey(region, group.getName()), group);
}
@@ -500,7 +537,7 @@ public class SchedulerService implements StoredResourceArns {
}
private String buildGroupArn(String region, String name) {
return regionResolver.buildArn("scheduler", region, "schedule-group/" + name);
return regionResolver.buildArn("scheduler", region, GROUP_RESOURCE + name);
}
private static String groupKey(String region, String name) {
@@ -14,7 +14,7 @@ public class ScheduleGroup {
private String state;
private Instant creationDate;
private Instant lastModificationDate;
private Map<String, String> tags = new HashMap<>();
private volatile Map<String, String> tags = new HashMap<>();
public ScheduleGroup() {}
@@ -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);