fix(identitystore): refuse an identity store to accounts outside its organization (#9346)

Identity Store checked only that an IdentityStoreId was well formed, so any
account could read and change the users, groups and memberships of any
store, the default account's IAM Identity Center store among them.

The IAM Identity Center User Guide says who may use an organization
instance's store: "Member accounts have access to Read actions on both the
sso-directory and identitystore namespaces", while adding, editing or
deleting users or groups is the management account's and a delegated
administrator's. SsoAdminService now answers how an account may use a store
from the instance that holds it: its own account, and a delegated
administrator for IAM Identity Center in an organization instance's
organization, in full; another account of that organization to read; any
other account not at all. Identity Store's handler refuses a store an
account cannot see as ResourceNotFoundException (ResourceType
IDENTITY_STORE) and a change from an account that may only read as
AccessDeniedException. A store no instance holds is used as before.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-24 10:40:42 -04:00
1 parent 0c4fa969e3
commit 49a59da5e6
6 files changed
+217 -21

No files matched your search

@@ -6,6 +6,8 @@ import io.restassured.response.ValidatableResponse;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
@@ -148,10 +150,59 @@ class IdentityStoreIntegrationTest {
.body("UserName", equalTo("immutable@example.com"));
}
/**
* The default account's IAM Identity Center instance holds its identity store, which an account outside that
* account's organization cannot see, and a store no instance holds stays usable by any account. The refused
* requests leave that account with no instance of its own.
*/
@Test
void anotherAccountCannotSeeTheDefaultAccountsIdentityStore() {
String outsiderAccount = "210987654321";
String outsider = "AWS4-HMAC-SHA256 Credential=" + outsiderAccount
+ "/20260904/us-east-1/identitystore/aws4_request";
String owned = "d-9067f2a3c1";
String userId = json("AWSIdentityStore.CreateUser",
"{\"IdentityStoreId\":\"" + owned + "\",\"UserName\":\"owner-only-" + UUID.randomUUID()
+ "@example.com\",\"DisplayName\":\"Owner Only\"}")
.statusCode(200).extract().path("UserId");
try {
json(outsider, "AWSIdentityStore.DescribeUser",
"{\"IdentityStoreId\":\"" + owned + "\",\"UserId\":\"" + userId + "\"}")
.statusCode(400)
.body("__type", equalTo("ResourceNotFoundException"))
.body("ResourceType", equalTo("IDENTITY_STORE"));
json(outsider, "AWSIdentityStore.ListUsers", "{\"IdentityStoreId\":\"" + owned + "\"}")
.statusCode(400).body("__type", equalTo("ResourceNotFoundException"));
json(outsider, "AWSIdentityStore.CreateUser",
"{\"IdentityStoreId\":\"" + owned + "\",\"UserName\":\"intruder-" + UUID.randomUUID()
+ "@example.com\",\"DisplayName\":\"Intruder\"}")
.statusCode(400).body("__type", equalTo("ResourceNotFoundException"));
json(outsider, "AWSIdentityStore.ListUsers", "{\"IdentityStoreId\":\"" + STORE + "\"}")
.statusCode(200);
given()
.contentType(TYPE)
.header("Authorization", "AWS4-HMAC-SHA256 Credential=" + outsiderAccount
+ "/20260904/us-east-1/sso/aws4_request")
.header("X-Amz-Target", "SWBExternalService.ListInstances")
.body("{}")
.post("/")
.then()
.statusCode(200)
.body("Instances", hasSize(0));
} finally {
json("AWSIdentityStore.DeleteUser",
"{\"IdentityStoreId\":\"" + owned + "\",\"UserId\":\"" + userId + "\"}");
}
}
private static ValidatableResponse json(String target, String body) {
return json(AUTH, target, body);
}
private static ValidatableResponse json(String auth, String target, String body) {
return given()
.contentType(TYPE)
.header("Authorization", AUTH)
.header("Authorization", auth)
.header("X-Amz-Target", target)
.body(body)
.post("/")
@@ -9,6 +9,7 @@ import io.floci.aws.core.storage.InMemoryStorage;
import io.floci.aws.core.storage.StorageBackend;
import io.floci.aws.services.identitystore.IdentityStoreService;
import io.floci.aws.services.organizations.OrganizationsService;
import io.floci.aws.services.organizations.model.OrganizationAccount;
import io.floci.aws.services.ssoadmin.model.ApplicationAccessScope;
import io.floci.aws.services.ssoadmin.model.ApplicationAssignment;
import io.floci.aws.services.ssoadmin.model.ApplicationAuthenticationMethod;
@@ -32,9 +33,11 @@ import org.mockito.Mockito;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -2057,6 +2060,47 @@ class SsoAdminServiceTest {
return request;
}
@Test
void anOrganizationInstancesStoreIsTheOwnersInFullItsMembersToReadAndNoOneElses() {
String store = service.getIdentityStoreId();
String member = "210987654321";
String delegated = "310987654321";
Mockito.when(organizationsService.findManagementAccountForResource(member)).thenReturn(Optional.of(ACCOUNT_ID));
Mockito.when(organizationsService.findManagementAccountForResource(delegated))
.thenReturn(Optional.of(ACCOUNT_ID));
Mockito.when(organizationsService.findAccount(member)).thenReturn(Optional.of(account(member)));
OrganizationAccount administrator = account(delegated);
administrator.getDelegatedServices().put("sso.amazonaws.com", Instant.EPOCH);
Mockito.when(organizationsService.findAccount(delegated)).thenReturn(Optional.of(administrator));
assertEquals(IdentityStoreAccess.FULL, service.identityStoreAccess(store, ACCOUNT_ID));
assertEquals(IdentityStoreAccess.READ, service.identityStoreAccess(store, member));
assertEquals(IdentityStoreAccess.FULL, service.identityStoreAccess(store, delegated));
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"));
}
@Test
void anAccountInstancesStoreIsItsAccountsAlone() {
String owner = "510987654321";
instances.put(owner, new SsoInstance("arn:aws:sso:::instance/ssoins-1111111111111111", "d-5555555555",
"account-instance", owner, "us-east-1", 0L, "ACTIVE", null, true, new LinkedHashMap<>()));
Mockito.when(organizationsService.findManagementAccountForResource(ACCOUNT_ID)).thenReturn(Optional.of(owner));
assertEquals(IdentityStoreAccess.FULL, service.identityStoreAccess("d-5555555555", owner));
assertEquals(IdentityStoreAccess.NONE, service.identityStoreAccess("d-5555555555", ACCOUNT_ID));
// An instance a reset or a restore takes away is not answered from what was last found.
instances.delete(owner);
assertEquals(IdentityStoreAccess.FULL, service.identityStoreAccess("d-5555555555", ACCOUNT_ID));
}
private static OrganizationAccount account(String id) {
OrganizationAccount account = new OrganizationAccount();
account.setId(id);
return account;
}
private static void assertError(String expectedCode, Runnable operation) {
AwsException error = assertThrows(AwsException.class, operation::run);
assertEquals(expectedCode, error.getErrorCode());