feat(iam): read Identity Store from the generated tables (#9315)

Move `identitystore` from NOT_COVERED to NAMESPACES in
regen_iam_request_resources.py, so Identity Store requests are checked on
the resources they name instead of `*`: the identity store its
IdentityStoreId names, and the group, user or membership its id names, whose
ARNs have no Region and no account; the list calls also on every group,
user or membership, as the Service Reference gives them.

A type an action requires that its request does not name is now read too.
Which types an action requires is what the Service Authorization Reference
marks with an asterisk, which neither botocore nor the Service Reference
says, so fetch_required_resource_types.py vendors that page's actions table
as it stands into tools/aws/sources/required-resource-types.json, granted
for Identity Store alone. Two generic readings use it: a required type the
record of the resource the request names holds is read through that
resource's id (DescribeGroupMembership and DeleteGroupMembership, the
membership's group and user), and a required type whose id a lookup returns
is found by the members its request gives, each way it may give them apart
(GetGroupMembershipId, GetGroupId, GetUserId). The reader lets a find name a
field of a structure at any depth and gives the service the members' paths
with their values, and Identity Store answers both as its handlers find
them. No other namespace's rows change.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-24 08:25:52 -04:00
1 parent 8758208313
commit 3fbb0ced10
20 files changed
+1045 -21

No files matched your search

@@ -49,6 +49,12 @@ final class RequestResourceMembers {
*/
private static final Pattern FILL_MEMBER = Pattern.compile("[A-Za-z][A-Za-z0-9_]*(\\[]|\\[]\\.[A-Za-z][A-Za-z0-9_]*"
+ "(\\.[A-Za-z][A-Za-z0-9_]*)?|\\{}|\\{}\\.[A-Za-z][A-Za-z0-9_]*|\\.[A-Za-z][A-Za-z0-9_]*)?");
/**
* A member a service finds a resource by: one list, or a value at any depth of structures, as a lookup's request
* gives it ({@code AlternateIdentifier.ExternalId.Id}).
*/
private static final Pattern FOUND_MEMBER =
Pattern.compile("[A-Za-z][A-Za-z0-9_]*(\\[]|(\\.[A-Za-z][A-Za-z0-9_]*)*)");
/** An ARN format's leading resource type word, and the rest of its resource. */
private static final Pattern RESOURCE_PART = Pattern.compile(
"^arn:\\$\\{Partition}:[^:]*:[^:]*:[^:]*:([A-Za-z][A-Za-z0-9-]*)(.*)$");
@@ -852,7 +858,7 @@ final class RequestResourceMembers {
});
List<Member> find = new ArrayList<>();
for (JsonNode member : resource.path("find")) {
find.add(member(operation, member.asText("")));
find.add(foundMember(operation, member.asText("")));
}
if (resource.has("find") && (!resource.path("find").isArray() || find.isEmpty() || !fill.isEmpty()
|| (find.size() > 1 && find.stream().anyMatch(Member::list))
@@ -1056,6 +1062,17 @@ final class RequestResourceMembers {
return path.endsWith("[]") ? new Member(path.substring(0, path.length() - 2), true) : new Member(path, false);
}
/** A member a service finds a resource by: {@code Name[]}, {@code Name}, or a field of its structures, any deep. */
private static Member foundMember(String operation, String path) {
if (!FOUND_MEMBER.matcher(path).matches()) {
throw new IllegalStateException(RESOURCE_NAME + " reads " + operation + " at " + path
+ ", which is no member");
}
int dot = path.indexOf('.');
return dot < 0 ? member(operation, path)
: new Member(path.substring(0, dot), false, foundMember(operation, path.substring(dot + 1)));
}
/**
* A member filling a variable: {@code Name}, {@code Name[]}, or a field of a structure, {@code Name.Field}, of
* each of a list's structures, {@code Name[].Field}, or of a field of each of them, {@code Name[].Item.Field}, or
@@ -1132,8 +1132,8 @@ public final class RequestResources {
return;
}
for (String value : values(form, body, resource.find().getFirst())) {
foundOne(arns, resource.types().getFirst(), List.of(value), formats, partition, region, account,
accountId, stored);
foundOne(arns, resource.types().getFirst(), List.of(resource.find().getFirst().path()),
List.of(value), formats, partition, region, account, accountId, stored);
}
return;
}
@@ -1152,15 +1152,19 @@ public final class RequestResources {
if (account == null) {
return;
}
foundOne(arns, resource.types().getFirst(), names, formats, partition, region, account, accountId, stored);
foundOne(arns, resource.types().getFirst(), resource.find().stream().map(RequestResourceMembers.Member::path)
.toList(), names, formats, partition, region, account, accountId, stored);
}
/** The resource of the type {@code stored} finds by the values in the account, or else its ARN with its id open. */
private static void foundOne(Set<String> arns, String type, List<String> names,
/**
* The resource of the type {@code stored} finds by the values of the members in the account, or else its ARN with
* its id open.
*/
private static void foundOne(Set<String> arns, String type, List<String> members, List<String> names,
Map<String, RequestResourceMembers.ArnFormat> formats, String partition,
String region, String account, String accountId, StoredResourceArns stored) {
Optional<String> found = stored == null ? Optional.empty()
: account.equals(accountId) ? stored.findByMembers(type, names, region)
: account.equals(accountId) ? stored.findByMembers(type, members, names, region)
: stored.findInAccount(type, names, account, region);
arns.add(found.orElseGet(() -> render(formats.get(type).format(), Map.of(), partition, region, account)));
}
@@ -1264,7 +1268,8 @@ public final class RequestResources {
* The ARN of the namespace's resource of {@code type} named by {@code id}, the one variable of its format past
* partition, Region and account, as a request naming the resource by its id gives it.
*/
static String idArn(String namespace, String type, String id, String partition, String region, String accountId) {
public static String idArn(String namespace, String type, String id, String partition, String region,
String accountId) {
return idArn(RequestResourceMembers.table().formats().get(namespace).get(type).format(), id, partition, region,
accountId);
}
@@ -227,4 +227,13 @@ public interface StoredResourceArns {
default Optional<String> findByMembers(String type, List<String> names, String region) {
return find(type, names, region);
}
/**
* As {@link #findByMembers(String, List, String)}, with the paths of the members the values come from, as the
* table writes them ({@code AlternateIdentifier.ExternalId.Id}), for a service whose request may name the resource
* in more than one way, each the same number of values.
*/
default Optional<String> findByMembers(String type, List<String> members, List<String> names, String region) {
return findByMembers(type, names, region);
}
}
@@ -315,6 +315,15 @@ public class IdentityStoreService implements Resettable {
.orElseThrow(() -> notFound("Group membership not found."));
}
/**
* The membership of that id, which its id alone names, as every identity store's ids are its own; empty when there
* is none.
*/
public Optional<Membership> findMembership(String membershipId) {
return memberships.scanForAccount(GLOBAL_PARTITION, key -> key.endsWith("::" + membershipId)).stream()
.findFirst();
}
public synchronized void deleteMembership(JsonNode request) {
String storeId = requireStore(required(request, "IdentityStoreId"));
String membershipId = requireResourceId(required(request, "MembershipId"), "MembershipId");
@@ -0,0 +1,93 @@
package io.floci.aws.services.identitystore;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.common.RequestResources;
import io.floci.aws.core.common.StoredResourceArns;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
/**
* What IAM asks Identity Store of the resources a request names: the group and the user of the membership a
* {@code MembershipId} names, and the group, user or membership a lookup's request names by other members (an
* alternate identifier, or a group and a member), which the Service Authorization Reference requires those actions
* on. Each is found as its handler finds it.
*/
@ApplicationScoped
public class IdentityStoreStoredResourceArns implements StoredResourceArns {
private static final ObjectMapper MAPPER = new ObjectMapper();
private final IdentityStoreService identityStore;
private final RegionResolver regions;
@Inject
public IdentityStoreStoredResourceArns(IdentityStoreService identityStore, RegionResolver regions) {
this.identityStore = identityStore;
this.regions = regions;
}
@Override
public String namespace() {
return "identitystore";
}
/** Identity Store finds its resources by the members a lookup names them by, never by one name alone. */
@Override
public Optional<String> find(String type, List<String> names, String region) {
return Optional.empty();
}
/**
* The group, user or membership the lookup the members make up finds, as {@code GetGroupId}, {@code GetUserId} and
* {@code GetGroupMembershipId} find it; empty when it finds none.
*/
@Override
public Optional<String> findByMembers(String type, List<String> members, List<String> names, String region) {
if (members.size() != names.size()) {
return Optional.empty();
}
ObjectNode request = MAPPER.createObjectNode();
for (int i = 0; i < members.size(); i++) {
ObjectNode node = request;
String[] path = members.get(i).split("\\.");
for (int j = 0; j < path.length - 1; j++) {
node = node.has(path[j]) ? (ObjectNode) node.get(path[j]) : node.putObject(path[j]);
}
node.put(path[path.length - 1], names.get(i));
}
try {
String id = switch (type) {
case "Group" -> identityStore.getGroupId(request).groupId();
case "User" -> identityStore.getUserId(request).userId();
case "GroupMembership" -> identityStore.getMembershipId(request).membershipId();
default -> null;
};
return Optional.ofNullable(id).map(found -> arn(type, found, region));
} catch (AwsException e) {
return Optional.empty();
}
}
/** The group and the user of the membership a {@code MembershipId} names; none when there is no such membership. */
@Override
public List<String> through(String member, String value, String region) {
if (!"MembershipId".equals(member)) {
return List.of();
}
return identityStore.findMembership(value)
.map(membership -> Stream.of(arn("Group", membership.groupId(), region),
arn("User", membership.userId(), region)).toList())
.orElse(List.of());
}
private String arn(String type, String id, String region) {
return RequestResources.idArn(namespace(), type, id, regions.partitionForRegion(region), region, "");
}
}