diff --git a/src/main/java/io/floci/aws/services/stepfunctions/SdkManagementTaskInvoker.java b/src/main/java/io/floci/aws/services/stepfunctions/SdkManagementTaskInvoker.java index 0d16e62b69..f7fa1b0d22 100644 --- a/src/main/java/io/floci/aws/services/stepfunctions/SdkManagementTaskInvoker.java +++ b/src/main/java/io/floci/aws/services/stepfunctions/SdkManagementTaskInvoker.java @@ -2,6 +2,7 @@ package io.floci.aws.services.stepfunctions; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; import io.floci.aws.core.common.AwsException; import io.floci.aws.core.common.RequestScopes; @@ -95,6 +96,27 @@ public class SdkManagementTaskInvoker { } } + /** + * The Lambda request a task's input sends, as the API models it: the mapping's {@code UUID}, the path label + * {@code UpdateEventSourceMapping} takes, from the task's {@code Uuid}, the Step Functions SDK spelling, and the + * rest of the input as its body, which holds no {@code UUID} of its own. + */ + static ObjectNode lambdaRequest(JsonNode input) { + ObjectNode request = JsonNodeFactory.instance.objectNode(); + if (!input.isObject()) { + return request; + } + input.properties().forEach(member -> { + if (!"Uuid".equals(member.getKey()) && !"UUID".equals(member.getKey())) { + request.set(member.getKey(), member.getValue()); + } + }); + if (input.hasNonNull("Uuid")) { + request.set("UUID", input.get("Uuid")); + } + return request; + } + private Response dispatch(StatesIntegration integration, JsonNode input, String region) { return switch (integration.service()) { case "ecs" -> ecs.handle(AslExecutor.capitalizeFirst(integration.api()), @@ -110,7 +132,7 @@ public class SdkManagementTaskInvoker { input.path("EventSourceArn").asText(null)); } case "updateEventSourceMapping" -> { - String uuid = input.path("Uuid").asText(null); + String uuid = lambdaRequest(input).path("UUID").asText(null); if (uuid == null || uuid.isBlank()) { throw new AwsException("InvalidParameterValueException", "Uuid is required.", 400); } diff --git a/src/main/java/io/floci/aws/services/stepfunctions/TaskPermissions.java b/src/main/java/io/floci/aws/services/stepfunctions/TaskPermissions.java index d092d97dce..53737fad63 100644 --- a/src/main/java/io/floci/aws/services/stepfunctions/TaskPermissions.java +++ b/src/main/java/io/floci/aws/services/stepfunctions/TaskPermissions.java @@ -617,18 +617,14 @@ record TaskPermissions(String deniedError, List permissions, boolean } /** - * {@code ListEventSourceMappings} has no resource type in the service reference, and - * {@code UpdateEventSourceMapping} acts on the mapping its {@code Uuid} names; a request naming none is refused - * by the integration. + * The check the vendored request resources give the same call made directly, on the request the integration + * sends ({@link SdkManagementTaskInvoker#lambdaRequest}): {@code ListEventSourceMappings} acts on no resource type, + * and {@code UpdateEventSourceMapping} on the mapping its {@code UUID} names; a request naming none is refused by + * the integration. */ private static TaskPermissions lambdaSdk(String api, JsonNode input, StateMachine machine) { - String action = "lambda:" + AslExecutor.capitalizeFirst(api); - if ("listEventSourceMappings".equals(api)) { - return accessDenied(LAMBDA_PREFIX, List.of(new Permission(action, ANY_RESOURCE))); - } - String uuid = text(input.path("Uuid")); - return accessDenied(LAMBDA_PREFIX, uuid == null ? List.of() - : List.of(new Permission(action, arn(machine, "lambda", "event-source-mapping:" + uuid)))); + return accessDenied(LAMBDA_PREFIX, requestPermissions("lambda", AslExecutor.capitalizeFirst(api), + SdkManagementTaskInvoker.lambdaRequest(input), machine, null)); } /** diff --git a/src/test/java/io/floci/aws/services/stepfunctions/SdkManagementTaskInvokerTest.java b/src/test/java/io/floci/aws/services/stepfunctions/SdkManagementTaskInvokerTest.java index 47f471a3c4..fc491507a6 100644 --- a/src/test/java/io/floci/aws/services/stepfunctions/SdkManagementTaskInvokerTest.java +++ b/src/test/java/io/floci/aws/services/stepfunctions/SdkManagementTaskInvokerTest.java @@ -26,6 +26,19 @@ class SdkManagementTaskInvokerTest { private final SdkManagementTaskInvoker invoker = new SdkManagementTaskInvoker(ecs, lambda, mock(SecretsManagerJsonHandler.class), registry, mapper); + /** + * The Lambda request a task sends, as the API models it: the mapping's UUID, its path label, from the task's + * Uuid alone, the rest of the input its body; a UUID in the input is no member the body holds, so it names none. + */ + @Test + void aLambdaTasksRequestTakesTheMappingsUuidAsTheApisUuid() throws Exception { + assertEquals(mapper.readTree("{\"UUID\":\"u-2\",\"BatchSize\":5}"), + SdkManagementTaskInvoker.lambdaRequest(mapper.readTree("{\"Uuid\":\"u-2\",\"BatchSize\":5}"))); + assertEquals(mapper.readTree("{\"BatchSize\":5}"), + SdkManagementTaskInvoker.lambdaRequest(mapper.readTree("{\"UUID\":\"u-1\",\"BatchSize\":5}"))); + assertEquals(mapper.readTree("{}"), SdkManagementTaskInvoker.lambdaRequest(mapper.readTree("[]"))); + } + @Test void lambdaMappingUpdateUsesSdkUuidWithoutMutatingTheTaskInput() throws Exception { when(registry.isServiceEnabled("lambda")).thenReturn(true);