From 7199c8580e1bc4d10e7e14ed89fb390b2aa1b235 Mon Sep 17 00:00:00 2001 From: Priamo Germosen <6233424+pgermosen@users.noreply.github.com> Date: Tue, 17 Nov 2026 02:09:51 -0400 Subject: [PATCH] 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. --- docs/services/iam.md | 6 +-- .../aws/core/common/StoredResourceArns.java | 6 +-- .../io/floci/aws/services/oam/OamService.java | 29 ++++++++++++++- .../floci/aws/services/oam/model/OamLink.java | 2 +- .../floci/aws/services/oam/model/OamSink.java | 2 +- ...amRestRouteEnforcementIntegrationTest.java | 37 +++++++++++++++++-- 6 files changed, 69 insertions(+), 13 deletions(-) diff --git a/docs/services/iam.md b/docs/services/iam.md index c9ddea455e..bec11d6376 100644 --- a/docs/services/iam.md +++ b/docs/services/iam.md @@ -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 diff --git a/src/main/java/io/floci/aws/core/common/StoredResourceArns.java b/src/main/java/io/floci/aws/core/common/StoredResourceArns.java index 0aec8c3ceb..3750c89386 100644 --- a/src/main/java/io/floci/aws/core/common/StoredResourceArns.java +++ b/src/main/java/io/floci/aws/core/common/StoredResourceArns.java @@ -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 diff --git a/src/main/java/io/floci/aws/services/oam/OamService.java b/src/main/java/io/floci/aws/services/oam/OamService.java index f9242eb478..ebb58c7c91 100644 --- a/src/main/java/io/floci/aws/services/oam/OamService.java +++ b/src/main/java/io/floci/aws/services/oam/OamService.java @@ -186,7 +186,7 @@ public class OamService implements StoredResourceArns { public Map tags(String arn) { return new LinkedHashMap<>(resourceTags(arn)); } - public void tag(String arn, Map tags) { + public synchronized void tag(String arn, Map tags) { validateTags(tags); Map 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 tagKeys) { + public synchronized void untag(String arn, List tagKeys) { if (tagKeys == null) throw missing("TagKeys"); Map 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 storedTags(String arn) { + String account = arnAccount(arn); + if (account == null || account.isEmpty() || !AwsArnUtils.isArnFor(arn, "oam")) { + return Map.of(); + } + Optional> 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 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) { diff --git a/src/main/java/io/floci/aws/services/oam/model/OamLink.java b/src/main/java/io/floci/aws/services/oam/model/OamLink.java index e37138aad5..d0470697a5 100644 --- a/src/main/java/io/floci/aws/services/oam/model/OamLink.java +++ b/src/main/java/io/floci/aws/services/oam/model/OamLink.java @@ -17,7 +17,7 @@ public class OamLink { private String sourceAccountId; private List resourceTypes = List.of(); private Map linkConfiguration = new LinkedHashMap<>(); - private Map tags = new LinkedHashMap<>(); + private volatile Map tags = new LinkedHashMap<>(); public OamLink() {} diff --git a/src/main/java/io/floci/aws/services/oam/model/OamSink.java b/src/main/java/io/floci/aws/services/oam/model/OamSink.java index f0410d803a..689259fee1 100644 --- a/src/main/java/io/floci/aws/services/oam/model/OamSink.java +++ b/src/main/java/io/floci/aws/services/oam/model/OamSink.java @@ -13,7 +13,7 @@ public class OamSink { private String region; private String ownerAccountId; private String policy; - private Map tags = new LinkedHashMap<>(); + private volatile Map tags = new LinkedHashMap<>(); public OamSink() {} diff --git a/src/test/java/io/floci/aws/services/iam/IamRestRouteEnforcementIntegrationTest.java b/src/test/java/io/floci/aws/services/iam/IamRestRouteEnforcementIntegrationTest.java index 78d6984e3b..1cf0898936 100644 --- a/src/test/java/io/floci/aws/services/iam/IamRestRouteEnforcementIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/iam/IamRestRouteEnforcementIntegrationTest.java @@ -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");