fix(oam): give resource-tag conditions the tags of the sink or link a request names (#8710)

The generated request resources give OAM's sink and link types the
aws:ResourceTag/ key, but OamService answered no tags, so a condition
on a sink's or a link's tags saw none. OamService.storedTags now reads
the sink or link stored under the ARN in the account it names, in
place, matched on the whole ARN they are kept by. Tagging and untagging
now take the service's lock, so two tag calls on one resource keep each
other's tags, and the tag fields are volatile; setTags already puts a
new map in place of the held one.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-17 02:09:51 -04:00
1 parent e0ef191767
commit 7199c8580e
6 files changed
+69 -13

No files matched your search

+3 -3
View File
@@ -3199,9 +3199,9 @@ floci populates:
workgroups and snapshots, DynamoDB for its tables and their indexes (the table's tags), ECR for its
repositories, Redshift for its clusters, snapshots, parameter groups, subnet groups, snapshot copy grants,
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, and IAM Identity Center for its instances,
permission sets, applications and trusted token issuers. Tag keys differing only in case are one condition key
holding every value.
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, and OAM for its sinks and links. 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 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; 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 and its
* groups' tags;
* for the sinks, invitations and shares of other accounts they act on, and OAM for the tags of a sink or a link;
* Secrets Manager, for the secret a name or an ARN names, 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, and the tags of a stack, a stack set
* or a change set; 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; Lambda, for the layer version a layer version ARN selects, the image of a MicroVM and the
@@ -186,7 +186,7 @@ public class OamService implements StoredResourceArns {
public Map<String, String> tags(String arn) { return new LinkedHashMap<>(resourceTags(arn)); }
public void tag(String arn, Map<String, String> tags) {
public synchronized void tag(String arn, Map<String, String> tags) {
validateTags(tags);
Map<String, String> merged = new LinkedHashMap<>(resourceTags(arn));
merged.putAll(tags == null ? Map.of() : tags);
@@ -194,7 +194,7 @@ public class OamService implements StoredResourceArns {
saveTags(arn, merged);
}
public void untag(String arn, List<String> tagKeys) {
public synchronized void untag(String arn, List<String> tagKeys) {
if (tagKeys == null) throw missing("TagKeys");
Map<String, String> updated = new LinkedHashMap<>(resourceTags(arn));
tagKeys.forEach(updated::remove);
@@ -235,6 +235,31 @@ public class OamService implements StoredResourceArns {
return Optional.empty();
}
/**
* The tags held on the sink or link stored under {@code arn}, in the account it names, read in place; both are kept
* by their whole ARN, so the ARN is matched whole. Empty for an ARN naming neither.
*/
@Override
public Map<String, String> storedTags(String arn) {
String account = arnAccount(arn);
if (account == null || account.isEmpty() || !AwsArnUtils.isArnFor(arn, "oam")) {
return Map.of();
}
Optional<Map<String, String>> tags = Optional.empty();
if (arn.contains(":sink/")) {
tags = AccountAwareStorageBackend.readInAccount(sinks, account, arn).map(OamSink::getTags);
} else if (arn.contains(":link/")) {
tags = AccountAwareStorageBackend.readInAccount(links, account, arn).map(OamLink::getTags);
}
Map<String, String> held = new LinkedHashMap<>();
tags.ifPresent(stored -> stored.forEach((key, value) -> {
if (key != null && value != null) {
held.put(key, value);
}
}));
return held;
}
/** A sink another account owns, which {@code CreateLink} finds in that account and links the caller's to. */
@Override
public boolean reachedInItsAccount(String arn, String accountId) {
@@ -17,7 +17,7 @@ public class OamLink {
private String sourceAccountId;
private List<String> resourceTypes = List.of();
private Map<String, Object> linkConfiguration = new LinkedHashMap<>();
private Map<String, String> tags = new LinkedHashMap<>();
private volatile Map<String, String> tags = new LinkedHashMap<>();
public OamLink() {}
@@ -13,7 +13,7 @@ public class OamSink {
private String region;
private String ownerAccountId;
private String policy;
private Map<String, String> tags = new LinkedHashMap<>();
private volatile Map<String, String> tags = new LinkedHashMap<>();
public OamSink() {}
@@ -1112,11 +1112,42 @@ class IamRestRouteEnforcementIntegrationTest {
refused(request(user, "fis", "PATCH", "/safetyLevers/default/state", body), action);
}
/**
* An {@code aws:ResourceTag} condition reads the tags OAM holds on the sink a request names: an allow on the team
* the sink is tagged with lets the caller read it, one on another team does not, and a deny on its team holds
* against an allow on every resource. A Region holds one sink, so the one sink answers each policy.
*/
@Test
void anOamResourceTagConditionReadsTheTagsOfTheSink() {
String sink = oamSink("{\"team\":\"data\"}");
String user = user("route-oam-tags");
String getSink = "{\"Identifier\":\"" + sink + "\"}";
policy(user, onTeam("Allow", "oam:GetSink", "data"));
request(user, "oam", "POST", "/GetSink", getSink).statusCode(200);
policy(user, onTeam("Allow", "oam:GetSink", "web"));
refused(request(user, "oam", "POST", "/GetSink", getSink), "oam:GetSink");
policy(user, allow("oam:GetSink", "*") + "," + onTeam("Deny", "oam:GetSink", "data"));
refused(request(user, "oam", "POST", "/GetSink", getSink), "oam:GetSink");
}
/** A statement with {@code effect} on {@code action} for every resource whose {@code team} tag is the one given. */
private static String onTeam(String effect, String action, String team) {
return "{\"Effect\":\"" + effect + "\",\"Action\":\"" + action + "\",\"Resource\":\"*\","
+ "\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"" + team + "\"}}}";
}
/** The ARN of a sink an administrator creates with the {@code tags} JSON object, deleted after the test. */
private String oamSink(String tags) {
String sink = adminOf("oam").body("{\"Name\":\"route-sink-" + suffix() + "\",\"Tags\":" + tags + "}")
.post("/CreateSink").then().statusCode(200).extract().path("Arn");
cleanup.register(() -> adminOf("oam").body("{\"Identifier\":\"" + sink + "\"}").post("/DeleteSink"));
return sink;
}
@Test
void oamIsCheckedOnTheArnItsIdentifiersHold() {
String sink = adminOf("oam").body("{\"Name\":\"route-sink-" + suffix() + "\"}").post("/CreateSink")
.then().statusCode(200).extract().path("Arn");
cleanup.register(() -> adminOf("oam").body("{\"Identifier\":\"" + sink + "\"}").post("/DeleteSink"));
String sink = oamSink("{}");
String link = "arn:aws:oam:us-east-1:" + ACCOUNT + ":link/absent";
String other = "arn:aws:oam:us-east-1:" + ACCOUNT + ":sink/other";
String user = user("route-oam");