fix(partitions): source the China CloudFront suffix and GovCloud API Gateway zones (#5618)

* fix(partitions): source the China CloudFront suffix and GovCloud API Gateway zones

Two values listed as open questions have a published source in the China and
GovCloud user guides, so they become vendored facts in aws/region-facts.json
instead of a commercial constant.

A generated CloudFront distribution domain name ended in cloudfront.net in
every partition. The China guide's CloudFront page names the default domain
there as *.cloudfront.cn
(https://docs.amazonaws.cn/en_us/aws/latest/userguide/cloudfront.html), and
the commercial suffix is the one in the example name of the botocore
CloudFront model (Distribution$DomainName, DistributionSummary$DomainName).
floci.services.cloudfront.domain-suffix loses its cloudfront.net default and
becomes optional: unset, the suffix follows the request's partition, with the
commercial one where a partition has no CloudFront; set, it applies in every
partition as before. CloudFront distributions and streaming distributions,
Cognito and AppSync custom domains and edge-optimized API Gateway domains all
resolve it through CloudFrontEdgeDomain.domainSuffix.

A regional API Gateway custom domain reported one placeholder hosted zone id in
every region. The GovCloud guide's API Gateway page states the regional
endpoint zone for us-gov-west-1 (Z1K6XKP9SAGWDV) and us-gov-east-1
(Z3SE9ATJYCRCZJ)
(https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/govcloud-abp.html);
those two regions now report it, and the generator resolves each region
through its description in partitions.json. No source gives the zone for any
other region, which keeps the placeholder and stays an open question.

The generator reads both sentences from either rendering of a guide page: the
page text, or the Markdown AWS serves at the same URL with .md, which escapes
the asterisk in the CloudFront sentence.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

* fix(partitions): require each sourced fact and resolve edge domains in the request's partition

The GovCloud API Gateway page parser accepted a page stating only one
region's regional hosted zone, so an edited guide would have dropped the
other zone from region-facts.json without failing. It now requires a zone
for every aws-us-gov region.

The region-facts self check validated cloudfrontDomainSuffix only when it
was present. It now requires the suffix for aws and aws-cn, and the
regional hosted zone for both GovCloud regions, as it already requires
consoleHost; a missing commercial suffix would otherwise have reached
the orElseThrow in CloudFrontEdgeDomain.domainSuffix at runtime.

CloudFrontEdgeDomain.create resolved its partition from the region alone,
falling back to the commercial one, so an AppSync or API Gateway custom
domain in a region no partition publishes (allowed under
allow-unknown-regions) took the commercial suffix and hosted zone in a
China deployment. It now takes the partition the caller's RegionResolver
resolves, which falls back to the deployment's partition, as the
CloudFront and Cognito paths already do.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>

---------

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-10-14 19:25:56 -04:00
1 parent 7f0da8ba2b
commit 3afb5b430e
21 files changed
+494 -99

No files matched your search

@@ -61,6 +61,26 @@ class AwsRegionFactsTest {
assertTrue(AwsRegionFacts.consoleHost(null).isEmpty());
}
/** The botocore model's example name for the commercial partition, the China guide for {@code aws-cn}. */
@Test
void cloudFrontDomainSuffixIsPerPartitionWhereCloudFrontExists() {
assertEquals(Optional.of("cloudfront.net"), AwsRegionFacts.cloudFrontDomainSuffix("aws"));
assertEquals(Optional.of("cloudfront.cn"), AwsRegionFacts.cloudFrontDomainSuffix("aws-cn"));
assertTrue(AwsRegionFacts.cloudFrontDomainSuffix("aws-us-gov").isEmpty());
assertTrue(AwsRegionFacts.cloudFrontDomainSuffix("aws-eusc").isEmpty());
assertTrue(AwsRegionFacts.cloudFrontDomainSuffix(null).isEmpty());
}
/** The GovCloud guide states the two regional endpoint zones; no source covers another region. */
@Test
void apiGatewayRegionalZoneIsPublishedForGovCloudOnly() {
assertEquals(Optional.of("Z1K6XKP9SAGWDV"), AwsRegionFacts.apiGatewayRegionalHostedZoneId("us-gov-west-1"));
assertEquals(Optional.of("Z3SE9ATJYCRCZJ"), AwsRegionFacts.apiGatewayRegionalHostedZoneId("us-gov-east-1"));
assertTrue(AwsRegionFacts.apiGatewayRegionalHostedZoneId("us-east-1").isEmpty());
assertTrue(AwsRegionFacts.apiGatewayRegionalHostedZoneId("cn-north-1").isEmpty());
assertTrue(AwsRegionFacts.apiGatewayRegionalHostedZoneId(null).isEmpty());
}
@ParameterizedTest
@CsvSource({
"us-east-1, s3, com.amazonaws.us-east-1.s3",
@@ -12,17 +12,35 @@ class CloudFrontEdgeDomainTest {
@Test
void namesADistributionOnTheConfiguredSuffix() {
CloudFrontEdgeDomain edge = CloudFrontEdgeDomain.create("us-east-1", "cloudfront.net");
CloudFrontEdgeDomain edge = CloudFrontEdgeDomain.create("aws", "cloudfront.net");
assertTrue(edge.domainName().matches("d[0-9a-f]{13}\\.cloudfront\\.net"), edge.domainName());
assertNotEquals(edge.domainName(), CloudFrontEdgeDomain.create("us-east-1", "cloudfront.net").domainName());
assertNotEquals(edge.domainName(), CloudFrontEdgeDomain.create("aws", "cloudfront.net").domainName());
}
@Test
void anUnconfiguredSuffixIsThePartitionsOwn() {
assertTrue(CloudFrontEdgeDomain.create("aws", null).domainName().endsWith(".cloudfront.net"));
assertTrue(CloudFrontEdgeDomain.create("aws-cn", null).domainName().endsWith(".cloudfront.cn"));
assertEquals("cloudfront.net", CloudFrontEdgeDomain.domainSuffix(null, "aws"));
assertEquals("cloudfront.cn", CloudFrontEdgeDomain.domainSuffix(null, "aws-cn"));
assertEquals("cloudfront.cn", CloudFrontEdgeDomain.domainSuffix(" ", "aws-cn"), "blank is unset");
assertEquals("cloudfront.net", CloudFrontEdgeDomain.domainSuffix(null, "aws-us-gov"),
"a partition without CloudFront keeps the commercial suffix");
assertEquals("cloudfront.net", CloudFrontEdgeDomain.domainSuffix(null, null));
}
@Test
void aConfiguredSuffixWinsInEveryPartition() {
assertEquals("cloudfront.local", CloudFrontEdgeDomain.domainSuffix("cloudfront.local", "aws-cn"));
assertTrue(CloudFrontEdgeDomain.create("aws-cn", "cloudfront.net").domainName().endsWith(".cloudfront.net"));
}
@Test
void hostedZoneIsThePartitionsCloudFrontZone() {
assertEquals("Z2FDTNDATAQYW2", CloudFrontEdgeDomain.create("eu-west-1", "cloudfront.net").hostedZoneId());
assertEquals("Z3RFFRIM2A3IF5", CloudFrontEdgeDomain.create("cn-north-1", "cloudfront.net").hostedZoneId());
assertNull(CloudFrontEdgeDomain.create("us-gov-west-1", "cloudfront.net").hostedZoneId(),
assertEquals("Z2FDTNDATAQYW2", CloudFrontEdgeDomain.create("aws", "cloudfront.net").hostedZoneId());
assertEquals("Z3RFFRIM2A3IF5", CloudFrontEdgeDomain.create("aws-cn", "cloudfront.net").hostedZoneId());
assertNull(CloudFrontEdgeDomain.create("aws-us-gov", "cloudfront.net").hostedZoneId(),
"GovCloud has no CloudFront");
}
}
@@ -11,6 +11,7 @@ import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -46,7 +47,7 @@ class ApiGatewayDomainTlsServiceTest {
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(invocation -> AccountAwareStorageBackend.inMemory("000000000000"));
certificateManager = mock(TlsCertificateManager.class);
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
when(config.services().cloudfront().domainSuffix()).thenReturn("cloudfront.net");
when(config.services().cloudfront().domainSuffix()).thenReturn(Optional.empty());
service = new ApiGatewayService(storageFactory, config, certificateManager,
new RegionResolver(REGION, "000000000000"));
}
@@ -13,6 +13,7 @@ import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -41,7 +42,7 @@ class ApiGatewayEdgeDomainPartitionTest {
stores.computeIfAbsent(invocation.getArgument(1, String.class),
ignored -> AccountAwareStorageBackend.inMemory("000000000000")));
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
when(config.services().cloudfront().domainSuffix()).thenReturn("cloudfront.net");
when(config.services().cloudfront().domainSuffix()).thenReturn(Optional.empty());
service = new ApiGatewayService(storageFactory, config, mock(TlsCertificateManager.class),
new RegionResolver(GOV_REGION, "000000000000"));
}
@@ -16,6 +16,7 @@ import org.junit.jupiter.params.provider.ValueSource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
@@ -43,7 +44,7 @@ class ApiGatewayEdgeRestApiPartitionTest {
stores.computeIfAbsent(invocation.getArgument(1, String.class),
ignored -> AccountAwareStorageBackend.inMemory("000000000000")));
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
when(config.services().cloudfront().domainSuffix()).thenReturn("cloudfront.net");
when(config.services().cloudfront().domainSuffix()).thenReturn(Optional.empty());
service = new ApiGatewayService(storageFactory, config, mock(TlsCertificateManager.class),
new RegionResolver("us-east-1", "000000000000"));
}
@@ -0,0 +1,57 @@
package io.github.hectorvent.floci.services.apigateway;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.config.TlsCertificateManager;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.apigateway.model.CustomDomain;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* The Route 53 hosted zone a regional custom domain reports. The GovCloud user guide states it for
* its two regions; every other region has no source and keeps the value it always reported.
*/
class ApiGatewayRegionalHostedZoneTest {
private ApiGatewayService service;
@BeforeEach
void setUp() {
StorageFactory storageFactory = mock(StorageFactory.class);
when(storageFactory.create(anyString(), anyString(), any()))
.thenAnswer(invocation -> AccountAwareStorageBackend.inMemory("000000000000"));
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
when(config.services().cloudfront().domainSuffix()).thenReturn(Optional.empty());
service = new ApiGatewayService(storageFactory, config, mock(TlsCertificateManager.class),
new RegionResolver("us-east-1", "000000000000"));
}
@ParameterizedTest
@CsvSource({
"us-gov-west-1, Z1K6XKP9SAGWDV",
"us-gov-east-1, Z3SE9ATJYCRCZJ",
"us-east-1, Z2FDTNDATAQYL2",
"cn-north-1, Z2FDTNDATAQYL2",
"eusc-de-east-1, Z2FDTNDATAQYL2"})
void regionalDomainReportsTheRegionsPublishedZone(String region, String hostedZoneId) {
CustomDomain domain = service.createDomainName(region, Map.of(
"domainName", "api." + region + ".example.com",
"endpointConfiguration", Map.of("types", List.of("REGIONAL"))));
assertEquals(hostedZoneId, domain.getRegionalHostedZoneId());
}
}
@@ -15,6 +15,7 @@ import org.junit.jupiter.api.Test;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -55,7 +56,7 @@ class ApiGatewayV2ApiMappingServiceTest {
when(storageFactory.create(anyString(), anyString(), any()))
.thenAnswer(invocation -> AccountAwareStorageBackend.inMemory("000000000000"));
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
when(config.services().cloudfront().domainSuffix()).thenReturn("cloudfront.net");
when(config.services().cloudfront().domainSuffix()).thenReturn(Optional.empty());
RegionResolver regionResolver = new RegionResolver(REGION, "000000000000");
v2Service = new ApiGatewayV2Service(storageFactory, config, regionResolver);
service = new ApiGatewayService(storageFactory, config, mock(TlsCertificateManager.class), regionResolver,
@@ -30,6 +30,7 @@ import java.time.ZoneOffset;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -50,6 +51,8 @@ class AppSyncServiceTest {
private AppSyncService service;
private AccountAwareStorageBackend<ApiKey> apiKeyStoreOverride;
private String region = "us-east-1";
/** The deployment partition, or null to derive it from {@link #region}. */
private String partition;
@BeforeEach
void setUp() {
@@ -59,7 +62,8 @@ class AppSyncServiceTest {
/**
* AppSync fronts a custom domain with CloudFront, so a DNS alias to {@code appsyncDomainName}
* lives in the partition's CloudFront hosted zone, as the CDK's AppSyncTarget builds it. A
* random zone id made every such alias point nowhere.
* random zone id made every such alias point nowhere. With no suffix configured the
* distribution name takes the partition's own.
*/
@Test
void customDomainIsFrontedByTheCloudFrontZoneOfItsPartition() {
@@ -72,6 +76,24 @@ class AppSyncServiceTest {
DomainName china = newService(Clock.fixed(NOW, ZoneOffset.UTC))
.createDomainName(Map.of("domainName", "api.example.cn"));
assertEquals("Z3RFFRIM2A3IF5", china.getHostedZoneId());
assertTrue(china.getAppsyncDomainName().matches("d[0-9a-f]{13}\\.cloudfront\\.cn"),
china.getAppsyncDomainName());
}
/**
* A region no partition publishes, accepted under {@code allow-unknown-regions}, belongs to the
* deployment's partition, so a China deployment fronts the domain with China's CloudFront
* suffix and zone rather than the commercial ones.
*/
@Test
void customDomainInAnUnpublishedRegionTakesTheDeploymentsPartition() {
region = "xx-test-1";
partition = "aws-cn";
DomainName domain = newService(Clock.fixed(NOW, ZoneOffset.UTC))
.createDomainName(Map.of("domainName", "api.example.cn"));
assertEquals("Z3RFFRIM2A3IF5", domain.getHostedZoneId());
assertTrue(domain.getAppsyncDomainName().endsWith(".cloudfront.cn"), domain.getAppsyncDomainName());
}
@Test
@@ -406,11 +428,12 @@ class AppSyncServiceTest {
lambdaAuthorizerCache = new LambdaAuthorizerCache();
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
when(config.effectiveBaseUrl()).thenReturn(baseUrl);
when(config.services().cloudfront().domainSuffix()).thenReturn("cloudfront.net");
when(config.services().cloudfront().domainSuffix()).thenReturn(Optional.empty());
return new AppSyncService(
storageFactory,
config,
new RegionResolver(region, "000000000000"),
partition == null ? new RegionResolver(region, "000000000000")
: new RegionResolver(region, "000000000000", partition),
schemaRegistry,
mock(SchemaCreationWorker.class),
requestContext,
@@ -127,6 +127,7 @@ class CloudFrontServiceTest {
return serviceWithDomainSuffix(domainSuffix, "us-east-1");
}
/** A null {@code domainSuffix} is {@code floci.services.cloudfront.domain-suffix} left unset. */
private CloudFrontService serviceWithDomainSuffix(String domainSuffix, String region) {
StorageFactory storageFactory = Mockito.mock(StorageFactory.class);
when(storageFactory.create(Mockito.anyString(), Mockito.anyString(), Mockito.any()))
@@ -143,7 +144,7 @@ class CloudFrontServiceTest {
when(dnsConfig.extraSuffixes()).thenReturn(Optional.empty());
when(config.services()).thenReturn(servicesConfig);
when(servicesConfig.cloudfront()).thenReturn(cloudFrontConfig);
when(cloudFrontConfig.domainSuffix()).thenReturn(domainSuffix);
when(cloudFrontConfig.domainSuffix()).thenReturn(Optional.ofNullable(domainSuffix));
return new CloudFrontService(storageFactory, config, new RegionResolver(region, ACCOUNT));
}
@@ -323,7 +324,7 @@ class CloudFrontServiceTest {
@Test
void createDistributionUsesDefaultDomainSuffix() {
CloudFrontService service = serviceWithDomainSuffix("cloudfront.net");
CloudFrontService service = serviceWithDomainSuffix(null);
Distribution dist = service.createDistribution(new Distribution(), Map.of());
@@ -364,6 +365,33 @@ class CloudFrontServiceTest {
"Expected configured suffix, got: " + dist.getDomainName());
}
/**
* China's distributions are named under {@code cloudfront.cn}; GovCloud has no CloudFront and
* so no suffix of its own, and keeps the commercial one.
*/
@Test
void anUnconfiguredDomainSuffixFollowsTheRequestsPartition() {
CloudFrontService china = serviceWithDomainSuffix(null, "cn-north-1");
CloudFrontService govCloud = serviceWithDomainSuffix(null, "us-gov-west-1");
Distribution dist = china.createDistribution(new Distribution(), Map.of());
StreamingDistribution streaming = china.createStreamingDistribution(new StreamingDistribution());
assertEquals(dist.getId().toLowerCase(Locale.ROOT) + ".cloudfront.cn", dist.getDomainName());
assertEquals(streaming.getId().toLowerCase(Locale.ROOT) + ".cloudfront.cn", streaming.getDomainName());
assertTrue(govCloud.createDistribution(new Distribution(), Map.of()).getDomainName().endsWith(".cloudfront.net"));
}
@Test
void aConfiguredDomainSuffixWinsOverThePartitions() {
CloudFrontService china = serviceWithDomainSuffix("cloudfront.local", "cn-north-1");
Distribution dist = china.createDistribution(new Distribution(), Map.of());
assertTrue(dist.getDomainName().endsWith(".cloudfront.local"),
"Expected configured suffix, got: " + dist.getDomainName());
}
@Test
void createStreamingDistributionHonorsConfiguredDomainSuffix() {
CloudFrontService service = serviceWithDomainSuffix("cloudfront.local");