fix(sso): give resource-tag conditions the tags of the resource a request names (#8703)

The generated request resources give IAM Identity Center's instance,
permission set, application and trusted token issuer types the
aws:ResourceTag/ key, but SsoAdminService answered no tags, so a
condition on such a resource's tags saw none. SsoAdminService.storedTags
now reads them as ListTagsForResource does, in place: the resource the
ARN names, found as the handlers find it by its whole ARN, then the tags
a tagging call left on it or else its own. Its tag writes already put a
new map in place of the held one.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-17 01:00:44 -04:00
1 parent 81f484fc18
commit a00b091da2
5 files changed
+86 -6

No files matched your search

@@ -1809,6 +1809,34 @@ class IamRequestResourceEnforcementIntegrationTest {
.body(containsString("InstanceGroups must contain at least one instance group."));
}
/**
* An {@code aws:ResourceTag} condition reads the tags IAM Identity Center holds on the permission set a request
* names, so an allow on one team's tag lets the caller describe that team's permission set and not another's.
*/
@Test
void anIdentityCenterResourceTagConditionReadsTheTagsOfThePermissionSet() {
String instance = ssoInstance();
String tagged = taggedPermissionSet(instance, "data");
String other = taggedPermissionSet(instance, "web");
User user = user("res-sso-tags");
user.policy(allowOn("sso:DescribePermissionSet", instance) + ",{\"Effect\":\"Allow\","
+ "\"Action\":\"sso:DescribePermissionSet\",\"Resource\":\"*\","
+ "\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
String describe = "{\"InstanceArn\":\"" + instance + "\",\"PermissionSetArn\":\"";
ssoAdmin(user, "DescribePermissionSet", describe + tagged + "\"}").statusCode(200);
refusedJson(ssoAdmin(user, "DescribePermissionSet", describe + other + "\"}"), "sso:DescribePermissionSet");
}
/** A permission set of the instance, tagged with the team by an administrator's TagResource. */
private String taggedPermissionSet(String instance, String team) {
String permissionSet = permissionSet(instance);
adminJson("sso", "SWBExternalService.TagResource").body("{\"InstanceArn\":\"" + instance
+ "\",\"ResourceArn\":\"" + permissionSet + "\",\"Tags\":[{\"Key\":\"team\",\"Value\":\"" + team
+ "\"}]}").post("/").then().statusCode(200);
return permissionSet;
}
/**
* An IAM Identity Center account assignment is checked on the account its {@code TargetId} names beside the
* instance and the permission set, so a grant scoped to one account does not reach another, and a deny on an
@@ -1334,6 +1334,31 @@ class SsoAdminServiceTest {
assertError("ServiceQuotaExceededException", () -> service.addRegion(overQuota));
}
/**
* IAM's tag lookup reads a resource's tags as ListTagsForResource does: its own until a tagging call changes them,
* then the changed set; nothing for an ARN naming no stored resource or one that is not an Identity Center ARN.
*/
@Test
void storedTagsAreTheTagsListTagsForResourceGives() {
ObjectNode create = mapper.createObjectNode();
create.put("InstanceArn", service.getInstanceArn());
create.put("Name", "StoredTagAdmins");
create.putArray("Tags").addObject().put("Key", "team").put("Value", "data");
PermissionSet permissionSet = service.createPermissionSet(create);
assertEquals(Map.of("team", "data"), service.storedTags(permissionSet.arn()));
ObjectNode tag = mapper.createObjectNode();
tag.put("ResourceArn", permissionSet.arn());
tag.putArray("Tags").addObject().put("Key", "env").put("Value", "prod");
service.tagResource(tag);
assertEquals(Map.of("team", "data", "env", "prod"), service.storedTags(permissionSet.arn()));
String unknown = permissionSet.arn().substring(0, permissionSet.arn().length() - 16) + "0000000000000000";
assertEquals(Map.of(), service.storedTags(unknown));
assertEquals(Map.of(), service.storedTags("arn:aws:s3:::bucket"));
}
@Test
void listTagsForResourceReturnsPermissionSetTagsAndValidatesContext() {
ObjectNode create = mapper.createObjectNode();