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

@@ -2888,7 +2888,7 @@ public interface EmulatorConfig {
* ARN AWS would refuse. The content is never fetched either way, so a function whose
* behaviour depends on the layer will not run correctly here.
*
* <p>A layer ARN outside the {@code aws} partition is rejected regardless: partitions
* <p>A layer ARN outside the request's partition is rejected regardless: partitions
* are isolated, so no resource policy can make one readable.
*
* Env var: FLOCI_SERVICES_LAMBDA_ACCEPT_EXTERNAL_LAYER_ARNS
@@ -5,8 +5,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.ServicePrincipals;
import io.github.hectorvent.floci.services.appsync.model.DataSource;
import io.github.hectorvent.floci.services.appsync.model.DataSourceType;
import io.github.hectorvent.floci.services.iam.AssumeRolePolicyEvaluator;
@@ -93,7 +93,7 @@ public class AppSyncDataSourceAuthorizer {
if (!roleArn.equals(role.get().getArn())) {
throw denied(dataSource, "service role does not exist");
}
String servicePrincipal = "appsync." + AwsRegions.dnsSuffixFor(region);
String servicePrincipal = ServicePrincipals.of("appsync");
if (!trustEvaluator.allowsService(role.get().getAssumeRolePolicyDocument(),
servicePrincipal, sourceArn, sourceAccount)) {
throw denied(dataSource, "service role does not trust " + servicePrincipal);
@@ -524,7 +524,7 @@ public class LambdaLayerService {
}
/**
* True when the ARN is a well-formed layer version ARN outside the {@code aws} partition.
* True when the ARN is a well-formed layer version ARN outside the request's partition.
* Partitions are isolated, so such a layer is unreachable rather than merely unreadable, and
* {@link #getLayerVersionByArn} already rejects it outright. Attaching one to a function has
* to reject too, or Floci would persist an ARN its own lookup path calls invalid.
@@ -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);