Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

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

Hector Venturadbf6c3016d63
diff --git a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
index daf74838b4..e20bc54072 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -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
diff --git a/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/datasource/AppSyncDataSourceAuthorizer.java b/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/datasource/AppSyncDataSourceAuthorizer.java
index fde7264e55..f1a58ddeb9 100644
--- a/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/datasource/AppSyncDataSourceAuthorizer.java
+++ b/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/datasource/AppSyncDataSourceAuthorizer.java
@@ -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);
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaLayerService.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaLayerService.java
index e19a0dbe80..a2b9945938 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaLayerService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaLayerService.java
@@ -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.
diff --git a/src/test/java/io/github/hectorvent/floci/services/appsync/graphql/datasource/AppSyncDataSourceAuthorizerTest.java b/src/test/java/io/github/hectorvent/floci/services/appsync/graphql/datasource/AppSyncDataSourceAuthorizerTest.java
index 8d879827d9..1155c38bee 100644
--- a/src/test/java/io/github/hectorvent/floci/services/appsync/graphql/datasource/AppSyncDataSourceAuthorizerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/appsync/graphql/datasource/AppSyncDataSourceAuthorizerTest.java
@@ -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);