From 41ceed4dba4d940a077676961e93673398317b5b Mon Sep 17 00:00:00 2001
From: lex00 <121451605+lex00@users.noreply.github.com>
Date: Thu, 24 Sep 2026 10:05:29 -0600
Subject: [PATCH] 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.
---
docs/services/lambda.md | 15 +-
...aCodeSigningConfigFunctionsController.java | 132 +++++++++--
.../LambdaCodeSigningConfigService.java | 205 ++++++++++++++++++
.../lambda/model/CodeSigningConfig.java | 69 ++++++
...SigningConfigLifecycleIntegrationTest.java | 158 ++++++++++++++
5 files changed, 562 insertions(+), 17 deletions(-)
create mode 100644 src/main/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigService.java
create mode 100644 src/main/java/io/github/hectorvent/floci/services/lambda/model/CodeSigningConfig.java
create mode 100644 src/test/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigLifecycleIntegrationTest.java
diff --git a/docs/services/lambda.md b/docs/services/lambda.md
index acfee960a9..8b22263bf2 100644
--- a/docs/services/lambda.md
+++ b/docs/services/lambda.md
@@ -33,7 +33,12 @@ Floci Lambda runs your function code locally inside real Docker containers - clo
| `GetPolicy` | Get the function resource policy |
| `RemovePermission` | Remove a resource-policy statement |
| `GetFunctionCodeSigningConfig` | Return code-signing config (always empty) |
-| `ListFunctionsByCodeSigningConfig` | Validates the ARN; no code-signing config can exist, so every well-formed ARN returns `ResourceNotFoundException` |
+| `ListFunctionsByCodeSigningConfig` | List functions carrying a config. Always empty, since nothing can attach one |
+| `CreateCodeSigningConfig` | Create a code signing configuration |
+| `GetCodeSigningConfig` | Read a code signing configuration |
+| `UpdateCodeSigningConfig` | Update the members the request names |
+| `DeleteCodeSigningConfig` | Delete a code signing configuration |
+| `ListCodeSigningConfigs` | List the configurations in the region |
| `CreateFunctionUrlConfig` | Provision a function URL |
| `GetFunctionUrlConfig` | Read function URL config |
| `UpdateFunctionUrlConfig` | Update function URL config |
@@ -305,7 +310,13 @@ These AWS Lambda operations have no handler in Floci. Calls will return `404` or
- Layer permissions (`AddLayerVersionPermission`, `RemoveLayerVersionPermission`, `GetLayerVersionPolicy`)
- Provisioned concurrency (`PutProvisionedConcurrencyConfig`, `GetProvisionedConcurrencyConfig`, `ListProvisionedConcurrencyConfigs`, `DeleteProvisionedConcurrencyConfig`)
- `InvokeWithResponseStream`
-- Code signing management (only `GetFunctionCodeSigningConfig` and `ListFunctionsByCodeSigningConfig` are wired; there is no `PutFunctionCodeSigningConfig` or `CreateCodeSigningConfig`, so no code-signing config can exist and `ListFunctionsByCodeSigningConfig` reports every well-formed ARN as `ResourceNotFoundException` — a malformed ARN or an out-of-range `MaxItems` is rejected with `InvalidParameterValueException` first)
+- Code signing enforcement. A configuration is created, read, updated, deleted and listed, and
+ nothing verifies a signature against it, so it never gates a deployment. Attaching one to a
+ function is not wired either: there is no `PutFunctionCodeSigningConfig`, so
+ `GetFunctionCodeSigningConfig` still reports an empty ARN and `ListFunctionsByCodeSigningConfig`
+ always reports no functions. An unknown configuration is `ResourceNotFoundException`, and a
+ malformed ARN or an out-of-range `MaxItems` is rejected with `InvalidParameterValueException`
+ first
## Configuration
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigFunctionsController.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigFunctionsController.java
index 2d2697e54c..2140856640 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigFunctionsController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigFunctionsController.java
@@ -1,19 +1,30 @@
package io.github.hectorvent.floci.services.lambda;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.services.lambda.model.CodeSigningConfig;
+import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.DELETE;
import jakarta.ws.rs.GET;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.PUT;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.QueryParam;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.HttpHeaders;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
+import java.util.List;
import java.util.regex.Pattern;
/**
- * ListFunctionsByCodeSigningConfig: GET /2020-04-22/code-signing-configs/{CodeSigningConfigArn}/functions.
+ * The code signing configuration resource, all under /2020-04-22/code-signing-configs.
*
*
A separate class from {@link LambdaCodeSigningController} because it lives
* under a different API version prefix (/2020-04-22 vs /2020-06-30) — JAX-RS
@@ -21,16 +32,15 @@ import java.util.regex.Pattern;
* one falls through to a more general catch-all route (S3's bucket-path matcher)
* instead of matching here.
*
- * Floci does not implement code signing config management — there is no
- * CreateCodeSigningConfig / PutFunctionCodeSigningConfig, so no code signing
- * config can ever exist. That does not make an unconditional empty list
- * the right answer: botocore models both {@code InvalidParameterValueException}
- * and {@code ResourceNotFoundException} for this operation, and the only resource
- * the path parameter can name is a code signing config. A malformed ARN is
- * therefore a 400 and a well-formed ARN is a 404, because every well-formed ARN
- * necessarily names a config that does not exist here. Returning 200 with an
- * empty list would tell a caller that the config exists and simply has no
- * functions attached, which is a different — and false — statement.
+ * Create, Get, Update, Delete and List manage the configuration itself.
+ * ListFunctionsByCodeSigningConfig reports which functions carry one, and always reports none:
+ * attaching a configuration to a function is PutFunctionCodeSigningConfig, which is not
+ * implemented, so nothing can be attached. It answers a configuration that does not exist with a
+ * 404 rather than an empty list, because an empty list would say the configuration exists and
+ * simply has no functions.
+ *
+ * Nothing here verifies a signature. Lambda's own code signing checks are not emulated, so a
+ * configuration never gates a deployment.
*/
@Path("/2020-04-22")
@Produces(MediaType.APPLICATION_JSON)
@@ -51,6 +61,19 @@ public class LambdaCodeSigningConfigFunctionsController {
private static final int MAX_ITEMS_MIN = 1;
private static final int MAX_ITEMS_MAX = 10000;
+ private final LambdaCodeSigningConfigService service;
+ private final RegionResolver regionResolver;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ public LambdaCodeSigningConfigFunctionsController(LambdaCodeSigningConfigService service,
+ RegionResolver regionResolver,
+ ObjectMapper objectMapper) {
+ this.service = service;
+ this.regionResolver = regionResolver;
+ this.objectMapper = objectMapper;
+ }
+
/**
* Validation order matches AWS: request parameters are rejected before the
* resource is resolved, so a bad {@code MaxItems} is reported as such rather
@@ -59,16 +82,95 @@ public class LambdaCodeSigningConfigFunctionsController {
@GET
@Path("/code-signing-configs/{codeSigningConfigArn}/functions")
public Response listFunctionsByCodeSigningConfig(
+ @Context HttpHeaders headers,
@PathParam("codeSigningConfigArn") String codeSigningConfigArn,
@QueryParam("Marker") String marker,
@QueryParam("MaxItems") String maxItems) {
requireValidArn(codeSigningConfigArn);
parseMaxItems(maxItems);
- // Marker is accepted and carries no state: the result set is always empty,
- // so any marker addresses a page past the end and NextMarker is never emitted.
+ // Resolving the config is what turns an unknown ARN into the 404. A known one has no
+ // functions, since PutFunctionCodeSigningConfig is not implemented, so Marker addresses a
+ // page past the end and NextMarker is never emitted.
+ service.get(regionResolver.resolveRegion(headers), codeSigningConfigArn);
- throw new AwsException("ResourceNotFoundException",
- "The code signing configuration " + codeSigningConfigArn + " does not exist.", 404);
+ ObjectNode root = objectMapper.createObjectNode();
+ root.putArray("FunctionArns");
+ return Response.ok(root).build();
+ }
+
+ @POST
+ @Path("/code-signing-configs")
+ public Response createCodeSigningConfig(@Context HttpHeaders headers, ObjectNode body) {
+ String region = regionResolver.resolveRegion(headers);
+ CodeSigningConfig config = service.create(region, regionResolver.getAccountId(),
+ text(body, "Description"), allowedPublishers(body), policies(body));
+ return Response.status(Response.Status.CREATED).entity(wrap(config)).build();
+ }
+
+ @GET
+ @Path("/code-signing-configs/{codeSigningConfigArn}")
+ public Response getCodeSigningConfig(@Context HttpHeaders headers,
+ @PathParam("codeSigningConfigArn") String codeSigningConfigArn) {
+ requireValidArn(codeSigningConfigArn);
+ return Response.ok(wrap(service.get(regionResolver.resolveRegion(headers), codeSigningConfigArn))).build();
+ }
+
+ @PUT
+ @Path("/code-signing-configs/{codeSigningConfigArn}")
+ public Response updateCodeSigningConfig(@Context HttpHeaders headers,
+ @PathParam("codeSigningConfigArn") String codeSigningConfigArn,
+ ObjectNode body) {
+ requireValidArn(codeSigningConfigArn);
+ CodeSigningConfig config = service.update(regionResolver.resolveRegion(headers), codeSigningConfigArn,
+ text(body, "Description"), allowedPublishers(body), policies(body));
+ return Response.ok(wrap(config)).build();
+ }
+
+ @DELETE
+ @Path("/code-signing-configs/{codeSigningConfigArn}")
+ public Response deleteCodeSigningConfig(@Context HttpHeaders headers,
+ @PathParam("codeSigningConfigArn") String codeSigningConfigArn) {
+ requireValidArn(codeSigningConfigArn);
+ service.delete(regionResolver.resolveRegion(headers), codeSigningConfigArn);
+ return Response.noContent().build();
+ }
+
+ @GET
+ @Path("/code-signing-configs")
+ public Response listCodeSigningConfigs(@Context HttpHeaders headers,
+ @QueryParam("Marker") String marker,
+ @QueryParam("MaxItems") String maxItems) {
+ parseMaxItems(maxItems);
+ List configs = service.list(regionResolver.resolveRegion(headers));
+ ObjectNode root = objectMapper.createObjectNode();
+ root.set("CodeSigningConfigs", objectMapper.valueToTree(configs));
+ return Response.ok(root).build();
+ }
+
+ private ObjectNode wrap(CodeSigningConfig config) {
+ ObjectNode root = objectMapper.createObjectNode();
+ root.set("CodeSigningConfig", objectMapper.valueToTree(config));
+ return root;
+ }
+
+ private static String text(ObjectNode body, String field) {
+ return body == null || !body.hasNonNull(field) ? null : body.get(field).asText();
+ }
+
+ private CodeSigningConfig.AllowedPublishers allowedPublishers(ObjectNode body) {
+ if (body == null || !body.hasNonNull("AllowedPublishers")) {
+ return null;
+ }
+ return objectMapper.convertValue(body.get("AllowedPublishers"),
+ CodeSigningConfig.AllowedPublishers.class);
+ }
+
+ private CodeSigningConfig.CodeSigningPolicies policies(ObjectNode body) {
+ if (body == null || !body.hasNonNull("CodeSigningPolicies")) {
+ return null;
+ }
+ return objectMapper.convertValue(body.get("CodeSigningPolicies"),
+ CodeSigningConfig.CodeSigningPolicies.class);
}
private void requireValidArn(String arn) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigService.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigService.java
new file mode 100644
index 0000000000..0e2d4400b8
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningConfigService.java
@@ -0,0 +1,205 @@
+package io.github.hectorvent.floci.services.lambda;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.storage.StorageBackend;
+import io.github.hectorvent.floci.core.storage.StorageFactory;
+import io.github.hectorvent.floci.services.lambda.model.CodeSigningConfig;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+
+import java.security.SecureRandom;
+import java.time.Instant;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Code signing configurations, the resource CreateCodeSigningConfig manages.
+ *
+ * Nothing is verified against these. Lambda's own signature checking is not emulated, so a
+ * configuration is stored and reported back and never gates a deployment.
+ */
+@ApplicationScoped
+public class LambdaCodeSigningConfigService {
+
+ /**
+ * Lowercase alphanumerics because the ARN is the stricter of the two patterns, not the id.
+ * CodeSigningConfigId allows {@code csc-[a-zA-Z0-9-_\.]{17}}, while CodeSigningConfigArn ends
+ * in {@code csc-[a-z0-9]{17}}. Widening this alphabet to match the id pattern would still mint
+ * a conforming id and an ARN that no longer conforms.
+ */
+ private static final String ID_ALPHABET = "abcdefghijklmnopqrstuvwxyz0123456789";
+ private static final int ID_LENGTH = 17;
+ private static final int MAX_DESCRIPTION = 256;
+ private static final int MAX_SIGNING_PROFILE_ARNS = 20;
+
+ /** The model documents Warn as the default when the request names no policy. */
+ static final String DEFAULT_UNTRUSTED_ARTIFACT_POLICY = "Warn";
+ private static final List POLICIES = List.of("Warn", "Enforce");
+
+ private static final DateTimeFormatter LAST_MODIFIED =
+ DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSXXX").withZone(ZoneOffset.UTC);
+
+ private final StorageBackend store;
+ private final SecureRandom random = new SecureRandom();
+
+ @Inject
+ public LambdaCodeSigningConfigService(StorageFactory storageFactory) {
+ this.store = storageFactory.create("lambda", "lambda-code-signing-configs.json",
+ new TypeReference