mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -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
@@ -57,6 +57,10 @@ OrganizationsTest#testFullLifecycle
|
||||
PipesTest#batchSizeInSourceParameters
|
||||
PipesTest#filterCriteriaFiltersMessages
|
||||
PipesTest#sqsToSqsForwarding
|
||||
RdsIamTokenCompatTest#sdkGeneratedTokenIsAccepted
|
||||
RdsJdbcCompatTest#connectWithIamAuthToken
|
||||
RdsJdbcCompatTest#modifyKeepsProxyReachableAndDeleteReleasesPort
|
||||
RdsJdbcCompatTest#toggleIamViaModifyOnRunningInstance
|
||||
ResourceExplorer2Test#viewFiltersFilterStringDeserializes
|
||||
Route53Test#crossAccountVpcAssociationLifecycleUsesAwsSdkWireContract
|
||||
S3TablesTest#createsAndGetsTableBucket
|
||||
@@ -109,29 +113,6 @@ S3Test#getBucketLocationEuCentral1
|
||||
StsTest#assumeRoleWithSaml
|
||||
StsTest#assumeRoleWithSamlAssumedRoleUser
|
||||
|
||||
# Floci bugs: RdsService checks a parsed ARN against the literal partition "aws", so RDS
|
||||
# resources created in China are not found after creation; the seeded IAM Identity Center
|
||||
# instance ARN is always arn:aws:. CloudFormationRdsDynamicReferenceTest and SsoPortalTest were
|
||||
# reproduced alone (they pass under us-east-1); the other RDS entries fail the same way. Fixed in
|
||||
# a follow-up PR.
|
||||
CloudFormationRdsDynamicReferenceTest#resolvesSecureSsmMasterPassword
|
||||
RdsControlPlaneTest#sdkCopiesModifiesAndDeletesManualSnapshots
|
||||
RdsControlPlaneTest#sdkCreatesCopiesRestoresAndDeletesClusterSnapshots
|
||||
RdsControlPlaneTest#sdkFaultsDeletingAnOptionGroupStillAttachedToAnInstance
|
||||
RdsControlPlaneTest#sdkRegistersDescribesAndDeregistersDbProxyInstanceTarget
|
||||
RdsControlPlaneTest#sdkResizesAndUpgradesAStandaloneInstance
|
||||
RdsControlPlaneTest#sdkRoundTripsAuroraServerlessV2ScalingConfiguration
|
||||
RdsControlPlaneTest#sdkRoundTripsDbProxyAndItsDefaultTargetGroup
|
||||
RdsControlPlaneTest#sdkRoundTripsIamDefaultAuthAndProxyUpdates
|
||||
RdsControlPlaneTest#sdkStopsAndStartsAStandaloneInstance
|
||||
RdsControlPlaneTest#sdkUnmarshalsDbSubnetGroupSubnets
|
||||
RdsIamTokenCompatTest#sdkGeneratedTokenIsAccepted
|
||||
RdsJdbcCompatTest#connectWithIamAuthToken
|
||||
RdsJdbcCompatTest#createDbInstanceAndConnectWithPassword
|
||||
RdsJdbcCompatTest#modifyKeepsProxyReachableAndDeleteReleasesPort
|
||||
RdsJdbcCompatTest#toggleIamViaModifyOnRunningInstance
|
||||
SsoPortalTest#listAccountsUsesAwsSdk
|
||||
|
||||
# Passes alone: in the full run OrganizationsTest#testFullLifecycle fails its arn:aws: assertion
|
||||
# before cleanup, leaving the caller as the Organizations management account.
|
||||
SsoAdminAccountAssignmentTest#createInstanceQuotaUsesAwsSdk
|
||||
+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) {
|
||||
|
||||
+12
@@ -1,5 +1,6 @@
|
||||
package io.github.hectorvent.floci.services.elasticache;
|
||||
|
||||
import io.github.hectorvent.floci.testing.PartitionMatrix;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Assumptions;
|
||||
@@ -202,6 +203,17 @@ class ElastiCacheParameterGroupIntegrationTest {
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body(containsString("no-such-pg is not present"));
|
||||
// In China the expected partition is aws-cn, so a China ARN passes the partition check
|
||||
// and reaches the resource lookup like a commercial one does in us-east-1.
|
||||
given()
|
||||
.header("Authorization", PartitionMatrix.sigV4Auth("cn-north-1", "elasticache"))
|
||||
.formParam("Action", "ListTagsForResource")
|
||||
.formParam("Version", "2015-02-02")
|
||||
.formParam("ResourceName", "arn:aws-cn:elasticache:cn-north-1:000000000000:parametergroup:no-such-pg")
|
||||
.when().post("/")
|
||||
.then()
|
||||
.statusCode(404)
|
||||
.body(containsString("no-such-pg is not present"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+3
-3
@@ -41,15 +41,15 @@ class RamServicePersistenceTest {
|
||||
RamService reloaded = serviceWithStorage(storage);
|
||||
|
||||
assertTrue(reloaded.isSharingWithOrganizationEnabled(OWNER));
|
||||
List<ResourceShare> owned = reloaded.getResourceShares(OWNER, "SELF");
|
||||
List<ResourceShare> owned = reloaded.getResourceShares(OWNER, "SELF", "us-east-1");
|
||||
assertEquals(1, owned.size());
|
||||
assertEquals(created.getResourceShareArn(), owned.getFirst().getResourceShareArn());
|
||||
assertEquals(created.getCreationTime(), owned.getFirst().getCreationTime());
|
||||
|
||||
List<ResourceShare> shared = reloaded.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS");
|
||||
List<ResourceShare> shared = reloaded.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS", "us-east-1");
|
||||
assertEquals(1, shared.size());
|
||||
List<SharedResource> resources = reloaded.listResources(
|
||||
ACCEPTER, "OTHER-ACCOUNTS", List.of(created.getResourceShareArn()));
|
||||
ACCEPTER, "OTHER-ACCOUNTS", List.of(created.getResourceShareArn()), "us-east-1");
|
||||
assertEquals(1, resources.size());
|
||||
assertEquals(TGW_ARN, resources.getFirst().arn());
|
||||
}
|
||||
|
||||
@@ -65,14 +65,14 @@ class RamServiceTest {
|
||||
// share through ListResources or ListPrincipals.
|
||||
ResourceShare share = service.createResourceShare(
|
||||
"delete-me", List.of(OU_ARN), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
service.deleteResourceShare(share.getResourceShareArn(), OWNER);
|
||||
service.deleteResourceShare(share.getResourceShareArn(), OWNER, "us-east-1");
|
||||
|
||||
assertTrue(service.listResources(ACCEPTER, "OTHER-ACCOUNTS", List.of()).isEmpty());
|
||||
assertTrue(service.listPrincipals(ACCEPTER, "OTHER-ACCOUNTS", List.of()).isEmpty());
|
||||
assertTrue(service.listResources(OWNER, "SELF", List.of()).isEmpty());
|
||||
assertTrue(service.listResources(ACCEPTER, "OTHER-ACCOUNTS", List.of(), "us-east-1").isEmpty());
|
||||
assertTrue(service.listPrincipals(ACCEPTER, "OTHER-ACCOUNTS", List.of(), "us-east-1").isEmpty());
|
||||
assertTrue(service.listResources(OWNER, "SELF", List.of(), "us-east-1").isEmpty());
|
||||
|
||||
// The share itself remains readable with DELETED status.
|
||||
List<ResourceShare> own = service.getResourceShares(OWNER, "SELF");
|
||||
List<ResourceShare> own = service.getResourceShares(OWNER, "SELF", "us-east-1");
|
||||
assertEquals(1, own.size());
|
||||
assertEquals("DELETED", own.get(0).getStatus());
|
||||
}
|
||||
@@ -86,7 +86,7 @@ class RamServiceTest {
|
||||
assertTrue(share.getResourceShareArn().startsWith("arn:aws:ram:us-east-1:" + OWNER + ":resource-share/"));
|
||||
assertEquals("ACTIVE", share.getStatus());
|
||||
|
||||
List<ResourceShare> own = service.getResourceShares(OWNER, "SELF");
|
||||
List<ResourceShare> own = service.getResourceShares(OWNER, "SELF", "us-east-1");
|
||||
assertEquals(1, own.size());
|
||||
assertEquals("us-east-1-tgw-share", own.get(0).getName());
|
||||
assertEquals(OWNER, own.get(0).getOwningAccountId());
|
||||
@@ -97,7 +97,7 @@ class RamServiceTest {
|
||||
service.createResourceShare(
|
||||
"us-east-1-tgw-share", List.of(OU_ARN), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
|
||||
List<ResourceShare> visible = service.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS");
|
||||
List<ResourceShare> visible = service.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS", "us-east-1");
|
||||
assertEquals(1, visible.size());
|
||||
assertEquals(OWNER, visible.get(0).getOwningAccountId());
|
||||
}
|
||||
@@ -107,8 +107,74 @@ class RamServiceTest {
|
||||
service.createResourceShare(
|
||||
"us-east-1-tgw-share", List.of(OU_ARN), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
|
||||
assertTrue(service.getResourceShares(OWNER, "OTHER-ACCOUNTS").isEmpty());
|
||||
assertTrue(service.getResourceShares(ACCEPTER, "SELF").isEmpty());
|
||||
assertTrue(service.getResourceShares(OWNER, "OTHER-ACCOUNTS", "us-east-1").isEmpty());
|
||||
assertTrue(service.getResourceShares(ACCEPTER, "SELF", "us-east-1").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void chinaOuPrincipalIsVisibleToOrgAccounts() {
|
||||
service.createResourceShare("cn-tgw-share",
|
||||
List.of("arn:aws-cn:organizations::000000000000:ou/o-abc123/ou-root-infra"),
|
||||
List.of("arn:aws-cn:ec2:cn-north-1:111111111111:transit-gateway/tgw-0abc"),
|
||||
false, "cn-north-1", OWNER);
|
||||
|
||||
assertEquals(1, service.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS", "cn-north-1").size());
|
||||
// A China share never reaches a commercial request, even for a member of the organization.
|
||||
assertTrue(service.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS", "us-east-1").isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* Mutations resolve a share in the request's region like the listings do: a share that
|
||||
* GetResourceShares in us-east-1 does not show cannot be deleted, changed or retagged from
|
||||
* there, and an invitation to it cannot be answered there.
|
||||
*/
|
||||
@Test
|
||||
void mutationsInAnotherRegionDoNotReachTheShare() {
|
||||
ResourceShare share = service.createResourceShare(
|
||||
"eu-share", List.of(ACCEPTER), List.of(TGW_ARN), false, "eu-west-1", OWNER);
|
||||
String arn = share.getResourceShareArn();
|
||||
String invitationArn = service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "eu-west-1")
|
||||
.get(0).resourceShareInvitationArn();
|
||||
|
||||
for (Runnable wrongRegion : List.<Runnable>of(
|
||||
() -> service.deleteResourceShare(arn, OWNER, "us-east-1"),
|
||||
() -> service.updateResourceShare(arn, "renamed", null, OWNER, "us-east-1"),
|
||||
() -> service.associateResourceShare(arn, List.of(), List.of("333333333333"), OWNER, "us-east-1"),
|
||||
() -> service.disassociateResourceShare(arn, List.of(TGW_ARN), List.of(), OWNER, "us-east-1"),
|
||||
() -> service.tagResource(arn, Map.of("env", "test"), OWNER, "us-east-1"),
|
||||
() -> service.untagResource(arn, List.of("env"), OWNER, "us-east-1"))) {
|
||||
AwsException ex = assertThrows(AwsException.class, wrongRegion::run);
|
||||
assertEquals("UnknownResourceException", ex.getErrorCode());
|
||||
}
|
||||
for (Runnable wrongRegion : List.<Runnable>of(
|
||||
() -> service.acceptResourceShareInvitation(invitationArn, ACCEPTER, "us-east-1"),
|
||||
() -> service.rejectResourceShareInvitation(invitationArn, ACCEPTER, "us-east-1"))) {
|
||||
AwsException ex = assertThrows(AwsException.class, wrongRegion::run);
|
||||
assertEquals("ResourceShareInvitationArnNotFoundException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
ResourceShare unchanged = service.getResourceShares(OWNER, "SELF", "eu-west-1").get(0);
|
||||
assertEquals("eu-share", unchanged.getName());
|
||||
assertEquals("ACTIVE", unchanged.getStatus());
|
||||
assertEquals(List.of(TGW_ARN), unchanged.getResourceArns());
|
||||
assertEquals("ACCEPTED", service.acceptResourceShareInvitation(invitationArn, ACCEPTER, "eu-west-1").status());
|
||||
}
|
||||
|
||||
/** A resource share is regional: the listing operations answer for the request's region only. */
|
||||
@Test
|
||||
void listingsAnswerForTheRequestsRegionOnly() {
|
||||
ResourceShare share = service.createResourceShare(
|
||||
"eu-share", List.of(ACCEPTER, OU_ARN), List.of(TGW_ARN), false, "eu-west-1", OWNER);
|
||||
|
||||
assertEquals(1, service.getResourceShares(OWNER, "SELF", "eu-west-1").size());
|
||||
assertTrue(service.getResourceShares(OWNER, "SELF", "us-east-1").isEmpty());
|
||||
assertTrue(service.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS", "us-east-1").isEmpty());
|
||||
assertTrue(service.listResources(ACCEPTER, "OTHER-ACCOUNTS", List.of(), "us-east-1").isEmpty());
|
||||
assertTrue(service.listPrincipals(OWNER, "SELF", List.of(), "us-east-1").isEmpty());
|
||||
assertEquals(List.of(share.getResourceShareArn()),
|
||||
service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "eu-west-1").stream()
|
||||
.map(ResourceShareInvitation::resourceShareArn).toList());
|
||||
assertTrue(service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,7 +182,7 @@ class RamServiceTest {
|
||||
service.createResourceShare(
|
||||
"direct-share", List.of(ACCEPTER), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
|
||||
assertEquals(1, service.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS").size());
|
||||
assertEquals(1, service.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS", "us-east-1").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -124,23 +190,23 @@ class RamServiceTest {
|
||||
service.createResourceShare(
|
||||
"ipam-pool-share", List.of(ACCEPTER), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
|
||||
assertTrue(service.getResourceShares("000000000000", "OTHER-ACCOUNTS").isEmpty());
|
||||
assertTrue(service.listResources("000000000000", "OTHER-ACCOUNTS", List.of()).isEmpty());
|
||||
assertTrue(service.listPrincipals("000000000000", "OTHER-ACCOUNTS", List.of()).isEmpty());
|
||||
assertTrue(service.getResourceShares("000000000000", "OTHER-ACCOUNTS", "us-east-1").isEmpty());
|
||||
assertTrue(service.listResources("000000000000", "OTHER-ACCOUNTS", List.of(), "us-east-1").isEmpty());
|
||||
assertTrue(service.listPrincipals("000000000000", "OTHER-ACCOUNTS", List.of(), "us-east-1").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectedInvitationNoLongerGrantsShareVisibility() {
|
||||
service.createResourceShare(
|
||||
"direct-share", List.of(ACCEPTER), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
String invitationArn = service.getResourceShareInvitations(ACCEPTER, List.of(), List.of())
|
||||
String invitationArn = service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1")
|
||||
.getFirst().resourceShareInvitationArn();
|
||||
|
||||
service.rejectResourceShareInvitation(invitationArn, ACCEPTER);
|
||||
service.rejectResourceShareInvitation(invitationArn, ACCEPTER, "us-east-1");
|
||||
|
||||
assertTrue(service.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS").isEmpty());
|
||||
assertTrue(service.listResources(ACCEPTER, "OTHER-ACCOUNTS", List.of()).isEmpty());
|
||||
assertTrue(service.listPrincipals(ACCEPTER, "OTHER-ACCOUNTS", List.of()).isEmpty());
|
||||
assertTrue(service.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS", "us-east-1").isEmpty());
|
||||
assertTrue(service.listResources(ACCEPTER, "OTHER-ACCOUNTS", List.of(), "us-east-1").isEmpty());
|
||||
assertTrue(service.listPrincipals(ACCEPTER, "OTHER-ACCOUNTS", List.of(), "us-east-1").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,7 +214,7 @@ class RamServiceTest {
|
||||
service.createResourceShare(
|
||||
"us-east-1-tgw-share", List.of(OU_ARN), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
|
||||
assertTrue(service.getResourceShareInvitations(ACCEPTER, List.of(), List.of()).isEmpty());
|
||||
assertTrue(service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,7 +223,7 @@ class RamServiceTest {
|
||||
"us-east-1-tgw-share", List.of(OU_ARN), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
|
||||
List<SharedResource> resources =
|
||||
service.listResources(ACCEPTER, "OTHER-ACCOUNTS", List.of(share.getResourceShareArn()));
|
||||
service.listResources(ACCEPTER, "OTHER-ACCOUNTS", List.of(share.getResourceShareArn()), "us-east-1");
|
||||
assertEquals(1, resources.size());
|
||||
assertEquals(TGW_ARN, resources.get(0).arn());
|
||||
assertEquals("ec2:TransitGateway", resources.get(0).type());
|
||||
@@ -173,7 +239,7 @@ class RamServiceTest {
|
||||
List.of("arn:aws:ec2:us-east-1:111111111111:subnet/subnet-1"), false, "us-east-1", OWNER);
|
||||
|
||||
List<SharedResource> resources =
|
||||
service.listResources(ACCEPTER, "OTHER-ACCOUNTS", List.of(other.getResourceShareArn()));
|
||||
service.listResources(ACCEPTER, "OTHER-ACCOUNTS", List.of(other.getResourceShareArn()), "us-east-1");
|
||||
assertEquals(1, resources.size());
|
||||
assertEquals("ec2:Subnet", resources.get(0).type());
|
||||
}
|
||||
@@ -187,14 +253,16 @@ class RamServiceTest {
|
||||
"us-east-1-tgw-share", List.of(OU_ARN), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
String arn = share.getResourceShareArn();
|
||||
|
||||
assertUnknownResource(() -> service.deleteResourceShare(arn, ACCEPTER));
|
||||
assertUnknownResource(() -> service.updateResourceShare(arn, "hijacked", null, ACCEPTER));
|
||||
assertUnknownResource(() -> service.associateResourceShare(arn, List.of(TGW_ARN), List.of(), ACCEPTER));
|
||||
assertUnknownResource(() -> service.disassociateResourceShare(arn, List.of(TGW_ARN), List.of(), ACCEPTER));
|
||||
assertUnknownResource(() -> service.tagResource(arn, Map.of("Owner", "attacker"), ACCEPTER));
|
||||
assertUnknownResource(() -> service.untagResource(arn, List.of("Owner"), ACCEPTER));
|
||||
assertUnknownResource(() -> service.deleteResourceShare(arn, ACCEPTER, "us-east-1"));
|
||||
assertUnknownResource(() -> service.updateResourceShare(arn, "hijacked", null, ACCEPTER, "us-east-1"));
|
||||
assertUnknownResource(() -> service.associateResourceShare(arn, List.of(TGW_ARN), List.of(), ACCEPTER,
|
||||
"us-east-1"));
|
||||
assertUnknownResource(() -> service.disassociateResourceShare(arn, List.of(TGW_ARN), List.of(), ACCEPTER,
|
||||
"us-east-1"));
|
||||
assertUnknownResource(() -> service.tagResource(arn, Map.of("Owner", "attacker"), ACCEPTER, "us-east-1"));
|
||||
assertUnknownResource(() -> service.untagResource(arn, List.of("Owner"), ACCEPTER, "us-east-1"));
|
||||
|
||||
ResourceShare untouched = service.getResourceShares(OWNER, "SELF").get(0);
|
||||
ResourceShare untouched = service.getResourceShares(OWNER, "SELF", "us-east-1").get(0);
|
||||
assertEquals("us-east-1-tgw-share", untouched.getName());
|
||||
assertEquals("ACTIVE", untouched.getStatus());
|
||||
assertEquals(List.of(TGW_ARN), untouched.getResourceArns());
|
||||
@@ -207,10 +275,10 @@ class RamServiceTest {
|
||||
"us-east-1-tgw-share", List.of(OU_ARN), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
String arn = share.getResourceShareArn();
|
||||
|
||||
assertEquals("renamed", service.updateResourceShare(arn, "renamed", null, OWNER).getName());
|
||||
service.tagResource(arn, Map.of("Owner", "network"), OWNER);
|
||||
assertEquals("network", service.getResourceShares(OWNER, "SELF").get(0).getTags().get("Owner"));
|
||||
assertEquals("DELETED", service.deleteResourceShare(arn, OWNER).getStatus());
|
||||
assertEquals("renamed", service.updateResourceShare(arn, "renamed", null, OWNER, "us-east-1").getName());
|
||||
service.tagResource(arn, Map.of("Owner", "network"), OWNER, "us-east-1");
|
||||
assertEquals("network", service.getResourceShares(OWNER, "SELF", "us-east-1").get(0).getTags().get("Owner"));
|
||||
assertEquals("DELETED", service.deleteResourceShare(arn, OWNER, "us-east-1").getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,12 +292,12 @@ class RamServiceTest {
|
||||
service.createResourceShare(
|
||||
"us-east-1-tgw-share", List.of(OU_ARN), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
|
||||
assertInvalidParameter(() -> service.getResourceShares(ACCEPTER, "self"));
|
||||
assertInvalidParameter(() -> service.listPrincipals(ACCEPTER, "EVERYTHING", List.of()));
|
||||
assertInvalidParameter(() -> service.listResources(ACCEPTER, "OTHER_ACCOUNTS", List.of()));
|
||||
assertInvalidParameter(() -> service.getResourceShares(ACCEPTER, "self", "us-east-1"));
|
||||
assertInvalidParameter(() -> service.listPrincipals(ACCEPTER, "EVERYTHING", List.of(), "us-east-1"));
|
||||
assertInvalidParameter(() -> service.listResources(ACCEPTER, "OTHER_ACCOUNTS", List.of(), "us-east-1"));
|
||||
|
||||
assertEquals(1, service.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS").size());
|
||||
assertEquals(0, service.getResourceShares(ACCEPTER, "SELF").size());
|
||||
assertEquals(1, service.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS", "us-east-1").size());
|
||||
assertEquals(0, service.getResourceShares(ACCEPTER, "SELF", "us-east-1").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -239,17 +307,19 @@ class RamServiceTest {
|
||||
ResourceShare share = service.createResourceShare(
|
||||
"gone", List.of(OU_ARN), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
String arn = share.getResourceShareArn();
|
||||
service.deleteResourceShare(arn, OWNER);
|
||||
service.deleteResourceShare(arn, OWNER, "us-east-1");
|
||||
|
||||
assertUnknownResource(() -> service.updateResourceShare(arn, "renamed", null, OWNER));
|
||||
assertUnknownResource(() -> service.associateResourceShare(arn, List.of(TGW_ARN), List.of(), OWNER));
|
||||
assertUnknownResource(() -> service.disassociateResourceShare(arn, List.of(TGW_ARN), List.of(), OWNER));
|
||||
assertUnknownResource(() -> service.tagResource(arn, Map.of("k", "v"), OWNER));
|
||||
assertUnknownResource(() -> service.untagResource(arn, List.of("k"), OWNER));
|
||||
assertUnknownResource(() -> service.deleteResourceShare(arn, OWNER));
|
||||
assertUnknownResource(() -> service.updateResourceShare(arn, "renamed", null, OWNER, "us-east-1"));
|
||||
assertUnknownResource(() -> service.associateResourceShare(arn, List.of(TGW_ARN), List.of(), OWNER,
|
||||
"us-east-1"));
|
||||
assertUnknownResource(() -> service.disassociateResourceShare(arn, List.of(TGW_ARN), List.of(), OWNER,
|
||||
"us-east-1"));
|
||||
assertUnknownResource(() -> service.tagResource(arn, Map.of("k", "v"), OWNER, "us-east-1"));
|
||||
assertUnknownResource(() -> service.untagResource(arn, List.of("k"), OWNER, "us-east-1"));
|
||||
assertUnknownResource(() -> service.deleteResourceShare(arn, OWNER, "us-east-1"));
|
||||
|
||||
// Still readable with DELETED status: mutation rejection must not hide it from reads.
|
||||
assertEquals("DELETED", service.getResourceShares(OWNER, "SELF").get(0).getStatus());
|
||||
assertEquals("DELETED", service.getResourceShares(OWNER, "SELF", "us-east-1").get(0).getStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -258,11 +328,11 @@ class RamServiceTest {
|
||||
service.createResourceShare("ipam-share", List.of(OU_ARN), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
|
||||
List<ResourceShare> matched =
|
||||
service.getResourceShares(OWNER, "SELF", "ipam-share", List.of(), null);
|
||||
service.getResourceShares(OWNER, "SELF", "ipam-share", List.of(), null, "us-east-1");
|
||||
assertEquals(1, matched.size());
|
||||
assertEquals("ipam-share", matched.get(0).getName());
|
||||
|
||||
assertTrue(service.getResourceShares(OWNER, "SELF", "no-such-share", List.of(), null).isEmpty());
|
||||
assertTrue(service.getResourceShares(OWNER, "SELF", "no-such-share", List.of(), null, "us-east-1").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -272,7 +342,7 @@ class RamServiceTest {
|
||||
service.createResourceShare("ipam-share", List.of(OU_ARN), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
|
||||
List<ResourceShare> matched = service.getResourceShares(
|
||||
OWNER, "SELF", null, List.of(wanted.getResourceShareArn()), null);
|
||||
OWNER, "SELF", null, List.of(wanted.getResourceShareArn()), null, "us-east-1");
|
||||
assertEquals(1, matched.size());
|
||||
assertEquals(wanted.getResourceShareArn(), matched.get(0).getResourceShareArn());
|
||||
}
|
||||
@@ -284,24 +354,24 @@ class RamServiceTest {
|
||||
service.createResourceShare("live", List.of(OU_ARN), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
ResourceShare doomed = service.createResourceShare(
|
||||
"gone", List.of(OU_ARN), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
service.deleteResourceShare(doomed.getResourceShareArn(), OWNER);
|
||||
service.deleteResourceShare(doomed.getResourceShareArn(), OWNER, "us-east-1");
|
||||
|
||||
List<ResourceShare> active = service.getResourceShares(OWNER, "SELF", null, List.of(), "ACTIVE");
|
||||
List<ResourceShare> active = service.getResourceShares(OWNER, "SELF", null, List.of(), "ACTIVE", "us-east-1");
|
||||
assertEquals(1, active.size());
|
||||
assertEquals("live", active.get(0).getName());
|
||||
|
||||
List<ResourceShare> deleted = service.getResourceShares(OWNER, "SELF", null, List.of(), "DELETED");
|
||||
List<ResourceShare> deleted = service.getResourceShares(OWNER, "SELF", null, List.of(), "DELETED", "us-east-1");
|
||||
assertEquals(1, deleted.size());
|
||||
assertEquals("gone", deleted.get(0).getName());
|
||||
|
||||
// No status filter still returns both, as it does today.
|
||||
assertEquals(2, service.getResourceShares(OWNER, "SELF").size());
|
||||
assertEquals(2, service.getResourceShares(OWNER, "SELF", "us-east-1").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unmodelledResourceShareStatusIsRejected() {
|
||||
assertInvalidParameter(() -> service.getResourceShares(OWNER, "SELF", null, List.of(), "active"));
|
||||
assertInvalidParameter(() -> service.getResourceShares(OWNER, "SELF", null, List.of(), "GONE"));
|
||||
assertInvalidParameter(() -> service.getResourceShares(OWNER, "SELF", null, List.of(), "active", "us-east-1"));
|
||||
assertInvalidParameter(() -> service.getResourceShares(OWNER, "SELF", null, List.of(), "GONE", "us-east-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -311,12 +381,12 @@ class RamServiceTest {
|
||||
String arn = created.getResourceShareArn();
|
||||
assertFalse(created.getLastUpdatedTime().isBefore(created.getCreationTime()));
|
||||
|
||||
ResourceShare renamed = service.updateResourceShare(arn, "renamed", null, OWNER);
|
||||
ResourceShare renamed = service.updateResourceShare(arn, "renamed", null, OWNER, "us-east-1");
|
||||
assertTrue(renamed.getLastUpdatedTime().isAfter(created.getLastUpdatedTime()));
|
||||
assertEquals(created.getCreationTime(), renamed.getCreationTime());
|
||||
|
||||
service.tagResource(arn, Map.of("Owner", "network"), OWNER);
|
||||
ResourceShare tagged = service.getResourceShares(OWNER, "SELF").get(0);
|
||||
service.tagResource(arn, Map.of("Owner", "network"), OWNER, "us-east-1");
|
||||
ResourceShare tagged = service.getResourceShares(OWNER, "SELF", "us-east-1").get(0);
|
||||
assertTrue(tagged.getLastUpdatedTime().isAfter(renamed.getLastUpdatedTime()));
|
||||
assertEquals(created.getCreationTime(), tagged.getCreationTime());
|
||||
}
|
||||
@@ -327,7 +397,7 @@ class RamServiceTest {
|
||||
"direct-share", List.of(ACCEPTER), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
|
||||
List<ResourceShareInvitation> invitations =
|
||||
service.getResourceShareInvitations(ACCEPTER, List.of(), List.of());
|
||||
service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1");
|
||||
assertEquals(1, invitations.size());
|
||||
ResourceShareInvitation invitation = invitations.get(0);
|
||||
assertEquals(share.getResourceShareArn(), invitation.resourceShareArn());
|
||||
@@ -337,9 +407,9 @@ class RamServiceTest {
|
||||
|
||||
// Receiver-only, per the API reference ("invitations that you have received"): the
|
||||
// sender does not see its own outstanding invitations through this call.
|
||||
assertTrue(service.getResourceShareInvitations(OWNER, List.of(), List.of()).isEmpty());
|
||||
assertTrue(service.getResourceShareInvitations(OWNER, List.of(), List.of(), "us-east-1").isEmpty());
|
||||
// But the share itself is visible regardless: invitations are bookkeeping, not a gate.
|
||||
assertEquals(1, service.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS").size());
|
||||
assertEquals(1, service.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS", "us-east-1").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -347,7 +417,7 @@ class RamServiceTest {
|
||||
service.createResourceShare(
|
||||
"ou-share", List.of(OU_ARN), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
|
||||
assertTrue(service.getResourceShareInvitations(ACCEPTER, List.of(), List.of()).isEmpty());
|
||||
assertTrue(service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -357,40 +427,40 @@ class RamServiceTest {
|
||||
service.createResourceShare(
|
||||
"direct-share", List.of(ACCEPTER), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
|
||||
assertTrue(service.getResourceShareInvitations(ACCEPTER, List.of(), List.of()).isEmpty());
|
||||
assertTrue(service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void associatingNewAccountPrincipalCreatesInvitationButReassociatingExistingOneDoesNot() {
|
||||
ResourceShare share = service.createResourceShare(
|
||||
"direct-share", List.of(ACCEPTER), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
assertEquals(1, service.getResourceShareInvitations(ACCEPTER, List.of(), List.of()).size());
|
||||
assertEquals(1, service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1").size());
|
||||
|
||||
// Re-associating the same principal must not spawn a second invitation.
|
||||
service.associateResourceShare(share.getResourceShareArn(), List.of(), List.of(ACCEPTER), OWNER);
|
||||
assertEquals(1, service.getResourceShareInvitations(ACCEPTER, List.of(), List.of()).size());
|
||||
service.associateResourceShare(share.getResourceShareArn(), List.of(), List.of(ACCEPTER), OWNER, "us-east-1");
|
||||
assertEquals(1, service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1").size());
|
||||
|
||||
// A genuinely new principal gets its own.
|
||||
String other = "333333333333";
|
||||
service.associateResourceShare(share.getResourceShareArn(), List.of(), List.of(other), OWNER);
|
||||
assertEquals(1, service.getResourceShareInvitations(other, List.of(), List.of()).size());
|
||||
assertEquals(1, service.getResourceShareInvitations(ACCEPTER, List.of(), List.of()).size());
|
||||
service.associateResourceShare(share.getResourceShareArn(), List.of(), List.of(other), OWNER, "us-east-1");
|
||||
assertEquals(1, service.getResourceShareInvitations(other, List.of(), List.of(), "us-east-1").size());
|
||||
assertEquals(1, service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void acceptResourceShareInvitationTransitionsToAcceptedAndIsThenTerminal() {
|
||||
service.createResourceShare(
|
||||
"direct-share", List.of(ACCEPTER), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
String invitationArn = service.getResourceShareInvitations(ACCEPTER, List.of(), List.of())
|
||||
String invitationArn = service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1")
|
||||
.get(0).resourceShareInvitationArn();
|
||||
|
||||
ResourceShareInvitation accepted = service.acceptResourceShareInvitation(invitationArn, ACCEPTER);
|
||||
ResourceShareInvitation accepted = service.acceptResourceShareInvitation(invitationArn, ACCEPTER, "us-east-1");
|
||||
assertEquals("ACCEPTED", accepted.status());
|
||||
assertEquals("ACCEPTED",
|
||||
service.getResourceShareInvitations(ACCEPTER, List.of(), List.of()).get(0).status());
|
||||
service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1").get(0).status());
|
||||
|
||||
AwsException repeat = assertThrows(AwsException.class,
|
||||
() -> service.acceptResourceShareInvitation(invitationArn, ACCEPTER));
|
||||
() -> service.acceptResourceShareInvitation(invitationArn, ACCEPTER, "us-east-1"));
|
||||
assertEquals("ResourceShareInvitationAlreadyAcceptedException", repeat.getErrorCode());
|
||||
}
|
||||
|
||||
@@ -398,14 +468,14 @@ class RamServiceTest {
|
||||
void rejectResourceShareInvitationTransitionsToRejectedAndIsThenTerminal() {
|
||||
service.createResourceShare(
|
||||
"direct-share", List.of(ACCEPTER), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
String invitationArn = service.getResourceShareInvitations(ACCEPTER, List.of(), List.of())
|
||||
String invitationArn = service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1")
|
||||
.get(0).resourceShareInvitationArn();
|
||||
|
||||
ResourceShareInvitation rejected = service.rejectResourceShareInvitation(invitationArn, ACCEPTER);
|
||||
ResourceShareInvitation rejected = service.rejectResourceShareInvitation(invitationArn, ACCEPTER, "us-east-1");
|
||||
assertEquals("REJECTED", rejected.status());
|
||||
|
||||
AwsException repeat = assertThrows(AwsException.class,
|
||||
() -> service.rejectResourceShareInvitation(invitationArn, ACCEPTER));
|
||||
() -> service.rejectResourceShareInvitation(invitationArn, ACCEPTER, "us-east-1"));
|
||||
assertEquals("ResourceShareInvitationAlreadyRejectedException", repeat.getErrorCode());
|
||||
}
|
||||
|
||||
@@ -413,43 +483,44 @@ class RamServiceTest {
|
||||
void reassociatingAfterRejectionSendsANewInvitation() {
|
||||
ResourceShare share = service.createResourceShare(
|
||||
"direct-share", List.of(ACCEPTER), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
String firstArn = service.getResourceShareInvitations(ACCEPTER, List.of(), List.of())
|
||||
String firstArn = service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1")
|
||||
.get(0).resourceShareInvitationArn();
|
||||
service.rejectResourceShareInvitation(firstArn, ACCEPTER);
|
||||
service.rejectResourceShareInvitation(firstArn, ACCEPTER, "us-east-1");
|
||||
|
||||
// Disassociate and re-associate, same as a Terraform apply that removes then re-adds
|
||||
// the principal: real AWS sends a fresh invitation rather than leaving the account
|
||||
// permanently locked out by an old rejection.
|
||||
service.disassociateResourceShare(share.getResourceShareArn(), List.of(), List.of(ACCEPTER), OWNER);
|
||||
service.associateResourceShare(share.getResourceShareArn(), List.of(), List.of(ACCEPTER), OWNER);
|
||||
service.disassociateResourceShare(share.getResourceShareArn(), List.of(), List.of(ACCEPTER), OWNER,
|
||||
"us-east-1");
|
||||
service.associateResourceShare(share.getResourceShareArn(), List.of(), List.of(ACCEPTER), OWNER, "us-east-1");
|
||||
|
||||
List<ResourceShareInvitation> invitations =
|
||||
service.getResourceShareInvitations(ACCEPTER, List.of(), List.of());
|
||||
service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1");
|
||||
assertEquals(2, invitations.size());
|
||||
assertTrue(invitations.stream().anyMatch(i -> "PENDING".equals(i.status())));
|
||||
|
||||
// The live invitation must keep the share visible even when the rejected historical
|
||||
// invitation is returned first by storage scans.
|
||||
assertEquals(1, service.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS").size());
|
||||
assertEquals(1, service.getResourceShares(ACCEPTER, "OTHER-ACCOUNTS", "us-east-1").size());
|
||||
assertEquals(1, service.listResources(ACCEPTER, "OTHER-ACCOUNTS",
|
||||
List.of(share.getResourceShareArn())).size());
|
||||
List.of(share.getResourceShareArn()), "us-east-1").size());
|
||||
assertEquals(1, service.listPrincipals(ACCEPTER, "OTHER-ACCOUNTS",
|
||||
List.of(share.getResourceShareArn())).size());
|
||||
List.of(share.getResourceShareArn()), "us-east-1").size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void onlyTheReceiverCanAcceptOrRejectAnInvitation() {
|
||||
service.createResourceShare(
|
||||
"direct-share", List.of(ACCEPTER), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
String invitationArn = service.getResourceShareInvitations(ACCEPTER, List.of(), List.of())
|
||||
String invitationArn = service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1")
|
||||
.get(0).resourceShareInvitationArn();
|
||||
|
||||
AwsException bySender = assertThrows(AwsException.class,
|
||||
() -> service.acceptResourceShareInvitation(invitationArn, OWNER));
|
||||
() -> service.acceptResourceShareInvitation(invitationArn, OWNER, "us-east-1"));
|
||||
assertEquals("OperationNotPermittedException", bySender.getErrorCode());
|
||||
|
||||
AwsException byStranger = assertThrows(AwsException.class,
|
||||
() -> service.rejectResourceShareInvitation(invitationArn, "444444444444"));
|
||||
() -> service.rejectResourceShareInvitation(invitationArn, "444444444444", "us-east-1"));
|
||||
assertEquals("OperationNotPermittedException", byStranger.getErrorCode());
|
||||
}
|
||||
|
||||
@@ -457,7 +528,8 @@ class RamServiceTest {
|
||||
void unknownInvitationArnFailsWithNotFoundException() {
|
||||
AwsException error = assertThrows(AwsException.class, () ->
|
||||
service.acceptResourceShareInvitation(
|
||||
"arn:aws:ram:us-east-1:222222222222:resource-share-invitation/does-not-exist", ACCEPTER));
|
||||
"arn:aws:ram:us-east-1:222222222222:resource-share-invitation/does-not-exist", ACCEPTER,
|
||||
"us-east-1"));
|
||||
assertEquals("ResourceShareInvitationArnNotFoundException", error.getErrorCode());
|
||||
assertEquals(400, error.getHttpStatus());
|
||||
}
|
||||
@@ -465,12 +537,12 @@ class RamServiceTest {
|
||||
@Test
|
||||
void malformedInvitationArnFailsWithMalformedArnException() {
|
||||
AwsException error = assertThrows(AwsException.class, () ->
|
||||
service.acceptResourceShareInvitation("not-an-arn", ACCEPTER));
|
||||
service.acceptResourceShareInvitation("not-an-arn", ACCEPTER, "us-east-1"));
|
||||
assertEquals("MalformedArnException", error.getErrorCode());
|
||||
assertEquals(400, error.getHttpStatus());
|
||||
|
||||
AwsException filterError = assertThrows(AwsException.class, () ->
|
||||
service.getResourceShareInvitations(ACCEPTER, List.of("not-an-arn"), List.of()));
|
||||
service.getResourceShareInvitations(ACCEPTER, List.of("not-an-arn"), List.of(), "us-east-1"));
|
||||
assertEquals("MalformedArnException", filterError.getErrorCode());
|
||||
}
|
||||
|
||||
@@ -480,23 +552,24 @@ class RamServiceTest {
|
||||
"direct-share", List.of(ACCEPTER), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
service.createResourceShare(
|
||||
"other-share", List.of(ACCEPTER), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
String invitationArn = service.getResourceShareInvitations(ACCEPTER, List.of(), List.of()).stream()
|
||||
String invitationArn = service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1").stream()
|
||||
.filter(i -> i.resourceShareArn().equals(share.getResourceShareArn()))
|
||||
.findFirst().orElseThrow().resourceShareInvitationArn();
|
||||
|
||||
assertEquals(1, service.getResourceShareInvitations(
|
||||
ACCEPTER, List.of(share.getResourceShareArn()), List.of()).size());
|
||||
ACCEPTER, List.of(share.getResourceShareArn()), List.of(), "us-east-1").size());
|
||||
assertEquals(1, service.getResourceShareInvitations(
|
||||
ACCEPTER, List.of(), List.of(invitationArn)).size());
|
||||
ACCEPTER, List.of(), List.of(invitationArn), "us-east-1").size());
|
||||
assertTrue(service.getResourceShareInvitations(
|
||||
ACCEPTER, List.of("arn:aws:ram:us-east-1:111111111111:resource-share/nope"), List.of()).isEmpty());
|
||||
ACCEPTER, List.of("arn:aws:ram:us-east-1:111111111111:resource-share/nope"), List.of(),
|
||||
"us-east-1").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void concurrentAcceptCallsOnTheSameInvitationOnlySucceedOnce() throws Exception {
|
||||
service.createResourceShare(
|
||||
"direct-share", List.of(ACCEPTER), List.of(TGW_ARN), false, "us-east-1", OWNER);
|
||||
String invitationArn = service.getResourceShareInvitations(ACCEPTER, List.of(), List.of())
|
||||
String invitationArn = service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1")
|
||||
.get(0).resourceShareInvitationArn();
|
||||
|
||||
int threadCount = 8;
|
||||
@@ -510,7 +583,7 @@ class RamServiceTest {
|
||||
ready.countDown();
|
||||
assertTrue(start.await(5, TimeUnit.SECONDS));
|
||||
try {
|
||||
service.acceptResourceShareInvitation(invitationArn, ACCEPTER);
|
||||
service.acceptResourceShareInvitation(invitationArn, ACCEPTER, "us-east-1");
|
||||
return true;
|
||||
} catch (AwsException e) {
|
||||
assertEquals("ResourceShareInvitationAlreadyAcceptedException", e.getErrorCode());
|
||||
@@ -548,7 +621,8 @@ class RamServiceTest {
|
||||
results.add(executor.submit(() -> {
|
||||
ready.countDown();
|
||||
assertTrue(start.await(5, TimeUnit.SECONDS));
|
||||
service.associateResourceShare(share.getResourceShareArn(), List.of(), List.of(ACCEPTER), OWNER);
|
||||
service.associateResourceShare(share.getResourceShareArn(), List.of(), List.of(ACCEPTER), OWNER,
|
||||
"us-east-1");
|
||||
return null;
|
||||
}));
|
||||
}
|
||||
@@ -561,7 +635,7 @@ class RamServiceTest {
|
||||
executor.shutdownNow();
|
||||
}
|
||||
|
||||
assertEquals(1, service.getResourceShareInvitations(ACCEPTER, List.of(), List.of()).size());
|
||||
assertEquals(1, service.getResourceShareInvitations(ACCEPTER, List.of(), List.of(), "us-east-1").size());
|
||||
}
|
||||
|
||||
private static void assertInvalidParameter(Executable read) {
|
||||
|
||||
@@ -191,6 +191,22 @@ class RdsServiceTest {
|
||||
assertEquals("arn:aws:rds:us-east-1:123456789012:db:mydb", instance.getDbInstanceArn());
|
||||
}
|
||||
|
||||
/** An instance created in China carries an aws-cn ARN, and its own lookup must still find it. */
|
||||
@Test
|
||||
void aChinaInstanceIsFoundAfterCreation() {
|
||||
regionResolver = new RegionResolver("cn-north-1", "123456789012");
|
||||
rdsService = newService(containerManager, proxyManager,
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>());
|
||||
|
||||
DbInstance instance = rdsService.createDbInstance("cn-db", "postgres", "13",
|
||||
"admin", "password", "dbname", "db.t3.micro",
|
||||
20, false, null, null, null, null, false);
|
||||
|
||||
assertEquals("arn:aws-cn:rds:cn-north-1:123456789012:db:cn-db", instance.getDbInstanceArn());
|
||||
assertEquals("cn-db", rdsService.getDbInstance("cn-db").getDbInstanceIdentifier());
|
||||
}
|
||||
|
||||
@Test
|
||||
void createDbInstanceSupportsSqlServerEngineIdentifiers() {
|
||||
DbInstance instance = rdsService.createDbInstance("sqlserver-db", "sqlserver-se", "15.00",
|
||||
@@ -1619,6 +1635,22 @@ class RdsServiceTest {
|
||||
assertEquals(java.util.Map.of(), rdsService.listTagsForResource(targetGroupArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void chinaDbProxyTargetGroupTagsRoundTripByArn() {
|
||||
regionResolver = new RegionResolver("cn-north-1", "123456789012");
|
||||
rdsService = newService(containerManager, proxyManager,
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>());
|
||||
rdsService.createDbProxy("app-proxy", "POSTGRESQL", true, false, PROXY_ROLE_ARN,
|
||||
PROXY_SUBNET_IDS, List.of(), PROXY_AUTH, Map.of());
|
||||
String targetGroupArn = rdsService.describeDbProxyTargetGroups("app-proxy")
|
||||
.iterator().next().getTargetGroupArn();
|
||||
assertTrue(targetGroupArn.startsWith("arn:aws-cn:rds:cn-north-1:"), targetGroupArn);
|
||||
|
||||
rdsService.addTagsToResource(targetGroupArn, Map.of("env", "test"));
|
||||
assertEquals(Map.of("env", "test"), rdsService.listTagsForResource(targetGroupArn));
|
||||
}
|
||||
|
||||
@Test
|
||||
void dbProxyTargetGroupTagOperationsRejectMissingTargetGroup() {
|
||||
AwsException exception = assertThrows(AwsException.class, () ->
|
||||
@@ -3463,6 +3495,30 @@ class RdsServiceTest {
|
||||
verify(containerManager).restorePostgresSnapshot(any(), eq("admin"), eq("MOCK_DUMP_DATA"));
|
||||
}
|
||||
|
||||
/** A China snapshot ARN is a source a China copy can read; a commercial one is not. */
|
||||
@Test
|
||||
void copyDbSnapshotReadsAChinaSourceArnWithinItsPartition() {
|
||||
regionResolver = new RegionResolver("cn-north-1", "123456789012");
|
||||
rdsService = newService(containerManager, proxyManager,
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(),
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>());
|
||||
rdsService.createDbInstance("mydb", "postgres", "13",
|
||||
"admin", "password", "dbname", "db.t3.micro",
|
||||
20, false, null, null, null, null, false);
|
||||
when(containerManager.createPostgresSnapshot(any(), eq("admin"))).thenReturn("MOCK_DUMP_DATA");
|
||||
DbSnapshot source = rdsService.createDbSnapshot("source", "mydb");
|
||||
assertEquals("arn:aws-cn:rds:cn-north-1:123456789012:snapshot:source", source.getDbSnapshotArn());
|
||||
|
||||
DbSnapshot copy = rdsService.copyDbSnapshot(source.getDbSnapshotArn(), "copy", false,
|
||||
Map.of(), null, null, "cn-north-1");
|
||||
assertEquals("copy", copy.getDbSnapshotIdentifier());
|
||||
|
||||
AwsException otherPartition = assertThrows(AwsException.class, () ->
|
||||
rdsService.copyDbSnapshot("arn:aws:rds:us-east-1:123456789012:snapshot:source", "other", false,
|
||||
Map.of(), null, null, "cn-north-1"));
|
||||
assertEquals("InvalidParameterValue", otherPartition.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void copyDbSnapshotRejectsDuplicateTargetsAndUnavailableSources() {
|
||||
rdsService.createDbInstance("mydb", "postgres", "13",
|
||||
|
||||
+47
-2
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.InMemoryStorage;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.services.ssoadmin.model.Assignment;
|
||||
import io.github.hectorvent.floci.services.ssoadmin.model.AssignmentOperation;
|
||||
import io.github.hectorvent.floci.services.ssoadmin.model.AssignmentDeletionOperation;
|
||||
@@ -25,6 +26,8 @@ import io.github.hectorvent.floci.services.organizations.OrganizationsService;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -1831,7 +1834,49 @@ class SsoAdminServiceTest {
|
||||
() -> service.getAssignmentOperation(service.getInstanceArn(), operation.requestId()));
|
||||
}
|
||||
|
||||
/** The seeded instance lives in the deployment's home region, so its ARN takes that partition. */
|
||||
@Test
|
||||
void seededInstanceTakesTheHomeRegionsPartition() {
|
||||
SsoAdminService china = emptyService("cn-north-1");
|
||||
|
||||
assertEquals("arn:aws-cn:sso:::instance/ssoins-7223b02a5d9f7c8e", china.getInstanceArn());
|
||||
assertEquals(List.of(china.getInstanceArn()),
|
||||
china.listInstances("999999999999").stream().map(SsoInstance::instanceArn).toList());
|
||||
ObjectNode addHome = mapper.createObjectNode()
|
||||
.put("InstanceArn", china.getInstanceArn())
|
||||
.put("RegionName", "cn-north-1");
|
||||
assertError("ConflictException", () -> china.addRegion(addHome));
|
||||
}
|
||||
|
||||
/**
|
||||
* A China deployment persisted before the seeded instance took its partition holds it as
|
||||
* arn:aws:, while its permission sets were already minted as arn:aws-cn:; the instance is
|
||||
* moved to the ARN they name.
|
||||
*/
|
||||
@Test
|
||||
void persistedCommercialBootstrapInstanceMovesToItsPrimaryRegionsPartition() {
|
||||
InMemoryStorage<String, SsoInstance> instances = new InMemoryStorage<>();
|
||||
instances.put("999999999999", new SsoInstance("arn:aws:sso:::instance/ssoins-7223b02a5d9f7c8e",
|
||||
"d-9067f2a3c1", "floci-identity-center", "999999999999", "cn-north-1", 0L, "ACTIVE",
|
||||
null, false, new LinkedHashMap<>()));
|
||||
|
||||
SsoAdminService china = emptyService("cn-north-1", instances);
|
||||
|
||||
assertEquals("arn:aws-cn:sso:::instance/ssoins-7223b02a5d9f7c8e",
|
||||
instances.get("999999999999").orElseThrow().instanceArn());
|
||||
assertEquals(List.of(china.getInstanceArn()),
|
||||
china.listInstances("999999999999").stream().map(SsoInstance::instanceArn).toList());
|
||||
}
|
||||
|
||||
private SsoAdminService emptyService() {
|
||||
return emptyService("us-east-1");
|
||||
}
|
||||
|
||||
private SsoAdminService emptyService(String defaultRegion) {
|
||||
return emptyService(defaultRegion, new InMemoryStorage<String, SsoInstance>());
|
||||
}
|
||||
|
||||
private SsoAdminService emptyService(String defaultRegion, StorageBackend<String, SsoInstance> instances) {
|
||||
return new SsoAdminService(
|
||||
new InMemoryStorage<String, PermissionSet>(),
|
||||
new InMemoryStorage<String, Assignment>(),
|
||||
@@ -1850,7 +1895,7 @@ class SsoAdminServiceTest {
|
||||
new InMemoryStorage<String, ApplicationGrant>(),
|
||||
new InMemoryStorage<String, String>(),
|
||||
new InMemoryStorage<String, Map<String, String>>(),
|
||||
new InMemoryStorage<String, SsoInstance>(),
|
||||
instances,
|
||||
new InMemoryStorage<String, InstanceUpdateState>(),
|
||||
new InMemoryStorage<String, String>(),
|
||||
new InMemoryStorage<String, Boolean>(),
|
||||
@@ -1861,7 +1906,7 @@ class SsoAdminServiceTest {
|
||||
identityStoreService,
|
||||
organizationsService,
|
||||
"999999999999",
|
||||
"us-east-1");
|
||||
defaultRegion);
|
||||
}
|
||||
|
||||
private ObjectNode trustedTokenIssuerRequest(String name, String clientToken) {
|
||||
|
||||
Reference in new issue
Block a user