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

@@ -2383,8 +2383,11 @@ public interface EmulatorConfig {
@WithDefault("true")
boolean enabled();
@WithDefault("cloudfront.net") // partition-literal: configurable; the China CDN suffix has no published source
String domainSuffix();
/**
* Suffix of generated distribution domain names, in every partition when set. Unset, the
* suffix follows the request's partition ({@code CloudFrontEdgeDomain#domainSuffix}).
*/
Optional<String> domainSuffix();
/**
* Exact custom-origin hostnames allowed to resolve to private or otherwise non-routable
@@ -13,9 +13,10 @@ import java.util.Set;
/**
* The per-region and per-partition constants AWS publishes only as prose tables, vendored in
* {@code aws/region-facts.json} by {@code tools/aws/regen_region_facts.py} from the Terraform
* provider, the CDK and the China and GovCloud user guides: load balancer and S3 website hosted
* zone ids, the CloudFront hosted zone per partition, the SAML sign-on URL and the management
* console host per partition and the VPC endpoint service-name prefixes. Every accessor is {@link Optional}: the ISO and EUSC partitions have no published
* provider, the CDK, the botocore models and the China and GovCloud user guides: load balancer,
* S3 website and GovCloud API Gateway hosted zone ids, the CloudFront hosted zone and distribution
* domain suffix per partition, the SAML sign-on URL and the management console host per partition
* and the VPC endpoint service-name prefixes. Every accessor is {@link Optional}: the ISO and EUSC partitions have no published
* hosted zones, and a service that needs one there has nothing faithful to answer.
*/
public final class AwsRegionFacts {
@@ -48,6 +49,22 @@ public final class AwsRegionFacts {
return regionText(region, "s3WebsiteHostedZoneId");
}
/**
* The hosted zone of an API Gateway regional endpoint, which a Route 53 alias to a regional
* custom domain targets. Published in the corpus for the two GovCloud regions only.
*/
public static Optional<String> apiGatewayRegionalHostedZoneId(String region) {
return regionText(region, "apiGatewayRegionalHostedZoneId");
}
/**
* The suffix of a distribution's generated domain name: {@code cloudfront.net}, and
* {@code cloudfront.cn} in {@code aws-cn}. Absent for the partitions without CloudFront.
*/
public static Optional<String> cloudFrontDomainSuffix(String partition) {
return partitionText(partition, "cloudfrontDomainSuffix");
}
/** Published for {@code aws} and {@code aws-cn} only, where CloudFront exists. */
public static Optional<String> cloudFrontHostedZoneId(String partition) {
return partitionText(partition, "cloudfrontHostedZoneId");
@@ -4,19 +4,41 @@ import java.util.UUID;
/**
* The CloudFront distribution AWS puts in front of a custom domain, an edge-optimized API Gateway
* domain or an AppSync custom domain: a distribution domain name on the configured CloudFront
* suffix, and the CloudFront hosted zone of the region's partition, which a Route 53 alias record
* targets. The zone is null in a partition without CloudFront.
* domain or an AppSync custom domain: a distribution domain name on the CloudFront suffix of the
* partition (or the configured one), and the partition's CloudFront hosted zone, which a Route 53
* alias record targets. The zone is null in a partition without CloudFront.
*
* @param domainName the distribution domain name, {@code d<13 hex>.<suffix>}
* @param hostedZoneId the partition's CloudFront hosted zone, or null where there is none
*/
public record CloudFrontEdgeDomain(String domainName, String hostedZoneId) {
public static CloudFrontEdgeDomain create(String region, String domainSuffix) {
/**
* @param partition the partition the domain is created in, as the caller's
* {@link RegionResolver#partitionForRegion} resolves it, so a region no
* partition publishes falls to the deployment's partition, not the
* commercial one
* @param configuredSuffix {@code floci.services.cloudfront.domain-suffix}, or null when unset
*/
public static CloudFrontEdgeDomain create(String partition, String configuredSuffix) {
String distributionId = "d" + UUID.randomUUID().toString().replace("-", "").substring(0, 13);
String hostedZoneId = AwsRegionFacts.cloudFrontHostedZoneId(
AwsPartitions.forRegionOrCommercial(region).id()).orElse(null);
return new CloudFrontEdgeDomain(distributionId + "." + domainSuffix, hostedZoneId);
String hostedZoneId = AwsRegionFacts.cloudFrontHostedZoneId(partition).orElse(null);
return new CloudFrontEdgeDomain(distributionId + "." + domainSuffix(configuredSuffix, partition), hostedZoneId);
}
/**
* The suffix of a generated distribution domain name. An explicitly configured suffix wins in
* every partition; otherwise it is the partition's own ({@code cloudfront.cn} in China), and
* the commercial one in a partition that has no CloudFront and so no suffix to publish.
*
* @param configuredSuffix {@code floci.services.cloudfront.domain-suffix}, or null when unset
*/
public static String domainSuffix(String configuredSuffix, String partition) {
if (configuredSuffix != null && !configuredSuffix.isBlank()) {
return configuredSuffix;
}
return AwsRegionFacts.cloudFrontDomainSuffix(partition)
.or(() -> AwsRegionFacts.cloudFrontDomainSuffix(AwsRegions.DEFAULT_PARTITION))
.orElseThrow();
}
}
@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsPartition;
import io.github.hectorvent.floci.core.common.AwsPartitions;
import io.github.hectorvent.floci.core.common.AwsRegionFacts;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.CloudFrontEdgeDomain;
import io.github.hectorvent.floci.core.common.RegionResolver;
@@ -86,6 +87,12 @@ public class ApiGatewayService implements ResourceProvider {
/** The only partition where API Gateway offers edge-optimized APIs and custom domain names. */
private static final Set<String> EDGE_OPTIMIZED_PARTITIONS = Set.of("aws");
/**
* The regional hosted zone a custom domain reports in a region with no published one. Only
* the two GovCloud regions have a sourced zone ({@link AwsRegionFacts#apiGatewayRegionalHostedZoneId}).
*/
private static final String UNSOURCED_REGIONAL_HOSTED_ZONE_ID = "Z2FDTNDATAQYL2"; // partition-literal: placeholder kept where no per-region source exists
private static final ObjectMapper JSON = new ObjectMapper();
/** Documented default page size for GetUsage. */
@@ -2115,7 +2122,8 @@ public class ApiGatewayService implements ResourceProvider {
domain.setRegionalCertificateName((String) request.get("regionalCertificateName"));
domain.setRegionalCertificateArn((String) request.get("regionalCertificateArn"));
domain.setRegionalDomainName(domainName + ".regional.local");
domain.setRegionalHostedZoneId("Z2FDTNDATAQYL2"); // partition-literal: no published per-region source for the regional zone
domain.setRegionalHostedZoneId(AwsRegionFacts.apiGatewayRegionalHostedZoneId(region)
.orElse(UNSOURCED_REGIONAL_HOSTED_ZONE_ID));
applyEndpointType(domain, endpointType, region);
domain.setSecurityPolicy((String) request.getOrDefault("securityPolicy", "TLS_1_2"));
// Nothing is provisioned behind the domain, so it is usable as soon as it exists.
@@ -2168,7 +2176,8 @@ public class ApiGatewayService implements ResourceProvider {
domain.setDistributionDomainName(null);
domain.setDistributionHostedZoneId(null);
} else if (domain.getDistributionDomainName() == null) {
CloudFrontEdgeDomain edge = CloudFrontEdgeDomain.create(region, config.services().cloudfront().domainSuffix());
CloudFrontEdgeDomain edge = CloudFrontEdgeDomain.create(regionResolver.partitionForRegion(region),
config.services().cloudfront().domainSuffix().orElse(null));
domain.setDistributionDomainName(edge.domainName());
domain.setDistributionHostedZoneId(edge.hostedZoneId());
}
@@ -60,7 +60,7 @@ public class AppSyncService {
private final ObjectMapper objectMapper;
private final Clock clock;
private final String baseUrl;
private final String cloudFrontDomainSuffix;
private final String configuredCloudFrontDomainSuffix;
private final LambdaAuthorizerCache lambdaAuthorizerCache;
@Inject
@@ -90,7 +90,7 @@ public class AppSyncService {
this.objectMapper = objectMapper;
this.clock = clock;
this.baseUrl = trimTrailingSlash(config.effectiveBaseUrl());
this.cloudFrontDomainSuffix = config.services().cloudfront().domainSuffix();
this.configuredCloudFrontDomainSuffix = config.services().cloudfront().domainSuffix().orElse(null);
this.lambdaAuthorizerCache = lambdaAuthorizerCache;
}
@@ -761,7 +761,8 @@ public class AppSyncService {
* Gateway domain gets.
*/
private void applyCloudFrontFront(DomainName dn, String region) {
CloudFrontEdgeDomain edge = CloudFrontEdgeDomain.create(region, cloudFrontDomainSuffix);
CloudFrontEdgeDomain edge = CloudFrontEdgeDomain.create(regionResolver.partitionForRegion(region),
configuredCloudFrontDomainSuffix);
dn.setAppsyncDomainName(edge.domainName());
dn.setHostedZoneId(edge.hostedZoneId());
}
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.cloudfront;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.CloudFrontEdgeDomain;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;
import io.github.hectorvent.floci.core.storage.StorageBackend;
@@ -126,7 +127,7 @@ public class CloudFrontService implements ServerCertificateReferenceProvider {
private final String accountId;
private final RegionResolver regionResolver;
private final IamService iamService;
private final String domainSuffix;
private final String configuredDomainSuffix;
/**
* Host suffixes under which every distribution is served as {@code <id><suffix>}, whatever
* {@code floci.services.cloudfront.domain-suffix} makes the assigned domain name. They carry the
@@ -182,7 +183,7 @@ public class CloudFrontService implements ServerCertificateReferenceProvider {
new TypeReference<Map<String, MonitoringSubscription>>() {});
this.accountId = config.defaultAccountId();
this.regionResolver = regionResolver;
this.domainSuffix = config.services().cloudfront().domainSuffix();
this.configuredDomainSuffix = config.services().cloudfront().domainSuffix().orElse(null);
this.localDeliverySuffixes = localDeliverySuffixes(config);
}
@@ -459,10 +460,12 @@ public class CloudFrontService implements ServerCertificateReferenceProvider {
/**
* The domain name a new distribution is served under. AWS assigns a lower-case host, and a
* browser lower-cases the authority it sends, so an upper-case id in the host would never match
* the resource a signed URL was signed for.
* the resource a signed URL was signed for. The suffix is the request partition's unless one
* is configured.
*/
private String domainNameFor(String id) {
return id.toLowerCase(Locale.ROOT) + "." + domainSuffix;
return id.toLowerCase(Locale.ROOT) + "."
+ CloudFrontEdgeDomain.domainSuffix(configuredDomainSuffix, regionResolver.getPartition());
}
private static List<String> localDeliverySuffixes(EmulatorConfig config) {
@@ -13,6 +13,7 @@ import io.github.hectorvent.floci.core.common.AwsPartition;
import io.github.hectorvent.floci.core.common.AwsPartitions;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.Base64Url;
import io.github.hectorvent.floci.core.common.CloudFrontEdgeDomain;
import io.github.hectorvent.floci.core.common.Digests;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
@@ -112,10 +113,10 @@ public class CognitoService implements ResourceProvider {
// JVM-local stripes bound lock memory without retaining one lock for every user key.
private static final int USER_LOCK_STRIPES = 512;
/**
* The commercial CloudFront suffix for the test constructors; CDI wires
* {@code floci.services.cloudfront.domain-suffix}.
* No configured CloudFront suffix, for the test constructors: the suffix then follows the
* request's partition. CDI wires {@code floci.services.cloudfront.domain-suffix}.
*/
private static final String DEFAULT_CLOUDFRONT_DOMAIN_SUFFIX = "cloudfront.net"; // partition-literal: test-shaped constructor default
private static final String UNCONFIGURED_CLOUDFRONT_DOMAIN_SUFFIX = null;
private static final Logger LOG = Logger.getLogger(CognitoService.class);
private static final ObjectMapper MAPPER = new ObjectMapper();
@@ -219,7 +220,7 @@ public class CognitoService implements ResourceProvider {
storageFactory.create("cognito", "cognito-revoked-tokens.json",
new TypeReference<Map<String, RevokedTokenInfo>>() {}),
trimTrailingSlash(emulatorConfig.effectiveBaseUrl()),
emulatorConfig.services().cloudfront().domainSuffix(),
emulatorConfig.services().cloudfront().domainSuffix().orElse(null),
regionResolver,
lambdaService,
acmService,
@@ -242,7 +243,7 @@ public class CognitoService implements ResourceProvider {
LambdaService lambdaService,
AcmService acmService) {
this(poolStore, clientStore, resourceServerStore, userStore, groupStore, revokedTokenStore, baseUrl,
DEFAULT_CLOUDFRONT_DOMAIN_SUFFIX, regionResolver, lambdaService, acmService);
UNCONFIGURED_CLOUDFRONT_DOMAIN_SUFFIX, regionResolver, lambdaService, acmService);
}
CognitoService(StorageBackend<String, UserPool> poolStore,
@@ -259,7 +260,7 @@ public class CognitoService implements ResourceProvider {
CognitoMessageDispatcher messageDispatcher,
TlsCertificateManager certificateManager) {
this(poolStore, clientStore, resourceServerStore, domainStore, identityProviderStore, userStore,
groupStore, revokedTokenStore, baseUrl, DEFAULT_CLOUDFRONT_DOMAIN_SUFFIX, regionResolver,
groupStore, revokedTokenStore, baseUrl, UNCONFIGURED_CLOUDFRONT_DOMAIN_SUFFIX, regionResolver,
lambdaService, acmService, verificationCodeService, messageDispatcher, certificateManager);
}
@@ -1934,8 +1935,10 @@ public class CognitoService implements ResourceProvider {
return AwsArnUtils.Arn.global(partition, "cloudfront", userPoolDomain.getAwsAccountId(), "distribution/" + id).toString();
}
/** A distribution name on the configured CloudFront suffix, or the request partition's when none is. */
private String generateCloudFrontDomain() {
return UUID.randomUUID().toString().replace("-", "").substring(0, 14) + "." + cloudFrontDomainSuffix;
return UUID.randomUUID().toString().replace("-", "").substring(0, 14) + "."
+ CloudFrontEdgeDomain.domainSuffix(cloudFrontDomainSuffix, regionResolver.getPartition());
}
private String generateDomainVersion() {