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

@@ -795,7 +795,11 @@ class RequestResourceMembersTest {
.noneMatch(unless -> unless.getValue().contains(values.getOrDefault(unless.getKey(), "")));
}
/** The value at the member's path in a body: in its list's first element, and in its field's structure. */
/**
* The value at the member's path in a body: in its list's first element, and in its field's structure, which the
* other fields the request gives of it share ({@code AlternateIdentifier.ExternalId}'s {@code Issuer} and
* {@code Id}).
*/
private static void put(ObjectNode body, Member member, String value) {
if (member.field() == null) {
if (member.map()) {
@@ -807,8 +811,11 @@ class RequestResourceMembersTest {
}
} else if (member.map()) {
put(body.putObject(member.name()).putObject("table"), member.field(), value);
} else if (member.list()) {
put(body.putArray(member.name()).addObject(), member.field(), value);
} else {
put(member.list() ? body.putArray(member.name()).addObject() : body.putObject(member.name()), member.field(), value);
put(body.get(member.name()) instanceof ObjectNode shared ? shared : body.putObject(member.name()),
member.field(), value);
}
}
@@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -55,6 +56,8 @@ class RequestResourcesTest {
void detachFindsBothAttachmentEndpointsAndKeepsTypedMissingFallbacks() {
String prefix = "arn:aws:ec2:us-east-1:000000000000:";
StoredResourceArns stored = mock(StoredResourceArns.class);
// The reader asks with the members' paths too, which a service finding by the values alone leaves to them.
when(stored.findByMembers(any(), any(), any(), any())).thenCallRealMethod();
when(stored.findByMembers("instance", List.of("eni-attach-one"), "us-east-1"))
.thenReturn(Optional.of(prefix + "instance/i-one"));
when(stored.findByMembers("network-interface", List.of("eni-attach-one"), "us-east-1"))
@@ -3495,6 +3495,118 @@ class IamRequestResourceEnforcementIntegrationTest {
.formParam("Description", "res").post("/").then();
}
/**
* An Identity Store user is checked on the identity store and on the user its id names, so a grant on both lets the
* caller read that user and not another.
*/
@Test
void anIdentityStoreUserIsCheckedOnItsStoreAndItself() {
String store = "d-1234567890";
String allowed = identityStoreUser(store);
String other = identityStoreUser(store);
User user = user("res-identitystore");
user.policy(allowOn("identitystore:DescribeUser", "arn:aws:identitystore::" + ACCOUNT + ":identitystore/" + store)
+ "," + allowOn("identitystore:DescribeUser", "arn:aws:identitystore:::user/" + allowed));
send(user, "identitystore", "AWSIdentityStore.DescribeUser", "1.1",
"{\"IdentityStoreId\":\"" + store + "\",\"UserId\":\"" + allowed + "\"}").statusCode(200);
refusedJson(send(user, "identitystore", "AWSIdentityStore.DescribeUser", "1.1",
"{\"IdentityStoreId\":\"" + store + "\",\"UserId\":\"" + other + "\"}"),
"identitystore:DescribeUser");
}
/**
* An Identity Store membership is checked on its group and its user too, which the Service Authorization Reference
* requires its actions on and its record holds, so a deny on one group refuses reading a membership of it and not
* one of another group.
*/
@Test
void anIdentityStoreMembershipIsCheckedOnItsGroupAndItsUser() {
String store = "d-1234567890";
String member = identityStoreUser(store);
String denied = identityStoreGroup(store, "res-denied-" + suffix());
String inDenied = identityStoreMembership(store, denied, member);
String inOther = identityStoreMembership(store, identityStoreGroup(store, "res-other-" + suffix()), member);
User user = user("res-identitystore-membership");
user.policy(allowOn("identitystore:DescribeGroupMembership", "*") + ","
+ denyOn("identitystore:DescribeGroupMembership", "arn:aws:identitystore:::group/" + denied));
refusedJson(send(user, "identitystore", "AWSIdentityStore.DescribeGroupMembership", "1.1",
"{\"IdentityStoreId\":\"" + store + "\",\"MembershipId\":\"" + inDenied + "\"}"),
"identitystore:DescribeGroupMembership");
send(user, "identitystore", "AWSIdentityStore.DescribeGroupMembership", "1.1",
"{\"IdentityStoreId\":\"" + store + "\",\"MembershipId\":\"" + inOther + "\"}").statusCode(200);
}
/**
* An Identity Store lookup is checked on what it finds, which the Service Authorization Reference requires it on:
* {@code GetUserId} on the user its alternate identifier names, {@code GetGroupMembershipId} on the membership of
* its group and member, so a deny on one refuses that lookup and not another's.
*/
@Test
void anIdentityStoreLookupIsCheckedOnWhatItFinds() {
String store = "d-1234567890";
String deniedName = "res-denied-" + suffix();
String denied = identityStoreUser(store, deniedName);
String otherName = "res-other-" + suffix();
String other = identityStoreUser(store, otherName);
String group = identityStoreGroup(store, "res-group-" + suffix());
String deniedMembership = identityStoreMembership(store, group, denied);
identityStoreMembership(store, group, other);
User user = user("res-identitystore-lookup");
String membershipArn = "arn:aws:identitystore:::membership/" + deniedMembership;
user.policy(allowOn("identitystore:GetUserId", "*") + "," + allowOn("identitystore:GetGroupMembershipId", "*")
+ "," + denyOn("identitystore:GetUserId", "arn:aws:identitystore:::user/" + denied) + ","
+ denyOn("identitystore:GetGroupMembershipId", membershipArn));
refusedJson(getUserId(user, store, deniedName), "identitystore:GetUserId");
getUserId(user, store, otherName).statusCode(200).body("UserId", equalTo(other));
refusedJson(getGroupMembershipId(user, store, group, denied), "identitystore:GetGroupMembershipId");
getGroupMembershipId(user, store, group, other).statusCode(200);
}
private static ValidatableResponse getUserId(User user, String store, String userName) {
return send(user, "identitystore", "AWSIdentityStore.GetUserId", "1.1", "{\"IdentityStoreId\":\"" + store
+ "\",\"AlternateIdentifier\":{\"UniqueAttribute\":{\"AttributePath\":\"userName\","
+ "\"AttributeValue\":\"" + userName + "\"}}}");
}
private static ValidatableResponse getGroupMembershipId(User user, String store, String group, String member) {
return send(user, "identitystore", "AWSIdentityStore.GetGroupMembershipId", "1.1", "{\"IdentityStoreId\":\""
+ store + "\",\"GroupId\":\"" + group + "\",\"MemberId\":{\"UserId\":\"" + member + "\"}}");
}
/** A group of the identity store, created as the admin and deleted after the test; its id. */
private String identityStoreGroup(String store, String displayName) {
String groupId = adminJson("identitystore", "AWSIdentityStore.CreateGroup")
.body("{\"IdentityStoreId\":\"" + store + "\",\"DisplayName\":\"" + displayName + "\"}")
.post("/").then().statusCode(200).extract().path("GroupId");
cleanup.register(() -> adminJson("identitystore", "AWSIdentityStore.DeleteGroup")
.body("{\"IdentityStoreId\":\"" + store + "\",\"GroupId\":\"" + groupId + "\"}").post("/"));
return groupId;
}
/** The membership of a user in a group of the identity store, created as the admin; its id. */
private String identityStoreMembership(String store, String group, String member) {
return adminJson("identitystore", "AWSIdentityStore.CreateGroupMembership")
.body("{\"IdentityStoreId\":\"" + store + "\",\"GroupId\":\"" + group + "\",\"MemberId\":{"
+ "\"UserId\":\"" + member + "\"}}")
.post("/").then().statusCode(200).extract().path("MembershipId");
}
/** A user of the identity store, created as the admin and deleted after the test; its id. */
private String identityStoreUser(String store) {
return identityStoreUser(store, "res-" + suffix());
}
/** A user of the identity store of that name, created as the admin and deleted after the test; its id. */
private String identityStoreUser(String store, String userName) {
String userId = adminJson("identitystore", "AWSIdentityStore.CreateUser")
.body("{\"IdentityStoreId\":\"" + store + "\",\"UserName\":\"" + userName + "\","
+ "\"DisplayName\":\"Res\"}")
.post("/").then().statusCode(200).extract().path("UserId");
cleanup.register(() -> adminJson("identitystore", "AWSIdentityStore.DeleteUser")
.body("{\"IdentityStoreId\":\"" + store + "\",\"UserId\":\"" + userId + "\"}").post("/"));
return userId;
}
private static ValidatableResponse glue(String operation, String body) {
return adminJson("glue", "AWSGlue." + operation).body(body).post("/").then();
}
@@ -3777,6 +3889,10 @@ class IamRequestResourceEnforcementIntegrationTest {
return "{\"Effect\":\"Allow\",\"Action\":\"" + action + "\",\"Resource\":\"" + resource + "\"}";
}
private static String denyOn(String action, String resource) {
return "{\"Effect\":\"Deny\",\"Action\":\"" + action + "\",\"Resource\":\"" + resource + "\"}";
}
private User user(String name) {
String userName = name + "-" + suffix();
return new User(userName, EnforcementFixtures.createUser(cleanup, baseUri.getPort(), auth(ADMIN, "iam"),
@@ -1977,6 +1977,72 @@ class ResourceArnBuilderTest {
builder.buildResources("elasticache", "elasticache:ModifyUserGroup", ctx, "us-west-2", ACCOUNT, "aws"));
}
// ── Identity Store ──────────────────────────────────────────────────────────
/**
* An Identity Store request is checked on the identity store its IdentityStoreId names and on the user or group its
* id names, whose ARN has no Region and no account; a list is checked on every user, as the Service Reference gives
* it.
*/
@Test
void identityStoreChecksTheStoreAndTheUserARequestNames() {
setJsonBody("{\"IdentityStoreId\":\"d-1234567890\",\"UserId\":\"1234567890-u1\"}");
assertEquals(List.of("arn:aws:identitystore::000000000000:identitystore/d-1234567890",
"arn:aws:identitystore:::user/1234567890-u1"),
builder.buildResources("identitystore", "identitystore:DescribeUser", ctx, "us-east-1", ACCOUNT, "aws"));
setJsonBody("{\"IdentityStoreId\":\"d-1234567890\"}");
assertEquals(List.of("arn:aws:identitystore:::user/*",
"arn:aws:identitystore::000000000000:identitystore/d-1234567890"),
builder.buildResources("identitystore", "identitystore:ListUsers", ctx, "us-east-1", ACCOUNT, "aws"));
}
/**
* A required type an Identity Store request does not name is asked of the service: a membership's group and user
* through its id, and a lookup's user by the members of the one way its alternate identifier is given, with their
* paths, as the table writes them.
*/
@Test
void identityStoreAsksTheServiceForTheRequiredTypesARequestDoesNotName() {
List<List<String>> asked = new ArrayList<>();
ResourceArnBuilder reading = reading(new StoredResourceArns() {
@Override
public String namespace() {
return "identitystore";
}
@Override
public Optional<String> find(String type, List<String> names, String region) {
return Optional.empty();
}
@Override
public Optional<String> findByMembers(String type, List<String> members, List<String> names,
String region) {
asked.add(members);
return Optional.of("arn:aws:identitystore:::user/" + names.getLast());
}
@Override
public List<String> through(String member, String value, String region) {
return List.of("arn:aws:identitystore:::group/g-of-" + value,
"arn:aws:identitystore:::user/u-of-" + value);
}
});
setJsonBody("{\"IdentityStoreId\":\"d-1234567890\",\"MembershipId\":\"m1\"}");
assertEquals(List.of("arn:aws:identitystore:::membership/m1",
"arn:aws:identitystore::000000000000:identitystore/d-1234567890",
"arn:aws:identitystore:::group/g-of-m1", "arn:aws:identitystore:::user/u-of-m1"),
reading.buildResources("identitystore", "identitystore:DeleteGroupMembership", ctx, "us-east-1",
ACCOUNT, "aws"));
setJsonBody("{\"IdentityStoreId\":\"d-1234567890\",\"AlternateIdentifier\":{\"UniqueAttribute\":"
+ "{\"AttributePath\":\"userName\",\"AttributeValue\":\"alice\"}}}");
assertEquals(List.of("arn:aws:identitystore::000000000000:identitystore/d-1234567890",
"arn:aws:identitystore:::user/alice"),
reading.buildResources("identitystore", "identitystore:GetUserId", ctx, "us-east-1", ACCOUNT, "aws"));
assertEquals(List.of(List.of("IdentityStoreId", "AlternateIdentifier.UniqueAttribute.AttributePath",
"AlternateIdentifier.UniqueAttribute.AttributeValue")), asked);
}
// ── S3 and S3 Control ───────────────────────────────────────────────────────
/** The resources an S3 or S3 Control request names, read from the generated table on the route it matches. */
@@ -0,0 +1,87 @@
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.RegionResolver;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.services.identitystore.model.Group;
import io.floci.aws.services.identitystore.model.Membership;
import io.floci.aws.services.identitystore.model.User;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Identity Store answers IAM with the group and the user of a membership its id names, and with the group, user or
* membership a lookup's members find, as its handlers find them.
*/
class IdentityStoreStoredResourceArnsTest {
private static final String STORE = "d-1234567890";
private static final String GLOBAL_PARTITION = "000000000000";
private static final String REGION = "us-east-1";
private final ObjectMapper mapper = new ObjectMapper();
private IdentityStoreService service;
private IdentityStoreStoredResourceArns stored;
private Group group;
private User user;
private Membership membership;
@BeforeEach
void setUp() {
service = new IdentityStoreService(AccountAwareStorageBackend.inMemory(GLOBAL_PARTITION),
AccountAwareStorageBackend.inMemory(GLOBAL_PARTITION),
AccountAwareStorageBackend.inMemory(GLOBAL_PARTITION), mapper);
stored = new IdentityStoreStoredResourceArns(service, new RegionResolver(REGION, GLOBAL_PARTITION));
group = service.createGroup(mapper.createObjectNode().put("IdentityStoreId", STORE)
.put("DisplayName", "Admins"));
user = service.createUser(mapper.createObjectNode().put("IdentityStoreId", STORE).put("UserName", "alice")
.put("DisplayName", "Alice"));
ObjectNode request = mapper.createObjectNode().put("IdentityStoreId", STORE).put("GroupId", group.groupId());
request.putObject("MemberId").put("UserId", user.userId());
membership = service.createMembership(request);
}
@Test
void aMembershipReachesItsGroupAndItsUser() {
assertEquals(List.of("arn:aws:identitystore:::group/" + group.groupId(),
"arn:aws:identitystore:::user/" + user.userId()),
stored.through("MembershipId", membership.membershipId(), REGION));
assertEquals(List.of(), stored.through("MembershipId", "1234567890-missing", REGION));
assertEquals(List.of(), stored.through("GroupId", group.groupId(), REGION));
}
@Test
void aLookupFindsWhatItsHandlerFinds() {
assertEquals(Optional.of("arn:aws:identitystore:::membership/" + membership.membershipId()),
stored.findByMembers("GroupMembership", List.of("IdentityStoreId", "GroupId", "MemberId.UserId"),
List.of(STORE, group.groupId(), user.userId()), REGION));
assertEquals(Optional.of("arn:aws:identitystore:::user/" + user.userId()),
stored.findByMembers("User", List.of("IdentityStoreId",
"AlternateIdentifier.UniqueAttribute.AttributePath",
"AlternateIdentifier.UniqueAttribute.AttributeValue"),
List.of(STORE, "userName", "alice"), REGION));
assertEquals(Optional.of("arn:aws:identitystore:::group/" + group.groupId()),
stored.findByMembers("Group", List.of("IdentityStoreId",
"AlternateIdentifier.UniqueAttribute.AttributePath",
"AlternateIdentifier.UniqueAttribute.AttributeValue"),
List.of(STORE, "displayName", "Admins"), REGION));
}
@Test
void aLookupFindingNothingFindsNone() {
assertEquals(Optional.empty(), stored.findByMembers("User", List.of("IdentityStoreId",
"AlternateIdentifier.UniqueAttribute.AttributePath",
"AlternateIdentifier.UniqueAttribute.AttributeValue"),
List.of(STORE, "userName", "nobody"), REGION));
assertEquals(Optional.empty(), stored.findByMembers("Group", List.of("IdentityStoreId",
"AlternateIdentifier.ExternalId.Issuer", "AlternateIdentifier.ExternalId.Id"),
List.of(STORE, "issuer", "none"), REGION));
assertEquals(Optional.empty(), stored.find("User", List.of("alice"), REGION));
}
}
@@ -414,6 +414,8 @@ class TaskPermissionsTest {
void aRedshiftDataCallOnAWorkgroupIsEvaluatedOnTheOneItsNameFinds() throws Exception {
String workgroup = "arn:aws:redshift-serverless:eu-west-1:" + ACCOUNT + ":workgroup/1234";
StoredResourceArns stored = mock(StoredResourceArns.class);
// The reader asks with the members' paths too, which a service finding by the values alone leaves to them.
when(stored.findByMembers(any(), any(), any(), any())).thenCallRealMethod();
when(stored.findByMembers(eq("workgroup"), eq(List.of("analytics")), eq("eu-west-1"))).thenReturn(Optional.of(workgroup));
assertEquals(List.of(new Permission("redshift-data:ExecuteStatement", workgroup),
new Permission("redshift-serverless:GetCredentials", workgroup)),