mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
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:
1 parent
0c4fa969e3
commit
49a59da5e6
6 files changed
+217
-21
No files matched your search
@@ -44,6 +44,8 @@ Deleting a user or group removes its related local group memberships so subseque
|
||||
|
||||
With IAM enforcement on, each action is checked on the resources the AWS Service Authorization Reference lists for it, read from the request: the identity store its `IdentityStoreId` names, `arn:aws:identitystore::<account>:identitystore/<id>`, and the group, user or membership its `GroupId`, `UserId`, `MemberId.UserId` or `MembershipId` names, `arn:aws:identitystore:::group/<id>` with no Region or account. The list actions are also checked on every group, user or membership (`arn:aws:identitystore:::user/*`), as the reference gives them. A type the reference marks an action as requiring that the request does not name is the one Identity Store finds from what it holds: `DescribeGroupMembership` and `DeleteGroupMembership` are also checked on the group and the user of the membership their `MembershipId` names, `GetGroupMembershipId` on the membership of its group and member, and `GetGroupId` and `GetUserId` on the group or user their `AlternateIdentifier` names; a lookup that finds nothing is checked on every resource of its type (`arn:aws:identitystore:::user/*`).
|
||||
|
||||
An identity store an IAM Identity Center instance holds belongs to that instance's account, as the IAM Identity Center User Guide describes: that account, and a delegated administrator for IAM Identity Center in an organization instance's organization, use it in full; another account of that organization can only read it ("Member accounts have access to Read actions on both the sso-directory and identitystore namespaces"), and a `Create`, `Update` or `Delete` action from it is refused with `AccessDeniedException`; any other account gets `ResourceNotFoundException` with `ResourceType` `IDENTITY_STORE`. A store no instance holds can be used by any account.
|
||||
|
||||
## IAM Identity Center SCIM
|
||||
|
||||
Floci also accepts IAM Identity Center SCIM v2 requests under `/{tenant_id}/scim/v2`. SCIM requests require the AWS-supported `Authorization: Bearer <token>` authentication shape. Because Floci does not provision real IAM Identity Center access tokens, it validates against the configured local token. The default is `floci-scim-token`; set `FLOCI_SERVICES_IDENTITYSTORE_SCIM_BEARER_TOKEN` to override it. The tenant must also resolve to an existing IAM Identity Center identity store.
|
||||
|
||||
@@ -6,30 +6,43 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.PaginatedResult;
|
||||
import io.floci.aws.core.common.RequestContext;
|
||||
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.IdentityStoreAccess;
|
||||
import io.floci.aws.services.ssoadmin.SsoAdminService;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ApplicationScoped
|
||||
public class IdentityStoreJsonHandler {
|
||||
private static final String ENTERPRISE_EXTENSION = "aws:identitystore:enterprise";
|
||||
/** The actions that change an identity store, which the Service Authorization Reference gives the Write level. */
|
||||
private static final Pattern WRITE_ACTION = Pattern.compile("(Create|Update|Delete)[A-Z]");
|
||||
|
||||
private final IdentityStoreService service;
|
||||
private final ObjectMapper mapper;
|
||||
private final SsoAdminService ssoAdmin;
|
||||
private final RequestContext requestContext;
|
||||
|
||||
@Inject
|
||||
public IdentityStoreJsonHandler(IdentityStoreService service, ObjectMapper mapper) {
|
||||
public IdentityStoreJsonHandler(IdentityStoreService service, ObjectMapper mapper, SsoAdminService ssoAdmin,
|
||||
RequestContext requestContext) {
|
||||
this.service = service;
|
||||
this.mapper = mapper;
|
||||
this.ssoAdmin = ssoAdmin;
|
||||
this.requestContext = requestContext;
|
||||
}
|
||||
|
||||
public Response handle(String action, JsonNode request) {
|
||||
requireAccess(action, request);
|
||||
return switch (action) {
|
||||
case "CreateGroup" -> createGroup(request);
|
||||
case "DeleteGroup" -> emptyAfter(() -> service.deleteGroup(request));
|
||||
@@ -55,6 +68,26 @@ public class IdentityStoreJsonHandler {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Refuses a request on an identity store the caller may not use so ({@link SsoAdminService#identityStoreAccess}):
|
||||
* one it cannot see as not found, and a change from an account that may only read the store as access denied.
|
||||
*/
|
||||
private void requireAccess(String action, JsonNode request) {
|
||||
String storeId = request == null ? null : request.path("IdentityStoreId").asText(null);
|
||||
if (storeId == null) {
|
||||
return;
|
||||
}
|
||||
IdentityStoreAccess access = ssoAdmin.identityStoreAccess(storeId, requestContext.getAccountId());
|
||||
if (access == IdentityStoreAccess.NONE) {
|
||||
throw new AwsException("ResourceNotFoundException", "Identity store not found: " + storeId, 400,
|
||||
Map.of("ResourceType", "IDENTITY_STORE", "ResourceId", storeId));
|
||||
}
|
||||
if (access == IdentityStoreAccess.READ && WRITE_ACTION.matcher(action).lookingAt()) {
|
||||
throw new AwsException("AccessDeniedException",
|
||||
"You do not have sufficient access to perform this action.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private Response createGroup(JsonNode request) {
|
||||
Group group = service.createGroup(request);
|
||||
ObjectNode out = mapper.createObjectNode();
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.floci.aws.services.ssoadmin;
|
||||
|
||||
/** How an account may use an identity store ({@link SsoAdminService#identityStoreAccess}). */
|
||||
public enum IdentityStoreAccess {
|
||||
/** Every Identity Store action: the store's own account, or its organization's delegated administrator. */
|
||||
FULL,
|
||||
/** Only the read actions: another account of an organization instance's organization. */
|
||||
READ,
|
||||
/** None: the store is not one the account can see. */
|
||||
NONE
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import io.floci.aws.core.common.EpochSeconds;
|
||||
import io.floci.aws.core.common.PaginatedResult;
|
||||
import io.floci.aws.core.common.Pagination;
|
||||
import io.floci.aws.core.common.Resettable;
|
||||
import io.floci.aws.core.common.ServicePrincipals;
|
||||
import io.floci.aws.core.common.StoredResourceArns;
|
||||
import io.floci.aws.core.common.UuidShapes;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
@@ -54,6 +55,7 @@ import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -61,6 +63,7 @@ import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -71,6 +74,8 @@ import java.util.stream.Collectors;
|
||||
public class SsoAdminService implements Resettable, StoredResourceArns {
|
||||
private static final String BOOTSTRAP_INSTANCE = "instance/ssoins-7223b02a5d9f7c8e";
|
||||
private static final String IDENTITY_STORE_ID = "d-9067f2a3c1";
|
||||
/** The service principal an organization registers a delegated administrator for IAM Identity Center under. */
|
||||
private static final String SSO_SERVICE_PRINCIPAL = ServicePrincipals.of("sso");
|
||||
private static final Pattern INSTANCE_ARN_PATTERN = Pattern.compile("arn:" + AwsArnUtils.PARTITION_REGEX + ":sso:::instance/(?:sso)?ins-[a-zA-Z0-9-.]{16}");
|
||||
private static final Pattern PERMISSION_SET_NAME = Pattern.compile("[\\w+=,.@-]+");
|
||||
private static final Pattern PERMISSION_SET_ARN = Pattern.compile("arn:" + AwsArnUtils.PARTITION_REGEX + ":sso:::permissionSet/(?:sso)?ins-[a-zA-Z0-9-.]{16}/ps-[a-zA-Z0-9-./]{16}");
|
||||
@@ -136,6 +141,11 @@ public class SsoAdminService implements Resettable, StoredResourceArns {
|
||||
private final StorageBackend<String, InstanceUpdateState> instanceUpdateStates;
|
||||
private final StorageBackend<String, String> instanceClientTokens;
|
||||
private final StorageBackend<String, Boolean> instanceDeletionMarkers;
|
||||
/**
|
||||
* The account whose instance holds each identity store, as last found: each entry is checked against that
|
||||
* account's instance before it is used, so one a reset or a restore outdates is found again by the scan.
|
||||
*/
|
||||
private final Map<String, String> identityStoreOwners = new ConcurrentHashMap<>();
|
||||
private final StorageBackend<String, InstanceAccessControlAttributeConfiguration> accessControlAttributeConfigurations;
|
||||
private final StorageBackend<String, TrustedTokenIssuer> trustedTokenIssuers;
|
||||
private final StorageBackend<String, TrustedTokenIssuer> trustedTokenIssuerUpdateOverrides;
|
||||
@@ -269,34 +279,78 @@ public class SsoAdminService implements Resettable, StoredResourceArns {
|
||||
public String getIdentityStoreId() { return IDENTITY_STORE_ID; }
|
||||
|
||||
public boolean hasIdentityStore(String identityStoreId) {
|
||||
return instanceHoldingIdentityStore(identityStoreId, defaultAccountId).isPresent();
|
||||
}
|
||||
|
||||
/**
|
||||
* How an account may use an identity store, as the IAM Identity Center User Guide gives it: the account its
|
||||
* instance belongs to, and a delegated administrator for IAM Identity Center in an organization instance's
|
||||
* organization, in full; another account of that organization only to read ("Member accounts have access to
|
||||
* Read actions on both the sso-directory and identitystore namespaces"); any other account not at all. A store
|
||||
* no instance holds is not IAM Identity Center's, and any account uses it in full.
|
||||
*/
|
||||
public IdentityStoreAccess identityStoreAccess(String identityStoreId, String callerAccountId) {
|
||||
Optional<SsoInstance> holding = instanceHoldingIdentityStore(identityStoreId, callerAccountId);
|
||||
if (holding.isEmpty() || holding.get().ownerAccountId().equals(callerAccountId)) {
|
||||
return IdentityStoreAccess.FULL;
|
||||
}
|
||||
SsoInstance instance = holding.get();
|
||||
boolean member = !instance.accountInstance() && organizationsService
|
||||
.findManagementAccountForResource(callerAccountId)
|
||||
.filter(instance.ownerAccountId()::equals)
|
||||
.isPresent();
|
||||
if (!member) {
|
||||
return IdentityStoreAccess.NONE;
|
||||
}
|
||||
boolean delegated = organizationsService.findAccount(callerAccountId)
|
||||
.map(account -> account.getDelegatedServices().containsKey(SSO_SERVICE_PRINCIPAL))
|
||||
.orElse(false);
|
||||
return delegated ? IdentityStoreAccess.FULL : IdentityStoreAccess.READ;
|
||||
}
|
||||
|
||||
/**
|
||||
* The instance holding the identity store, read where its account keeps its one instance: the caller's, the
|
||||
* default account's, or the one last found holding it ({@code identityStoreOwners}). Only a store none of those
|
||||
* holds is looked for among every account's instances, which records each instance's store for the next request.
|
||||
*/
|
||||
private Optional<SsoInstance> instanceHoldingIdentityStore(String identityStoreId, String callerAccountId) {
|
||||
if (identityStoreId == null) {
|
||||
return false;
|
||||
return Optional.empty();
|
||||
}
|
||||
// Self-heals like listInstances(): storageFactory.clearAll() wipes `instances` right after
|
||||
// clear() re-seeds it, so /state/reset otherwise leaves the bootstrap instance missing.
|
||||
ensureBootstrapInstance(defaultAccountId, defaultRegion);
|
||||
if (instances.scan(key -> true).stream()
|
||||
.anyMatch(instance -> identityStoreId.equals(instance.identityStoreId()))) {
|
||||
return true;
|
||||
Set<String> accounts = new LinkedHashSet<>(List.of(callerAccountId, defaultAccountId));
|
||||
Optional.ofNullable(identityStoreOwners.get(identityStoreId)).ifPresent(accounts::add);
|
||||
for (String account : accounts) {
|
||||
Optional<SsoInstance> own = AccountAwareStorageBackend.getInAccount(instances, account, account)
|
||||
.filter(instance -> identityStoreId.equals(instance.identityStoreId()));
|
||||
if (own.isPresent()) {
|
||||
return own;
|
||||
}
|
||||
}
|
||||
if (instances instanceof AccountAwareStorageBackend<?> accountAware) {
|
||||
return accountAware.scanAllAccounts().stream()
|
||||
.filter(SsoInstance.class::isInstance)
|
||||
.map(SsoInstance.class::cast)
|
||||
.anyMatch(instance -> identityStoreId.equals(instance.identityStoreId()));
|
||||
}
|
||||
return false;
|
||||
identityStoreOwners.remove(identityStoreId);
|
||||
List<SsoInstance> all = instances instanceof AccountAwareStorageBackend<SsoInstance> accountAware
|
||||
? accountAware.scanAllAccounts() : instances.scan(key -> true);
|
||||
all.forEach(instance -> identityStoreOwners.put(instance.identityStoreId(), instance.ownerAccountId()));
|
||||
return all.stream().filter(instance -> identityStoreId.equals(instance.identityStoreId())).findFirst();
|
||||
}
|
||||
|
||||
/**
|
||||
* Seeds the account's bootstrap instance where that account keeps it, whichever account's request runs: an
|
||||
* Identity Store request of another account heals the default account's instance, never a copy of its own.
|
||||
*/
|
||||
void ensureBootstrapInstance(String ownerAccountId, String region) {
|
||||
if (instanceDeletionMarkers.get(ownerAccountId).orElse(false)) {
|
||||
if (AccountAwareStorageBackend.getInAccount(instanceDeletionMarkers, ownerAccountId, ownerAccountId)
|
||||
.orElse(false)) {
|
||||
return;
|
||||
}
|
||||
Optional<SsoInstance> stored = instances.get(ownerAccountId);
|
||||
Optional<SsoInstance> stored = AccountAwareStorageBackend.getInAccount(instances, ownerAccountId,
|
||||
ownerAccountId);
|
||||
if (stored.isEmpty()) {
|
||||
instances.put(ownerAccountId, new SsoInstance(bootstrapInstanceArn, IDENTITY_STORE_ID,
|
||||
"floci-identity-center", ownerAccountId, region, System.currentTimeMillis(), "ACTIVE",
|
||||
null, false, new LinkedHashMap<>()));
|
||||
AccountAwareStorageBackend.putInAccount(instances, ownerAccountId, ownerAccountId,
|
||||
new SsoInstance(bootstrapInstanceArn, IDENTITY_STORE_ID, "floci-identity-center", ownerAccountId,
|
||||
region, System.currentTimeMillis(), "ACTIVE", null, false, new LinkedHashMap<>()));
|
||||
return;
|
||||
}
|
||||
// Before the seeded instance took its partition it was stored as arn:aws: in every
|
||||
@@ -305,9 +359,10 @@ public class SsoAdminService implements Resettable, StoredResourceArns {
|
||||
SsoInstance instance = stored.get();
|
||||
String expectedArn = globalArn("sso", instance.primaryRegion(), "", BOOTSTRAP_INSTANCE);
|
||||
if (instance.instanceArn().endsWith(":" + BOOTSTRAP_INSTANCE) && !instance.instanceArn().equals(expectedArn)) {
|
||||
instances.put(ownerAccountId, new SsoInstance(expectedArn, instance.identityStoreId(), instance.name(),
|
||||
instance.ownerAccountId(), instance.primaryRegion(), instance.createdDateEpochMillis(),
|
||||
instance.status(), instance.statusReason(), instance.accountInstance(), instance.tags()));
|
||||
AccountAwareStorageBackend.putInAccount(instances, ownerAccountId, ownerAccountId,
|
||||
new SsoInstance(expectedArn, instance.identityStoreId(), instance.name(),
|
||||
instance.ownerAccountId(), instance.primaryRegion(), instance.createdDateEpochMillis(),
|
||||
instance.status(), instance.statusReason(), instance.accountInstance(), instance.tags()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+52
-1
@@ -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());
|
||||
|
||||
Reference in new issue
Block a user