fix(stepfunctions): check Lambda event source mapping tasks from the generated request resources (#8466)

TaskPermissions gave a Step Functions listEventSourceMappings task a literal *
and built updateEventSourceMapping's event-source-mapping:<Uuid> itself. With
Lambda now read whole from iam-request-resources.json, both go through the
generic requestPermissions, on the request the integration sends:
SdkManagementTaskInvoker.lambdaRequest takes the mapping's UUID, the path label
the API takes, from the task's Uuid, as the invoker already did, so
ListEventSourceMappings is checked on * because its action acts on no
resource type, and UpdateEventSourceMapping on the mapping its UUID names.
The checks are the same as before.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-15 11:42:22 -04:00
1 parent 9e05c07bfc
commit 9bc2f16a9d
3 files changed
+42 -11

No files matched your search

@@ -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);
}
@@ -617,18 +617,14 @@ record TaskPermissions(String deniedError, List<Permission> 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));
}
/**
@@ -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);