fix(identitystore): check an identity store in the account that holds it (#9363)

Under IAM enforcement an Identity Store request was checked on
arn:aws:identitystore::<caller>:identitystore/<id>, whatever account's IAM
Identity Center instance holds the store, so another account of its
organization reading it was checked on a store of its own account, and a
grant there reached it.

Every ARN names the account owning its resource. Identity Store's lookup
now answers the store's ARN in the account whose instance holds it
(SsoAdminService.identityStoreOwner), which the reader already asks a
service for for a resource filled from one member, so the request is checked
on the store where it is. A store no instance holds keeps the caller's
account, as before. No generator or table change.

The lookup a store's owner takes remembers a store no instance holds, so
a request naming one again does not look through every account's
instances again; the record empties whenever an instance is written and on
reset, as only those make a store held that was not, and starts over past
10,000 stores.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-24 11:58:15 -04:00
1 parent 93460ae2d9
commit bb579d5fe4
6 files changed
+121 -12

No files matched your search

@@ -1996,6 +1996,32 @@ class ResourceArnBuilderTest {
builder.buildResources("identitystore", "identitystore:ListUsers", ctx, "us-east-1", ACCOUNT, "aws"));
}
/**
* An identity store is checked in the account whose instance holds it, which the service answers for the store an
* {@code IdentityStoreId} names, not in the caller's.
*/
@Test
void identityStoreChecksTheStoreInTheAccountItsServiceGives() {
ResourceArnBuilder reading = reading(new StoredResourceArns() {
@Override
public String namespace() {
return "identitystore";
}
@Override
public Optional<String> find(String type, List<String> names, String region) {
return "Identitystore".equals(type)
? Optional.of("arn:aws:identitystore::111122223333:identitystore/" + names.getFirst())
: Optional.empty();
}
});
setJsonBody("{\"IdentityStoreId\":\"d-1234567890\",\"UserId\":\"1234567890-u1\"}");
assertEquals(List.of("arn:aws:identitystore::111122223333:identitystore/d-1234567890",
"arn:aws:identitystore:::user/1234567890-u1"),
reading.buildResources("identitystore", "identitystore:DescribeUser", 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
@@ -7,8 +7,10 @@ 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 io.floci.aws.services.ssoadmin.SsoAdminService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import java.util.List;
import java.util.Optional;
@@ -27,6 +29,7 @@ class IdentityStoreStoredResourceArnsTest {
private final ObjectMapper mapper = new ObjectMapper();
private IdentityStoreService service;
private SsoAdminService ssoAdmin;
private IdentityStoreStoredResourceArns stored;
private Group group;
private User user;
@@ -37,7 +40,8 @@ class IdentityStoreStoredResourceArnsTest {
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));
ssoAdmin = Mockito.mock(SsoAdminService.class);
stored = new IdentityStoreStoredResourceArns(service, ssoAdmin, 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")
@@ -73,6 +77,16 @@ class IdentityStoreStoredResourceArnsTest {
List.of(STORE, "displayName", "Admins"), REGION));
}
@Test
void anIdentityStoreIsTheOneInTheAccountWhoseInstanceHoldsIt() {
Mockito.when(ssoAdmin.identityStoreOwner(STORE)).thenReturn(Optional.of("111122223333"));
assertEquals(Optional.of("arn:aws:identitystore::111122223333:identitystore/" + STORE),
stored.find("Identitystore", List.of(STORE), REGION));
// A store no instance holds is not answered, so it stays in the caller's account.
Mockito.when(ssoAdmin.identityStoreOwner("d-0000000000")).thenReturn(Optional.empty());
assertEquals(Optional.empty(), stored.find("Identitystore", List.of("d-0000000000"), REGION));
}
@Test
void aLookupFindingNothingFindsNone() {
assertEquals(Optional.empty(), stored.findByMembers("User", List.of("IdentityStoreId",
@@ -39,6 +39,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -61,6 +62,7 @@ class SsoAdminServiceTest {
private InMemoryStorage<String, ApplicationAuthenticationMethod> applicationAuthenticationMethods;
private InMemoryStorage<String, ApplicationGrant> applicationGrants;
private InMemoryStorage<String, SsoInstance> instances;
private int instanceScans;
@BeforeEach
void setUp() {
@@ -70,7 +72,13 @@ class SsoAdminServiceTest {
applicationAccessScopes = new InMemoryStorage<>();
applicationAuthenticationMethods = new InMemoryStorage<>();
applicationGrants = new InMemoryStorage<>();
instances = new InMemoryStorage<>();
instances = new InMemoryStorage<>() {
@Override
public List<SsoInstance> scan(Predicate<String> keyFilter) {
instanceScans++;
return super.scan(keyFilter);
}
};
service = new SsoAdminService(
new InMemoryStorage<String, PermissionSet>(),
new InMemoryStorage<String, Assignment>(),
@@ -2079,6 +2087,8 @@ class SsoAdminServiceTest {
assertEquals(IdentityStoreAccess.NONE, service.identityStoreAccess(store, "410987654321"));
// A store no instance holds is not IAM Identity Center's: any account uses it.
assertEquals(IdentityStoreAccess.FULL, service.identityStoreAccess("d-1234567890", "410987654321"));
assertEquals(Optional.of(ACCOUNT_ID), service.identityStoreOwner(store));
assertEquals(Optional.empty(), service.identityStoreOwner("d-1234567890"));
}
@Test
@@ -2095,6 +2105,21 @@ class SsoAdminServiceTest {
assertEquals(IdentityStoreAccess.FULL, service.identityStoreAccess("d-5555555555", ACCOUNT_ID));
}
@Test
void aStoreNoInstanceHoldsIsLookedForOnceUntilAnInstanceIsWritten() {
int before = instanceScans;
assertEquals(IdentityStoreAccess.FULL, service.identityStoreAccess("d-0000000000", "410987654321"));
assertEquals(IdentityStoreAccess.FULL, service.identityStoreAccess("d-0000000000", "410987654321"));
assertEquals(Optional.empty(), service.identityStoreOwner("d-0000000000"));
assertEquals(before + 1, instanceScans);
// A reset forgets it, so a store an instance comes to hold is found.
service.clear();
String owner = "510987654321";
instances.put(owner, new SsoInstance("arn:aws:sso:::instance/ssoins-2222222222222222", "d-0000000000",
"account-instance", owner, "us-east-1", 0L, "ACTIVE", null, true, new LinkedHashMap<>()));
assertEquals(Optional.of(owner), service.identityStoreOwner("d-0000000000"));
}
private static OrganizationAccount account(String id) {
OrganizationAccount account = new OrganizationAccount();
account.setId(id);