From 6568700e02b5266f0f5cac17d7db12ccfa77607f Mon Sep 17 00:00:00 2001 From: Hector Ventura Date: Sat, 3 Oct 2026 20:43:28 -0500 Subject: [PATCH] test(partition): positive China Lambda layer test, partitions.md gaps, drop AwsRegions.ALL (#5023) Close-out items of the multi-partition initiative (#4272): - Lambda layers were only tested across partitions negatively. A layer published under a cn-north-1 scope now has its own test: the returned ARN is arn:aws-cn:lambda:cn-north-1:..., GetLayerVersionByArn resolves it, and a China function attaches it (BL-104). - partitions.md names FLOCI_PARTITIONS_ALLOW_UNKNOWN_REGIONS under Related and lists two more unsourced values: the EKS Pod Identity token audience outside the commercial partition, and the exact error AWS WAF returns for the CLOUDFRONT scope where the partition has no CloudFront (BL-105). - AwsRegions.ALL, the commercial advertised list kept as a deprecated alias during the partition sweep, had no caller left in src/main. It is removed and its three tests call advertised("aws"); the KNOWN_IDS javadoc no longer points at it (BL-106). --- docs/configuration/partitions.md | 9 +- .../floci/core/common/AwsRegions.java | 18 +-- .../config/TlsCertificateHostnameTest.java | 2 +- .../floci/core/common/AwsRegionsTest.java | 5 +- .../services/eks/EksClusterManagerTest.java | 12 +- .../LambdaLayerChinaIntegrationTest.java | 107 ++++++++++++++++++ 6 files changed, 129 insertions(+), 24 deletions(-) create mode 100644 src/test/java/io/github/hectorvent/floci/services/lambda/LambdaLayerChinaIntegrationTest.java diff --git a/docs/configuration/partitions.md b/docs/configuration/partitions.md index ba2d2a4b3d..1dbab80b30 100644 --- a/docs/configuration/partitions.md +++ b/docs/configuration/partitions.md @@ -169,14 +169,19 @@ the commercial value or Floci's own base host until sourced: - the console device-authorization client ids (`arn:aws:signin:::devtools/...`) outside the commercial partition; - the STS web-identity audience outside the commercial partition; +- the EKS Pod Identity token audience (`pods.eks.amazonaws.com`) outside the commercial partition; - the Lambda function-URL host outside the commercial partition; - whether AWS managed policy documents differ in content in China or GovCloud; - the API Gateway regional hosted zone per region; - S3 `LocationConstraint` enum values and Route 53 hosted zones for the ISO and EUSC regions; - the SAML sign-on URL in `aws-iso-e`, `aws-iso-f` and `aws-eusc`, where assertions keep being - checked against the commercial `https://signin.aws.amazon.com/saml`. + checked against the commercial `https://signin.aws.amazon.com/saml`; +- the exact error AWS WAF returns for the `CLOUDFRONT` scope in a partition without CloudFront + (GovCloud, the ISO partitions): Floci refuses it with `WAFInvalidParameterException` and its own + message. ## Related -- [Environment Variables](environment-variables.md): `FLOCI_DEFAULT_REGION`, `FLOCI_PARTITIONS_ID`, `FLOCI_PARTITIONS_STRICT` +- [Environment Variables](environment-variables.md): `FLOCI_DEFAULT_REGION`, `FLOCI_PARTITIONS_ID`, + `FLOCI_PARTITIONS_STRICT`, `FLOCI_PARTITIONS_ALLOW_UNKNOWN_REGIONS` - [Multi-Account Isolation](multi-account.md): the account half of the credential scope diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsRegions.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsRegions.java index a8ffc783b6..4306bce0b8 100644 --- a/src/main/java/io/github/hectorvent/floci/core/common/AwsRegions.java +++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsRegions.java @@ -11,21 +11,15 @@ import java.util.Set; */ public final class AwsRegions { - /** - * The commercial partition's published regions, in botocore order. Callers that serve one - * request should prefer {@link #advertised(String)} with the request's partition; this list - * is what static, deployment-wide consumers (certificate SANs) enumerate. - */ - public static final List ALL = advertised(AwsPartitions.COMMERCIAL_ID); - /** * Every published AWS region id, across all partitions. * - *

Distinct from {@link #ALL}, and deliberately a superset of it. {@code ALL} is what - * this emulator advertises in the commercial partition. {@code KNOWN_IDS} is for - * recognising a region id that a client wrote, most importantly inside a hostname, - * where the alternative is a shape like {@code [a-z]{2}-[a-z-]+-\d+} that also matches - * perfectly ordinary strings ({@code my-cd-1}, {@code eu-team-2}). + *

Distinct from {@link #advertised(String)}, and deliberately a superset of every advertised + * list: {@code advertised} is what this emulator advertises in one partition, while + * {@code KNOWN_IDS} is for recognising a region id that a client wrote, most + * importantly inside a hostname, where the alternative is a shape like + * {@code [a-z]{2}-[a-z-]+-\d+} that also matches perfectly ordinary strings ({@code my-cd-1}, + * {@code eu-team-2}). * *

It follows botocore's published lists ({@code make aws-data-sync}); the cost of a * region newer than the vendored data is documented at each call site, because it differs diff --git a/src/test/java/io/github/hectorvent/floci/config/TlsCertificateHostnameTest.java b/src/test/java/io/github/hectorvent/floci/config/TlsCertificateHostnameTest.java index e399befbe8..696b456e69 100644 --- a/src/test/java/io/github/hectorvent/floci/config/TlsCertificateHostnameTest.java +++ b/src/test/java/io/github/hectorvent/floci/config/TlsCertificateHostnameTest.java @@ -485,7 +485,7 @@ class TlsCertificateHostnameTest { X509Certificate cert = parseCertificate(certFile); List sans = extractSansFromCertificate(cert); - for (String region : AwsRegions.ALL) { + for (String region : AwsRegions.advertised("aws")) { String expectedWildcard = "*.dkr.ecr." + region + ".localhost.floci.io"; assertTrue(TlsConfigSource.DEFAULT_SAN_HOSTNAMES.contains(expectedWildcard), "DEFAULT_SAN_HOSTNAMES missing ECR wildcard for region " + region); diff --git a/src/test/java/io/github/hectorvent/floci/core/common/AwsRegionsTest.java b/src/test/java/io/github/hectorvent/floci/core/common/AwsRegionsTest.java index 7895df14c7..3e0b1d9ecf 100644 --- a/src/test/java/io/github/hectorvent/floci/core/common/AwsRegionsTest.java +++ b/src/test/java/io/github/hectorvent/floci/core/common/AwsRegionsTest.java @@ -21,7 +21,7 @@ class AwsRegionsTest { */ @Test void everyAdvertisedRegionIsAKnownRegionId() { - for (String region : AwsRegions.ALL) { + for (String region : AwsRegions.advertised("aws")) { assertTrue(AwsRegions.KNOWN_IDS.contains(region), region + " is advertised by DescribeRegions but is not a known region id"); } @@ -111,8 +111,7 @@ class AwsRegionsTest { @Test void advertisedListsArePerPartition() { - assertEquals(AwsRegions.ALL, AwsRegions.advertised("aws")); - assertEquals(34, AwsRegions.ALL.size()); + assertEquals(34, AwsRegions.advertised("aws").size()); assertEquals(List.of("cn-north-1", "cn-northwest-1"), AwsRegions.advertised("aws-cn")); assertTrue(AwsRegions.KNOWN_IDS.contains("eusc-de-east-1")); assertTrue(AwsRegions.KNOWN_IDS.contains("us-isof-south-1")); diff --git a/src/test/java/io/github/hectorvent/floci/services/eks/EksClusterManagerTest.java b/src/test/java/io/github/hectorvent/floci/services/eks/EksClusterManagerTest.java index 1879bf674e..a84e89083d 100644 --- a/src/test/java/io/github/hectorvent/floci/services/eks/EksClusterManagerTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/eks/EksClusterManagerTest.java @@ -169,17 +169,17 @@ class EksClusterManagerTest { @Test void registriesYamlMirrorsEveryRegionHostnameAndThePathStyleForm() { String yaml = EksClusterManager.buildRegistriesYaml( - "000000000000", AwsRegions.ALL, 4566, "http://floci:4566"); + "000000000000", AwsRegions.advertised("aws"), 4566, "http://floci:4566"); assertTrue(yaml.startsWith("mirrors:\n")); - for (String region : AwsRegions.ALL) { + for (String region : AwsRegions.advertised("aws")) { assertTrue(yaml.contains("\"000000000000.dkr.ecr." + region + ".localhost:4566\":"), "should mirror the " + region + " hostname"); } assertTrue(yaml.contains("\"localhost:4566\":"), "should mirror the path-style form"); assertFalse(yaml.contains("\"*\""), "must not catch-all public registries"); long endpoints = yaml.lines().filter(l -> l.contains("- \"http://floci:4566\"")).count(); - assertEquals(AwsRegions.ALL.size() + 1, endpoints, + assertEquals(AwsRegions.advertised("aws").size() + 1, endpoints, "every mirror should point at Floci's in-network data plane"); } @@ -197,9 +197,9 @@ class EksClusterManagerTest { void registriesYamlTlsAliasesPreserveLoopbackMirrorsAndInternalHttpEndpoint() { String endpoint = "http://host.docker.internal:4577"; String yaml = EksClusterManager.buildRegistriesYaml( - "111122223333", AwsRegions.ALL, 4577, endpoint, true); + "111122223333", AwsRegions.advertised("aws"), 4577, endpoint, true); - for (String region : AwsRegions.ALL) { + for (String region : AwsRegions.advertised("aws")) { assertTrue(yaml.contains("\"111122223333.dkr.ecr." + region + ".localhost:4577\":")); assertTrue(yaml.contains("\"111122223333.dkr.ecr." + region + ".localhost.floci.io:4577\":")); } @@ -211,7 +211,7 @@ class EksClusterManagerTest { assertFalse(yaml.contains("ghcr.io")); assertFalse(yaml.contains("https://"), "internal pulls still use the HTTP data plane"); long endpoints = yaml.lines().filter(line -> line.contains("- \"" + endpoint + "\"")).count(); - assertEquals(2L * (AwsRegions.ALL.size() + 1), endpoints); + assertEquals(2L * (AwsRegions.advertised("aws").size() + 1), endpoints); } @Test diff --git a/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaLayerChinaIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaLayerChinaIntegrationTest.java new file mode 100644 index 0000000000..f63106fdda --- /dev/null +++ b/src/test/java/io/github/hectorvent/floci/services/lambda/LambdaLayerChinaIntegrationTest.java @@ -0,0 +1,107 @@ +package io.github.hectorvent.floci.services.lambda; + +import io.github.hectorvent.floci.testing.PartitionCleanup; +import io.github.hectorvent.floci.testing.PartitionMatrix; +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.io.ByteArrayOutputStream; +import java.util.Base64; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.startsWith; + +/** + * The positive twin of the cross-partition layer cases: a layer published under a cn-north-1 + * scope carries an {@code arn:aws-cn:} ARN, and that ARN resolves for a caller in the same + * partition, both through GetLayerVersionByArn and when a function attaches it. + */ +@QuarkusTest +class LambdaLayerChinaIntegrationTest { + + private static final String REGION = "cn-north-1"; + private static final String LAYER_NAME = "china-positive-layer"; + private static final String FUNCTION_NAME = "china-positive-layer-fn"; + + @RegisterExtension + final PartitionCleanup cleanup = new PartitionCleanup(); + + private static String auth() { + return PartitionMatrix.sigV4Auth(REGION, "lambda"); + } + + private static String zipBase64(String path, String content) throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try (ZipOutputStream zos = new ZipOutputStream(baos)) { + zos.putNextEntry(new ZipEntry(path)); + zos.write(content.getBytes()); + zos.closeEntry(); + } + return Base64.getEncoder().encodeToString(baos.toByteArray()); + } + + @Test + void aLayerPublishedInChinaResolvesByItsChinaArn() throws Exception { + String layerVersionArn = given() + .header("Authorization", auth()) + .contentType("application/json") + .body(""" + { + "Content": { "ZipFile": "%s" }, + "CompatibleRuntimes": ["python3.12"] + } + """.formatted(zipBase64("python/shared.py", "VALUE = 1"))) + .when() + .post("/2018-10-31/layers/" + LAYER_NAME + "/versions") + .then() + .statusCode(201) + .body("LayerVersionArn", startsWith("arn:aws-cn:lambda:cn-north-1:000000000000:layer:" + LAYER_NAME + ":")) + .extract().path("LayerVersionArn"); + String version = layerVersionArn.substring(layerVersionArn.lastIndexOf(':') + 1); + cleanup.register(() -> given() + .header("Authorization", auth()) + .when() + .delete("/2018-10-31/layers/" + LAYER_NAME + "/versions/" + version) + .then() + .statusCode(204)); + + given() + .header("Authorization", auth()) + .queryParam("find", "LayerVersion") + .queryParam("Arn", layerVersionArn) + .when() + .get("/2018-10-31/layers") + .then() + .statusCode(200) + .body("LayerVersionArn", equalTo(layerVersionArn)); + + given() + .header("Authorization", auth()) + .contentType("application/json") + .body(""" + { + "FunctionName": "%s", + "Runtime": "python3.12", + "Role": "arn:aws-cn:iam::000000000000:role/r", + "Handler": "handler.handler", + "Code": { "ZipFile": "%s" }, + "Layers": ["%s"] + } + """.formatted(FUNCTION_NAME, zipBase64("handler.py", "def handler(e, c): return {}"), layerVersionArn)) + .when() + .post("/2015-03-31/functions") + .then() + .statusCode(201) + .body("Layers[0].Arn", equalTo(layerVersionArn)); + cleanup.register(() -> given() + .header("Authorization", auth()) + .when() + .delete("/2015-03-31/functions/" + FUNCTION_NAME) + .then() + .statusCode(204)); + } +}