From 4e0bf080edbc34798ca6d11039edb40486d19fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TATSUNO=20=E2=80=9CTaz=E2=80=9D=20Yasuhiro?= Date: Sat, 24 Oct 2026 21:37:19 +0900 Subject: [PATCH] fix(lambdaweb): refuse a function name another region already has (#6409) * fix(lambdaweb): refuse a function name another region already has AWS keeps web function names unique across the regions of an account. CreateWebFunction with a name another region has is 409 ConflictException "A function named already exists in the account. Function names must be unique across all regions in an account.", at the same point as the same-region conflict. * fix(lambdaweb): key the function name lock by account * perf(lambdaweb): find a name in other regions without copying every key --- docs/services/lambda-web-functions.md | 1 + .../services/lambdaweb/LambdaWebService.java | 28 +++++++++++++------ .../lambdaweb/LambdaWebIntegrationTest.java | 12 ++++++++ 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/docs/services/lambda-web-functions.md b/docs/services/lambda-web-functions.md index e02fe9e88f..bf7e6785d5 100644 --- a/docs/services/lambda-web-functions.md +++ b/docs/services/lambda-web-functions.md @@ -40,6 +40,7 @@ The `Lambda Web` service model (apiVersion 2025-03-07, `aws lambda-web` in the A - **Each revision keeps its own copy of the code**, read at creation from the version the request names or the current one, under the Lambda `code-path`. As on AWS, a later write or delete in the bucket does not change what the revision runs. AWS moves a revision to `Failed` when it later finds its object version gone, which Floci does not do. - **Execution role:** a role in another account is `403 AccessDeniedException` "Cross-account pass role is not allowed.". A role that does not exist in IAM, or whose trust policy does not let `lambda.amazonaws.com` assume it, is `400 ValidationException` "The execution role cannot be assumed by lambda.amazonaws.com. Verify its trust policy. If the role was just created, retry in a few seconds.". As on AWS, this check sets no `aws:SourceAccount` or `aws:SourceArn`, so a trust policy that requires either refuses the role. The network connector ARN is checked for shape only. - **Resource policies** are checked the way AWS checks them before storing: the document grammar, a `lambda:` action, a `Resource` that names the function, a valid principal, and no public `Allow`. A wildcard principal needs a positive condition (`StringEquals`, `StringLike`, `ArnLike`, `Bool`) on a trusted key such as `aws:PrincipalAccount` or `aws:PrincipalArn`, with no wildcard in the account it names. An `IamAuth` endpoint evaluates it on requests, as below. +- **Function names** are unique across the regions of an account, as on AWS. A name that another region already has is `409 ConflictException` "A function named already exists in the account. Function names must be unique across all regions in an account.". - **ARNs** given as identifiers must name the request's region and the caller's account, as on AWS. A revision or endpoint ARN resolves by its id or name only. - **Page tokens** are base64 cursors that carry the request and the position of the page, not the UUIDs AWS issues. A token reused with other parameters gets the AWS "does not match the request" error, and any other token the "invalid or has expired" error. - **Domain names** take the form `.001.lambda-web..` and `.lambda-web.global.`, with the host and port of `floci.base-url`. A `PerRegion` endpoint gets one domain per region in `regionalEndpoints`. diff --git a/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebService.java b/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebService.java index e384a49601..c9dbeff56d 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebService.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebService.java @@ -335,19 +335,29 @@ public class LambdaWebService implements Resettable { } } - /** Stores a new function under its lock, refusing a name the region already has. */ + /** + * Stores a new function under its lock, refusing a name the account already has in any region. + * Creates of one name in every region of the account share a lock, so two regions cannot both take it. + */ private WebFunction storeNewFunction(String region, String functionName, Map tags, Consumer populate) { String accountId = regionResolver.getAccountId(); - synchronized (lockFor(region, functionName)) { - if (functions.get(key(region, functionName)).isPresent()) { - throw new AwsException("ConflictException", - "The function " + functionArn(region, accountId, functionName) + " already exists.", 409); + synchronized (locks.computeIfAbsent(accountId + "/" + functionName, k -> new Object())) { + synchronized (lockFor(region, functionName)) { + if (functions.get(key(region, functionName)).isPresent()) { + throw new AwsException("ConflictException", + "The function " + functionArn(region, accountId, functionName) + " already exists.", 409); + } + if (!functions.scan(k -> k.endsWith("/" + functionName)).isEmpty()) { + throw new AwsException("ConflictException", "A function named " + functionName + + " already exists in the account. Function names must be unique across all regions" + + " in an account.", 409); + } + WebFunction fn = newFunction(region, accountId, functionName, tags == null ? Map.of() : tags); + populate.accept(fn); + functions.put(key(region, functionName), fn); + return copy(fn, WebFunction.class); } - WebFunction fn = newFunction(region, accountId, functionName, tags == null ? Map.of() : tags); - populate.accept(fn); - functions.put(key(region, functionName), fn); - return copy(fn, WebFunction.class); } } diff --git a/src/test/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebIntegrationTest.java index 45c10ce103..dfe20f59b9 100644 --- a/src/test/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebIntegrationTest.java @@ -571,6 +571,18 @@ class LambdaWebIntegrationTest { .when().put(BASE + "/web-functions") .then().statusCode(409) .body("message", equalTo("The function " + ARN + " already exists.")); + given().contentType("application/json") + .header("Authorization", "AWS4-HMAC-SHA256 Credential=test/20260101/us-west-2/lambda/aws4_request") + .body(""" + {"functionName": "%s", + "revisionConfig": {"buildConfig": %s, "serviceConfig": {"executionRoleArn": "%s"}}, + "endpointConfig": {"endpointName": "dev", "endpointType": "HomeRegion", + "authType": "ApplicationManaged"}} + """.formatted(FN, BUILD.replace("nodejs24.x", "nodejs22.x"), ROLE)) + .when().put(BASE + "/web-functions") + .then().statusCode(409) + .body("message", equalTo("A function named " + FN + " already exists in the account. Function names" + + " must be unique across all regions in an account.")); given().when().get(BASE + "/web-functions/does-not-exist") .then().statusCode(404) .body("message", equalTo("The function arn:aws:lambda:us-east-1:000000000000:web-function/does-not-exist"