fix(lambda): preserve code signing ARN partition (#6913)

This commit is contained in:
Jimmy Liu Jia authored and GitHub committed 2026-10-29 08:02:41 -04:00
1 parent 23d815f08b
commit 479595e6ec
3 files changed
+39 -4

No files matched your search

+6 -3
View File
@@ -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
@@ -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();
@@ -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(