fix(appsync): name the one service principal in a data-source denial (#5593)

AppSyncDataSourceAuthorizer built its principal as "appsync." plus the
region's DNS suffix, so in China the denial read "service role does not
trust appsync.amazonaws.com.cn". A service principal is
<service>.amazonaws.com in every partition; the trust check already
folded both forms, so only the message was wrong. It now comes from
ServicePrincipals.of, as the repository rules ask.

Two Javadocs said a layer ARN "outside the aws partition" is rejected.
The check compares with the request's partition (the deployment's only
outside a request), so for a China request the foreign partition is
aws. They now say "outside the request's partition".

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-10-13 20:07:10 -04:00
1 parent 8058535709
commit dbf6c3016d
4 files changed
+22 -4

No files matched your search

@@ -122,6 +122,24 @@ class AppSyncDataSourceAuthorizerTest {
verifyNoInteractions(iam);
}
@Test
void untrustedRoleDenialNamesTheOnePrincipalOfEveryPartition() {
String chinaRoleArn = "arn:aws-cn:iam::000000000000:role/appsync/Resolver";
DataSource source = dataSource(DataSourceType.AWS_LAMBDA);
source.setDataSourceArn("arn:aws-cn:appsync:cn-north-1:000000000000:apis/example/datasources/Products");
source.setServiceRoleArn(chinaRoleArn);
IamRole role = new IamRole("id", "Resolver", "/appsync/", chinaRoleArn, """
{"Statement":{"Effect":"Allow","Action":"sts:AssumeRole",
"Principal":{"Service":"lambda.amazonaws.com"}}}
""");
when(iam.findRole("000000000000", "Resolver")).thenReturn(Optional.of(role));
AwsException error = assertThrows(AwsException.class,
() -> authorizer.authorize(source, Map.of("operation", "Invoke"), "cn-north-1"));
assertEquals("AccessDeniedException", error.getErrorCode());
assertEquals("AppSync data source Products: service role does not trust appsync.amazonaws.com",
error.getMessage());
}
@Test
void untrustedRoleDenies() {
DataSource source = dataSource(DataSourceType.AWS_LAMBDA);