diff --git a/docs/services/lambda.md b/docs/services/lambda.md index b966b03296..b19bd23f50 100644 --- a/docs/services/lambda.md +++ b/docs/services/lambda.md @@ -593,9 +593,12 @@ Code signing enforcement is not emulated: an attached configuration never gates The attachment lifecycle is supported for `$LATEST`: `PutFunctionCodeSigningConfig` attaches or replaces a configuration, `GetFunctionCodeSigningConfig` reads it, `DeleteFunctionCodeSigningConfig` detaches it, and `ListFunctionsByCodeSigningConfig` returns -attached functions with marker pagination. An unknown configuration is -`ResourceNotFoundException`; a malformed ARN or out-of-range `MaxItems` is rejected with -`InvalidParameterValueException` first. +attached functions with marker pagination. `PutFunctionCodeSigningConfig` and the +`CodeSigningConfigArn` supplied to `CreateFunction` return +`CodeSigningConfigNotFoundException` when the named configuration does not exist. +Configuration resource reads and `ListFunctionsByCodeSigningConfig` return +`ResourceNotFoundException` for an unknown configuration. A malformed ARN or out-of-range +`MaxItems` is rejected with `InvalidParameterValueException` first. ## Configuration diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java index d22d742ef0..8bde8e3789 100644 --- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java +++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaService.java @@ -702,7 +702,7 @@ public class LambdaService implements ResourceProvider { AwsArnUtils.Arn arn = AwsArnUtils.parse(functionName); if (!region.equals(arn.region()) || !regionResolver.getAccountId().equals(arn.accountId()) - || !AwsRegions.partitionFor(region).equals(arn.partition())) { + || !regionResolver.partitionForRegion(region).equals(arn.partition())) { throw new AwsException("ResourceNotFoundException", "Function not found: " + functionName, 404); } return reference.name(); diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningAccountScopeTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningAccountScopeTest.java index 00796717e3..30d728a577 100644 --- a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningAccountScopeTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaCodeSigningAccountScopeTest.java @@ -164,6 +164,38 @@ class LambdaCodeSigningAccountScopeTest { .orElseThrow().getCodeSigningConfigArn()); } + @Test + void unpublishedRegionFunctionArnUsesDeploymentPartition(@TempDir Path codePath) { + String region = "xx-nowhere-9"; + String functionArn = "arn:aws-cn:lambda:" + region + ":" + CALLER_ACCOUNT + + ":function:" + FUNCTION_NAME; + String configArn = "arn:aws-cn:lambda:" + region + ":" + CALLER_ACCOUNT + + ":code-signing-config:csc-0123456789abcdef0"; + LambdaFunctionStore store = new LambdaFunctionStore( + AccountAwareStorageBackend.inMemory(CALLER_ACCOUNT)); + LambdaFunction function = function(CALLER_ACCOUNT); + function.setFunctionArn(functionArn); + store.saveForAccount(CALLER_ACCOUNT, region, function); + RegionResolver regions = new RegionResolver("cn-north-1", CALLER_ACCOUNT); + LambdaService service = new LambdaService(store, new WarmPool(), new CodeStore(codePath), + new ZipExtractor(), regions); + + service.putFunctionCodeSigningConfig(region, functionArn, configArn); + assertEquals(configArn, service.getFunctionForCodeSigningConfig(region, functionArn) + .getCodeSigningConfigArn()); + + String foreignArn = functionArn.replace("arn:aws-cn:", "arn:aws:"); + AwsException error = assertThrows(AwsException.class, + () -> service.putFunctionCodeSigningConfig(region, foreignArn, configArn)); + assertEquals("ResourceNotFoundException", error.getErrorCode()); + assertEquals(configArn, store.getForAccount(CALLER_ACCOUNT, region, FUNCTION_NAME) + .orElseThrow().getCodeSigningConfigArn()); + + service.deleteFunctionCodeSigningConfig(region, functionArn); + assertNull(store.getForAccount(CALLER_ACCOUNT, region, FUNCTION_NAME) + .orElseThrow().getCodeSigningConfigArn()); + } + @Test void foreignPartialRegionAndAccountReferencesCannotMutateCallerFunction(@TempDir Path codePath) { LambdaFunctionStore store = new LambdaFunctionStore(