mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(core): compare ARN partitions with the resource's region, not the literal aws (#4791)
* fix(core): compare ARN partitions with the resource's region, not the literal aws Part of #4272 (P10b). Running the Java SDK suite against a Floci deployed in cn-north-1 (#4790) found five checks comparing a parsed ARN with "aws" and a seeded ARN fixed to the commercial partition: - RdsService.hasRdsResourceIdentity required partition aws, so DB instances, clusters, DB and cluster snapshots and subnet groups created outside aws failed their own ownership check and were not found right after creation. The proxy target group check had the same comparison, and CopyDBSnapshot refused any source ARN outside aws; it now requires the target region's partition, since a snapshot copies within its partition. - ElastiCache ListTagsForResource rejected every arn:aws-cn: ARN; it now expects the request region's partition and names it in the message. - RAM ignored organization principals outside aws; any published partition is accepted, the organization id ties the principal to the caller's. - The seeded IAM Identity Center instance was arn:aws:sso:::instance/... in every deployment, so China permission sets never found it. It now takes the partition of the deployment's home region, and AddRegion compares against the instance's own primary region instead of a fixed us-east-1. * fix(sso): move a persisted bootstrap instance to its partition, and drop the fixed China allowlist entries Greptile on #4791: a deployment persisted before the seeded instance took its partition keeps it as arn:aws:sso:::instance/..., while its permission sets were already minted in the instance's own partition, so the fix would not reach it. ensureBootstrapInstance now rewrites a stored bootstrap instance whose ARN is not in its primary region's partition. pgermosen on #4791: with #4790 on main, the cn-north-1 allowlist entries this fixes would turn stale and fail the nightly. Measured against this branch in cn-north-1: CloudFormationRdsDynamicReferenceTest, the ten RdsControlPlaneTest entries, RdsJdbcCompatTest#createDbInstanceAndConnectWithPassword and SsoPortalTest now pass and are deleted. The four IAM-token connection tests still fail because they sign their tokens for a pinned us-east-1, which a cn-north-1 database rightly refuses; they move to the group of tests that pin commercial values. * fix(ram): answer the listing operations for the request's region only Greptile on #4791: with organization principals accepted in every partition, a commercial GetResourceShares from a member of the organization returned a China share. The cause predates this PR: GetResourceShares, ListResources, ListPrincipals and GetResourceShareInvitations walked every stored share, so a share created in eu-west-1 was listed through us-east-1 too, while a resource share is a regional resource. RamController now passes the request region and the four operations keep only shares (and invitations to shares) in it, which also keeps a share out of another partition. * fix(ram): resolve a share or invitation to mutate in the request's region only pgermosen on #4791: after the listings were scoped to the request's region, findOwnedShare still walked every stored share, so a share invisible to GetResourceShares in one region could still be deleted, updated, associated, disassociated or retagged from there; AssociateResourceShare would add a resource the same endpoint's ListResources does not report. Accept and RejectResourceShareInvitation had the same gap. The six share mutations and the two invitation responses now take the request region from RamController and resolve only a share or invitation in it: one from another region gets UnknownResourceException or ResourceShareInvitationArnNotFoundException, like an ARN that does not exist.
This commit is contained in:
1 parent
9840b5a998
commit
d72923ab33
11 files changed
+408
-188
No files matched your search
+4
-2
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.elasticache;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegions;
|
||||
import io.github.hectorvent.floci.core.common.BackupWindows;
|
||||
import io.github.hectorvent.floci.core.common.AwsNamespaces;
|
||||
import io.github.hectorvent.floci.core.common.AwsQueryResponse;
|
||||
@@ -660,8 +661,9 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
// Every component names part of the resource, so each is checked before the name is
|
||||
// used: a partition, service, region or account that is not this one asks about a
|
||||
// different resource, and answering from the trailing name would describe the wrong.
|
||||
if (!"aws".equals(arn[1])) {
|
||||
throw new AwsException("InvalidARN", "partition field is wrong. Expected value is aws", 400);
|
||||
String partition = AwsRegions.partitionFor(regionResolver.getRegion());
|
||||
if (!partition.equals(arn[1])) {
|
||||
throw new AwsException("InvalidARN", "partition field is wrong. Expected value is " + partition, 400);
|
||||
}
|
||||
if (!"elasticache".equals(arn[2])) {
|
||||
throw new AwsException("InvalidARN",
|
||||
|
||||
@@ -114,7 +114,8 @@ public class RamController {
|
||||
request.hasNonNull("name") ? request.path("name").asText() : null,
|
||||
stringList(request.path("resourceShareArns")),
|
||||
request.hasNonNull("resourceShareStatus")
|
||||
? request.path("resourceShareStatus").asText() : null);
|
||||
? request.path("resourceShareStatus").asText() : null,
|
||||
regionResolver.getRegion());
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode array = objectMapper.createArrayNode();
|
||||
@@ -128,7 +129,7 @@ public class RamController {
|
||||
@Consumes(MediaType.WILDCARD)
|
||||
public Response deleteResourceShare(@QueryParam("resourceShareArn") String resourceShareArn,
|
||||
@QueryParam("clientToken") String clientToken) {
|
||||
service.deleteResourceShare(resourceShareArn, regionResolver.getAccountId());
|
||||
service.deleteResourceShare(resourceShareArn, regionResolver.getAccountId(), regionResolver.getRegion());
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.put("returnValue", true);
|
||||
@@ -150,7 +151,7 @@ public class RamController {
|
||||
request.hasNonNull("name") ? request.path("name").asText() : null,
|
||||
request.hasNonNull("allowExternalPrincipals")
|
||||
? request.path("allowExternalPrincipals").asBoolean() : null,
|
||||
regionResolver.getAccountId());
|
||||
regionResolver.getAccountId(), regionResolver.getRegion());
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("resourceShare", shareNode(updated));
|
||||
@@ -166,7 +167,8 @@ public class RamController {
|
||||
List<String> resourceArns = stringList(request.path("resourceArns"));
|
||||
List<String> principals = stringList(request.path("principals"));
|
||||
ResourceShare updated = service.associateResourceShare(
|
||||
resourceShareArn, resourceArns, principals, regionResolver.getAccountId());
|
||||
resourceShareArn, resourceArns, principals, regionResolver.getAccountId(),
|
||||
regionResolver.getRegion());
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("resourceShareAssociations",
|
||||
@@ -183,7 +185,8 @@ public class RamController {
|
||||
List<String> resourceArns = stringList(request.path("resourceArns"));
|
||||
List<String> principals = stringList(request.path("principals"));
|
||||
ResourceShare updated = service.disassociateResourceShare(
|
||||
resourceShareArn, resourceArns, principals, regionResolver.getAccountId());
|
||||
resourceShareArn, resourceArns, principals, regionResolver.getAccountId(),
|
||||
regionResolver.getRegion());
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
response.set("resourceShareAssociations",
|
||||
@@ -199,7 +202,8 @@ public class RamController {
|
||||
String resourceOwner = request.hasNonNull("resourceOwner")
|
||||
? request.path("resourceOwner").asText() : null;
|
||||
List<PrincipalAssociation> principals = service.listPrincipals(
|
||||
regionResolver.getAccountId(), resourceOwner, stringList(request.path("resourceShareArns")));
|
||||
regionResolver.getAccountId(), resourceOwner, stringList(request.path("resourceShareArns")),
|
||||
regionResolver.getRegion());
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode array = objectMapper.createArrayNode();
|
||||
@@ -224,7 +228,7 @@ public class RamController {
|
||||
Map<String, String> tags = new LinkedHashMap<>();
|
||||
request.path("tags").forEach(tag -> tags.put(tag.path("key").asText(), tag.path("value").asText()));
|
||||
service.tagResource(request.path("resourceShareArn").asText(), tags,
|
||||
regionResolver.getAccountId());
|
||||
regionResolver.getAccountId(), regionResolver.getRegion());
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
@@ -234,7 +238,7 @@ public class RamController {
|
||||
public Response untagResource(String body) {
|
||||
JsonNode request = readTree(body);
|
||||
service.untagResource(request.path("resourceShareArn").asText(),
|
||||
stringList(request.path("tagKeys")), regionResolver.getAccountId());
|
||||
stringList(request.path("tagKeys")), regionResolver.getAccountId(), regionResolver.getRegion());
|
||||
return Response.ok(objectMapper.createObjectNode()).build();
|
||||
}
|
||||
|
||||
@@ -246,7 +250,8 @@ public class RamController {
|
||||
List<ResourceShareInvitation> invitations = service.getResourceShareInvitations(
|
||||
regionResolver.getAccountId(),
|
||||
stringList(request.path("resourceShareArns")),
|
||||
stringList(request.path("resourceShareInvitationArns")));
|
||||
stringList(request.path("resourceShareInvitationArns")),
|
||||
regionResolver.getRegion());
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode array = objectMapper.createArrayNode();
|
||||
@@ -262,7 +267,8 @@ public class RamController {
|
||||
JsonNode request = readTree(body);
|
||||
String clientToken = request.hasNonNull("clientToken") ? request.path("clientToken").asText() : null;
|
||||
ResourceShareInvitation invitation = service.acceptResourceShareInvitation(
|
||||
request.path("resourceShareInvitationArn").asText(), regionResolver.getAccountId());
|
||||
request.path("resourceShareInvitationArn").asText(), regionResolver.getAccountId(),
|
||||
regionResolver.getRegion());
|
||||
return invitationResponse(invitation, clientToken);
|
||||
}
|
||||
|
||||
@@ -273,7 +279,8 @@ public class RamController {
|
||||
JsonNode request = readTree(body);
|
||||
String clientToken = request.hasNonNull("clientToken") ? request.path("clientToken").asText() : null;
|
||||
ResourceShareInvitation invitation = service.rejectResourceShareInvitation(
|
||||
request.path("resourceShareInvitationArn").asText(), regionResolver.getAccountId());
|
||||
request.path("resourceShareInvitationArn").asText(), regionResolver.getAccountId(),
|
||||
regionResolver.getRegion());
|
||||
return invitationResponse(invitation, clientToken);
|
||||
}
|
||||
|
||||
@@ -308,7 +315,8 @@ public class RamController {
|
||||
String resourceOwner = request.hasNonNull("resourceOwner")
|
||||
? request.path("resourceOwner").asText() : null;
|
||||
List<SharedResource> resources = service.listResources(
|
||||
regionResolver.getAccountId(), resourceOwner, stringList(request.path("resourceShareArns")));
|
||||
regionResolver.getAccountId(), resourceOwner, stringList(request.path("resourceShareArns")),
|
||||
regionResolver.getRegion());
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode array = objectMapper.createArrayNode();
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.ram;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsPartitions;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -118,9 +119,9 @@ public class RamService {
|
||||
return stored;
|
||||
}
|
||||
|
||||
/** The unfiltered read: every share visible to the caller under {@code resourceOwner}. */
|
||||
public List<ResourceShare> getResourceShares(String callerAccountId, String resourceOwner) {
|
||||
return getResourceShares(callerAccountId, resourceOwner, null, List.of(), null);
|
||||
/** The unfiltered read: every share in {@code region} visible to the caller under {@code resourceOwner}. */
|
||||
public List<ResourceShare> getResourceShares(String callerAccountId, String resourceOwner, String region) {
|
||||
return getResourceShares(callerAccountId, resourceOwner, null, List.of(), null, region);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,14 +130,15 @@ public class RamService {
|
||||
* @param name exact share name to match, or null for any
|
||||
* @param resourceShareArns share ARNs to restrict the result to, or empty for any
|
||||
* @param resourceShareStatus one {@code ResourceShareStatus} value to match, or null for any
|
||||
* @param region the request's region: a resource share is a regional resource
|
||||
*/
|
||||
public List<ResourceShare> getResourceShares(String callerAccountId, String resourceOwner,
|
||||
String name, List<String> resourceShareArns,
|
||||
String resourceShareStatus) {
|
||||
String resourceShareStatus, String region) {
|
||||
requireResourceOwner(resourceOwner);
|
||||
requireResourceShareStatus(resourceShareStatus);
|
||||
List<ResourceShare> result = new ArrayList<>();
|
||||
for (ResourceShare share : allShares()) {
|
||||
for (ResourceShare share : sharesIn(region)) {
|
||||
if (!isVisible(share, callerAccountId, resourceOwner)) {
|
||||
continue;
|
||||
}
|
||||
@@ -160,7 +162,8 @@ public class RamService {
|
||||
*/
|
||||
public List<ResourceShareInvitation> getResourceShareInvitations(String callerAccountId,
|
||||
List<String> resourceShareArns,
|
||||
List<String> resourceShareInvitationArns) {
|
||||
List<String> resourceShareInvitationArns,
|
||||
String region) {
|
||||
requireValidArns(resourceShareArns);
|
||||
requireValidArns(resourceShareInvitationArns);
|
||||
List<ResourceShareInvitation> result = new ArrayList<>();
|
||||
@@ -168,7 +171,8 @@ public class RamService {
|
||||
// "Retrieves details about invitations that you have received": receiver only,
|
||||
// not the sender (verified against the API reference; unlike GetResourceShares,
|
||||
// there is no SELF/OTHER-ACCOUNTS style toggle here).
|
||||
if (!callerAccountId.equals(invitation.receiverAccountId())) {
|
||||
if (!callerAccountId.equals(invitation.receiverAccountId())
|
||||
|| !region.equals(extractRegion(invitation.resourceShareArn()))) {
|
||||
continue;
|
||||
}
|
||||
if (!resourceShareArns.isEmpty() && !resourceShareArns.contains(invitation.resourceShareArn())) {
|
||||
@@ -203,17 +207,17 @@ public class RamService {
|
||||
}
|
||||
|
||||
public ResourceShareInvitation acceptResourceShareInvitation(String resourceShareInvitationArn,
|
||||
String callerAccountId) {
|
||||
return resolveInvitation(resourceShareInvitationArn, callerAccountId, "ACCEPTED");
|
||||
String callerAccountId, String region) {
|
||||
return resolveInvitation(resourceShareInvitationArn, callerAccountId, region, "ACCEPTED");
|
||||
}
|
||||
|
||||
public ResourceShareInvitation rejectResourceShareInvitation(String resourceShareInvitationArn,
|
||||
String callerAccountId) {
|
||||
return resolveInvitation(resourceShareInvitationArn, callerAccountId, "REJECTED");
|
||||
String callerAccountId, String region) {
|
||||
return resolveInvitation(resourceShareInvitationArn, callerAccountId, region, "REJECTED");
|
||||
}
|
||||
|
||||
private ResourceShareInvitation resolveInvitation(String resourceShareInvitationArn,
|
||||
String callerAccountId, String newStatus) {
|
||||
String callerAccountId, String region, String newStatus) {
|
||||
if (!isValidArn(resourceShareInvitationArn)) {
|
||||
throw new AwsException("MalformedArnException",
|
||||
"The specified Amazon Resource Name (ARN) has a format that isn't valid: "
|
||||
@@ -222,8 +226,10 @@ public class RamService {
|
||||
// Serializes the status check against the write: two concurrent Accept calls on the
|
||||
// same invitation must not both observe PENDING and both succeed.
|
||||
synchronized (this) {
|
||||
// An invitation, like its share, is answered in its own region only.
|
||||
ResourceShareInvitation invitation = allInvitations().stream()
|
||||
.filter(i -> i.resourceShareInvitationArn().equals(resourceShareInvitationArn))
|
||||
.filter(i -> region.equals(extractRegion(i.resourceShareArn())))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new AwsException("ResourceShareInvitationArnNotFoundException",
|
||||
"ResourceShareInvitation " + resourceShareInvitationArn + " does not exist.", 400));
|
||||
@@ -306,10 +312,10 @@ public class RamService {
|
||||
}
|
||||
|
||||
public List<SharedResource> listResources(String callerAccountId, String resourceOwner,
|
||||
List<String> resourceShareArns) {
|
||||
List<String> resourceShareArns, String region) {
|
||||
requireResourceOwner(resourceOwner);
|
||||
List<SharedResource> result = new ArrayList<>();
|
||||
for (ResourceShare share : allShares()) {
|
||||
for (ResourceShare share : sharesIn(region)) {
|
||||
if (!isVisible(share, callerAccountId, resourceOwner)) {
|
||||
continue;
|
||||
}
|
||||
@@ -329,14 +335,15 @@ public class RamService {
|
||||
return result;
|
||||
}
|
||||
|
||||
public ResourceShare deleteResourceShare(String resourceShareArn, String callerAccountId) {
|
||||
public ResourceShare deleteResourceShare(String resourceShareArn, String callerAccountId, String region) {
|
||||
return putForOwner(
|
||||
requireOwnedShare(resourceShareArn, callerAccountId).withStatus("DELETED"));
|
||||
requireOwnedShare(resourceShareArn, callerAccountId, region).withStatus("DELETED"));
|
||||
}
|
||||
|
||||
public ResourceShare updateResourceShare(String resourceShareArn, String name,
|
||||
Boolean allowExternalPrincipals, String callerAccountId) {
|
||||
ResourceShare share = requireOwnedShare(resourceShareArn, callerAccountId);
|
||||
Boolean allowExternalPrincipals, String callerAccountId,
|
||||
String region) {
|
||||
ResourceShare share = requireOwnedShare(resourceShareArn, callerAccountId, region);
|
||||
if (name != null) {
|
||||
share = share.withName(name);
|
||||
}
|
||||
@@ -347,13 +354,13 @@ public class RamService {
|
||||
}
|
||||
|
||||
public ResourceShare associateResourceShare(String resourceShareArn, List<String> resourceArns,
|
||||
List<String> principals, String callerAccountId) {
|
||||
List<String> principals, String callerAccountId, String region) {
|
||||
// The read, the merged write, and the resulting invitation creation must all happen as
|
||||
// one operation: two concurrent associates for different principals on the same share
|
||||
// must not each read the pre-update share and overwrite each other's addition, which
|
||||
// would also leave an invitation on record for a principal the stored share lost.
|
||||
synchronized (this) {
|
||||
ResourceShare share = requireOwnedShare(resourceShareArn, callerAccountId);
|
||||
ResourceShare share = requireOwnedShare(resourceShareArn, callerAccountId, region);
|
||||
ResourceShare updated = share.withPrincipalsAndResources(
|
||||
mergeDistinct(share.getPrincipals(), principals),
|
||||
mergeDistinct(share.getResourceArns(), resourceArns));
|
||||
@@ -366,8 +373,9 @@ public class RamService {
|
||||
}
|
||||
|
||||
public ResourceShare disassociateResourceShare(String resourceShareArn, List<String> resourceArns,
|
||||
List<String> principals, String callerAccountId) {
|
||||
ResourceShare share = requireOwnedShare(resourceShareArn, callerAccountId);
|
||||
List<String> principals, String callerAccountId,
|
||||
String region) {
|
||||
ResourceShare share = requireOwnedShare(resourceShareArn, callerAccountId, region);
|
||||
ResourceShare updated = share.withPrincipalsAndResources(
|
||||
withoutAll(share.getPrincipals(), principals),
|
||||
withoutAll(share.getResourceArns(), resourceArns));
|
||||
@@ -379,10 +387,10 @@ public class RamService {
|
||||
* {@link #getResourceShares}
|
||||
*/
|
||||
public List<PrincipalAssociation> listPrincipals(String callerAccountId, String resourceOwner,
|
||||
List<String> resourceShareArns) {
|
||||
List<String> resourceShareArns, String region) {
|
||||
requireResourceOwner(resourceOwner);
|
||||
List<PrincipalAssociation> result = new ArrayList<>();
|
||||
for (ResourceShare share : allShares()) {
|
||||
for (ResourceShare share : sharesIn(region)) {
|
||||
if (!isVisible(share, callerAccountId, resourceOwner)) {
|
||||
continue;
|
||||
}
|
||||
@@ -402,34 +410,38 @@ public class RamService {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void tagResource(String resourceShareArn, Map<String, String> newTags, String callerAccountId) {
|
||||
ResourceShare share = requireOwnedShare(resourceShareArn, callerAccountId);
|
||||
public void tagResource(String resourceShareArn, Map<String, String> newTags, String callerAccountId,
|
||||
String region) {
|
||||
ResourceShare share = requireOwnedShare(resourceShareArn, callerAccountId, region);
|
||||
Map<String, String> merged = new LinkedHashMap<>(share.getTags());
|
||||
merged.putAll(newTags);
|
||||
putForOwner(share.withTags(merged));
|
||||
}
|
||||
|
||||
public void untagResource(String resourceShareArn, List<String> tagKeys, String callerAccountId) {
|
||||
ResourceShare share = requireOwnedShare(resourceShareArn, callerAccountId);
|
||||
public void untagResource(String resourceShareArn, List<String> tagKeys, String callerAccountId,
|
||||
String region) {
|
||||
ResourceShare share = requireOwnedShare(resourceShareArn, callerAccountId, region);
|
||||
Map<String, String> remaining = new LinkedHashMap<>(share.getTags());
|
||||
tagKeys.forEach(remaining::remove);
|
||||
putForOwner(share.withTags(remaining));
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a share the caller may mutate. A share owned by another account gets the same
|
||||
* UnknownResourceException as one that was never created: AWS resolves a share ARN within
|
||||
* the caller's own account, so a non-owner must not learn that the ARN exists, let alone
|
||||
* be able to rename, retag, or delete it.
|
||||
* Resolves a share the caller may mutate. A share owned by another account, or in another
|
||||
* region than the request's, gets the same UnknownResourceException as one that was never
|
||||
* created: AWS resolves a share ARN within the caller's own account and region, so a
|
||||
* non-owner must not learn that the ARN exists, let alone be able to rename, retag, or delete
|
||||
* it, and a request in one region does not reach a share the listings there do not show.
|
||||
*/
|
||||
private ResourceShare requireOwnedShare(String resourceShareArn, String callerAccountId) {
|
||||
return findOwnedShare(resourceShareArn, callerAccountId)
|
||||
private ResourceShare requireOwnedShare(String resourceShareArn, String callerAccountId, String region) {
|
||||
return findOwnedShare(resourceShareArn, callerAccountId, region)
|
||||
.orElseThrow(() -> new AwsException("UnknownResourceException",
|
||||
"ResourceShare " + resourceShareArn + " does not exist.", 400));
|
||||
}
|
||||
|
||||
private Optional<ResourceShare> findOwnedShare(String resourceShareArn, String callerAccountId) {
|
||||
return allShares().stream()
|
||||
private Optional<ResourceShare> findOwnedShare(String resourceShareArn, String callerAccountId,
|
||||
String region) {
|
||||
return sharesIn(region).stream()
|
||||
.filter(share -> share.getResourceShareArn().equals(resourceShareArn))
|
||||
.filter(share -> share.getOwningAccountId().equals(callerAccountId))
|
||||
// DELETED is terminal: the share stays readable via GetResourceShares for the
|
||||
@@ -466,6 +478,16 @@ public class RamService {
|
||||
return stamped;
|
||||
}
|
||||
|
||||
/**
|
||||
* The shares of one region. A resource share is a regional resource, so the listing operations
|
||||
* answer for the request's region only, which also keeps a share out of another partition.
|
||||
*/
|
||||
private List<ResourceShare> sharesIn(String region) {
|
||||
return allShares().stream()
|
||||
.filter(share -> region.equals(extractRegion(share.getResourceShareArn())))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private List<ResourceShare> allShares() {
|
||||
if (shares instanceof AccountAwareStorageBackend<ResourceShare> accountAware) {
|
||||
return accountAware.scanAllAccounts();
|
||||
@@ -543,7 +565,8 @@ public class RamService {
|
||||
return false;
|
||||
}
|
||||
String[] arn = principal.split(":", 6);
|
||||
if (arn.length != 6 || !"aws".equals(arn[1]) || !"organizations".equals(arn[2])) {
|
||||
// Any published partition: the organization id below is what ties the ARN to the caller's.
|
||||
if (arn.length != 6 || AwsPartitions.find(arn[1]).isEmpty() || !"organizations".equals(arn[2])) {
|
||||
return false;
|
||||
}
|
||||
String[] resource = arn[5].split("/");
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegions;
|
||||
import io.github.hectorvent.floci.core.common.BackupWindows;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.docker.ContainerStorageHelper;
|
||||
@@ -1068,7 +1069,10 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
if (sourceIdentifier != null && sourceIdentifier.startsWith("arn:")) {
|
||||
try {
|
||||
AwsArnUtils.Arn parsed = AwsArnUtils.parse(sourceIdentifier);
|
||||
if (!"aws".equals(parsed.partition()) || !"rds".equals(parsed.service())
|
||||
// A snapshot copies within its partition only, so a source ARN naming another
|
||||
// partition than the target region's is not a snapshot this copy can read.
|
||||
if (!AwsRegions.partitionFor(targetRegion).equals(parsed.partition())
|
||||
|| !"rds".equals(parsed.service())
|
||||
|| !parsed.resource().startsWith("snapshot:")) {
|
||||
throw new IllegalArgumentException("not an RDS snapshot ARN");
|
||||
}
|
||||
@@ -6782,7 +6786,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
}
|
||||
try {
|
||||
AwsArnUtils.Arn arn = AwsArnUtils.parse(targetGroup.getTargetGroupArn());
|
||||
return "aws".equals(arn.partition())
|
||||
return AwsRegions.partitionFor(region).equals(arn.partition())
|
||||
&& "rds".equals(arn.service())
|
||||
&& Objects.equals(accountId, arn.accountId())
|
||||
&& Objects.equals(region, arn.region())
|
||||
@@ -8266,7 +8270,7 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
String resourceType, String resourceId) {
|
||||
try {
|
||||
AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
|
||||
return "aws".equals(parsed.partition())
|
||||
return AwsRegions.partitionFor(region).equals(parsed.partition())
|
||||
&& "rds".equals(parsed.service())
|
||||
&& Objects.equals(accountId, parsed.accountId())
|
||||
&& Objects.equals(region, parsed.region())
|
||||
|
||||
@@ -45,15 +45,15 @@ import java.util.Comparator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ApplicationScoped
|
||||
public class SsoAdminService implements Resettable {
|
||||
private static final String INSTANCE_ARN = globalArn("sso", "us-east-1", "", "instance/ssoins-7223b02a5d9f7c8e"); // partition-literal: seeded Identity Center instance home region
|
||||
private static final String BOOTSTRAP_INSTANCE = "instance/ssoins-7223b02a5d9f7c8e";
|
||||
private static final String IDENTITY_STORE_ID = "d-9067f2a3c1";
|
||||
private static final String PRIMARY_REGION = "us-east-1"; // partition-literal: seeded Identity Center instance home region
|
||||
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}");
|
||||
@@ -127,6 +127,8 @@ public class SsoAdminService implements Resettable {
|
||||
private final OrganizationsService organizationsService;
|
||||
private final String defaultAccountId;
|
||||
private final String defaultRegion;
|
||||
/** The seeded instance lives in the deployment's home region, so its ARN takes that partition. */
|
||||
private final String bootstrapInstanceArn;
|
||||
|
||||
@Inject
|
||||
public SsoAdminService(StorageFactory storageFactory, IdentityStoreService identityStoreService,
|
||||
@@ -221,10 +223,11 @@ public class SsoAdminService implements Resettable {
|
||||
this.organizationsService = organizationsService;
|
||||
this.defaultAccountId = defaultAccountId;
|
||||
this.defaultRegion = defaultRegion;
|
||||
this.bootstrapInstanceArn = globalArn("sso", defaultRegion, "", BOOTSTRAP_INSTANCE);
|
||||
ensureBootstrapInstance(defaultAccountId, defaultRegion);
|
||||
}
|
||||
|
||||
public String getInstanceArn() { return INSTANCE_ARN; }
|
||||
public String getInstanceArn() { return bootstrapInstanceArn; }
|
||||
public String getIdentityStoreId() { return IDENTITY_STORE_ID; }
|
||||
|
||||
public boolean hasIdentityStore(String identityStoreId) {
|
||||
@@ -251,10 +254,22 @@ public class SsoAdminService implements Resettable {
|
||||
if (instanceDeletionMarkers.get(ownerAccountId).orElse(false)) {
|
||||
return;
|
||||
}
|
||||
if (instances.get(ownerAccountId).isEmpty()) {
|
||||
instances.put(ownerAccountId, new SsoInstance(INSTANCE_ARN, IDENTITY_STORE_ID, "floci-identity-center",
|
||||
ownerAccountId, region, System.currentTimeMillis(), "ACTIVE", null, false,
|
||||
new LinkedHashMap<>()));
|
||||
Optional<SsoInstance> stored = instances.get(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<>()));
|
||||
return;
|
||||
}
|
||||
// Before the seeded instance took its partition it was stored as arn:aws: in every
|
||||
// deployment, while permission sets were already minted in the instance's own partition,
|
||||
// so a persisted outside-aws instance is moved to the ARN those permission sets name.
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1445,9 +1460,9 @@ public class SsoAdminService implements Resettable {
|
||||
}
|
||||
|
||||
public synchronized RegionMetadata addRegion(JsonNode request) {
|
||||
requireInstance(required(request, "InstanceArn"));
|
||||
SsoInstance instance = requireInstance(required(request, "InstanceArn"));
|
||||
String regionName = validateRegionName(required(request, "RegionName"));
|
||||
if (PRIMARY_REGION.equals(regionName) || regions.get(regionName).isPresent()) {
|
||||
if (instance.primaryRegion().equals(regionName) || regions.get(regionName).isPresent()) {
|
||||
throw conflict("Region is already enabled for this IAM Identity Center instance: " + regionName);
|
||||
}
|
||||
if (regions.scan(key -> true).size() >= REGION_QUOTA - 1) {
|
||||
|
||||
Reference in new issue
Block a user