mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(lambda-web): answer a delete marker as the code object as AWS does (#7079)
* fix(lambda-web): answer a delete marker as the code object as AWS does A delete marker as the latest version is refused with AWS's own message, and a versionId that names a delete marker is an internal error, as on AWS. * test(lambda-web): cover the null delete marker of a suspended bucket
This commit is contained in:
1 parent
fbd07bd6f5
commit
02b9669066
5 files changed
+51
-1
No files matched your search
@@ -36,7 +36,7 @@ The `Lambda Web` service model (apiVersion 2025-03-07, `aws lambda-web` in the A
|
||||
|
||||
- **Instant convergence:** a revision and an endpoint are stored `Active`, or `Failed` as below, and an endpoint update is stored `Successful`. The create and update responses still report the transitional state AWS reports (`Pending`, `updateStatus: InProgress`, and the per-region block as it was before the update), so a waiter sees one poll.
|
||||
- **Failed revisions:** a revision whose code is not a zip, or whose files add up to more than 512 MiB, is stored `Failed`, as on AWS. It cannot be deployed: weights that name it, or `LatestRevision` while it is the newest revision, are `409 ConflictException`, and `LatestRevision` endpoints stay on their revision. The endpoint of a `CreateWebFunction` whose revision fails is `Failed` too. It answers every request with `409` and `Platform.EndpointNotActive` and refuses updates until it is deleted. In a stack, the revision's resource fails with the revision's `stateReason` and the rollback deletes it. An empty object is a `500 InternalServerException` with the body `{}`, and an object over 512 MiB is a `400 ValidationException`, as on AWS.
|
||||
- **Code comes from S3 only.** The object named in `buildConfig.codeConfig.s3Object` must exist in Floci's S3, as on AWS. A request without `versionId` is refused when the latest version is the null version, so the object has to be written after the bucket's versioning is enabled, as on AWS. When IAM enforcement is on, the bucket policy must also let `lambda.amazonaws.com` take `s3:GetObjectVersion` on the object. The policy sees the new revision ARN as `aws:SourceArn`, the function's account as `aws:SourceAccount` and the version Lambda reads as `s3:VersionId`. As on AWS, `s3:GetObject` is not evaluated, although the error names it. Floci does not check the caller's own S3 permissions or the KMS key policy of an encrypted object.
|
||||
- **Code comes from S3 only.** The object named in `buildConfig.codeConfig.s3Object` must exist in Floci's S3, as on AWS. A request without `versionId` is refused when the latest version is the null version, so the object has to be written after the bucket's versioning is enabled, as on AWS. A delete marker as the latest version is refused with its own `400 ValidationException`, and a `versionId` that names a delete marker is a `500 InternalServerException` with the body `{}`, as on AWS. When IAM enforcement is on, the bucket policy must also let `lambda.amazonaws.com` take `s3:GetObjectVersion` on the object. The policy sees the new revision ARN as `aws:SourceArn`, the function's account as `aws:SourceAccount` and the version Lambda reads as `s3:VersionId`. As on AWS, `s3:GetObject` is not evaluated, although the error names it. Floci does not check the caller's own S3 permissions or the KMS key policy of an encrypted object.
|
||||
- **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 in the bucket or a delete marker does not change what the revision runs. Deleting that object version, or taking away Lambda's `s3:GetObjectVersion` on it under IAM enforcement, moves the revision to `Failed` for good, as on AWS. AWS does this when it next checks the object, at a time it does not document. Floci checks each time it reads the revision's state or routes a request to it, so the revision fails at once. Its `stateReason` is the `CreateWebFunctionRevision` refusal for the same cause, as AWS's wording was not seen. Endpoints keep their weights, and the requests routed to the revision get `409` with `Platform.RevisionNotActive`.
|
||||
- **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.
|
||||
|
||||
@@ -864,6 +864,14 @@ public class LambdaWebService implements Resettable {
|
||||
LOG.debugv("Web function code object s3://{0}/{1} is not readable: {2}", build.bucket, build.key,
|
||||
e.getMessage());
|
||||
String object = "s3://" + build.bucket + "/" + build.key;
|
||||
if (s3Service.isDeleteMarker(build.bucket, build.key, build.versionId)) {
|
||||
if (build.versionId != null) {
|
||||
// AWS fails internally on a version that is a delete marker.
|
||||
throw new LambdaWebInternalServerException();
|
||||
}
|
||||
throw new AwsException("ValidationException", "The latest version of the S3 object is a delete marker."
|
||||
+ " Upload a new object version or pass an explicit S3ObjectVersion.", 400);
|
||||
}
|
||||
if (build.versionId == null) {
|
||||
throw new AwsException("ValidationException", "The specified S3 object does not exist: " + object
|
||||
+ ". Verify the object exists in the bucket.", 400);
|
||||
|
||||
@@ -2132,6 +2132,14 @@ public class S3Service implements Resettable, ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether the version {@code versionId} names, the current one when it is null, is a delete marker. */
|
||||
public boolean isDeleteMarker(String bucketName, String key, String versionId) {
|
||||
return resolveBucketEntry(bucketName)
|
||||
.flatMap(bucket -> findStoredObject(bucket, bucketName, key, versionId))
|
||||
.map(S3Object::isDeleteMarker)
|
||||
.orElse(false);
|
||||
}
|
||||
|
||||
public InputStream openObjectStream(String bucketName, String key, String versionId) {
|
||||
if ("null".equals(versionId)) {
|
||||
return openObject(bucketName, key, versionId).body();
|
||||
|
||||
+9
@@ -88,6 +88,15 @@ class LambdaWebCodeBucketIntegrationTest {
|
||||
refused(null, VERSIONING);
|
||||
}
|
||||
|
||||
@Test
|
||||
void theNullDeleteMarkerOfASuspendedBucketIsRefusedBeforeTheBucketPolicy() {
|
||||
s3Service.putBucketVersioning(bucket, "Suspended");
|
||||
put(bucket);
|
||||
s3Service.deleteObject(bucket, "app.zip");
|
||||
refused(null, "The latest version of the S3 object is a delete marker. Upload a new object version or pass"
|
||||
+ " an explicit S3ObjectVersion.");
|
||||
}
|
||||
|
||||
@Test
|
||||
void lambdaNeedsGetObjectVersionUnderTheConditionsItSends() {
|
||||
s3Service.putBucketVersioning(bucket, "Enabled");
|
||||
|
||||
+25
@@ -455,6 +455,31 @@ class LambdaWebIntegrationTest {
|
||||
.body("message", equalTo("The specified S3 object does not exist: s3://" + BUCKET
|
||||
+ "/missing.zip. Verify the object exists in the bucket."));
|
||||
|
||||
s3Service.putObject(BUCKET, "deleted.zip", LambdaWebZips.indexJs(""), "application/zip", Map.of());
|
||||
String marker = s3Service.deleteObject(BUCKET, "deleted.zip").getVersionId();
|
||||
given().contentType("application/json")
|
||||
.body("""
|
||||
{"buildConfig": {"codeConfig": {"s3Object": {"bucket": "%s", "key": "deleted.zip"}},
|
||||
"runtimeConfig": {"runtime": "nodejs24.x"}},
|
||||
"serviceConfig": {"executionRoleArn": "%s"}}
|
||||
""".formatted(BUCKET, ROLE))
|
||||
.when().post(revisions)
|
||||
.then().statusCode(400)
|
||||
.header("X-Amzn-Errortype", "ValidationException")
|
||||
.body("message", equalTo("The latest version of the S3 object is a delete marker. Upload a new object"
|
||||
+ " version or pass an explicit S3ObjectVersion."));
|
||||
given().contentType("application/json")
|
||||
.body("""
|
||||
{"buildConfig": {"codeConfig": {"s3Object": {"bucket": "%s", "key": "deleted.zip",
|
||||
"versionId": "%s"}},
|
||||
"runtimeConfig": {"runtime": "nodejs24.x"}},
|
||||
"serviceConfig": {"executionRoleArn": "%s"}}
|
||||
""".formatted(BUCKET, marker, ROLE))
|
||||
.when().post(revisions)
|
||||
.then().statusCode(500)
|
||||
.header("X-Amzn-Errortype", "InternalServerException")
|
||||
.body(equalTo("{}"));
|
||||
|
||||
given().contentType("application/json")
|
||||
.body("""
|
||||
{"buildConfig": %s, "serviceConfig": {"executionRoleArn": "%s",
|
||||
|
||||
Reference in new issue
Block a user