feat(lambda): manage code signing configurations (#4286)

* feat(lambda): manage code signing configurations

CreateCodeSigningConfig and its Get, Update, Delete and List siblings were
missing, so aws_lambda_code_signing_config and anything else that manages the
resource had nothing to call.

Adds the five, backed by a store. Constraints come from the model: an id of
csc- plus 17 characters, AllowedPublishers required with one to twenty signing
profile ARNs, a Description of at most 256 characters, and Warn as the default
UntrustedArtifactOnDeployment.

ListFunctionsByCodeSigningConfig now resolves the configuration instead of
answering every well-formed ARN with a 404. That answer was correct only while
no configuration could exist. A known one reports no functions, since
PutFunctionCodeSigningConfig is still not wired.

Nothing verifies a signature, so a configuration never gates a deployment. The
docs say so.

* fix(lambda): register the code signing config model for reflection

PersistedModelReflectionTest flagged it: a type reachable from persisted
storage needs @RegisterForReflection or native-image persistence breaks on
restart. The two nested shapes need it too.

* docs(lambda): name the ARN pattern as the reason the id alphabet is lowercase

The comment credited the id pattern, which is the looser of the two.
CodeSigningConfigId allows csc-[a-zA-Z0-9-_\.]{17} and CodeSigningConfigArn
ends in csc-[a-z0-9]{17}, so the ARN is what binds the alphabet. Anyone
reconciling the code against the old comment could widen it, still satisfy the
id pattern, and start emitting ARNs that do not conform.

Also imports List in the new test instead of writing java.util.List.of inline.

* fix(lambda): mint the code signing config ARN through AwsArnUtils

The ARN was assembled from a hardcoded arn:aws: prefix, so it named the
commercial partition whatever region the request carried. AwsArnUtils resolves
the partition from the region, which is what the partition-literals gate asks
for.

* fix(lambda): validate every member of an update before applying any

The store hands back the live instance, so validating and setting in turn left
an earlier member written when a later one was rejected. An update carrying a
valid Description and an empty AllowedPublishers answered 400 with the
description already changed, visible to the next GetCodeSigningConfig and
saved by the persistent and hybrid stores on their next write.

aRejectedUpdateChangesNothing sends that combination, and the same shape with
the policy as the rejected member, and asserts the description is unchanged
after each. It fails without the reordering.
This commit is contained in:
lex00 authored and GitHub committed 2026-09-24 12:05:29 -04:00
1 parent db07c56704
commit 41ceed4dba
5 files changed
+562 -17

No files matched your search

@@ -0,0 +1,158 @@
package io.github.hectorvent.floci.services.lambda;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.Test;
import java.util.List;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.matchesRegex;
import static org.hamcrest.Matchers.nullValue;
/** Create, Get, Update, Delete and List for a code signing configuration. */
@QuarkusTest
class LambdaCodeSigningConfigLifecycleIntegrationTest {
private static final String BASE = "/2020-04-22/code-signing-configs";
private static final String PROFILE =
"arn:aws:signer:us-east-1:000000000000:/signing-profiles/prof/AbCdEfGhIj";
private static String create(String body) {
return given().contentType("application/json").body(body)
.when().post(BASE)
.then().statusCode(201)
.extract().path("CodeSigningConfig.CodeSigningConfigArn");
}
@Test
void createReportsTheModelsIdAndArnShapeAndDefaultsThePolicy() {
given()
.contentType("application/json")
.body("{\"AllowedPublishers\":{\"SigningProfileVersionArns\":[\"" + PROFILE + "\"]},"
+ "\"Description\":\"release artifacts\"}")
.when()
.post(BASE)
.then()
.statusCode(201)
.body("CodeSigningConfig.CodeSigningConfigId", matchesRegex("csc-[a-z0-9]{17}"))
.body("CodeSigningConfig.CodeSigningConfigArn",
matchesRegex("arn:aws:lambda:us-east-1:\\d{12}:code-signing-config:csc-[a-z0-9]{17}"))
.body("CodeSigningConfig.Description", is("release artifacts"))
.body("CodeSigningConfig.AllowedPublishers.SigningProfileVersionArns", contains(PROFILE))
// The model documents Warn as the default when the request names no policy.
.body("CodeSigningConfig.CodeSigningPolicies.UntrustedArtifactOnDeployment", is("Warn"))
.body("CodeSigningConfig.LastModified",
matchesRegex("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z"));
}
@Test
void getReadsBackWhatCreateStored() {
String arn = create("{\"AllowedPublishers\":{\"SigningProfileVersionArns\":[\"" + PROFILE + "\"]},"
+ "\"CodeSigningPolicies\":{\"UntrustedArtifactOnDeployment\":\"Enforce\"}}");
given().when().get(BASE + "/" + arn).then()
.statusCode(200)
.body("CodeSigningConfig.CodeSigningConfigArn", is(arn))
.body("CodeSigningConfig.CodeSigningPolicies.UntrustedArtifactOnDeployment", is("Enforce"));
}
@Test
void updateAppliesOnlyTheMembersTheRequestNames() {
String arn = create("{\"AllowedPublishers\":{\"SigningProfileVersionArns\":[\"" + PROFILE + "\"]},"
+ "\"Description\":\"first\"}");
// Description alone. AllowedPublishers is omitted and must survive.
given().contentType("application/json").body("{\"Description\":\"second\"}")
.when().put(BASE + "/" + arn)
.then().statusCode(200)
.body("CodeSigningConfig.Description", is("second"))
.body("CodeSigningConfig.AllowedPublishers.SigningProfileVersionArns", contains(PROFILE));
}
@Test
void aRejectedUpdateChangesNothing() {
String arn = create("{\"AllowedPublishers\":{\"SigningProfileVersionArns\":[\"" + PROFILE + "\"]},"
+ "\"Description\":\"before\"}");
// Valid Description, invalid AllowedPublishers. The description must not survive the 400.
given().contentType("application/json")
.body("{\"Description\":\"after\",\"AllowedPublishers\":{\"SigningProfileVersionArns\":[]}}")
.when().put(BASE + "/" + arn)
.then().statusCode(400)
.body("__type", is("InvalidParameterValueException"));
given().when().get(BASE + "/" + arn).then()
.statusCode(200)
.body("CodeSigningConfig.Description", is("before"));
// The same shape with the policy as the rejected member.
given().contentType("application/json")
.body("{\"Description\":\"after\","
+ "\"CodeSigningPolicies\":{\"UntrustedArtifactOnDeployment\":\"Ignore\"}}")
.when().put(BASE + "/" + arn)
.then().statusCode(400);
given().when().get(BASE + "/" + arn).then()
.statusCode(200)
.body("CodeSigningConfig.Description", is("before"));
}
@Test
void listReturnsTheConfigsAndDeleteRemovesOne() {
String arn = create("{\"AllowedPublishers\":{\"SigningProfileVersionArns\":[\"" + PROFILE + "\"]}}");
given().when().get(BASE).then().statusCode(200)
.body("CodeSigningConfigs.CodeSigningConfigArn", hasItem(arn));
given().when().delete(BASE + "/" + arn).then().statusCode(204);
given().when().get(BASE + "/" + arn).then().statusCode(404)
.body("__type", is("ResourceNotFoundException"));
given().when().delete(BASE + "/" + arn).then().statusCode(404);
}
@Test
void anUnknownConfigIsNotFoundAndAKnownOneListsNoFunctions() {
String arn = create("{\"AllowedPublishers\":{\"SigningProfileVersionArns\":[\"" + PROFILE + "\"]}}");
// A config now exists, so the functions route reports an empty attachment list rather than
// the 404 it had to give when no config could exist at all.
given().when().get(BASE + "/" + arn + "/functions").then()
.statusCode(200)
.body("FunctionArns", is(List.of()))
.body("NextMarker", nullValue());
String missing = "arn:aws:lambda:us-east-1:000000000000:code-signing-config:csc-abcdefghij1234567";
given().when().get(BASE + "/" + missing + "/functions").then().statusCode(404);
}
@Test
void allowedPublishersIsRequiredAndBounded() {
given().contentType("application/json").body("{\"Description\":\"no publishers\"}")
.when().post(BASE).then().statusCode(400)
.body("__type", is("InvalidParameterValueException"));
given().contentType("application/json")
.body("{\"AllowedPublishers\":{\"SigningProfileVersionArns\":[]}}")
.when().post(BASE).then().statusCode(400);
StringBuilder many = new StringBuilder();
for (int i = 0; i < 21; i++) {
many.append(i > 0 ? "," : "").append('"').append(PROFILE).append('"');
}
given().contentType("application/json")
.body("{\"AllowedPublishers\":{\"SigningProfileVersionArns\":[" + many + "]}}")
.when().post(BASE).then().statusCode(400);
}
@Test
void anUnmodelledPolicyValueIsRejected() {
given().contentType("application/json")
.body("{\"AllowedPublishers\":{\"SigningProfileVersionArns\":[\"" + PROFILE + "\"]},"
+ "\"CodeSigningPolicies\":{\"UntrustedArtifactOnDeployment\":\"Ignore\"}}")
.when().post(BASE).then().statusCode(400)
.body("__type", is("InvalidParameterValueException"));
}
}