mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(partition): accept EFS access points in ISO-E and ISO-F and list the execution's regions in Step Functions (#5485)
* fix(partition): accept EFS access points in ISO-E and ISO-F and list the execution's regions in Step Functions Lambda validated a FileSystemConfigs ARN with a region pattern whose ISO branch was -iso(b)?, so an access point in eu-isoe-west-1, us-isof-south-1 or us-isof-east-1 was refused. The branch is now -iso[a-z]?, as in the Lambda model's FileSystemArn pattern. The Step Functions aws-sdk:ec2:describeRegions integration listed the regions of the deployment's partition. It now lists those of the partition the state machine runs in, as a direct DescribeRegions call does. Signed-off-by: Hector Ventura <hectorvent@gmail.com> * fix(stepfunctions): read the describeRegions partition from the state machine ARN and reuse the test helpers The partition now comes from the state machine's ARN, so a state machine in a region no partition publishes (floci.partitions.allow-unknown-regions) lists the regions of the partition its ARN was minted in, not the commercial ones. A published region resolves as before. The new test built its own create, start and describe loop to send a cn-north-1 Authorization header. The class's helpers take the header instead, and a run that never finishes now fails through waitForExecution's own message. Signed-off-by: Hector Ventura <hectorvent@gmail.com> --------- Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
4e2ccfb44f
commit
78377921e3
4 files changed
+76
-16
No files matched your search
@@ -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]+");
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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");
|
||||
|
||||
+45
-10
@@ -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);
|
||||
}
|
||||
|
||||
private String createStateMachine(String name, String definition) {
|
||||
Response resp = given()
|
||||
/** 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 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("""
|
||||
|
||||
Reference in new issue
Block a user