fix(ram): give resource-tag conditions the tags of the resource share a request names (#8713)

The generated request resources give RAM's resource-share type the
aws:ResourceTag/ and ram:ResourceTag/ keys, but RamService answered no
tags, so a condition on a share's tags saw none. RamService.storedTags now reads the share stored
under the ARN in the owning account the ARN names, in place, matched on
the whole ARN shares are kept by, when the caller may see it as
GetResourceShares shows it: one it owns or one made visible to it, so a
decision never turns on a share RAM hides from the caller. A share is immutable and tagging
stores a new one under the service's lock, so the lookup always reads
one whole set of tags.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-17 03:15:14 -04:00
1 parent 751c97dde6
commit da39feee4e
5 files changed
+76 -3

No files matched your search

+2 -2
View File
@@ -3200,8 +3200,8 @@ floci populates:
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, 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.
permission sets, applications and trusted token issuers, OAM for its sinks and links, and RAM for its resource
shares. 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,7 +25,8 @@ 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, and OAM for the tags of a sink or a link;
* for the sinks, invitations and shares of other accounts they act on, OAM for the tags of a sink or a link, and
* RAM for the tags of a resource share;
* 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
@@ -375,6 +375,30 @@ public class RamService implements StoredResourceArns {
return share.filter(shared -> !"DELETED".equals(shared.getStatus())).isPresent();
}
/**
* The tags held on the resource share stored under {@code arn}, in the account that owns it, which the ARN names,
* read in place, when the caller may see that share as GetResourceShares shows it: one it owns, or one another
* account made visible to it. Shares are kept by their whole ARN, so the ARN is matched whole. Empty for an ARN
* naming no share or one the caller cannot see, so a decision never turns on a share RAM hides from it.
*/
@Override
public Map<String, String> storedTags(String arn) {
if (!isResourceShareArn(arn) || !(shares instanceof AccountAwareStorageBackend<ResourceShare> aware)) {
return Map.of();
}
String caller = aware.accountId();
Map<String, String> held = new LinkedHashMap<>();
AccountAwareStorageBackend.readInAccount(shares, AwsArnUtils.parse(arn).accountId(), arn)
.filter(share -> isVisible(share, caller, "SELF") || isVisible(share, caller, "OTHER-ACCOUNTS"))
.map(ResourceShare::getTags)
.ifPresent(tags -> tags.forEach((key, value) -> {
if (key != null && value != null) {
held.put(key, value);
}
}));
return held;
}
private List<ResourceShareInvitation> allInvitations() {
if (invitations instanceof AccountAwareStorageBackend<ResourceShareInvitation> accountAware) {
return accountAware.scanAllAccounts();
@@ -1208,6 +1208,33 @@ class IamRestRouteEnforcementIntegrationTest {
request(user, "ram", "DELETE", "/deleteresourceshare?resourceShareArn=" + encoded(share), null).statusCode(200);
}
/**
* An {@code aws:ResourceTag} condition reads the tags RAM holds on the resource share a request names, so an allow
* on one team's tag lets the caller update that team's share and not another's.
*/
@Test
void aRamResourceTagConditionReadsTheTagsOfTheResourceShare() {
String tagged = taggedShare("data");
String other = taggedShare("web");
String user = user("route-ram-tags");
policy(user, "{\"Effect\":\"Allow\",\"Action\":\"ram:UpdateResourceShare\",\"Resource\":\"*\","
+ "\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
request(user, "ram", "POST", "/updateresourceshare", "{\"resourceShareArn\":\"" + tagged + "\"}")
.statusCode(200);
refused(request(user, "ram", "POST", "/updateresourceshare", "{\"resourceShareArn\":\"" + other + "\"}"),
"ram:UpdateResourceShare");
}
/** A resource share an administrator makes and tags with the team, deleted after the test; its ARN. */
private String taggedShare(String team) {
String share = madeShare(adminOf("ram").body("{\"name\":\"route-share-" + suffix() + "\"}")
.post("/createresourceshare").then());
adminOf("ram").body("{\"resourceShareArn\":\"" + share + "\",\"tags\":[{\"key\":\"team\",\"value\":\""
+ team + "\"}]}").post("/tagresource").then().statusCode(200);
return share;
}
@Test
void ramCreateIsCheckedOnTheShareItMakesAndThePermissionsItNames() {
String user = user("route-ram-create");
@@ -70,6 +70,27 @@ class RamServiceTest {
service.initializeStorage();
}
/**
* IAM's tag lookup reads the tags held on the share the whole ARN names, in the owning account the ARN names, as
* tagging leaves them, when the caller may see the share: the caller's own share gives its tags, another account's
* share not shared with it gives none, as RAM hides it; nothing for another share's ARN or one that is not a
* share's.
*/
@Test
void storedTagsAreTheTagsOfTheShareTheArnNamesWhenTheCallerMaySeeIt() {
String caller = "000000000000";
ResourceShare own = service.createResourceShare("tagged", List.of(), List.of(), false, "us-east-1", caller);
service.tagResource(own.getResourceShareArn(), Map.of("team", "data"), caller, "us-east-1");
service.tagResource(own.getResourceShareArn(), Map.of("env", "prod"), caller, "us-east-1");
ResourceShare hidden = service.createResourceShare("hidden", List.of(), List.of(), false, "us-east-1", OWNER);
service.tagResource(hidden.getResourceShareArn(), Map.of("team", "data"), OWNER, "us-east-1");
assertEquals(Map.of("team", "data", "env", "prod"), service.storedTags(own.getResourceShareArn()));
assertEquals(Map.of(), service.storedTags(hidden.getResourceShareArn()));
assertEquals(Map.of(), service.storedTags(own.getResourceShareArn() + "0"));
assertEquals(Map.of(), service.storedTags("arn:aws:s3:::bucket"));
}
@Test
void deletedShareStopsExposingItsResourcesAndPrincipals() {
// Real RAM keeps a deleted share visible (status DELETED) for a retention