mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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:
1 parent
81f484fc18
commit
a00b091da2
5 files changed
+86
-6
No files matched your search
@@ -3199,8 +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, and CloudFront for every resource it tags, by its ARN. 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, 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.
|
||||
- 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
|
||||
|
||||
@@ -23,10 +23,11 @@ import java.util.Optional;
|
||||
* connections and API destinations; Application Auto Scaling, for its scalable targets; Redshift Data, for the
|
||||
* Redshift Serverless workgroups it runs statements on and the targets of its sessions; Payment Cryptography, for
|
||||
* 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; 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;
|
||||
* 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;
|
||||
* 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
|
||||
|
||||
@@ -1963,6 +1963,31 @@ public class SsoAdminService implements Resettable, StoredResourceArns {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags held on the instance, permission set, application or trusted token issuer {@code arn} names, as
|
||||
* ListTagsForResource reads them: the tags a tagging call left on it, else the resource's own; read in place where
|
||||
* the handlers find these resources, by their whole ARN. Empty for an ARN naming nothing stored.
|
||||
*/
|
||||
@Override
|
||||
public Map<String, String> storedTags(String arn) {
|
||||
Map<String, String> tags;
|
||||
try {
|
||||
TaggableResource resource = resolveTaggableResource(arn);
|
||||
tags = resourceTagOverrides.get(arn).orElseGet(resource::tags);
|
||||
} catch (AwsException notStored) {
|
||||
return Map.of();
|
||||
}
|
||||
Map<String, String> held = new LinkedHashMap<>();
|
||||
if (tags != null) {
|
||||
tags.forEach((key, value) -> {
|
||||
if (key != null && value != null) {
|
||||
held.put(key, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
return held;
|
||||
}
|
||||
|
||||
private void ensurePermissionSetProvisioned(String permissionSetArn, String accountId) {
|
||||
String key = permissionSetArn + "::" + accountId;
|
||||
PermissionSet permissionSet = permissionSetForPortal(permissionSetArn);
|
||||
|
||||
+28
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user