mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(lambda): preserve alias identity in qualified reads (#6757)
Preserve the requested alias ARN while returning the resolved published version configuration. Retain snapshot-versus-latest regressions for both read APIs. Signed-off-by: Andre Kurait <akurait@amazon.com> Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
65df465fc3
commit
0332b5cc24
4 files changed
+144
-11
No files matched your search
@@ -0,0 +1,52 @@
|
||||
"""Alias reads preserve the requested ARN while returning the primary version."""
|
||||
|
||||
import io
|
||||
import zipfile
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize("form", ["name", "arn", "partial"])
|
||||
@pytest.mark.parametrize("embedded", [False, True])
|
||||
def test_alias_read_identity(lambda_client, minimal_lambda_zip, unique_name, form, embedded):
|
||||
created = lambda_client.create_function(
|
||||
FunctionName=unique_name, Runtime="nodejs22.x", Handler="index.handler",
|
||||
Role="arn:aws:iam::000000000000:role/lambda-role",
|
||||
Code={"ZipFile": minimal_lambda_zip},
|
||||
)
|
||||
try:
|
||||
version = lambda_client.publish_version(FunctionName=unique_name)["Version"]
|
||||
alias = lambda_client.create_alias(
|
||||
FunctionName=unique_name, Name="stable", FunctionVersion=version
|
||||
)
|
||||
changed_zip = io.BytesIO()
|
||||
with zipfile.ZipFile(changed_zip, "w") as archive:
|
||||
archive.writestr("index.js", "exports.handler = async () => 'changed latest';")
|
||||
changed = lambda_client.update_function_code(
|
||||
FunctionName=unique_name, ZipFile=changed_zip.getvalue()
|
||||
)
|
||||
assert changed["CodeSha256"] != created["CodeSha256"]
|
||||
arn = created["FunctionArn"]
|
||||
reference = {"name": unique_name, "arn": arn, "partial": arn.split(":", 4)[4]}[form]
|
||||
request = (
|
||||
{"FunctionName": reference + ":stable"} if embedded
|
||||
else {"FunctionName": reference, "Qualifier": "stable"}
|
||||
)
|
||||
function = lambda_client.get_function(**request)["Configuration"]
|
||||
configuration = lambda_client.get_function_configuration(**request)
|
||||
for response in (function, configuration):
|
||||
assert response["FunctionArn"] == alias["AliasArn"]
|
||||
assert response["Version"] == version
|
||||
assert response["CodeSha256"] == created["CodeSha256"]
|
||||
numeric = lambda_client.get_function(
|
||||
FunctionName=unique_name, Qualifier=version
|
||||
)["Configuration"]
|
||||
latest = lambda_client.get_function(FunctionName=unique_name)["Configuration"]
|
||||
assert (numeric["FunctionArn"], numeric["Version"]) == (arn + ":" + version, version)
|
||||
assert numeric["CodeSha256"] == created["CodeSha256"]
|
||||
assert (latest["FunctionArn"], latest["Version"]) == (arn, "$LATEST")
|
||||
assert latest["CodeSha256"] == changed["CodeSha256"]
|
||||
latest_configuration = lambda_client.get_function_configuration(FunctionName=unique_name)
|
||||
assert latest_configuration["CodeSha256"] == changed["CodeSha256"]
|
||||
finally:
|
||||
lambda_client.delete_function(FunctionName=unique_name)
|
||||
@@ -109,6 +109,14 @@ part in authorizing calls to the function:
|
||||
- `aws:PrincipalOrgID` is not part of the request context, so a grant added with `PrincipalOrgID`
|
||||
admits no caller.
|
||||
|
||||
### Qualified reads
|
||||
|
||||
`GetFunction` and `GetFunctionConfiguration` preserve an alias in the returned
|
||||
`FunctionArn`, while `Version` identifies that alias's primary published version.
|
||||
This applies to a `Qualifier` parameter and aliases embedded in a name, full ARN
|
||||
or partial ARN. Reading an alias does not change the stored version or the
|
||||
identities returned by subsequent unqualified and numeric-version reads.
|
||||
|
||||
### Reserved Concurrency
|
||||
|
||||
Unqualified `GetFunction` reads include `Concurrency.ReservedConcurrentExecutions` when a reservation
|
||||
|
||||
@@ -100,9 +100,10 @@ public class LambdaController {
|
||||
@QueryParam("Qualifier") String qualifier) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
LambdaFunction fn = lambdaService.getFunction(region, functionName, qualifier);
|
||||
String effectiveQualifier = LambdaArnUtils.resolveWithQualifier(functionName, qualifier).qualifier();
|
||||
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
root.set("Configuration", objectMapper.valueToTree(buildFunctionConfiguration(fn)));
|
||||
root.set("Configuration", objectMapper.valueToTree(buildReadConfiguration(fn, effectiveQualifier)));
|
||||
ObjectNode code = root.putObject("Code");
|
||||
if ("Image".equals(fn.getPackageType()) && fn.getImageUri() != null) {
|
||||
code.put("RepositoryType", "ECR");
|
||||
@@ -133,7 +134,6 @@ public class LambdaController {
|
||||
}
|
||||
|
||||
Integer reservedConcurrency = fn.getReservedConcurrentExecutions();
|
||||
String effectiveQualifier = LambdaArnUtils.resolveWithQualifier(functionName, qualifier).qualifier();
|
||||
if (effectiveQualifier == null && reservedConcurrency != null) {
|
||||
root.putObject("Concurrency").put("ReservedConcurrentExecutions", reservedConcurrency);
|
||||
}
|
||||
@@ -171,7 +171,8 @@ public class LambdaController {
|
||||
@QueryParam("Qualifier") String qualifier) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
LambdaFunction fn = lambdaService.getFunction(region, functionName, qualifier);
|
||||
return Response.ok(buildFunctionConfiguration(fn)).build();
|
||||
String effectiveQualifier = LambdaArnUtils.resolveWithQualifier(functionName, qualifier).qualifier();
|
||||
return Response.ok(buildReadConfiguration(fn, effectiveQualifier)).build();
|
||||
}
|
||||
|
||||
// ──────────────────────────── UpdateFunctionConfiguration ────────────────────────────
|
||||
@@ -723,6 +724,15 @@ public class LambdaController {
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> buildReadConfiguration(LambdaFunction fn, String qualifier) {
|
||||
Map<String, Object> configuration = buildFunctionConfiguration(fn);
|
||||
if (qualifier != null && !"$LATEST".equals(qualifier) && !qualifier.equals(fn.getVersion())) {
|
||||
unqualifyArn(configuration);
|
||||
configuration.put("FunctionArn", configuration.get("FunctionArn") + ":" + qualifier);
|
||||
}
|
||||
return configuration;
|
||||
}
|
||||
|
||||
private Map<String, Object> buildFunctionConfiguration(LambdaFunction fn) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("FunctionName", fn.getFunctionName());
|
||||
|
||||
+71
-8
@@ -4,6 +4,8 @@ import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Base64;
|
||||
@@ -12,6 +14,7 @@ import java.util.zip.ZipOutputStream;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
|
||||
/**
|
||||
* Issue #2821: GetFunction and GetFunctionConfiguration ignored Qualifier and answered with
|
||||
@@ -25,6 +28,61 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
@QuarkusTest
|
||||
class LambdaQualifiedReadIntegrationTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"name, true", "name, false",
|
||||
"arn, true", "arn, false",
|
||||
"partial, true", "partial, false"
|
||||
})
|
||||
void aliasReadsKeepTheRequestedArnAndResolvedVersion(String form, boolean query) throws Exception {
|
||||
String fn = "alias-identity-" + Long.toString(System.nanoTime(), 36);
|
||||
createFunction(fn, "published");
|
||||
try {
|
||||
String arn = given().when().get("/2015-03-31/functions/" + fn)
|
||||
.then().statusCode(200).extract().path("Configuration.FunctionArn");
|
||||
String publishedHash = given().contentType("application/json").body("{}")
|
||||
.when().post("/2015-03-31/functions/" + fn + "/versions")
|
||||
.then().statusCode(201).body("Version", equalTo("1"))
|
||||
.extract().path("CodeSha256");
|
||||
String aliasArn = given().contentType("application/json")
|
||||
.body("{\"Name\":\"stable\",\"FunctionVersion\":\"1\"}")
|
||||
.when().post("/2015-03-31/functions/" + fn + "/aliases")
|
||||
.then().statusCode(anyOf200Or201()).extract().path("AliasArn");
|
||||
String latestHash = given().contentType("application/json")
|
||||
.body("{\"ZipFile\": \"%s\"}".formatted(zipB64("latest")))
|
||||
.when().put("/2015-03-31/functions/" + fn + "/code")
|
||||
.then().statusCode(200).extract().path("CodeSha256");
|
||||
assertNotEquals(publishedHash, latestHash);
|
||||
String reference = switch (form) {
|
||||
case "arn" -> arn;
|
||||
case "partial" -> "000000000000:function:" + fn;
|
||||
default -> fn;
|
||||
};
|
||||
String path = "/2015-03-31/functions/" + reference + (query ? "" : ":stable");
|
||||
String suffix = query ? "?Qualifier=stable" : "";
|
||||
given().when().get(path + suffix).then().statusCode(200)
|
||||
.body("Configuration.FunctionArn", equalTo(aliasArn))
|
||||
.body("Configuration.Version", equalTo("1"))
|
||||
.body("Configuration.CodeSha256", equalTo(publishedHash));
|
||||
given().when().get(path + "/configuration" + suffix).then().statusCode(200)
|
||||
.body("FunctionArn", equalTo(aliasArn))
|
||||
.body("Version", equalTo("1"))
|
||||
.body("CodeSha256", equalTo(publishedHash));
|
||||
given().when().get("/2015-03-31/functions/" + fn + ":1").then().statusCode(200)
|
||||
.body("Configuration.FunctionArn", equalTo(arn + ":1"))
|
||||
.body("Configuration.Version", equalTo("1"))
|
||||
.body("Configuration.CodeSha256", equalTo(publishedHash));
|
||||
given().when().get("/2015-03-31/functions/" + fn).then().statusCode(200)
|
||||
.body("Configuration.FunctionArn", equalTo(arn))
|
||||
.body("Configuration.Version", equalTo("$LATEST"))
|
||||
.body("Configuration.CodeSha256", equalTo(latestHash));
|
||||
given().when().get("/2015-03-31/functions/" + fn + "/configuration")
|
||||
.then().statusCode(200).body("CodeSha256", equalTo(latestHash));
|
||||
} finally {
|
||||
given().when().delete("/2015-03-31/functions/" + fn).then().statusCode(204);
|
||||
}
|
||||
}
|
||||
|
||||
private static String zipB64(String body) throws Exception {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
try (ZipOutputStream zos = new ZipOutputStream(baos)) {
|
||||
@@ -59,30 +117,35 @@ class LambdaQualifiedReadIntegrationTest {
|
||||
String fn = "qual-read-" + Long.toString(System.nanoTime(), 36);
|
||||
createFunction(fn, "v1");
|
||||
|
||||
given().contentType("application/json").body("{}")
|
||||
String publishedHash = given().contentType("application/json").body("{}")
|
||||
.when().post("/2015-03-31/functions/" + fn + "/versions")
|
||||
.then().statusCode(201).body("Version", equalTo("1"));
|
||||
.then().statusCode(201).body("Version", equalTo("1")).extract().path("CodeSha256");
|
||||
|
||||
// $LATEST moves on past version 1.
|
||||
given()
|
||||
String latestHash = given()
|
||||
.contentType("application/json")
|
||||
.body("{\"ZipFile\": \"%s\"}".formatted(zipB64("v2")))
|
||||
.when()
|
||||
.put("/2015-03-31/functions/" + fn + "/code")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
.statusCode(200).extract().path("CodeSha256");
|
||||
assertNotEquals(publishedHash, latestHash);
|
||||
|
||||
given().when().get("/2015-03-31/functions/" + fn + "?Qualifier=1")
|
||||
.then().statusCode(200).body("Configuration.Version", equalTo("1"));
|
||||
.then().statusCode(200).body("Configuration.Version", equalTo("1"))
|
||||
.body("Configuration.CodeSha256", equalTo(publishedHash));
|
||||
|
||||
given().when().get("/2015-03-31/functions/" + fn + "/configuration?Qualifier=1")
|
||||
.then().statusCode(200).body("Version", equalTo("1"));
|
||||
.then().statusCode(200).body("Version", equalTo("1"))
|
||||
.body("CodeSha256", equalTo(publishedHash));
|
||||
|
||||
// Unqualified and an explicit $LATEST both still mean $LATEST.
|
||||
given().when().get("/2015-03-31/functions/" + fn)
|
||||
.then().statusCode(200).body("Configuration.Version", equalTo("$LATEST"));
|
||||
.then().statusCode(200).body("Configuration.Version", equalTo("$LATEST"))
|
||||
.body("Configuration.CodeSha256", equalTo(latestHash));
|
||||
given().when().get("/2015-03-31/functions/" + fn + "?Qualifier=$LATEST")
|
||||
.then().statusCode(200).body("Configuration.Version", equalTo("$LATEST"));
|
||||
.then().statusCode(200).body("Configuration.Version", equalTo("$LATEST"))
|
||||
.body("Configuration.CodeSha256", equalTo(latestHash));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user