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
@@ -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() {}
|
||||
|
||||
|
||||
Reference in new issue
Block a user