fix(lambdaweb): accept a policy Action of "*" or any case of lambda (#6883)

Lambda takes "*" or "<service>:<action>" with a service of letters,
digits, dots and dashes. Each action names lambda in any case, unless the
list also holds "*", which lets actions of other services through.
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-28 21:07:10 -04:00
1 parent 3f36c4e99e
commit 177f8e9360
4 files changed
+42 -4

No files matched your search

+1 -1
View File
@@ -41,7 +41,7 @@ The `Lambda Web` service model (apiVersion 2025-03-07, `aws lambda-web` in the A
- **Revision cleanup:** when a revision turns `Active` and the function has more than 50, the oldest revisions that no endpoint routes to are deleted until 50 are left, `Failed` ones included, as on AWS. A new `Failed` revision deletes nothing. The revision that a `LatestRevision` endpoint leaves is not deleted before the next revision turns `Active`, as on AWS.
- **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 <arn> 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.
- **Egress network connectors:** `egressNetworkConnectorArn` names a connector version by the connector id, in the function's region, as on AWS. A version that does not exist, a connector name, or another region is `404 ResourceNotFoundException` "The egress network connector <arn> does not exist.". A connector without `WebFunction` in its `AssociatedComputeResourceTypes` is `400 ValidationException`. An unknown region, a partition that is not the region's, or a version such as `0` or `01` is `400 ValidationException` "The egress network connector ARN: '<arn>' is not valid. ...", and a connector in another account is `403 AccessDeniedException`. A version past the 64-bit range is `500 InternalServerException` with the body `{}`, as on AWS. Only a `HomeRegion` endpoint can serve such a revision: `CreateWebFunction` with another endpoint type, and weights of a `PerRegion` or `MultiRegion` endpoint that name such a revision, are `400 ValidationException`. Floci settles a connector at once, so the AWS refusal of a `PENDING` version never happens. When IAM enforcement is on, the caller also needs `lambda:PassNetworkConnector` on the version ARN as the request gives it, refused as on AWS (see [IAM](iam.md)). Floci checks it before the request reaches Lambda, so a refusal comes before the ARN checks above, which AWS runs first. The connector does not change the network of the function's container.
- **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`. AWS reads only the service and the resource of a `Resource`, so `lambda` with `web-function/<name>`, `web-function/<name>*` or `web-function/<name>/...` passes in any partition, region or account, as on AWS. 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 `Allow` for a `Federated` principal is public in the same way, unless its values include `*`, as on AWS. AWS checks no pattern on `Federated` and `CanonicalUser` values. Every principal has to exist, as on AWS. A role or user is looked up by its ARN in the account the ARN names, or by its unique id (`AROA...`, `AIDA...`) in the function's account, and a missing one, an assumed-role session, a `CanonicalUser` or an ARN in another partition is `400 ValidationException` "The provided principal was invalid. Please check the principal and try again.". A role or user named under a path other than its own is "The principal arn provided does not match the actual principal arn. Please check your input and try again.". Each check runs on every statement before the next check starts, in the order AWS reports them, so an `Effect` other than `Allow` or `Deny` ("Invalid effect: <value>") in any statement comes before a principal error in another. The principals are looked up once every statement passes its other checks, and before any statement is refused as public. Floci holds every account, so any account id or root is taken to exist, and it keeps no list of service principals, so an unknown one is accepted. An `IamAuth` endpoint evaluates the policy on requests, as below.
- **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`. An action is `*` or `<service>:<action>`, and each one names `lambda` in any case unless the list also holds `*`, as on AWS. AWS reads only the service and the resource of a `Resource`, so `lambda` with `web-function/<name>`, `web-function/<name>*` or `web-function/<name>/...` passes in any partition, region or account, as on AWS. 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 `Allow` for a `Federated` principal is public in the same way, unless its values include `*`, as on AWS. AWS checks no pattern on `Federated` and `CanonicalUser` values. Every principal has to exist, as on AWS. A role or user is looked up by its ARN in the account the ARN names, or by its unique id (`AROA...`, `AIDA...`) in the function's account, and a missing one, an assumed-role session, a `CanonicalUser` or an ARN in another partition is `400 ValidationException` "The provided principal was invalid. Please check the principal and try again.". A role or user named under a path other than its own is "The principal arn provided does not match the actual principal arn. Please check your input and try again.". Each check runs on every statement before the next check starts, in the order AWS reports them, so an `Effect` other than `Allow` or `Deny` ("Invalid effect: <value>") in any statement comes before a principal error in another. The principals are looked up once every statement passes its other checks, and before any statement is refused as public. Floci holds every account, so any account id or root is taken to exist, and it keeps no list of service principals, so an unknown one is accepted. An `IamAuth` endpoint evaluates the policy 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 <name> 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.
@@ -135,6 +135,7 @@ public class LambdaWebService implements Resettable {
private static final Pattern PRINCIPAL_AWS = Pattern.compile("[\\w+=,.@\\:-]*");
private static final Pattern PRINCIPAL_AWS_ARN = Pattern.compile("[\\w+=/:,.@-]*");
private static final Pattern PRINCIPAL_SERVICE = Pattern.compile("[\\w+=,.@-]*");
private static final Pattern POLICY_ACTION = Pattern.compile("\\*|[a-zA-Z0-9.-]+:[^:]*");
/** AWS assigns one shard label per cell. */
private static final String DOMAIN_SHARD = "001";
@@ -1519,11 +1520,17 @@ public class LambdaWebService implements Resettable {
if (statement.has("NotPrincipal") || statement.has("NotAction") || statement.has("NotResource")) {
throw policySyntax();
}
for (String action : policyValues(statement.get("Action"))) {
if (!action.startsWith("lambda:")) {
List<String> actions = policyValues(statement.get("Action"));
for (String action : actions) {
if (!POLICY_ACTION.matcher(action).matches()) {
throw policySyntax();
}
}
// AWS lets an action of any service through when the list also holds "*".
if (!actions.contains("*")
&& !actions.stream().allMatch(action -> action.regionMatches(true, 0, "lambda:", 0, 7))) {
throw policySyntax();
}
String function = AwsArnUtils.parse(functionArn).resource();
for (String resource : policyValues(statement.get("Resource"))) {
if (!namesFunction(resource, function)) {
@@ -533,6 +533,12 @@ class LambdaWebIntegrationTest {
.then().statusCode(400)
.body("message", equalTo("Lambda blocked the creation of this policy because it would grant public"
+ " access to your function."));
given().contentType("application/json")
.body(Map.of("Policy", publicPolicy.replace("\"lambda:InvokeWebFunctionEndpoint\"", "\"*\"")))
.when().put(policyPath)
.then().statusCode(400)
.body("message", equalTo("Lambda blocked the creation of this policy because it would grant public"
+ " access to your function."));
given().contentType("application/json").body(Map.of("Policy", publicPolicy.replace("\"Allow\"", "\"Maybe\"")))
.when().put(policyPath)
.then().statusCode(400)
@@ -944,8 +944,33 @@ class LambdaWebServiceTest {
}
private static String resourcePolicy(String resource) {
return grantPolicy("\"lambda:GetWebFunction\"", resource);
}
private static String grantPolicy(String action, String resource) {
return "{\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"000000000000\"},"
+ "\"Action\":\"lambda:GetWebFunction\",\"Resource\":" + resource + "}]}";
+ "\"Action\":" + action + ",\"Resource\":" + resource + "}]}";
}
@Test
void aPolicyActionIsAStarOrALambdaActionInAnyCase() {
LambdaWebService service = service();
String missing = "arn:aws:lambda:us-east-1:000000000000:web-function/missing";
for (String accepted : List.of("\"*\"", "\"Lambda:GetWebFunction\"", "\"LAMBDA:GetWebFunction\"", "\"lambda:\"",
"\"lambda:*x\"", "\"lambda:Get?ebFunction\"", "\"lambda:a b!c\"", "[\"*\",\"s3:GetObject\"]",
"[\"s3:GetObject\",\"*\"]", "[\"*\",\"*\"]", "[\"*\",\"a.b:x\"]", "[\"*\",\"9:x\"]", "[\"*\",\"s3:\"]",
"[\"lambda:GetWebFunction\",\"Lambda:x\"]")) {
assertEquals("ResourceNotFoundException", error(() -> service.putResourcePolicy(REGION, missing,
policy(grantPolicy(accepted, "\"" + missing + "\"")))).getErrorCode(), accepted);
}
for (String refused : List.of("\"lambda*\"", "\"*:*\"", "\"*:GetWebFunction\"", "\" lambda:GetWebFunction\"",
"\"lambda :GetWebFunction\"", "\"lambda\"", "\"**\"", "\"*x\"", "\"?\"", "\"lambda::x\"", "\"\"",
"\"s3:GetObject\"", "[\"lambda:GetWebFunction\",\"s3:GetObject\"]", "[\"lambda:*\",\"s3:GetObject\"]",
"[\"*\",\"garbage\"]", "[\"*\",\"\"]", "[\"*\",\"lambda::x\"]", "[\"*\",\"a_b:x\"]", "[\"*\",\"a+b:x\"]",
"[\"*\",\"l*:x\"]")) {
assertEquals("Policy has syntax errors.", message(() -> service.putResourcePolicy(REGION, missing,
policy(grantPolicy(refused, "\"" + missing + "\"")))), refused);
}
}
private static String principalPolicy(String effect, String principal, String functionArn) {