mirror of
https://github.com/floci-io/floci.git
synced 2026-12-02 17:58:05 -05:00
fix(iam): check the rest of the Lambda function API's routes (#6226)
Under IAM enforcement a REST request whose route no rule maps is let through unchecked. 51 operations of Lambda's function API had no rule, 25 of them served by Floci, so any signed caller could read a function's configuration, environment variables included, publish versions, set its concurrency and event invoke config, and create, read or delete layer versions and code signing configs, with no Lambda permission at all. ListFunctionsByCodeSigningConfig, whose route ends in /functions, was checked as lambda:ListFunctions. Every operation of the function API now has a rule and is checked as the action of its own name, as the Service Authorization Reference gives it, including the routes Floci does not serve yet: provisioned concurrency, capacity providers, layer version permissions, the recursion, scaling and runtime management configs, PutFunctionCodeSigningConfig, InvokeAsync, ListFunctionUrlConfigs and the resource policy routes. IamRestRouteCoverageTest checks every operation of the lambda model, as it does Scheduler, Pipes, MicroVMs and network connectors. Each is checked against the resource the reference gives it: - a function's settings against the function, as the other function routes are; - an event source mapping against event-source-mapping:<uuid>, which DeleteEventSourceMapping now gets too in place of *; - a code signing config against code-signing-config:<id>, the id that ends the ARN the route takes, in the request's account and Region, as Lambda looks it up; - a layer version, its policy and its permissions against layer:<name>:<version>, the name as given, even a name given as an ARN or holding an encoded /, since Lambda looks the layer up by it as it is, and the version as the number Lambda parses, so 01 is checked as 1; PublishLayerVersion against layer:<name>, and GetLayerVersionByArn against the version its Arn names, its number read the same way; - account settings, creating a config, and listing configs, layers or a layer's versions against *, as they name no resource. AWS also checks lambda:AddPermission, lambda:GetPolicy or lambda:RemovePermission for the resource policy operations, and iam:PassRole for CreateCapacityProvider. Floci serves neither, so they are checked as their own action alone. docs/services/iam.md says which Lambda routes are mapped and what each is checked against.
This commit is contained in:
1 parent
8427c0b71d
commit
6763b405dd
7 files changed
+353
-13
No files matched your search
@@ -57,6 +57,14 @@ public class IamActionRegistry {
|
||||
rule("s3", "HEAD", "^/[^/]+/.+", "s3:GetObject"),
|
||||
|
||||
// ── Lambda ──────────────────────────────────────────────────────────────
|
||||
// Code signing configs first: a config's function list ends in /functions, as ListFunctions does.
|
||||
rule("lambda", "GET", "^/2020-04-22/code-signing-configs/[^/]+/functions$",
|
||||
"lambda:ListFunctionsByCodeSigningConfig"),
|
||||
rule("lambda", "GET", "^/2020-04-22/code-signing-configs/[^/]+$", "lambda:GetCodeSigningConfig"),
|
||||
rule("lambda", "PUT", "^/2020-04-22/code-signing-configs/[^/]+$", "lambda:UpdateCodeSigningConfig"),
|
||||
rule("lambda", "DELETE", "^/2020-04-22/code-signing-configs/[^/]+$", "lambda:DeleteCodeSigningConfig"),
|
||||
rule("lambda", "GET", "^/2020-04-22/code-signing-configs$", "lambda:ListCodeSigningConfigs"),
|
||||
rule("lambda", "POST", "^/2020-04-22/code-signing-configs$", "lambda:CreateCodeSigningConfig"),
|
||||
rule("lambda", "GET", ".*/functions$", "lambda:ListFunctions"),
|
||||
rule("lambda", "POST", ".*/functions$", "lambda:CreateFunction"),
|
||||
rule("lambda", "GET", ".*/functions/[^/]+$", "lambda:GetFunction"),
|
||||
@@ -90,6 +98,60 @@ public class IamActionRegistry {
|
||||
rule("lambda", "POST", ".*/durable-execution-callbacks/.+/fail$", "lambda:SendDurableExecutionCallbackFailure"),
|
||||
rule("lambda", "POST", ".*/durable-execution-callbacks/.+/heartbeat$",
|
||||
"lambda:SendDurableExecutionCallbackHeartbeat"),
|
||||
rule("lambda", "GET", ".*/event-source-mappings/[^/]+$", "lambda:GetEventSourceMapping"),
|
||||
rule("lambda", "PUT", ".*/event-source-mappings/[^/]+$", "lambda:UpdateEventSourceMapping"),
|
||||
rule("lambda", "GET", ".*/functions/[^/]+/configuration$", "lambda:GetFunctionConfiguration"),
|
||||
rule("lambda", "GET", ".*/functions/[^/]+/versions$", "lambda:ListVersionsByFunction"),
|
||||
rule("lambda", "POST", ".*/functions/[^/]+/versions$", "lambda:PublishVersion"),
|
||||
rule("lambda", "POST", ".*/functions/[^/]+/invoke-async$", "lambda:InvokeAsync"),
|
||||
rule("lambda", "GET", ".*/functions/[^/]+/urls$", "lambda:ListFunctionUrlConfigs"),
|
||||
rule("lambda", "GET", ".*/functions/[^/]+/concurrency$", "lambda:GetFunctionConcurrency"),
|
||||
rule("lambda", "PUT", ".*/functions/[^/]+/concurrency$", "lambda:PutFunctionConcurrency"),
|
||||
rule("lambda", "DELETE", ".*/functions/[^/]+/concurrency$", "lambda:DeleteFunctionConcurrency"),
|
||||
rule("lambda", "GET", ".*/functions/[^/]+/provisioned-concurrency$", "List", "ALL",
|
||||
"lambda:ListProvisionedConcurrencyConfigs"),
|
||||
rule("lambda", "GET", ".*/functions/[^/]+/provisioned-concurrency$",
|
||||
"lambda:GetProvisionedConcurrencyConfig"),
|
||||
rule("lambda", "PUT", ".*/functions/[^/]+/provisioned-concurrency$",
|
||||
"lambda:PutProvisionedConcurrencyConfig"),
|
||||
rule("lambda", "DELETE", ".*/functions/[^/]+/provisioned-concurrency$",
|
||||
"lambda:DeleteProvisionedConcurrencyConfig"),
|
||||
rule("lambda", "GET", ".*/functions/[^/]+/event-invoke-config/list$",
|
||||
"lambda:ListFunctionEventInvokeConfigs"),
|
||||
rule("lambda", "GET", ".*/functions/[^/]+/event-invoke-config$", "lambda:GetFunctionEventInvokeConfig"),
|
||||
rule("lambda", "PUT", ".*/functions/[^/]+/event-invoke-config$", "lambda:PutFunctionEventInvokeConfig"),
|
||||
rule("lambda", "POST", ".*/functions/[^/]+/event-invoke-config$", "lambda:UpdateFunctionEventInvokeConfig"),
|
||||
rule("lambda", "DELETE", ".*/functions/[^/]+/event-invoke-config$", "lambda:DeleteFunctionEventInvokeConfig"),
|
||||
rule("lambda", "GET", ".*/functions/[^/]+/code-signing-config$", "lambda:GetFunctionCodeSigningConfig"),
|
||||
rule("lambda", "PUT", ".*/functions/[^/]+/code-signing-config$", "lambda:PutFunctionCodeSigningConfig"),
|
||||
rule("lambda", "DELETE", ".*/functions/[^/]+/code-signing-config$", "lambda:DeleteFunctionCodeSigningConfig"),
|
||||
rule("lambda", "GET", ".*/functions/[^/]+/recursion-config$", "lambda:GetFunctionRecursionConfig"),
|
||||
rule("lambda", "PUT", ".*/functions/[^/]+/recursion-config$", "lambda:PutFunctionRecursionConfig"),
|
||||
rule("lambda", "GET", ".*/functions/[^/]+/function-scaling-config$", "lambda:GetFunctionScalingConfig"),
|
||||
rule("lambda", "PUT", ".*/functions/[^/]+/function-scaling-config$", "lambda:PutFunctionScalingConfig"),
|
||||
rule("lambda", "GET", ".*/functions/[^/]+/runtime-management-config$", "lambda:GetRuntimeManagementConfig"),
|
||||
rule("lambda", "PUT", ".*/functions/[^/]+/runtime-management-config$", "lambda:PutRuntimeManagementConfig"),
|
||||
rule("lambda", "GET", "^/2016-08-19/account-settings/?$", "lambda:GetAccountSettings"),
|
||||
rule("lambda", "GET", "^/2018-10-31/layers/[^/]+/versions/[^/]+/policy$", "lambda:GetLayerVersionPolicy"),
|
||||
rule("lambda", "POST", "^/2018-10-31/layers/[^/]+/versions/[^/]+/policy$",
|
||||
"lambda:AddLayerVersionPermission"),
|
||||
rule("lambda", "DELETE", "^/2018-10-31/layers/[^/]+/versions/[^/]+/policy/[^/]+$",
|
||||
"lambda:RemoveLayerVersionPermission"),
|
||||
rule("lambda", "GET", "^/2018-10-31/layers/[^/]+/versions/[^/]+$", "lambda:GetLayerVersion"),
|
||||
rule("lambda", "DELETE", "^/2018-10-31/layers/[^/]+/versions/[^/]+$", "lambda:DeleteLayerVersion"),
|
||||
rule("lambda", "GET", "^/2018-10-31/layers/[^/]+/versions$", "lambda:ListLayerVersions"),
|
||||
rule("lambda", "POST", "^/2018-10-31/layers/[^/]+/versions$", "lambda:PublishLayerVersion"),
|
||||
rule("lambda", "GET", "^/2025-11-30/capacity-providers/[^/]+/function-versions$",
|
||||
"lambda:ListFunctionVersionsByCapacityProvider"),
|
||||
rule("lambda", "GET", "^/2025-11-30/capacity-providers/[^/]+$", "lambda:GetCapacityProvider"),
|
||||
rule("lambda", "PUT", "^/2025-11-30/capacity-providers/[^/]+$", "lambda:UpdateCapacityProvider"),
|
||||
rule("lambda", "DELETE", "^/2025-11-30/capacity-providers/[^/]+$", "lambda:DeleteCapacityProvider"),
|
||||
rule("lambda", "GET", "^/2025-11-30/capacity-providers$", "lambda:ListCapacityProviders"),
|
||||
rule("lambda", "POST", "^/2025-11-30/capacity-providers$", "lambda:CreateCapacityProvider"),
|
||||
// The resource policy routes of the function API (2026-07-09) and of Web Functions (2025-03-07).
|
||||
rule("lambda", "PUT", "^/2026-07-09/resource-policy/.+", "lambda:PutResourcePolicy"),
|
||||
rule("lambda", "GET", "^/2026-07-09/resource-policy/.+", "lambda:GetResourcePolicy"),
|
||||
rule("lambda", "DELETE", "^/2026-07-09/resource-policy/.+", "lambda:DeleteResourcePolicy"),
|
||||
|
||||
// ── Lambda Web Functions (/2025-03-07, signs as lambda) ─────────────────
|
||||
rule("lambda", "PUT", "^/2025-03-07/web-functions$", "lambda:CreateWebFunction"),
|
||||
@@ -116,6 +178,7 @@ public class IamActionRegistry {
|
||||
// Invoke and GetLayerVersion (iam-authorized-actions.json).
|
||||
rule("lambda", "POST", ".*/functions/[^/]+/response-streaming-invocations$", "lambda:InvokeFunction"),
|
||||
rule("lambda", "GET", "^/2018-10-31/layers$", "find", "LayerVersion", "lambda:GetLayerVersion"),
|
||||
rule("lambda", "GET", "^/2018-10-31/layers$", "lambda:ListLayers"),
|
||||
// Lambda MicroVMs (2025-09-09) and their tags, and network connectors (2026-04-04).
|
||||
rule("lambda", "POST", "^/2025-09-09/microvms/[^/]+/auth-token$", "lambda:CreateMicrovmAuthToken"),
|
||||
rule("lambda", "POST", "^/2025-09-09/microvms/[^/]+/shell-auth-token$", "lambda:CreateMicrovmShellAuthToken"),
|
||||
@@ -425,7 +488,7 @@ public class IamActionRegistry {
|
||||
* The request path relative to the application root, as {@link UriInfo#getPath()} gives it, but
|
||||
* still percent-encoded.
|
||||
*/
|
||||
private static String rawPath(UriInfo uriInfo) {
|
||||
static String rawPath(UriInfo uriInfo) {
|
||||
String path = uriInfo.getRequestUri().getRawPath();
|
||||
String base = uriInfo.getBaseUri().getRawPath();
|
||||
if (base != null && base.length() > 1 && path.startsWith(base)) {
|
||||
|
||||
@@ -23,6 +23,8 @@ import jakarta.ws.rs.core.MediaType;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLDecoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -704,6 +706,10 @@ public class ResourceArnBuilder {
|
||||
if (executionArn != null) {
|
||||
return executionArn;
|
||||
}
|
||||
String childArn = lambdaChildArn(path, ctx, region, accountId);
|
||||
if (childArn != null) {
|
||||
return childArn;
|
||||
}
|
||||
// path: /2015-03-31/functions/name or similar
|
||||
String name = extractSegmentAfter(path, "functions");
|
||||
if (name == null) return "*";
|
||||
@@ -733,6 +739,81 @@ public class ResourceArnBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The resource of a Lambda event source mapping, code signing config or layer route, as the Service
|
||||
* Reference gives it. A mapping is looked up by its UUID, a config by the id that ends its ARN and a
|
||||
* layer version by its layer's name as given, an ARN included, and its number, each in the request's
|
||||
* account and Region, so that is the resource checked. A layer route's path is split as the router
|
||||
* splits it, before decoding, so an encoded {@code /} stays inside the layer's name, and its version
|
||||
* number is read as Lambda parses it, so {@code 01} is version 1. {@code PublishLayerVersion} is checked
|
||||
* against the layer and {@code GetLayerVersionByArn} against the version its {@code Arn} names, its
|
||||
* number read the same way. Listing configs, layers or a layer's versions, and creating a config, name
|
||||
* no resource, so they are {@code *}. Null for every other Lambda route.
|
||||
*/
|
||||
private static String lambdaChildArn(String path, ContainerRequestContext ctx, String region, String accountId) {
|
||||
String mapping = segmentAfterPrefix(path, "/2015-03-31/event-source-mappings/");
|
||||
if (mapping != null) {
|
||||
return AwsArnUtils.Arn.of("lambda", region, accountId, "event-source-mapping:" + mapping).toString();
|
||||
}
|
||||
if (path.startsWith("/2020-04-22/code-signing-configs")) {
|
||||
String config = segmentAfterPrefix(path, "/2020-04-22/code-signing-configs/");
|
||||
return config == null ? "*"
|
||||
: AwsArnUtils.Arn.of("lambda", region, accountId,
|
||||
"code-signing-config:" + trailingName(config)).toString();
|
||||
}
|
||||
if (path.equals("/2018-10-31/layers")) {
|
||||
String arn = ctx.getUriInfo().getQueryParameters().getFirst("Arn");
|
||||
boolean byArn = "LayerVersion".equals(ctx.getUriInfo().getQueryParameters().getFirst("find"));
|
||||
return byArn && AwsArnUtils.isArnFor(arn, "lambda") ? layerVersionArn(arn) : "*";
|
||||
}
|
||||
String layers = "/2018-10-31/layers/";
|
||||
if (!path.startsWith(layers)) {
|
||||
return null;
|
||||
}
|
||||
String raw = IamActionRegistry.rawPath(ctx.getUriInfo());
|
||||
if (!raw.startsWith(layers)) {
|
||||
return "*";
|
||||
}
|
||||
String[] segments = raw.substring(layers.length()).split("/");
|
||||
if (segments.length < 2 || !"versions".equals(segments[1])) {
|
||||
return "*";
|
||||
}
|
||||
String layer = "layer:" + pathSegment(segments[0]);
|
||||
if (segments.length == 2) {
|
||||
return "POST".equalsIgnoreCase(ctx.getMethod())
|
||||
? AwsArnUtils.Arn.of("lambda", region, accountId, layer).toString() : "*";
|
||||
}
|
||||
return AwsArnUtils.Arn.of("lambda", region, accountId,
|
||||
layer + ":" + layerVersion(pathSegment(segments[2]))).toString();
|
||||
}
|
||||
|
||||
/** A layer version ARN, its version number written as Lambda parses it. */
|
||||
private static String layerVersionArn(String arn) {
|
||||
int colon = arn.lastIndexOf(':');
|
||||
return arn.substring(0, colon + 1) + layerVersion(arn.substring(colon + 1));
|
||||
}
|
||||
|
||||
/** A layer version number as Lambda parses it, so {@code 01} is 1; as given when it is no number. */
|
||||
private static String layerVersion(String version) {
|
||||
try {
|
||||
return Long.toString(Long.parseLong(version));
|
||||
} catch (NumberFormatException e) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A path segment as sent, decoded as a path parameter is: a {@code +} stays a {@code +}. A malformed
|
||||
* escape is kept as sent.
|
||||
*/
|
||||
private static String pathSegment(String raw) {
|
||||
try {
|
||||
return URLDecoder.decode(raw.replace("+", "%2B"), StandardCharsets.UTF_8);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return raw;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The resource of a Lambda MicroVM or network connector route, as the Service Reference gives it:
|
||||
* {@code microvm-image:<name>} for an action on an image, its versions and builds, and
|
||||
|
||||
Reference in new issue
Block a user