Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

fix(partition): accept EFS access points in ISO-E and ISO-F and list the execution's regions in Step Functions (#5485)

Hector Ventura78377921e3ff
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java
index 7394fb327f..bc84a7c8b7 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java
@@ -86,7 +86,7 @@ public class LambdaService implements ResourceProvider {
private static final Pattern QUALIFIER = Pattern.compile(QUALIFIER_PATTERN);
private static final Pattern EFS_ACCESS_POINT_ARN = Pattern.compile(
"^arn:" + AwsArnUtils.PARTITION_REGEX + ":elasticfilesystem:(?:eusc-)?[a-z]{2}"
- + "(?:(?:-gov)|(?:-iso(?:b)?))?-[a-z]+-\\d:"
+ + "(?:(?:-gov)|(?:-iso[a-z]?))?-[a-z]+-\\d:"
+ "\\d{12}:access-point/fsap-[a-f0-9]{17}$");
private static final Pattern FILE_SYSTEM_LOCAL_MOUNT_PATH = Pattern.compile("^/mnt/[A-Za-z0-9._-]+$");
private static final Pattern LOG_GROUP_PATTERN = Pattern.compile("[.\\-_/#A-Za-z0-9]+");
diff --git a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java
index 4dc4242bde..7f27da3f70 100644
--- a/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java
+++ b/src/main/java/io/github/hectorvent/floci/services/stepfunctions/AslExecutor.java
@@ -22,7 +22,6 @@ import io.github.hectorvent.floci.core.common.AwsPartition;
import io.github.hectorvent.floci.core.common.AwsPartitions;
import io.github.hectorvent.floci.core.common.CsvParser;
import io.github.hectorvent.floci.core.common.CustomResourceLiveness;
-import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.RequestContext;
import io.github.hectorvent.floci.core.common.RequestScopes;
import io.github.hectorvent.floci.core.common.ServiceRegistry;
@@ -1308,7 +1307,7 @@ public class AslExecutor {
// AWS SDK service integration: EC2 DescribeRegions
if (integration.isSdk("ec2", "describeRegions")) {
- return invokeAwsSdkEc2DescribeRegions();
+ return invokeAwsSdkEc2DescribeRegions(sm.getStateMachineArn());
}
// S3 PutObject — optimized and aws-sdk integrations
@@ -1415,11 +1414,17 @@ public class AslExecutor {
}
}
- private JsonNode invokeAwsSdkEc2DescribeRegions() {
+ /**
+ * The regions of the partition the state machine lives in. The partition is read from its ARN,
+ * so a state machine in a region no partition publishes (allowed by
+ * {@code floci.partitions.allow-unknown-regions}) lists the regions of the partition its ARN
+ * was minted in.
+ */
+ private JsonNode invokeAwsSdkEc2DescribeRegions(String stateMachineArn) {
ObjectNode result = objectMapper.createObjectNode();
ArrayNode regions = objectMapper.createArrayNode();
- AwsPartition partition = AwsPartitions.byId(
- RegionResolver.effectivePartition(config.defaultRegion(), config.partitions().id()));
+ AwsPartition partition = AwsPartitions.find(AwsArnUtils.parse(stateMachineArn).partition())
+ .orElseGet(() -> AwsPartitions.forRegionOrCommercial(extractRegionFromArn(stateMachineArn)));
for (AwsPartition.Region name : ec2Service.describeRegions(partition, false)) {
ObjectNode region = objectMapper.createObjectNode();
region.put("RegionName", name.id());
diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaServiceTest.java
index 09ea6867e5..e158a2fc9f 100644
--- a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaServiceTest.java
@@ -179,6 +179,26 @@ class LambdaServiceTest {
assertEquals("InvalidParameterValueException", error.getErrorCode());
}
+ @ParameterizedTest
+ @ValueSource(strings = {
+ "arn:aws-cn:elasticfilesystem:cn-north-1:",
+ "arn:aws-us-gov:elasticfilesystem:us-gov-west-1:",
+ "arn:aws-iso:elasticfilesystem:us-iso-east-1:",
+ "arn:aws-iso-b:elasticfilesystem:us-isob-east-1:",
+ "arn:aws-iso-e:elasticfilesystem:eu-isoe-west-1:",
+ "arn:aws-iso-f:elasticfilesystem:us-isof-south-1:",
+ "arn:aws-eusc:elasticfilesystem:eusc-de-east-1:"})
+ void createFunctionAcceptsAnEfsAccessPointInEveryPartition(String arnPrefix) {
+ String arn = arnPrefix + "000000000000:access-point/fsap-0123456789abcdef0";
+ Map<String, Object> request = baseRequest("efs-partition-function");
+ request.put("VpcConfig", vpcConfig());
+ request.put("FileSystemConfigs", List.of(Map.of("Arn", arn, "LocalMountPath", "/mnt/shared")));
+
+ LambdaFunction created = service.createFunction(REGION, request);
+
+ assertEquals(arn, created.getFileSystemConfigs().getFirst().getArn());
+ }
+
@Test
void createFunctionRejectsUnsupportedS3FilesAccessPointArn() {
Map<String, Object> request = baseRequest("s3-files-function");
diff --git a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAwsSdkQueryIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAwsSdkQueryIntegrationTest.java
index dd6b59a3d4..e6d2042a16 100644
--- a/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAwsSdkQueryIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/stepfunctions/StepFunctionsAwsSdkQueryIntegrationTest.java
@@ -2,13 +2,17 @@ package io.github.hectorvent.floci.services.stepfunctions;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import io.github.hectorvent.floci.testing.PartitionMatrix;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.Response;
+import io.restassured.specification.RequestSpecification;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import java.util.List;
+
import static io.restassured.RestAssured.given;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -41,6 +45,32 @@ class StepFunctionsAwsSdkQueryIntegrationTest {
assertFalse(result.path("Regions").get(0).path("RegionName").asText().isBlank());
}
+ @Test
+ void ec2DescribeRegions_listsTheRegionsOfTheExecutionsPartition() throws Exception {
+ String auth = PartitionMatrix.sigV4Auth("cn-north-1", "states");
+ String definition = """
+ {"StartAt":"Action","States":{"Action":{"Type":"Task",
+ "Resource":"arn:aws-cn:states:::aws-sdk:ec2:describeRegions","Parameters":{},"End":true}}}
+ """;
+ String smArn = createStateMachine(auth, "ec2-regions-cn-" + System.currentTimeMillis(), definition,
+ "arn:aws-cn:iam::000000000000:role/test-role");
+ try {
+ JsonNode regions = mapper.readTree(waitForExecution(auth, startExecution(auth, smArn))).path("Regions");
+ List<String> names = regions.findValuesAsText("RegionName");
+ assertEquals(List.of("cn-north-1", "cn-northwest-1"), names.stream().sorted().toList());
+ assertEquals("ec2.cn-north-1.amazonaws.com.cn",
+ regions.get(names.indexOf("cn-north-1")).path("Endpoint").asText());
+ } finally {
+ signed(auth)
+ .header("X-Amz-Target", "AWSStepFunctions.DeleteStateMachine")
+ .contentType(SFN_CONTENT_TYPE)
+ .body("""
+ {"stateMachineArn": "%s"}
+ """.formatted(smArn))
+ .when().post("/");
+ }
+ }
+
@Test
void cloudFormation_validateTemplate_dispatchesAndParses() throws Exception {
String params = """
@@ -74,25 +104,30 @@ class StepFunctionsAwsSdkQueryIntegrationTest {
String definition = """
{"StartAt":"Action","States":{"Action":{"Type":"Task","Resource":"%s","Parameters":%s,"End":true}}}
""".formatted(resource, parameters.strip());
- String smArn = createStateMachine(nameSuffix + "-" + System.currentTimeMillis(), definition);
- String execArn = startExecution(smArn);
- return waitForExecution(execArn);
+ String smArn = createStateMachine(null, nameSuffix + "-" + System.currentTimeMillis(), definition, ROLE_ARN);
+ String execArn = startExecution(null, smArn);
+ return waitForExecution(null, execArn);
+ }
+
+ /** A request signed with {@code auth}, or unsigned (the default region) when it is null. */
+ private static RequestSpecification signed(String auth) {
+ return auth == null ? given() : given().header("Authorization", auth);
}
- private String createStateMachine(String name, String definition) {
- Response resp = given()
+ private String createStateMachine(String auth, String name, String definition, String roleArn) {
+ Response resp = signed(auth)
.header("X-Amz-Target", "AWSStepFunctions.CreateStateMachine")
.contentType(SFN_CONTENT_TYPE)
.body("""
{"name": "%s", "definition": %s, "roleArn": "%s"}
- """.formatted(name, quote(definition), ROLE_ARN))
+ """.formatted(name, quote(definition), roleArn))
.when().post("/");
resp.then().statusCode(200);
return resp.jsonPath().getString("stateMachineArn");
}
- private String startExecution(String smArn) {
- Response resp = given()
+ private String startExecution(String auth, String smArn) {
+ Response resp = signed(auth)
.header("X-Amz-Target", "AWSStepFunctions.StartExecution")
.contentType(SFN_CONTENT_TYPE)
.body("""
@@ -103,9 +138,9 @@ class StepFunctionsAwsSdkQueryIntegrationTest {
return resp.jsonPath().getString("executionArn");
}
- private String waitForExecution(String execArn) throws InterruptedException {
+ private String waitForExecution(String auth, String execArn) throws InterruptedException {
for (int i = 0; i < 50; i++) {
- Response resp = given()
+ Response resp = signed(auth)
.header("X-Amz-Target", "AWSStepFunctions.DescribeExecution")
.contentType(SFN_CONTENT_TYPE)
.body("""