diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsArnUtils.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsArnUtils.java index fb9ca15f16..3757554572 100644 --- a/src/main/java/io/github/hectorvent/floci/core/common/AwsArnUtils.java +++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsArnUtils.java @@ -91,6 +91,44 @@ public final class AwsArnUtils { } } + /** + * Regex fragment matching any AWS partition id: {@code aws}, {@code aws-cn}, + * {@code aws-us-gov}, and the classified {@code aws-iso*} and {@code aws-eusc} partitions. + * + *
Transcribed from the shape AWS publishes in its own service models, where every + * partition-carrying ARN member is patterned {@code arn:aws(-[a-z]{1,5}){0,3}:...}. The group + * is non-capturing so it can be dropped into an existing pattern without shifting the + * numbering of the groups around it. + * + *
Exists because a literal {@code ^arn:aws:} anchors a pattern to the commercial partition + * and silently rejects every legal ARN outside it. + */ + public static final String PARTITION_REGEX = "aws(?:-[a-z]{1,5}){0,3}"; + + /** + * True when {@code value} is syntactically an ARN: six colon-delimited segments, the first + * of which is {@code arn}. Says nothing about whether the resource part is well formed for + * its service, which only that service can decide. + * + *
The partition-tolerant replacement for a {@code startsWith("arn:aws:")} probe.
+ */
+ public static boolean isArn(String value) {
+ if (value == null || value.isBlank()) {
+ return false;
+ }
+ String[] parts = value.split(":", 6);
+ return parts.length == 6 && "arn".equals(parts[0]);
+ }
+
+ /**
+ * True when {@code value} is an ARN naming {@code service}, in any partition. The common use
+ * is telling an identifier that may be either a bare name or a full ARN apart, e.g. a
+ * DynamoDB {@code TableName} that clients are allowed to give either way.
+ */
+ public static boolean isArnFor(String value, String service) {
+ return isArn(value) && value.split(":", 6)[2].equals(service);
+ }
+
/**
* Converts an SQS ARN to a queue URL using the given base URL.
* Example: arn:aws:sqs:us-east-1:000000000000:my-queue → http://localhost:4566/000000000000/my-queue
diff --git a/src/main/java/io/github/hectorvent/floci/services/apigateway/AwsServiceRouter.java b/src/main/java/io/github/hectorvent/floci/services/apigateway/AwsServiceRouter.java
index 0352056ea1..a70da7f159 100644
--- a/src/main/java/io/github/hectorvent/floci/services/apigateway/AwsServiceRouter.java
+++ b/src/main/java/io/github/hectorvent/floci/services/apigateway/AwsServiceRouter.java
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.apigateway;
+import io.github.hectorvent.floci.core.common.AwsArnUtils;
import com.fasterxml.jackson.databind.JsonNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.acm.AcmJsonHandler;
@@ -22,7 +23,6 @@ import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;
import org.jboss.logging.Logger;
import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* Routes API Gateway AWS integration requests to the correct internal service handler.
@@ -82,13 +82,6 @@ public class AwsServiceRouter {
this.acmHandler = acmHandler;
}
- private static final Pattern ACTION_URI_PATTERN = Pattern.compile(
- "^arn:aws:apigateway:([^:]+):([^:]+):action/(.+)$"
- );
- private static final Pattern PATH_URI_PATTERN = Pattern.compile(
- "^arn:aws:apigateway:([^:]+):([^:]+):path/(.+)$"
- );
-
/**
* Parsed components of an API Gateway AWS integration URI.
*/
@@ -113,7 +106,7 @@ public class AwsServiceRouter {
* @return parsed target, or null if the URI format is not recognized
*/
public IntegrationTarget parseIntegrationUri(String uri) {
- if (uri == null || !uri.startsWith("arn:aws:apigateway:")) {
+ if (!AwsArnUtils.isArnFor(uri, "apigateway")) {
return null;
}
// arn:aws:apigateway:{region}:{service}:{action/{Action}|path/{resourcePath}}
diff --git a/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/auth/IamAuthValidator.java b/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/auth/IamAuthValidator.java
index cf1a6ee226..00026a00cf 100644
--- a/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/auth/IamAuthValidator.java
+++ b/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/auth/IamAuthValidator.java
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.appsync.graphql.auth;
+import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.AccountResolver;
import io.github.hectorvent.floci.services.iam.IamPolicyEvaluator;
import io.github.hectorvent.floci.services.iam.IamService;
@@ -63,13 +64,22 @@ public class IamAuthValidator {
return "test".equals(accessKeyId);
}
+ /**
+ * The resource these two build is matched against a policy the customer wrote using the ARN
+ * AppSync handed them, and that ARN carries the region's partition. Pinning {@code aws} here
+ * meant a GovCloud policy naming its own API never matched, and the request was denied.
+ */
+ private static String appsyncArnPrefix(String region) {
+ return "arn:" + AwsRegions.partitionFor(region) + ":appsync:";
+ }
+
static String requestArn(String region, String accountId, String apiId) {
- return "arn:aws:appsync:" + nullToEmpty(region) + ":" + nullToEmpty(accountId)
+ return appsyncArnPrefix(region) + nullToEmpty(region) + ":" + nullToEmpty(accountId)
+ ":apis/" + apiId + "/*";
}
static String fieldArn(String region, String accountId, String apiId, String typeName, String fieldName) {
- return "arn:aws:appsync:" + nullToEmpty(region) + ":" + nullToEmpty(accountId)
+ return appsyncArnPrefix(region) + nullToEmpty(region) + ":" + nullToEmpty(accountId)
+ ":apis/" + apiId + "/types/" + typeName + "/fields/" + fieldName;
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbJsonHandler.java
index 3d744a80a9..c47bb60510 100644
--- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/DynamoDbJsonHandler.java
@@ -1802,9 +1802,14 @@ public class DynamoDbJsonHandler {
return Response.ok(response).build();
}
+ /**
+ * Botocore gives DynamoDB's {@code ResourceArnString} no pattern at all, only a length range,
+ * so this shape is the emulator's own. Widening the partition keeps it from rejecting a legal
+ * GovCloud or China table ARN.
+ */
private static final java.util.regex.Pattern DYNAMODB_TABLE_ARN_PATTERN =
- java.util.regex.Pattern.compile(
- "^arn:aws:dynamodb:[a-z0-9-]+:\\d{12}:table/[a-zA-Z0-9._-]+$");
+ java.util.regex.Pattern.compile("^arn:" + AwsArnUtils.PARTITION_REGEX
+ + ":dynamodb:[a-z0-9-]+:\\d{12}:table/[a-zA-Z0-9._-]+$");
private static boolean isValidDynamoDbTableArn(String arn) {
return arn != null && DYNAMODB_TABLE_ARN_PATTERN.matcher(arn).matches();
diff --git a/src/main/java/io/github/hectorvent/floci/services/ecs/container/EcsContainerManager.java b/src/main/java/io/github/hectorvent/floci/services/ecs/container/EcsContainerManager.java
index ab2fa072a3..4ea6f41d87 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ecs/container/EcsContainerManager.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ecs/container/EcsContainerManager.java
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.ecs.container;
+import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
@@ -421,7 +422,7 @@ public class EcsContainerManager {
String value;
String jsonKey = null;
try {
- if (valueFrom != null && valueFrom.startsWith("arn:aws:secretsmanager:")) {
+ if (AwsArnUtils.isArnFor(valueFrom, "secretsmanager")) {
// The valueFrom may carry the ECS selector suffix
// (:json-key:version-stage:version-id); the parser strips it so the base ARN
// reaches SecretsManagerService intact, keeping its partial-ARN fallback working.
@@ -479,7 +480,7 @@ public class EcsContainerManager {
}
private String ssmParameterName(String valueFrom) {
- if (valueFrom != null && valueFrom.startsWith("arn:aws:ssm:")) {
+ if (AwsArnUtils.isArnFor(valueFrom, "ssm")) {
int parameterMarker = valueFrom.indexOf(":parameter");
if (parameterMarker >= 0) {
return valueFrom.substring(parameterMarker + ":parameter".length());
diff --git a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java
index 5499b4384e..3cc3ad5cc6 100644
--- a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java
@@ -1096,8 +1096,8 @@ public class EventBridgeService implements ResourceProvider {
if (busName == null || busName.isBlank()) {
return "default";
}
- // Handle ARN format: arn:aws:events:region:account-id:event-bus/bus-name
- if (busName.startsWith("arn:aws:events:")) {
+ // Handle ARN format: arn: The caller's partition is carried across rather than assumed. IAM ARNs are regionless, so
+ * {@code Arn.of} cannot derive it, and hardcoding {@code aws} here would rewrite a GovCloud
+ * caller into a commercial role ARN that no GovCloud trust policy can match: the caller would
+ * be denied a role they are entitled to, with nothing in the response saying why.
*/
private static String assumedRoleToRoleArn(String arn) {
var m = ASSUMED_ROLE_ARN.matcher(arn);
- return m.matches() ? AwsArnUtils.Arn.of("iam", "", m.group(1), "role/" + m.group(2)).toString() : null;
+ if (!m.matches()) {
+ return null;
+ }
+ return new AwsArnUtils.Arn(m.group(1), "iam", "", m.group(2), "role/" + m.group(3)).toString();
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilder.java b/src/main/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilder.java
index 1a3976ea28..6961f3f55b 100644
--- a/src/main/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilder.java
+++ b/src/main/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilder.java
@@ -263,7 +263,7 @@ public class ResourceArnBuilder {
}
private String toDynamoDbTableArn(String tableName, String region, String accountId) {
- if (tableName.startsWith("arn:aws:dynamodb:")) {
+ if (AwsArnUtils.isArnFor(tableName, "dynamodb")) {
return tableName;
}
return AwsArnUtils.Arn.of("dynamodb", region, accountId, "table/" + tableName).toString();
@@ -282,7 +282,7 @@ public class ResourceArnBuilder {
if (json.hasNonNull("StreamName")) {
String streamName = json.get("StreamName").asText().trim();
if (!streamName.isEmpty()) {
- if (streamName.startsWith("arn:aws:kinesis:")) {
+ if (AwsArnUtils.isArnFor(streamName, "kinesis")) {
return streamName;
}
return AwsArnUtils.Arn.of("kinesis", region, accountId, "stream/" + streamName).toString();
@@ -305,7 +305,7 @@ public class ResourceArnBuilder {
if (json.hasNonNull("SecretId")) {
String secretId = json.get("SecretId").asText().trim();
if (!secretId.isEmpty()) {
- if (secretId.startsWith("arn:aws:secretsmanager:")) {
+ if (AwsArnUtils.isArnFor(secretId, "secretsmanager")) {
return secretId;
}
return AwsArnUtils.Arn.of("secretsmanager", region, accountId, "secret:" + secretId).toString();
@@ -322,7 +322,7 @@ public class ResourceArnBuilder {
if (json.hasNonNull("Name")) {
String name = json.get("Name").asText().trim();
if (!name.isEmpty()) {
- if (name.startsWith("arn:aws:ssm:")) {
+ if (AwsArnUtils.isArnFor(name, "ssm")) {
return name;
}
String paramResource = name.startsWith("/") ? "parameter" + name : "parameter/" + name;
diff --git a/src/main/java/io/github/hectorvent/floci/services/kms/KmsService.java b/src/main/java/io/github/hectorvent/floci/services/kms/KmsService.java
index 1eeed08165..1c06517645 100644
--- a/src/main/java/io/github/hectorvent/floci/services/kms/KmsService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/kms/KmsService.java
@@ -2008,7 +2008,7 @@ public class KmsService implements ResourceProvider {
id = aliasStore.get(aliasKey)
.map(KmsAlias::getTargetKeyId)
.orElseThrow(() -> new AwsException("NotFoundException", "Alias not found: " + keyIdOrArn, 404));
- } else if (id.startsWith("arn:aws:kms:")) {
+ } else if (AwsArnUtils.isArnFor(id, "kms")) {
// Key arn
id = id.substring(id.lastIndexOf("/") + 1);
} else if (id.startsWith("alias/")) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/secretsmanager/SecretsManagerService.java b/src/main/java/io/github/hectorvent/floci/services/secretsmanager/SecretsManagerService.java
index b2fe2666f3..ec4a7eae4d 100644
--- a/src/main/java/io/github/hectorvent/floci/services/secretsmanager/SecretsManagerService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/secretsmanager/SecretsManagerService.java
@@ -998,17 +998,21 @@ public class SecretsManagerService implements ResourceProvider {
// 2. Partial-ARN fallback: extract region + name and do a name-based lookup.
// AWS supports ARNs without the trailing "-XXXXXX" random suffix.
- // ARN format: arn:aws:secretsmanager: Deliberately stops before the account segment: the store holds resources for more than
+ * one account under account isolation, so {@code RegionResolver.buildArn} is the wrong helper
+ * here, since it appends its own account id.
+ */
+ private static String regionArnPrefix(String region) {
+ return "arn:" + AwsRegions.partitionFor(region) + ":states:" + region + ":";
+ }
+
public List The region drives the partition, and it comes from the request's SigV4 credential scope.
+ */
+@QuarkusTest
+class DynamoDbTagResourcePartitionIntegrationTest {
+
+ private static final String CONTENT_TYPE = "application/x-amz-json-1.0";
+
+ /**
+ * Tables created here live in the emulator's shared state for the rest of the suite, and the
+ * non-commercial ones carry a non-commercial ARN. ResourceExplorer2's cross-service scan
+ * asserts that every resource it can see is in the commercial partition, so leaving these
+ * behind fails an unrelated test. Every table this class creates is removed again.
+ */
+ private final List Region comes from the SigV4 credential scope. The bus is deleted again: @QuarkusTest
+ * classes share one emulator, and a non-commercial ARN left behind fails the cross-service
+ * scan in ResourceExplorer2IntegrationTest.
+ */
+ @org.junit.jupiter.params.ParameterizedTest
+ @org.junit.jupiter.params.provider.CsvSource({
+ "us-east-1, arn:aws:events:",
+ "us-gov-west-1, arn:aws-us-gov:events:",
+ "cn-north-1, arn:aws-cn:events:"})
+ @Order(10)
+ void describeEventBus_withArn_inAnyPartition(String region, String expectedArnPrefix) {
+ String busName = "partition-bus-" + region;
+ String auth = "AWS4-HMAC-SHA256 Credential=AKID/20260215/" + region
+ + "/events/aws4_request, SignedHeaders=host, Signature=abc";
+
+ String busArn = given()
+ .header("Authorization", auth)
+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSEvents.CreateEventBus")
+ .body("{\"Name\":\"" + busName + "\"}")
+ .when().post("/")
+ .then().statusCode(200)
+ .extract().jsonPath().getString("EventBusArn");
+
+ org.hamcrest.MatcherAssert.assertThat(busArn, org.hamcrest.Matchers.startsWith(expectedArnPrefix));
+
+ try {
+ given()
+ .header("Authorization", auth)
+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSEvents.DescribeEventBus")
+ .body("{\"Name\":\"" + busArn + "\"}")
+ .when().post("/")
+ .then()
+ .statusCode(200)
+ .body("Name", equalTo(busName))
+ .body("Arn", equalTo(busArn));
+ } finally {
+ given()
+ .header("Authorization", auth)
+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSEvents.DeleteEventBus")
+ .body("{\"Name\":\"" + busName + "\"}")
+ .when().post("/");
+ }
+ }
+
+ /**
+ * A truncated ARN must still be reported as a malformed ARN rather than quietly taken as a
+ * literal bus name. This is why the gate matches an ARN prefix instead of asking
+ * whether the whole string is a well-formed EventBridge ARN.
+ */
+ @Test
+ @Order(10)
+ void describeEventBus_withTruncatedArn_isRejected() {
+ given()
+ .contentType(EVENT_BRIDGE_CONTENT_TYPE)
+ .header("X-Amz-Target", "AWSEvents.DescribeEventBus")
+ .body("{\"Name\":\"arn:aws:events:\"}")
+ .when().post("/")
+ .then()
+ .statusCode(400)
+ .body(containsString("ValidationException"));
+ }
+
@Test
@Order(11)
void describeEventBus_withArn() {
diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/AssumeRolePolicyEvaluatorTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/AssumeRolePolicyEvaluatorTest.java
index 6797faf19c..766e6644a7 100644
--- a/src/test/java/io/github/hectorvent/floci/services/iam/AssumeRolePolicyEvaluatorTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/iam/AssumeRolePolicyEvaluatorTest.java
@@ -151,6 +151,45 @@ class AssumeRolePolicyEvaluatorTest {
assumedRoleArn, CALLER_ACCOUNT));
}
+ @Test
+ void allowsAssumedRoleCallerAgainstRolePrincipalArnInGovCloud() {
+ // The silent-denial case. Resolving the session back to its role used to rebuild the role
+ // ARN with a hardcoded "aws" partition, so a GovCloud caller was compared against
+ // arn:aws:iam::... and never matched the arn:aws-us-gov:iam::... principal its own trust
+ // policy names. AssumeRole was refused with nothing in the response explaining why.
+ String assumedRoleArn = "arn:aws-us-gov:sts::111111111111:assumed-role/AppRole/session-abc";
+ assertTrue(evaluator.allows(
+ trust("{\"AWS\":\"arn:aws-us-gov:iam::111111111111:role/AppRole\"}"),
+ assumedRoleArn, CALLER_ACCOUNT));
+ }
+
+ @Test
+ void allowsAssumedRoleCallerAgainstRolePrincipalArnInChina() {
+ String assumedRoleArn = "arn:aws-cn:sts::111111111111:assumed-role/AppRole/session-abc";
+ assertTrue(evaluator.allows(
+ trust("{\"AWS\":\"arn:aws-cn:iam::111111111111:role/AppRole\"}"),
+ assumedRoleArn, CALLER_ACCOUNT));
+ }
+
+ /**
+ * The guard against over-widening. Partitions are isolated, so a session in one must not
+ * satisfy a trust policy written for another even when account, role and session all match.
+ */
+ @Test
+ void deniesAssumedRoleCallerFromAnotherPartition() {
+ String assumedRoleArn = "arn:aws-us-gov:sts::111111111111:assumed-role/AppRole/session-abc";
+ assertFalse(evaluator.allows(
+ trust("{\"AWS\":\"arn:aws:iam::111111111111:role/AppRole\"}"),
+ assumedRoleArn, CALLER_ACCOUNT));
+ }
+
+ @Test
+ void allowsAccountRootPrincipalInGovCloud() {
+ assertTrue(evaluator.allows(
+ trust("{\"AWS\":\"arn:aws-us-gov:iam::111111111111:root\"}"),
+ "arn:aws-us-gov:iam::111111111111:user/alice", CALLER_ACCOUNT));
+ }
+
@Test
void deniesServiceOnlyPrincipal() {
assertFalse(evaluator.allows(
diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilderTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilderTest.java
index 4e319f33ca..d39c9e0cfd 100644
--- a/src/test/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilderTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/iam/ResourceArnBuilderTest.java
@@ -71,6 +71,29 @@ class ResourceArnBuilderTest {
assertEquals("arn:aws:dynamodb:us-east-1:000000000000:table/FgacTable", arn);
}
+ /**
+ * Pass-through used to be a {@code startsWith("arn:aws:dynamodb:")} probe, so a table ARN from
+ * any other partition was not recognised as an ARN at all and got rebuilt as
+ * {@code table/arn:aws-cn:dynamodb:...}, a resource name that matches no policy.
+ */
+ @Test
+ void dynamoDbReturnsExactArnForAnyPartition() {
+ for (String fullArn : List.of(
+ "arn:aws-us-gov:dynamodb:us-gov-west-1:000000000000:table/FgacTable",
+ "arn:aws-cn:dynamodb:cn-north-1:000000000000:table/FgacTable")) {
+ setJsonBody("{\"TableName\":\"" + fullArn + "\"}");
+ assertEquals(fullArn, builder.build("dynamodb", ctx, "us-east-1", "000000000000"));
+ }
+ }
+
+ /** A bare name that merely looks ARN-ish is still a name, not an ARN. */
+ @Test
+ void dynamoDbTreatsAnIncompleteArnAsATableName() {
+ setJsonBody("{\"TableName\":\"arn:aws:dynamodb:us-east-1\"}");
+ assertEquals("arn:aws:dynamodb:us-east-1:000000000000:table/arn:aws:dynamodb:us-east-1",
+ builder.build("dynamodb", ctx, "us-east-1", "000000000000"));
+ }
+
@Test
void dynamoDbReturnsExactArnIfTableNameIsAlreadyArn() {
String fullArn = "arn:aws:dynamodb:us-east-1:000000000000:table/FgacTable";
diff --git a/src/test/java/io/github/hectorvent/floci/services/kms/KmsServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/kms/KmsServiceTest.java
index 6639c08832..ffe8137544 100644
--- a/src/test/java/io/github/hectorvent/floci/services/kms/KmsServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/kms/KmsServiceTest.java
@@ -67,6 +67,22 @@ class KmsServiceTest {
);
}
+ /**
+ * Round-trip in a non-commercial partition. The key ARN a GovCloud or China deployment mints
+ * carries that partition, and resolving a key by ARN used to test
+ * {@code startsWith("arn:aws:kms:")}, so the emulator refused to find a key it had just
+ * created and reported NotFound for a key that exists.
+ */
+ @Test
+ void resolvesAKeyByItsOwnArnInAnyPartition() {
+ for (String region : List.of("us-gov-west-1", "cn-north-1", "us-east-1")) {
+ KmsKey created = kmsService.createKey("partition key", region);
+
+ assertEquals(created.getKeyId(), kmsService.describeKey(created.getArn(), region).getKeyId(),
+ "key in " + region + " was not resolvable by its own ARN " + created.getArn());
+ }
+ }
+
@Test
void createKeyAndDescribe() {
KmsKey key = kmsService.createKey("my test key", REGION);
diff --git a/src/test/java/io/github/hectorvent/floci/services/secretsmanager/SecretsManagerServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/secretsmanager/SecretsManagerServiceTest.java
index 77d65a3ef8..a8df6fa728 100644
--- a/src/test/java/io/github/hectorvent/floci/services/secretsmanager/SecretsManagerServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/secretsmanager/SecretsManagerServiceTest.java
@@ -678,6 +678,39 @@ class SecretsManagerServiceTest {
assertEquals("db-pass", version.getSecretString());
}
+ /**
+ * A secret name may contain colons, and the partial-ARN fallback used to preserve them by
+ * splitting the ARN tail with an explicit limit. Reading the name off the parsed resource has
+ * to keep that property: strip only the leading "secret:", never split again.
+ */
+ @Test
+ void getSecretValueByPartialArnWithColonsInNameSucceeds() {
+ Secret secret = service.createSecret("team:app:db", "colon-pass", null, null, null, null, REGION);
+ String partialArn = secret.getArn().substring(0, secret.getArn().length() - 7);
+
+ SecretVersion version = service.getSecretValue(partialArn, null, null, REGION);
+ assertEquals("colon-pass", version.getSecretString());
+ }
+
+ /**
+ * The partial-ARN fallback matched a literal "arn:aws:secretsmanager:", so outside the
+ * commercial partition a secret's own ARN, minus the random suffix AWS lets clients omit,
+ * resolved to nothing. Round trip through the ARN the emulator itself minted.
+ */
+ @org.junit.jupiter.params.ParameterizedTest
+ @org.junit.jupiter.params.provider.CsvSource({
+ "us-east-1, arn:aws:secretsmanager:",
+ "us-gov-west-1, arn:aws-us-gov:secretsmanager:",
+ "cn-north-1, arn:aws-cn:secretsmanager:"})
+ void getSecretValueByPartialArnSucceedsInAnyPartition(String region, String expectedArnPrefix) {
+ Secret secret = service.createSecret("p-secret", "value", null, null, null, null, region);
+
+ assertTrue(secret.getArn().startsWith(expectedArnPrefix), "minted ARN was " + secret.getArn());
+
+ String partialArn = secret.getArn().substring(0, secret.getArn().length() - 7);
+ assertEquals("value", service.getSecretValue(partialArn, null, null, region).getSecretString());
+ }
+
@Test
void getSecretValueByFullArnStillWorks() {
Secret secret = service.createSecret("my-secret", "value", null, null, null, null, REGION);
diff --git a/src/test/java/io/github/hectorvent/floci/services/sqs/SqsServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/sqs/SqsServiceTest.java
index 95a1cdbae1..1e880fb452 100644
--- a/src/test/java/io/github/hectorvent/floci/services/sqs/SqsServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/sqs/SqsServiceTest.java
@@ -780,6 +780,73 @@ class SqsServiceTest {
assertEquals(25, task.maxNumberOfMessagesPerSecond());
}
+ /**
+ * The DLQ redrive path resolves a queue URL from the {@code deadLetterTargetArn} a client read
+ * back out of GetQueueAttributes, and SQS mints that ARN with the region's own partition. The
+ * resolver used to require a literal {@code arn:aws:sqs:}, so in GovCloud or China it returned
+ * null, the move block was skipped, and messages stayed on the source queue with nothing
+ * logged. A silent redrive failure is the worst shape this bug takes.
+ */
+ @org.junit.jupiter.params.ParameterizedTest
+ @org.junit.jupiter.params.provider.CsvSource({
+ "us-east-1, arn:aws:sqs:us-east-1:000000000000:",
+ "us-gov-west-1, arn:aws-us-gov:sqs:us-gov-west-1:000000000000:",
+ "cn-north-1, arn:aws-cn:sqs:cn-north-1:000000000000:"})
+ void startMessageMoveTask_acceptsAQueueArnFromAnyPartition(String region, String arnPrefix) {
+ sqsService.createQueue("p-dlq", null, region);
+ String dlqArn = arnPrefix + "p-dlq";
+ sqsService.createQueue("p-src",
+ Map.of("RedrivePolicy",
+ "{\"deadLetterTargetArn\":\"" + dlqArn + "\",\"maxReceiveCount\":\"1\"}"), region);
+ sqsService.createQueue("p-dest", null, region);
+
+ String taskHandle = sqsService.startMessageMoveTask(dlqArn, arnPrefix + "p-dest", 5, region);
+
+ assertNotNull(taskHandle);
+ assertEquals(dlqArn, sqsService.listMessageMoveTasks(dlqArn, region).get(0).sourceArn());
+ }
+
+ /**
+ * The ARN the emulator itself hands back must be the one it accepts. This is the assertion
+ * that ties the two halves together rather than trusting a hand-written prefix.
+ */
+ @org.junit.jupiter.params.ParameterizedTest
+ @org.junit.jupiter.params.provider.ValueSource(strings = {"us-east-1", "us-gov-west-1", "cn-north-1"})
+ void startMessageMoveTask_acceptsTheQueueArnGetQueueAttributesReturned(String region) {
+ sqsService.createQueue("rt-dlq", null, region);
+ String dlqArn = sqsService.getQueueAttributes(
+ sqsService.getQueueUrl("rt-dlq", region), List.of("QueueArn"), region).get("QueueArn");
+ sqsService.createQueue("rt-src",
+ Map.of("RedrivePolicy",
+ "{\"deadLetterTargetArn\":\"" + dlqArn + "\",\"maxReceiveCount\":\"1\"}"), region);
+ sqsService.createQueue("rt-dest", null, region);
+ String destArn = sqsService.getQueueAttributes(
+ sqsService.getQueueUrl("rt-dest", region), List.of("QueueArn"), region).get("QueueArn");
+
+ assertNotNull(sqsService.startMessageMoveTask(dlqArn, destArn, 5, region));
+ }
+
+ /**
+ * Widening the partition must not turn "queue does not exist" into something softer: an ARN
+ * naming a queue nobody created is still ResourceNotFound, exactly as a commercial one is.
+ *
+ * Note the resolver takes only the account and queue name out of the ARN and looks them up
+ * in the caller's region, so the ARN's own region is not enforced. That is pre-existing and
+ * already applied to a cross-region commercial ARN; this change does not alter it.
+ */
+ @Test
+ void startMessageMoveTask_foreignPartitionQueueThatDoesNotExistIsNotFound() {
+ sqsService.createQueue("fp-dlq", null, "us-east-1");
+ String dlqArn = queueArn("fp-dlq");
+ sqsService.createQueue("fp-src",
+ Map.of("RedrivePolicy",
+ "{\"deadLetterTargetArn\":\"" + dlqArn + "\",\"maxReceiveCount\":\"1\"}"), "us-east-1");
+
+ AwsException ex = assertThrows(AwsException.class, () -> sqsService.startMessageMoveTask(
+ dlqArn, "arn:aws-cn:sqs:cn-north-1:000000000000:never-created", 0, "us-east-1"));
+ assertEquals("ResourceNotFoundException", ex.getErrorCode());
+ }
+
@Test
void startMessageMoveTask_destinationDoesNotExist_throwsResourceNotFound() {
sqsService.createQueue("a-dlq", null, "us-east-1");
diff --git a/src/test/java/io/github/hectorvent/floci/services/ssoadmin/SsoAdminServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/ssoadmin/SsoAdminServiceTest.java
index c7e0565015..1671fd3037 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ssoadmin/SsoAdminServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ssoadmin/SsoAdminServiceTest.java
@@ -1425,6 +1425,57 @@ class SsoAdminServiceTest {
"arn:aws:iam::aws:policy/OverQuotaPolicy"));
}
+ /**
+ * The model's ManagedPolicyArn pattern is partition-tolerant. Pinning it to the commercial
+ * partition refused a legal GovCloud or China managed-policy ARN.
+ */
+ @Test
+ void attachAcceptsManagedPolicyArnsFromEveryPartition() {
+ PermissionSet permissionSet = createPermissionSet("PartitionAdmins");
+
+ service.attachPolicy(service.getInstanceArn(), permissionSet.arn(),
+ "arn:aws-us-gov:iam::aws:policy/ReadOnlyAccess");
+ service.attachPolicy(service.getInstanceArn(), permissionSet.arn(),
+ "arn:aws-cn:iam::aws:policy/SecurityAudit");
+ service.attachPolicy(service.getInstanceArn(), permissionSet.arn(),
+ "arn:aws-iso-b:iam::aws:policy/ViewOnlyAccess");
+ }
+
+ /** AWS-managed policies live under a path, which the previous {@code .+} tail also allowed. */
+ @Test
+ void attachAcceptsAServiceRolePath() {
+ PermissionSet permissionSet = createPermissionSet("PathAdmins");
+
+ service.attachPolicy(service.getInstanceArn(), permissionSet.arn(),
+ "arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy");
+ }
+
+ /**
+ * Tightening the tail from {@code .+} to the model's charset. A space is not a legal policy
+ * name and used to be accepted.
+ */
+ @Test
+ void attachRejectsAPolicyNameOutsideTheModelCharset() {
+ PermissionSet permissionSet = createPermissionSet("StrictAdmins");
+
+ assertThrows(AwsException.class, () -> service.attachPolicy(service.getInstanceArn(),
+ permissionSet.arn(), "arn:aws:iam::aws:policy/bad name"));
+ }
+
+ /**
+ * AttachManagedPolicyToPermissionSet takes AWS-managed policies only, which the model spells
+ * as the literal {@code ::aws:policy} account segment. Customer-managed policies go through
+ * the separate customer-managed-reference operations, so this rejection is correct AWS
+ * behaviour and must survive the widening above.
+ */
+ @Test
+ void attachStillRejectsACustomerManagedPolicy() {
+ PermissionSet permissionSet = createPermissionSet("CustomerAdmins");
+
+ assertThrows(AwsException.class, () -> service.attachPolicy(service.getInstanceArn(),
+ permissionSet.arn(), "arn:aws:iam::" + ACCOUNT_ID + ":policy/MyOwnPolicy"));
+ }
+
@Test
void managedPolicyPaginationHonorsMaxResultsAndNextToken() {
PermissionSet permissionSet = createPermissionSet("PlatformAdmins");
diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsListPartitionTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsListPartitionTest.java
new file mode 100644
index 0000000000..9e6bd12330
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsListPartitionTest.java
@@ -0,0 +1,107 @@
+package io.github.hectorvent.floci.services.stepfunctions;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.stepfunctions.model.Activity;
+import io.github.hectorvent.floci.services.stepfunctions.model.Execution;
+import io.github.hectorvent.floci.services.stepfunctions.model.StateMachine;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+/**
+ * Step Functions is the only service that keys its stores by the full ARN; the others key by
+ * {@code region::name}. Once ARNs carried the region's real partition, the list operations still
+ * scanned for a {@code arn:aws:states:} prefix, so a state machine or activity created in GovCloud
+ * or China was stored under {@code arn:aws-us-gov:...} and listing returned nothing: the write path
+ * and the read path disagreed about the same resource.
+ *
+ * A real {@link RegionResolver} is used deliberately, not a mock, because the whole point is
+ * that the list prefix agrees with what {@code buildArn} actually produced.
+ */
+class StepFunctionsListPartitionTest {
+
+ private static final String ACCOUNT = "000000000000";
+
+ private StepFunctionsService buildService() {
+ StorageFactory factory = mock(StorageFactory.class);
+ doReturn(AccountAwareStorageBackend.> envCaptor = ArgumentCaptor.forClass(List.class);
+ verify(builder).withEnv(envCaptor.capture());
+
+ List