Skip to content

armgit / floci

Public Imported from GitHub
0

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

fix(core): build and recognise AWS hostnames in every partition (#4451)

Hector Ventura2cccc73499f0
diff --git a/docs/configuration/partitions.md b/docs/configuration/partitions.md
index f31ad392dd..d0cc004de2 100644
--- a/docs/configuration/partitions.md
+++ b/docs/configuration/partitions.md
@@ -66,8 +66,13 @@ did before.
- **DescribeRegions**: the request's partition's regions, with the partition's endpoints.
As on AWS, a commercial deployment lists the 17 regions that need no opt-in by default and
all 34 with `AllRegions=true`, where opt-in regions report `not-opted-in`.
-- **Hostname recognition**: every published region id, in every partition, is a region label
- in an S3 virtual-host or execute-api hostname.
+- **Hostnames**: AWS-shaped hosts in responses (an HTTP API's `ApiEndpoint`, a bucket's
+ `RegionalDomainName` and `WebsiteURL`, Cognito and EKS OIDC issuers, EC2 public DNS names)
+ use the DNS suffix of their region's partition, so a `cn-north-1` API answers
+ `<id>.execute-api.cn-north-1.amazonaws.com.cn`. `DualStackDomainName` is only returned where
+ S3 publishes a dual-stack endpoint.
+- **Hostname recognition**: every published region id and DNS suffix, in every partition, is
+ recognised in an S3 virtual-host, execute-api, ECR image or CloudFront origin hostname.
## What does not change
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 569e554d0d..ac008f5492 100644
--- a/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
+++ b/src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java
@@ -2247,7 +2247,7 @@ public interface EmulatorConfig {
@WithDefault("true")
boolean enabled();
- @WithDefault("cloudfront.net")
+ @WithDefault("cloudfront.net") // partition-literal: configurable; the China CDN suffix has no published source
String domainSuffix();
/**
@@ -2602,7 +2602,7 @@ public interface EmulatorConfig {
* {@code floci.ecr-base-uri} (env {@code FLOCI_ECR_BASE_URI}) still works
* (see {@link FlociConfigRelocationsInterceptor}), but is deprecated.
*/
- @WithDefault("public.ecr.aws")
+ @WithDefault("public.ecr.aws") // partition-literal: configurable; ECR Public exists only in the commercial partition
String ecrBaseUri();
@WithDefault("128")
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsEndpoints.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsEndpoints.java
new file mode 100644
index 0000000000..4d04bae0a5
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsEndpoints.java
@@ -0,0 +1,74 @@
+package io.github.hectorvent.floci.core.common;
+
+/**
+ * The AWS hostnames the emulator hands back for a region: every one is
+ * {@code <service>.<region>.<dnsSuffix>} with the region's partition suffix, plus the handful of
+ * shapes that break that rule (the S3 website endpoint's two forms, the EC2 public DNS name,
+ * the region-less S3 bucket host). Floci itself serves everything on its own base URL; these are
+ * the values AWS-shaped fields carry ({@code ApiEndpoint}, {@code RegionalDomainName},
+ * {@code PublicDnsName}, OIDC issuers), which clients compare against or parse.
+ */
+public final class AwsEndpoints {
+
+ private AwsEndpoints() {
+ }
+
+ /** {@code <service>.<region>.<dnsSuffix>}. */
+ public static String host(String service, String region) {
+ return AwsPartitions.forRegionOrCommercial(region).regionalHostname(service, region);
+ }
+
+ /** {@code <apiId>.execute-api.<region>.<dnsSuffix>}. */
+ public static String executeApiHost(String apiId, String region) {
+ return apiId + "." + host("execute-api", region);
+ }
+
+ /** The region-less bucket host, {@code <bucket>.s3.<dnsSuffix>} (CloudFormation's {@code DomainName}). */
+ public static String s3Host(String bucket, String region) {
+ return bucket + ".s3." + AwsRegions.dnsSuffixFor(region);
+ }
+
+ /** {@code <bucket>.s3.<region>.<dnsSuffix>} (CloudFormation's {@code RegionalDomainName}). */
+ public static String s3RegionalHost(String bucket, String region) {
+ return bucket + "." + host("s3", region);
+ }
+
+ /**
+ * {@code <bucket>.s3.dualstack.<region>.<dnsSuffix>}; only meaningful where
+ * {@link AwsPartition#supportsS3DualStack} holds.
+ */
+ public static String s3DualStackHost(String bucket, String region) {
+ return bucket + ".s3.dualstack." + region + "." + AwsRegions.dnsSuffixFor(region);
+ }
+
+ /**
+ * The S3 static website host. The nine regions that predate the regional-subdomain rule
+ * ({@code us-east-1}, {@code us-west-1}, {@code us-west-2}, {@code eu-west-1},
+ * {@code ap-southeast-1}, {@code ap-southeast-2}, {@code ap-northeast-1}, {@code sa-east-1},
+ * {@code us-gov-west-1}) use the dash form {@code s3-website-<region>}; every later region
+ * uses {@code s3-website.<region>} (the CDK's {@code RULE_S3_WEBSITE_REGIONAL_SUBDOMAIN}).
+ */
+ public static String s3WebsiteHost(String bucket, String region) {
+ AwsPartition partition = AwsPartitions.forRegionOrCommercial(region);
+ boolean dashForm = partition.region(region).map(AwsPartition.Region::s3WebsiteDashForm).orElse(false);
+ return bucket + (dashForm ? ".s3-website-" : ".s3-website.") + region + "." + partition.dnsSuffix();
+ }
+
+ /** CloudFormation's {@code WebsiteURL}: {@code http://} + the website host + a trailing slash. */
+ public static String s3WebsiteUrl(String bucket, String region) {
+ return "http://" + s3WebsiteHost(bucket, region) + "/";
+ }
+
+ /**
+ * The EC2 public DNS name for {@code ip}: {@code ec2-<ip>.compute-1.amazonaws.com} in
+ * {@code us-east-1} and {@code ec2-<ip>.<region>.compute.<dnsSuffix>} everywhere else, the
+ * rule the AWS Terraform provider applies.
+ */
+ public static String ec2PublicDns(String ip, String region) {
+ String dashed = "ec2-" + ip.replace('.', '-');
+ if ("us-east-1".equals(region)) {
+ return dashed + ".compute-1." + AwsRegions.DEFAULT_DNS_SUFFIX;
+ }
+ return dashed + "." + region + ".compute." + AwsRegions.dnsSuffixFor(region);
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsPartition.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsPartition.java
index 28a2c8c11e..397f9a6435 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/AwsPartition.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsPartition.java
@@ -28,6 +28,7 @@ import java.util.regex.Pattern;
* @param globalServices services with a partition-wide endpoint, by service key
* @param supportsDualStack whether the partition publishes dual-stack endpoints
* @param supportsFips whether the partition publishes FIPS endpoints
+ * @param s3DualStackRegions the regions whose S3 endpoint publishes a dual-stack variant
*/
public record AwsPartition(
String id,
@@ -41,7 +42,8 @@ public record AwsPartition(
Set<String> services,
Map<String, GlobalEndpoint> globalServices,
boolean supportsDualStack,
- boolean supportsFips) {
+ boolean supportsFips,
+ Set<String> s3DualStackRegions) {
/**
* A published region.
@@ -72,6 +74,16 @@ public record AwsPartition(
regions = List.copyOf(regions);
services = Set.copyOf(services);
globalServices = Map.copyOf(globalServices);
+ s3DualStackRegions = Set.copyOf(s3DualStackRegions);
+ }
+
+ /**
+ * True when S3 publishes a dual-stack endpoint in {@code region}: every region in the
+ * commercial, China, GovCloud and ISO partitions, only {@code us-isob-east-1} in ISO-B, none
+ * in ISO-E, ISO-F or EUSC.
+ */
+ public boolean supportsS3DualStack(String region) {
+ return region != null && s3DualStackRegions.contains(region.trim().toLowerCase(Locale.ROOT));
}
/** True when {@code endpoints.json} lists {@code service} for this partition. */
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsPartitions.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsPartitions.java
index 3ca186230f..0857662c12 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/AwsPartitions.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsPartitions.java
@@ -158,6 +158,20 @@ public final class AwsPartitions {
return Optional.empty();
}
+ /** True when {@code host} is exactly a published DNS suffix ({@code amazonaws.com.cn}, {@code api.aws}, ...). */
+ public static boolean isDnsSuffix(String host) {
+ return host != null && Holder.CATALOG.dnsSuffixesLongestFirst().contains(host.trim().toLowerCase(Locale.ROOT));
+ }
+
+ /**
+ * A non-capturing regex alternation of every published DNS suffix, longest first and quoted,
+ * for patterns that must recognise a hostname in any partition.
+ */
+ public static String dnsSuffixRegex() {
+ List<String> quoted = Holder.CATALOG.dnsSuffixesLongestFirst().stream().map(Pattern::quote).toList();
+ return "(?:" + String.join("|", quoted) + ")";
+ }
+
private static String normalize(String label) {
if (label == null || label.isBlank()) {
return null;
@@ -229,6 +243,10 @@ public final class AwsPartitions {
for (JsonNode service : node.path("services")) {
services.add(service.asText());
}
+ Set<String> s3DualStackRegions = new LinkedHashSet<>();
+ for (JsonNode region : node.path("s3DualStackRegions")) {
+ s3DualStackRegions.add(region.asText());
+ }
Map<String, AwsPartition.GlobalEndpoint> globalServices = new LinkedHashMap<>();
JsonNode globalNode = node.path("globalServices");
globalNode.fieldNames().forEachRemaining(service -> {
@@ -251,7 +269,8 @@ public final class AwsPartitions {
services,
globalServices,
node.path("supportsDualStack").asBoolean(false),
- node.path("supportsFips").asBoolean(false));
+ node.path("supportsFips").asBoolean(false),
+ s3DualStackRegions);
}
private static String required(JsonNode node, String field) {
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 afdade1f83..a8ffc783b6 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
@@ -37,7 +37,7 @@ public final class AwsRegions {
public static final String DEFAULT_PARTITION = AwsPartitions.COMMERCIAL_ID;
/** The DNS suffix of the commercial partition, shared with {@code aws-us-gov}. */
- public static final String DEFAULT_DNS_SUFFIX = "amazonaws.com";
+ public static final String DEFAULT_DNS_SUFFIX = "amazonaws.com"; // partition-literal: the commercial suffix, by definition
/**
* The regions a partition publishes, in botocore order, e.g. the 34 commercial regions for
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/IamEnforcementFilter.java b/src/main/java/io/github/hectorvent/floci/core/common/IamEnforcementFilter.java
index 8466726301..f0fc7df390 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/IamEnforcementFilter.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/IamEnforcementFilter.java
@@ -643,19 +643,6 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
return credential == null || credential.isBlank() ? null : "Credential=" + credential;
}
- /**
- * Builds a 403 Access Denied response in the wire format the calling SDK
- * expects. AWS SDKs hard-fail when they receive the wrong shape: an XML
- * parser blows up on a leading {@code {}, and a JSON parser blows up on
- * {@code <}. Pick the shape from request signals:
- *
- * <ul>
- * <li>S3 → S3-flavored XML {@code <Error>...</Error>}</li>
- * <li>{@code application/x-www-form-urlencoded} body → AWS Query
- * {@code <ErrorResponse>...</ErrorResponse>} (IAM/STS/EC2/SQS/SNS/...)</li>
- * <li>everything else (JSON 1.x, REST-JSON) → keep the historical JSON shape</li>
- * </ul>
- */
/**
* The request's resource ARNs as the resources are actually named, so that a policy written
* against a resource living in another partition than the request's still matches it.
@@ -689,6 +676,19 @@ public class IamEnforcementFilter implements ContainerRequestFilter {
return policies;
}
+ /**
+ * Builds a 403 Access Denied response in the wire format the calling SDK
+ * expects. AWS SDKs hard-fail when they receive the wrong shape: an XML
+ * parser blows up on a leading {@code {}, and a JSON parser blows up on
+ * {@code <}. Pick the shape from request signals:
+ *
+ * <ul>
+ * <li>S3 → S3-flavored XML {@code <Error>...</Error>}</li>
+ * <li>{@code application/x-www-form-urlencoded} body → AWS Query
+ * {@code <ErrorResponse>...</ErrorResponse>} (IAM/STS/EC2/SQS/SNS/...)</li>
+ * <li>everything else (JSON 1.x, REST-JSON) → keep the historical JSON shape</li>
+ * </ul>
+ */
// Package-private for unit testing.
static Response accessDeniedResponse(String action, String credentialScope, MediaType requestMediaType) {
return accessDeniedResponse(action, credentialScope, requestMediaType, null);
diff --git a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayExecuteApiHostFilter.java b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayExecuteApiHostFilter.java
index 100bd73441..c7e6bb486c 100644
--- a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayExecuteApiHostFilter.java
+++ b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayExecuteApiHostFilter.java
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.apigateway;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.AwsPartitions;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.RequestContext;
import io.github.hectorvent.floci.core.common.RequestHost;
@@ -248,7 +249,7 @@ public class ApiGatewayExecuteApiHostFilter implements ContainerRequestFilter {
String endpointHost = tail.substring(firstDot + 1);
if ("localhost".equalsIgnoreCase(endpointHost)
- || "amazonaws.com".equalsIgnoreCase(endpointHost)
+ || AwsPartitions.isDnsSuffix(endpointHost)
|| (baseHostname != null && baseHostname.equalsIgnoreCase(endpointHost))) {
return matcher.group(1).toLowerCase(Locale.ROOT);
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayExecuteController.java b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayExecuteController.java
index cdaf99f8b8..5e6c4bc908 100644
--- a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayExecuteController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayExecuteController.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.apigateway;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsEndpoints;
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
@@ -1282,7 +1283,7 @@ public class ApiGatewayExecuteController {
}
String arnRegion = region != null ? region : regionResolver.getDefaultRegion();
- String domainName = apiId + ".execute-api." + arnRegion + ".amazonaws.com";
+ String domainName = AwsEndpoints.executeApiHost(apiId, arnRegion);
long nowMillis = System.currentTimeMillis();
String requestTime = java.time.format.DateTimeFormatter
.ofPattern("dd/MMM/yyyy:HH:mm:ss Z")
@@ -2975,7 +2976,7 @@ public class ApiGatewayExecuteController {
String arnRegion = region != null ? region : regionResolver.getDefaultRegion();
ctx.put("accountId", regionResolver.getAccountId());
ctx.put("apiId", apiId);
- ctx.put("domainName", apiId + ".execute-api." + arnRegion + ".amazonaws.com");
+ ctx.put("domainName", AwsEndpoints.executeApiHost(apiId, arnRegion));
ctx.put("domainPrefix", apiId);
ctx.put("requestId", UUID.randomUUID().toString());
ctx.put("routeKey", routeKey != null ? routeKey : "$default");
@@ -3200,7 +3201,7 @@ public class ApiGatewayExecuteController {
ObjectNode ctx = event.putObject("requestContext");
ctx.put("accountId", regionResolver.getAccountId());
ctx.put("apiId", apiId);
- ctx.put("domainName", apiId + ".execute-api." + region + ".amazonaws.com");
+ ctx.put("domainName", AwsEndpoints.executeApiHost(apiId, region));
ctx.put("domainPrefix", apiId);
ctx.put("requestId", requestId);
ctx.put("routeKey", routeKey != null ? routeKey : "$default");
@@ -3503,7 +3504,7 @@ public class ApiGatewayExecuteController {
Map<String, Object> context = new LinkedHashMap<>();
context.put("accountId", regionResolver.getAccountId());
context.put("apiId", scope.apiId());
- context.put("domainName", scope.apiId() + ".execute-api." + region + ".amazonaws.com");
+ context.put("domainName", AwsEndpoints.executeApiHost(scope.apiId(), region));
context.put("domainPrefix", scope.apiId());
context.put("extendedRequestId", requestId);
context.put("httpMethod", scope.httpMethod());
diff --git a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayService.java b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayService.java
index dfcdee6a34..01a416b259 100644
--- a/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayService.java
@@ -96,6 +96,7 @@ public class ApiGatewayService {
*/
private final Object domainNameLock = new Object();
private final TlsCertificateManager certificateManager;
+ private final EmulatorConfig config;
// Constants
private static final String EPC_KEY = "endpointConfiguration";
@@ -106,6 +107,7 @@ public class ApiGatewayService {
public ApiGatewayService(StorageFactory storageFactory, EmulatorConfig config,
TlsCertificateManager certificateManager) {
this.certificateManager = certificateManager;
+ this.config = config;
this.apiStore = storageFactory.create("apigateway", "apigateway-apis.json",
new TypeReference<>() {
});
@@ -1920,14 +1922,15 @@ public class ApiGatewayService {
* regional domain has none, so a move to {@code REGIONAL} drops the distribution again while a
* move to {@code EDGE} puts one in front of the domain, as the migration does on AWS.
*/
- private static void applyEndpointType(CustomDomain domain, String endpointType) {
+ private void applyEndpointType(CustomDomain domain, String endpointType) {
domain.setEndpointConfigurationType(endpointType);
if (!"EDGE".equals(endpointType)) {
domain.setDistributionDomainName(null);
domain.setDistributionHostedZoneId(null);
} else if (domain.getDistributionDomainName() == null) {
domain.setDistributionDomainName(
- "d" + UUID.randomUUID().toString().replace("-", "").substring(0, 13) + ".cloudfront.net");
+ "d" + UUID.randomUUID().toString().replace("-", "").substring(0, 13) + "."
+ + config.services().cloudfront().domainSuffix());
domain.setDistributionHostedZoneId("Z2FDTNDATAQYW2");
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2Service.java b/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2Service.java
index 17803580e3..273d54b5b0 100644
--- a/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2Service.java
+++ b/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2Service.java
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.apigatewayv2;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsEndpoints;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.ReservedTags;
@@ -107,9 +108,9 @@ public class ApiGatewayV2Service {
api.setDisableExecuteApiEndpoint(booleanValue(request.get("disableExecuteApiEndpoint")));
if ("WEBSOCKET".equals(protocolType)) {
- api.setApiEndpoint(String.format("wss://%s.execute-api.%s.amazonaws.com", api.getApiId(), region));
+ api.setApiEndpoint("wss://" + AwsEndpoints.executeApiHost(api.getApiId(), region));
} else {
- api.setApiEndpoint(String.format("https://%s.execute-api.%s.amazonaws.com", api.getApiId(), region));
+ api.setApiEndpoint("https://" + AwsEndpoints.executeApiHost(api.getApiId(), region));
}
if (tags != null) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/websocket/WebSocketProxyEventBuilder.java b/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/websocket/WebSocketProxyEventBuilder.java
index 0df2132cb4..4e6a0486d8 100644
--- a/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/websocket/WebSocketProxyEventBuilder.java
+++ b/src/main/java/io/github/hectorvent/floci/services/apigatewayv2/websocket/WebSocketProxyEventBuilder.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsEndpoints;
import io.github.hectorvent.floci.core.common.RegionResolver;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
@@ -287,7 +288,7 @@ public class WebSocketProxyEventBuilder {
}
private String buildDomainName(String apiId, String region) {
- return apiId + ".execute-api." + region + ".amazonaws.com";
+ return AwsEndpoints.executeApiHost(apiId, region);
}
private String buildMethodArn(String region, String apiId, String stageName) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/appsync/AppSyncService.java b/src/main/java/io/github/hectorvent/floci/services/appsync/AppSyncService.java
index 1a74f5c624..74834c4908 100644
--- a/src/main/java/io/github/hectorvent/floci/services/appsync/AppSyncService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/appsync/AppSyncService.java
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.core.common.AwsArnUtils;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.config.EmulatorConfig;
+import io.github.hectorvent.floci.core.common.AwsEndpoints;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.RequestContext;
@@ -735,7 +736,7 @@ public class AppSyncService {
dn.setDescription((String) request.get("description"));
dn.setCertificateArn((String) request.get("certificateArn"));
String shortId = generateShortId();
- dn.setAppsyncDomainName(shortId + ".appsync-api.us-east-1.amazonaws.com");
+ dn.setAppsyncDomainName(shortId + "." + AwsEndpoints.host("appsync-api", regionResolver.getDefaultRegion()));
dn.setHostedZoneId("Z" + generateShortId());
dn.setDomainNameArn(regionResolver.buildArn("appsync", regionResolver.getDefaultRegion(),
"domainnames/" + domainName));
diff --git a/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/auth/IamAuthValidator.java b/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/auth/IamAuthValidator.java
index f602b86855..8ebe45bc84 100644
--- a/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/auth/IamAuthValidator.java
+++ b/src/main/java/io/github/hectorvent/floci/services/appsync/graphql/auth/IamAuthValidator.java
@@ -1,8 +1,8 @@
package io.github.hectorvent.floci.services.appsync.graphql.auth;
+import io.github.hectorvent.floci.core.common.AccountResolver;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsRegions;
-import io.github.hectorvent.floci.core.common.AccountResolver;
import io.github.hectorvent.floci.core.common.auth.CredentialScope;
import io.github.hectorvent.floci.core.common.auth.SigV4AuthorizationHeader;
import io.github.hectorvent.floci.core.common.auth.SigV4RequestValidator;
diff --git a/src/main/java/io/github/hectorvent/floci/services/aps/ApsService.java b/src/main/java/io/github/hectorvent/floci/services/aps/ApsService.java
index 1276f101a6..cf39427442 100644
--- a/src/main/java/io/github/hectorvent/floci/services/aps/ApsService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/aps/ApsService.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.aps;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsEndpoints;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
@@ -58,7 +59,7 @@ public class ApsService implements TagHandler {
// (Pending CREATING, Target ACTIVE) completes on its first DescribeWorkspace poll.
workspace.setStatus("ACTIVE");
workspace.setPrometheusEndpoint(
- "https://aps-workspaces." + region + ".amazonaws.com/workspaces/" + workspaceId + "/");
+ "https://" + AwsEndpoints.host("aps-workspaces", region) + "/workspaces/" + workspaceId + "/");
workspace.setCreatedAt(Instant.now());
workspace.setKmsKeyArn(kmsKeyArn);
if (tags != null) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/bedrockagentcorecontrol/BedrockAgentCoreCredentialProviderService.java b/src/main/java/io/github/hectorvent/floci/services/bedrockagentcorecontrol/BedrockAgentCoreCredentialProviderService.java
index 9a8fef863d..6f8b626bd9 100644
--- a/src/main/java/io/github/hectorvent/floci/services/bedrockagentcorecontrol/BedrockAgentCoreCredentialProviderService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/bedrockagentcorecontrol/BedrockAgentCoreCredentialProviderService.java
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsEndpoints;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.core.common.PaginatedResult;
@@ -204,7 +205,7 @@ public class BedrockAgentCoreCredentialProviderService {
item.put("name", name);
item.put("credentialProviderArn", oauthCredentialProviderArn(region, name));
item.put("credentialProviderVendor", vendor);
- item.put("callbackUrl", "https://bedrock-agentcore." + region + ".amazonaws.com/oauth2/callback");
+ item.put("callbackUrl", "https://" + AwsEndpoints.host("bedrock-agentcore", region) + "/oauth2/callback");
item.put("clientSecretSource", source);
if (source.equals("EXTERNAL")) {
item.putObject("clientSecretArn").put("secretArn", secretConfig.path("secretId").asText());
diff --git a/src/main/java/io/github/hectorvent/floci/services/bedrockagentcorecontrol/BedrockAgentCoreGatewayService.java b/src/main/java/io/github/hectorvent/floci/services/bedrockagentcorecontrol/BedrockAgentCoreGatewayService.java
index a7f91c7cd5..bd1d48c40f 100644
--- a/src/main/java/io/github/hectorvent/floci/services/bedrockagentcorecontrol/BedrockAgentCoreGatewayService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/bedrockagentcorecontrol/BedrockAgentCoreGatewayService.java
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.bedrockagentcorecontrol;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
+import io.github.hectorvent.floci.core.common.AwsEndpoints;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.core.common.PaginatedResult;
@@ -66,7 +67,7 @@ public class BedrockAgentCoreGatewayService {
gateway.setProtocolType("MCP");
gateway.setStatus(STATUS_READY);
gateway.setDescription(description);
- gateway.setGatewayUrl("https://" + id + ".gateway.bedrock-agentcore." + region + ".amazonaws.com");
+ gateway.setGatewayUrl("https://" + id + ".gateway." + AwsEndpoints.host("bedrock-agentcore", region));
gateway.setWorkloadIdentityArn(regionResolver.buildArn(ARN_SERVICE, region,
"workload-identity-directory/default/workload-identity/" + id));
gateway.setCreatedAt(now);
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CognitoCfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CognitoCfnProvisioner.java
index af30e7e887..9956522476 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CognitoCfnProvisioner.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CognitoCfnProvisioner.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.cloudformation.provisioners;
import com.fasterxml.jackson.databind.JsonNode;
+import io.github.hectorvent.floci.core.common.AwsEndpoints;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.cognito.CognitoService;
@@ -193,7 +194,7 @@ public class CognitoCfnProvisioner implements CfnResourceProvisioner {
// ProviderName is what a template feeds into an identity pool's CognitoIdentityProviders,
// cognito-idp.<region>.amazonaws.com/<pool id> on AWS. ProviderURL stays the issuer Floci
// mints tokens with, so a template wiring it into a JWT authorizer validates locally.
- r.getAttributes().put("ProviderName", "cognito-idp." + ctx.region() + ".amazonaws.com/" + pool.getId());
+ r.getAttributes().put("ProviderName", AwsEndpoints.host("cognito-idp", ctx.region()) + "/" + pool.getId());
r.getAttributes().put("ProviderURL", cognitoService.getIssuer(pool.getId()));
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/S3CfnProvisioner.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/S3CfnProvisioner.java
index dc8109a37e..80932ce678 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/S3CfnProvisioner.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/S3CfnProvisioner.java
@@ -2,8 +2,10 @@ package io.github.hectorvent.floci.services.cloudformation.provisioners;
import com.fasterxml.jackson.databind.JsonNode;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsEndpoints;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsNamespaces;
+import io.github.hectorvent.floci.core.common.AwsPartitions;
import io.github.hectorvent.floci.core.common.XmlBuilder;
import io.github.hectorvent.floci.services.cloudformation.model.StackResource;
import io.github.hectorvent.floci.services.s3.S3Service;
@@ -85,12 +87,15 @@ public class S3CfnProvisioner implements CfnResourceProvisioner {
applyBucketTags(bucketName, props, ctx);
r.setPhysicalId(bucketName);
r.getAttributes().put("Arn", AwsArnUtils.Arn.of("s3", "", "", bucketName).toString());
- r.getAttributes().put("DomainName", bucketName + ".s3.amazonaws.com");
- r.getAttributes().put("RegionalDomainName", bucketName + ".s3." + ctx.region() + ".amazonaws.com");
- r.getAttributes().put("DualStackDomainName",
- bucketName + ".s3.dualstack." + ctx.region() + ".amazonaws.com");
- r.getAttributes().put("WebsiteURL",
- "http://" + bucketName + ".s3-website." + ctx.region() + ".amazonaws.com");
+ r.getAttributes().put("DomainName", AwsEndpoints.s3Host(bucketName, ctx.region()));
+ r.getAttributes().put("RegionalDomainName", AwsEndpoints.s3RegionalHost(bucketName, ctx.region()));
+ if (AwsPartitions.forRegionOrCommercial(ctx.region()).supportsS3DualStack(ctx.region())) {
+ r.getAttributes().put("DualStackDomainName", AwsEndpoints.s3DualStackHost(bucketName, ctx.region()));
+ } else {
+ // An update arrives with the prior attributes already on the resource.
+ r.getAttributes().remove("DualStackDomainName");
+ }
+ r.getAttributes().put("WebsiteURL", AwsEndpoints.s3WebsiteUrl(bucketName, ctx.region()));
r.getAttributes().put("BucketName", bucketName);
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontRequestRouter.java b/src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontRequestRouter.java
index 8cf632351f..8e169eb338 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontRequestRouter.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontRequestRouter.java
@@ -1,5 +1,6 @@
package io.github.hectorvent.floci.services.cloudfront;
+import io.github.hectorvent.floci.core.common.AwsPartitions;
import io.github.hectorvent.floci.services.cloudfront.model.CacheBehavior;
import io.github.hectorvent.floci.services.cloudfront.model.DefaultCacheBehavior;
import io.github.hectorvent.floci.services.cloudfront.model.DistributionConfig;
@@ -36,10 +37,10 @@ public final class CloudFrontRequestRouter {
private static final int PATTERN_CACHE_CAPACITY = 256;
private static final String REGION_PATTERN = "[a-z0-9-]+-[0-9]+";
private static final Pattern AWS_S3_ENDPOINT = Pattern.compile(
- "(?:s3|s3\\.(?:dualstack\\.)?" + REGION_PATTERN
+ "(?:s3|s3(?:-fips)?\\.(?:dualstack\\.)?" + REGION_PATTERN
+ "|s3-" + REGION_PATTERN
+ "|s3-website[.-]" + REGION_PATTERN
- + "|s3-accelerate(?:\\.dualstack)?)\\.amazonaws\\.com(?:\\.cn)?");
+ + "|s3-accelerate(?:\\.dualstack)?)\\." + AwsPartitions.dnsSuffixRegex());
private static final Pattern LOCAL_S3_ENDPOINT = Pattern.compile(
"(?:s3(?:\\." + REGION_PATTERN + ")?"
+ "|s3-website[.-]" + REGION_PATTERN
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailService.java b/src/main/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailService.java
index 0ed6848c15..b83a984cf1 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailService.java
@@ -6,7 +6,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsEndpoints;
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.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
@@ -356,7 +358,7 @@ public class CloudTrailService {
if (matched.isEmpty()) {
return;
}
- ObjectNode record = buildS3Record(in);
+ ObjectNode record = buildS3Record(in, region);
for (MatchedTrail mt : matched) {
ObjectNode copy = record.deepCopy();
copy.put("recipientAccountId", regionResolver.getAccountId());
@@ -784,7 +786,16 @@ public class CloudTrailService {
};
}
- private ObjectNode buildS3Record(S3EventInput in) {
+ /**
+ * {@code region} is the event's region, resolved by the caller. Hosts and ARNs are built from it
+ * rather than from the request scope, because the log writer emits its own deliveries from the
+ * flush thread, where the request region falls back to the deployment default.
+ */
+ private ObjectNode buildS3Record(S3EventInput in, String region) {
+ String s3Host = in.bucketName() == null
+ ? "s3." + AwsRegions.dnsSuffixFor(region)
+ : AwsEndpoints.s3Host(in.bucketName(), region);
+ String partition = AwsRegions.partitionFor(region);
ObjectNode record = mapper.createObjectNode();
record.put("eventVersion", EVENT_VERSION);
record.set("userIdentity", buildUserIdentity(in.accessKeyId()));
@@ -794,7 +805,7 @@ public class CloudTrailService {
.truncatedTo(java.time.temporal.ChronoUnit.SECONDS)));
record.put("eventSource", S3_EVENT_SOURCE);
record.put("eventName", in.eventName());
- record.put("awsRegion", in.region());
+ record.put("awsRegion", region);
record.put("sourceIPAddress", in.sourceIp() == null ? "127.0.0.1" : in.sourceIp());
record.put("userAgent", in.userAgent() == null ? "" : in.userAgent());
@@ -807,9 +818,7 @@ public class CloudTrailService {
ObjectNode reqParams = mapper.createObjectNode();
if (in.bucketName() != null) reqParams.put("bucketName", in.bucketName());
- reqParams.put("Host", in.bucketName() == null
- ? "s3.amazonaws.com"
- : in.bucketName() + ".s3.amazonaws.com");
+ reqParams.put("Host", s3Host);
if (in.key() != null) reqParams.put("key", in.key());
record.set("requestParameters", reqParams);
record.set("responseElements", mapper.nullNode());
@@ -831,12 +840,13 @@ public class CloudTrailService {
ObjectNode bucketRes = mapper.createObjectNode();
bucketRes.put("accountId", regionResolver.getAccountId());
bucketRes.put("type", "AWS::S3::Bucket");
- bucketRes.put("ARN", regionResolver.buildGlobalArn("s3", "", in.bucketName()));
+ bucketRes.put("ARN", AwsArnUtils.Arn.global(partition, "s3", "", in.bucketName()).toString());
resources.add(bucketRes);
if (in.key() != null) {
ObjectNode objRes = mapper.createObjectNode();
objRes.put("type", "AWS::S3::Object");
- objRes.put("ARN", regionResolver.buildGlobalArn("s3", "", in.bucketName() + "/" + in.key()));
+ objRes.put("ARN",
+ AwsArnUtils.Arn.global(partition, "s3", "", in.bucketName() + "/" + in.key()).toString());
resources.add(objRes);
}
record.set("resources", resources);
@@ -849,9 +859,7 @@ public class CloudTrailService {
ObjectNode tls = mapper.createObjectNode();
tls.put("tlsVersion", "TLSv1.3");
tls.put("cipherSuite", "TLS_AES_128_GCM_SHA256");
- tls.put("clientProvidedHostHeader", in.bucketName() == null
- ? "s3.amazonaws.com"
- : in.bucketName() + ".s3.amazonaws.com");
+ tls.put("clientProvidedHostHeader", s3Host);
record.set("tlsDetails", tls);
return record;
diff --git a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java
index d9072d61b0..d6d0869eef 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java
@@ -90,6 +90,11 @@ 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}.
+ */
+ private static final String DEFAULT_CLOUDFRONT_DOMAIN_SUFFIX = "cloudfront.net"; // partition-literal: test-shaped constructor default
private static final Logger LOG = Logger.getLogger(CognitoService.class);
private static final ObjectMapper MAPPER = new ObjectMapper();
@@ -130,6 +135,7 @@ public class CognitoService implements ResourceProvider {
private final StorageBackend<String, CognitoGroup> groupStore;
private final StorageBackend<String, RevokedTokenInfo> revokedTokenStore;
private final String baseUrl;
+ private final String cloudFrontDomainSuffix;
private final RegionResolver regionResolver;
private final LambdaService lambdaService;
private final AcmService acmService;
@@ -177,6 +183,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(),
regionResolver,
lambdaService,
acmService,
@@ -196,9 +203,42 @@ public class CognitoService implements ResourceProvider {
RegionResolver regionResolver,
LambdaService lambdaService,
AcmService acmService) {
+ this(poolStore, clientStore, resourceServerStore, userStore, groupStore, revokedTokenStore, baseUrl,
+ DEFAULT_CLOUDFRONT_DOMAIN_SUFFIX, regionResolver, lambdaService, acmService);
+ }
+
+ CognitoService(StorageBackend<String, UserPool> poolStore,
+ StorageBackend<String, UserPoolClient> clientStore,
+ StorageBackend<String, ResourceServer> resourceServerStore,
+ StorageBackend<String, UserPoolDomain> domainStore,
+ StorageBackend<String, IdentityProvider> identityProviderStore,
+ StorageBackend<String, CognitoUser> userStore,
+ StorageBackend<String, CognitoGroup> groupStore,
+ StorageBackend<String, RevokedTokenInfo> revokedTokenStore,
+ String baseUrl,
+ RegionResolver regionResolver, LambdaService lambdaService, AcmService acmService,
+ VerificationCodeService verificationCodeService,
+ CognitoMessageDispatcher messageDispatcher,
+ TlsCertificateManager certificateManager) {
+ this(poolStore, clientStore, resourceServerStore, domainStore, identityProviderStore, userStore,
+ groupStore, revokedTokenStore, baseUrl, DEFAULT_CLOUDFRONT_DOMAIN_SUFFIX, regionResolver,
+ lambdaService, acmService, verificationCodeService, messageDispatcher, certificateManager);
+ }
+
+ CognitoService(StorageBackend<String, UserPool> poolStore,
+ StorageBackend<String, UserPoolClient> clientStore,
+ StorageBackend<String, ResourceServer> resourceServerStore,
+ StorageBackend<String, CognitoUser> userStore,
+ StorageBackend<String, CognitoGroup> groupStore,
+ StorageBackend<String, RevokedTokenInfo> revokedTokenStore,
+ String baseUrl,
+ String cloudFrontDomainSuffix,
+ RegionResolver regionResolver,
+ LambdaService lambdaService,
+ AcmService acmService) {
this(poolStore, clientStore, resourceServerStore, new InMemoryStorage<>(),
new InMemoryStorage<>(), userStore, groupStore, revokedTokenStore, baseUrl,
- regionResolver, lambdaService, acmService, null, null, null);
+ cloudFrontDomainSuffix, regionResolver, lambdaService, acmService, null, null, null);
}
CognitoService(StorageBackend<String, UserPool> poolStore,
@@ -210,6 +250,7 @@ public class CognitoService implements ResourceProvider {
StorageBackend<String, CognitoGroup> groupStore,
StorageBackend<String, RevokedTokenInfo> revokedTokenStore,
String baseUrl,
+ String cloudFrontDomainSuffix,
RegionResolver regionResolver, LambdaService lambdaService, AcmService acmService,
VerificationCodeService verificationCodeService,
CognitoMessageDispatcher messageDispatcher,
@@ -223,6 +264,7 @@ public class CognitoService implements ResourceProvider {
this.groupStore = groupStore;
this.revokedTokenStore = revokedTokenStore;
this.baseUrl = baseUrl;
+ this.cloudFrontDomainSuffix = cloudFrontDomainSuffix;
this.regionResolver = regionResolver;
this.lambdaService = lambdaService;
this.acmService = acmService;
@@ -1464,7 +1506,7 @@ public class CognitoService implements ResourceProvider {
}
private String generateCloudFrontDomain() {
- return UUID.randomUUID().toString().replace("-", "").substring(0, 14) + ".cloudfront.net";
+ return UUID.randomUUID().toString().replace("-", "").substring(0, 14) + "." + cloudFrontDomainSuffix;
}
private String generateDomainVersion() {
diff --git a/src/main/java/io/github/hectorvent/floci/services/ecr/registry/EcrRegistryManager.java b/src/main/java/io/github/hectorvent/floci/services/ecr/registry/EcrRegistryManager.java
index 7e391d0d39..1ea88f0271 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ecr/registry/EcrRegistryManager.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ecr/registry/EcrRegistryManager.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.ecr.registry;
import io.github.hectorvent.floci.config.EmulatorConfig;
+import io.github.hectorvent.floci.core.common.AwsPartitions;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.docker.ContainerBuilder;
import io.github.hectorvent.floci.core.common.docker.ContainerDetector;
@@ -34,6 +35,8 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* Manages the lifecycle of the shared {@code registry:2} container that backs
@@ -54,9 +57,12 @@ public class EcrRegistryManager {
private static final String NAMED_VOLUME = "ecr-registry-data";
private static final String REPOSITORIES_PATH = "/var/lib/registry/docker/registry/v2/repositories/";
- /** Matches an AWS-shaped ECR image URI: {@code <account>.dkr.ecr.<region>.amazonaws.com/<repo>[:tag]}. */
- private static final java.util.regex.Pattern AWS_ECR_URI =
- java.util.regex.Pattern.compile("^([0-9]{12})\\.dkr\\.ecr\\.([a-z0-9-]+)\\.amazonaws\\.com/(.+)$");
+ /**
+ * Matches an AWS-shaped ECR image URI in any partition:
+ * {@code <account>.dkr.ecr.<region>.<dnsSuffix>/<repo>[:tag]}.
+ */
+ private static final Pattern AWS_ECR_URI = Pattern.compile(
+ "^([0-9]{12})\\.dkr\\.ecr\\.([a-z0-9-]+)\\." + AwsPartitions.dnsSuffixRegex() + "/(.+)$");
/**
* The container name actually in use. Differs from {@link #registryContainerName()} only when
@@ -115,7 +121,7 @@ public class EcrRegistryManager {
if (image == null) {
return null;
}
- java.util.regex.Matcher m = AWS_ECR_URI.matcher(image);
+ Matcher m = AWS_ECR_URI.matcher(image);
if (!m.matches()) {
return image;
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/eks/EksOidcService.java b/src/main/java/io/github/hectorvent/floci/services/eks/EksOidcService.java
index de5910e3f0..fb3f88cd42 100644
--- a/src/main/java/io/github/hectorvent/floci/services/eks/EksOidcService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/eks/EksOidcService.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsEndpoints;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.OidcIssuerKeyLookup;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
@@ -67,7 +68,7 @@ public class EksOidcService implements OidcIssuerKeyLookup {
*/
public String newIssuerUrl(String region) {
String id = UUID.randomUUID().toString().replace("-", "").toUpperCase();
- return "https://oidc.eks." + region + ".amazonaws.com/id/" + id;
+ return "https://" + AwsEndpoints.host("oidc.eks", region) + "/id/" + id;
}
/**
diff --git a/src/main/java/io/github/hectorvent/floci/services/emr/EmrHandler.java b/src/main/java/io/github/hectorvent/floci/services/emr/EmrHandler.java
index d6ab870853..29ca8b5d5b 100644
--- a/src/main/java/io/github/hectorvent/floci/services/emr/EmrHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/emr/EmrHandler.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.github.hectorvent.floci.core.common.AwsEndpoints;
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsJson11Controller;
@@ -462,7 +463,7 @@ public class EmrHandler {
ObjectNode node = objectMapper.createObjectNode();
node.put("Id", "ci-" + index + cluster.getId());
node.put("Ec2InstanceId", "i-" + String.format("%017d", index));
- node.put("PublicDnsName", "ec2-203-0-113-" + index + ".compute-1.amazonaws.com");
+ node.put("PublicDnsName", AwsEndpoints.ec2PublicDns("203.0.113." + index, cluster.getRegion()));
node.put("PrivateDnsName", "ip-10-0-0-" + index + ".ec2.internal");
node.put("PrivateIpAddress", "10.0.0." + index);
node.put("InstanceGroupId", group.getId());
diff --git a/src/main/java/io/github/hectorvent/floci/services/s3/S3VirtualHostFilter.java b/src/main/java/io/github/hectorvent/floci/services/s3/S3VirtualHostFilter.java
index 6f931f92aa..59bbf59a62 100644
--- a/src/main/java/io/github/hectorvent/floci/services/s3/S3VirtualHostFilter.java
+++ b/src/main/java/io/github/hectorvent/floci/services/s3/S3VirtualHostFilter.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.s3;
import io.github.hectorvent.floci.config.EmulatorConfig;
+import io.github.hectorvent.floci.core.common.AwsPartitions;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.RequestHost;
import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;
@@ -291,9 +292,12 @@ public class S3VirtualHostFilter implements ContainerRequestFilter {
return bucketFromPrefix(prefix, false);
}
- // Fallback: well-known AWS S3 domains, for users who route AWS DNS to Floci. An S3
- // qualifier is required here, so a plain foo.amazonaws.com is not an S3 bucket.
- String awsPrefix = stripHostSuffix(hostname, "amazonaws.com");
+ // Fallback: well-known AWS S3 domains in any partition, for users who route AWS DNS to
+ // Floci. Longest suffix first, so a China host keeps its .cn. An S3 qualifier is required
+ // here, so a plain foo.amazonaws.com is not an S3 bucket.
+ String awsPrefix = AwsPartitions.stripKnownDnsSuffix(hostname)
+ .map(AwsPartitions.DnsSuffixMatch::prefix)
+ .orElse(null);
if (awsPrefix != null) {
return bucketFromPrefix(awsPrefix, true);
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/verifiedpermissions/VerifiedPermissionsService.java b/src/main/java/io/github/hectorvent/floci/services/verifiedpermissions/VerifiedPermissionsService.java
index 66422dcc13..e53470003b 100644
--- a/src/main/java/io/github/hectorvent/floci/services/verifiedpermissions/VerifiedPermissionsService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/verifiedpermissions/VerifiedPermissionsService.java
@@ -6,6 +6,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
+import io.github.hectorvent.floci.core.common.AwsEndpoints;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
@@ -597,7 +598,7 @@ public class VerifiedPermissionsService implements Resettable {
throw validation("The Cognito user pool must be in the same Region as the policy store.");
}
String poolId = arnParts[5].substring("userpool/".length());
- cognito.put("issuer", "https://cognito-idp." + arnParts[3] + ".amazonaws.com/" + poolId);
+ cognito.put("issuer", "https://" + AwsEndpoints.host("cognito-idp", arnParts[3]) + "/" + poolId);
validateStringArray(cognito.get("clientIds"), "clientIds", 0, 1000);
JsonNode group = cognito.get("groupConfiguration");
if (group != null && !group.isNull()) {
diff --git a/src/main/java/io/github/hectorvent/floci/tools/ami/AmiImageTool.java b/src/main/java/io/github/hectorvent/floci/tools/ami/AmiImageTool.java
index 70e86fbd5a..68988ef543 100644
--- a/src/main/java/io/github/hectorvent/floci/tools/ami/AmiImageTool.java
+++ b/src/main/java/io/github/hectorvent/floci/tools/ami/AmiImageTool.java
@@ -252,7 +252,7 @@ public final class AmiImageTool {
"library/ubuntu:24.04",
"docker.io/ubuntu:24.04",
"docker.io/library/ubuntu:24.04",
- "public.ecr.aws/docker/library/ubuntu:24.04" -> true;
+ "public.ecr.aws/docker/library/ubuntu:24.04" -> true; // partition-literal: the AMI build tool pulls its base image from ECR Public
default -> false;
};
}
diff --git a/src/main/resources/aws/partitions.json b/src/main/resources/aws/partitions.json
index c9c372477b..f5d05cd159 100644
--- a/src/main/resources/aws/partitions.json
+++ b/src/main/resources/aws/partitions.json
@@ -638,7 +638,43 @@
"signingRegion": "us-east-1",
"regionalized": false
}
- }
+ },
+ "s3DualStackRegions": [
+ "af-south-1",
+ "ap-east-1",
+ "ap-east-2",
+ "ap-northeast-1",
+ "ap-northeast-2",
+ "ap-northeast-3",
+ "ap-south-1",
+ "ap-south-2",
+ "ap-southeast-1",
+ "ap-southeast-2",
+ "ap-southeast-3",
+ "ap-southeast-4",
+ "ap-southeast-5",
+ "ap-southeast-6",
+ "ap-southeast-7",
+ "ca-central-1",
+ "ca-west-1",
+ "eu-central-1",
+ "eu-central-2",
+ "eu-north-1",
+ "eu-south-1",
+ "eu-south-2",
+ "eu-west-1",
+ "eu-west-2",
+ "eu-west-3",
+ "il-central-1",
+ "me-central-1",
+ "me-south-1",
+ "mx-central-1",
+ "sa-east-1",
+ "us-east-1",
+ "us-east-2",
+ "us-west-1",
+ "us-west-2"
+ ]
},
{
"id": "aws-cn",
@@ -871,7 +907,11 @@
"signingRegion": "cn-north-1",
"regionalized": true
}
- }
+ },
+ "s3DualStackRegions": [
+ "cn-north-1",
+ "cn-northwest-1"
+ ]
},
{
"id": "aws-eusc",
@@ -1006,7 +1046,8 @@
"wafv2",
"xray"
],
- "globalServices": {}
+ "globalServices": {},
+ "s3DualStackRegions": []
},
{
"id": "aws-iso",
@@ -1171,7 +1212,11 @@
"signingRegion": "us-iso-east-1",
"regionalized": true
}
- }
+ },
+ "s3DualStackRegions": [
+ "us-iso-east-1",
+ "us-iso-west-1"
+ ]
},
{
"id": "aws-iso-b",
@@ -1328,7 +1373,10 @@
"signingRegion": "us-isob-east-1",
"regionalized": true
}
- }
+ },
+ "s3DualStackRegions": [
+ "us-isob-east-1"
+ ]
},
{
"id": "aws-iso-e",
@@ -1455,7 +1503,8 @@
"signingRegion": "eu-isoe-west-1",
"regionalized": false
}
- }
+ },
+ "s3DualStackRegions": []
},
{
"id": "aws-iso-f",
@@ -1613,7 +1662,8 @@
"signingRegion": "us-isof-south-1",
"regionalized": false
}
- }
+ },
+ "s3DualStackRegions": []
},
{
"id": "aws-us-gov",
@@ -1858,7 +1908,11 @@
"signingRegion": "us-gov-west-1",
"regionalized": true
}
- }
+ },
+ "s3DualStackRegions": [
+ "us-gov-east-1",
+ "us-gov-west-1"
+ ]
}
]
}
diff --git a/src/test/java/io/github/hectorvent/floci/core/common/AwsEndpointsTest.java b/src/test/java/io/github/hectorvent/floci/core/common/AwsEndpointsTest.java
new file mode 100644
index 0000000000..e51593bdb1
--- /dev/null
+++ b/src/test/java/io/github/hectorvent/floci/core/common/AwsEndpointsTest.java
@@ -0,0 +1,82 @@
+package io.github.hectorvent.floci.core.common;
+
+import io.github.hectorvent.floci.testing.PartitionMatrix;
+import io.github.hectorvent.floci.testing.PartitionMatrix.PartitionCase;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.CsvSource;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+/**
+ * The hostnames AWS-shaped response fields carry. The S3 website form and the EC2 public DNS
+ * name are the two shapes that are not a plain {@code service.region.suffix}, and both were
+ * wrong in the commercial partition before this helper existed.
+ */
+class AwsEndpointsTest {
+
+ @ParameterizedTest
+ @MethodSource("io.github.hectorvent.floci.testing.PartitionMatrix#cases")
+ void regionalHostsCarryThePartitionSuffix(PartitionCase partitionCase) {
+ String region = partitionCase.region();
+ PartitionMatrix.assertHostIn(partitionCase, AwsEndpoints.host("ec2", region));
+ assertEquals("ec2." + region + "." + partitionCase.dnsSuffix(), AwsEndpoints.host("ec2", region));
+ assertEquals("abc123.execute-api." + region + "." + partitionCase.dnsSuffix(),
+ AwsEndpoints.executeApiHost("abc123", region));
+ assertEquals("b.s3." + partitionCase.dnsSuffix(), AwsEndpoints.s3Host("b", region));
+ assertEquals("b.s3." + region + "." + partitionCase.dnsSuffix(), AwsEndpoints.s3RegionalHost("b", region));
+ assertEquals("b.s3.dualstack." + region + "." + partitionCase.dnsSuffix(), AwsEndpoints.s3DualStackHost("b", region));
+ }
+
+ /**
+ * The nine regions before the CDK's {@code RULE_S3_WEBSITE_REGIONAL_SUBDOMAIN} keep the
+ * dash form; everything after it uses the dot form. CloudFormation's own {@code WebsiteURL}
+ * example ends with a slash ({@code http://mystack-mybucket-kdwwxmddtr2g.s3-website-us-east-2.amazonaws.com/}).
+ */
+ @ParameterizedTest
+ @CsvSource({
+ "us-east-1, b.s3-website-us-east-1.amazonaws.com",
+ "eu-west-1, b.s3-website-eu-west-1.amazonaws.com",
+ "us-west-1, b.s3-website-us-west-1.amazonaws.com",
+ "ap-southeast-1, b.s3-website-ap-southeast-1.amazonaws.com",
+ "ap-northeast-1, b.s3-website-ap-northeast-1.amazonaws.com",
+ "us-gov-west-1, b.s3-website-us-gov-west-1.amazonaws.com",
+ "us-west-2, b.s3-website-us-west-2.amazonaws.com",
+ "sa-east-1, b.s3-website-sa-east-1.amazonaws.com",
+ "ap-southeast-2, b.s3-website-ap-southeast-2.amazonaws.com",
+ "us-east-2, b.s3-website.us-east-2.amazonaws.com",
+ "eu-central-1, b.s3-website.eu-central-1.amazonaws.com",
+ "us-gov-east-1, b.s3-website.us-gov-east-1.amazonaws.com",
+ "cn-north-1, b.s3-website.cn-north-1.amazonaws.com.cn",
+ "us-iso-east-1, b.s3-website.us-iso-east-1.c2s.ic.gov",
+ "xx-nowhere-9, b.s3-website.xx-nowhere-9.amazonaws.com"})
+ void s3WebsiteHostUsesTheDashFormOnlyForTheNineLegacyRegions(String region, String host) {
+ assertEquals(host, AwsEndpoints.s3WebsiteHost("b", region));
+ assertEquals("http://" + host + "/", AwsEndpoints.s3WebsiteUrl("b", region));
+ }
+
+ @ParameterizedTest
+ @CsvSource({
+ "us-east-1, ec2-203-0-113-7.compute-1.amazonaws.com",
+ "us-west-2, ec2-203-0-113-7.us-west-2.compute.amazonaws.com",
+ "us-gov-west-1, ec2-203-0-113-7.us-gov-west-1.compute.amazonaws.com",
+ "cn-north-1, ec2-203-0-113-7.cn-north-1.compute.amazonaws.com.cn",
+ "eusc-de-east-1, ec2-203-0-113-7.eusc-de-east-1.compute.amazonaws.eu"})
+ void ec2PublicDnsIsComputeOneOnlyInVirginia(String region, String expected) {
+ assertEquals(expected, AwsEndpoints.ec2PublicDns("203.0.113.7", region));
+ }
+
+ @Test
+ void s3DualStackAvailabilityFollowsEndpointsJson() {
+ assertEquals(true, AwsPartitions.commercial().supportsS3DualStack("us-east-1"));
+ assertEquals(true, AwsPartitions.byId("aws-cn").supportsS3DualStack("cn-north-1"));
+ assertEquals(true, AwsPartitions.byId("aws-iso").supportsS3DualStack("us-iso-east-1"));
+ assertEquals(true, AwsPartitions.byId("aws-iso-b").supportsS3DualStack("us-isob-east-1"));
+ assertEquals(false, AwsPartitions.byId("aws-iso-b").supportsS3DualStack("us-isob-west-1"));
+ assertEquals(false, AwsPartitions.byId("aws-iso-e").supportsS3DualStack("eu-isoe-west-1"));
+ assertEquals(false, AwsPartitions.byId("aws-iso-f").supportsS3DualStack("us-isof-south-1"));
+ assertEquals(false, AwsPartitions.byId("aws-eusc").supportsS3DualStack("eusc-de-east-1"));
+ assertEquals(false, AwsPartitions.commercial().supportsS3DualStack(null));
+ }
+}
diff --git a/src/test/java/io/github/hectorvent/floci/core/common/AwsPartitionsTest.java b/src/test/java/io/github/hectorvent/floci/core/common/AwsPartitionsTest.java
index 86de8f4ff4..f85427145a 100644
--- a/src/test/java/io/github/hectorvent/floci/core/common/AwsPartitionsTest.java
+++ b/src/test/java/io/github/hectorvent/floci/core/common/AwsPartitionsTest.java
@@ -14,6 +14,7 @@ import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Optional;
import java.util.Set;
+import java.util.regex.Pattern;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -218,6 +219,23 @@ class AwsPartitionsTest {
assertTrue(AwsPartitions.stripKnownDnsSuffix(host).isEmpty());
}
+ @Test
+ void dnsSuffixHelpersRecogniseEveryPublishedSuffix() {
+ assertTrue(AwsPartitions.isDnsSuffix("amazonaws.com"));
+ assertTrue(AwsPartitions.isDnsSuffix("AMAZONAWS.COM.CN"));
+ assertTrue(AwsPartitions.isDnsSuffix("api.aws"));
+ assertTrue(AwsPartitions.isDnsSuffix("c2s.ic.gov"));
+ assertFalse(AwsPartitions.isDnsSuffix("localhost"));
+ assertFalse(AwsPartitions.isDnsSuffix("s3.amazonaws.com"));
+ assertFalse(AwsPartitions.isDnsSuffix(null));
+ Pattern host = Pattern.compile("^bucket\\.s3\\." + AwsPartitions.dnsSuffixRegex() + "$");
+ assertTrue(host.matcher("bucket.s3.amazonaws.com").matches());
+ assertTrue(host.matcher("bucket.s3.amazonaws.com.cn").matches());
+ assertTrue(host.matcher("bucket.s3.csp.hci.ic.gov").matches());
+ assertFalse(host.matcher("bucket.s3.amazonaws.com.evil").matches());
+ assertFalse(host.matcher("bucket.s3.amazonawsXcom").matches(), "the suffix dots are quoted");
+ }
+
@Test
void aMalformedCatalogFailsLoudly() {
assertThrows(IllegalStateException.class, () -> AwsPartitions.parse(
diff --git a/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayDomainTlsServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayDomainTlsServiceTest.java
index 03c7e56f66..0d61bcd12f 100644
--- a/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayDomainTlsServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayDomainTlsServiceTest.java
@@ -19,6 +19,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
@@ -43,7 +44,9 @@ class ApiGatewayDomainTlsServiceTest {
StorageFactory storageFactory = mock(StorageFactory.class);
when(storageFactory.create(anyString(), anyString(), any())).thenAnswer(invocation -> AccountAwareStorageBackend.inMemory("000000000000"));
certificateManager = mock(TlsCertificateManager.class);
- service = new ApiGatewayService(storageFactory, mock(EmulatorConfig.class), certificateManager);
+ EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
+ when(config.services().cloudfront().domainSuffix()).thenReturn("cloudfront.net");
+ service = new ApiGatewayService(storageFactory, config, certificateManager);
}
private static Map<String, Object> regional(String domain) {
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/S3CfnProvisionerTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/S3CfnProvisionerTest.java
index 851d1b7f64..08873375af 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/S3CfnProvisionerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudformation/provisioners/S3CfnProvisionerTest.java
@@ -13,6 +13,7 @@ import org.mockito.ArgumentCaptor;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
@@ -28,6 +29,7 @@ class S3CfnProvisionerTest {
private static final ObjectMapper MAPPER = new ObjectMapper();
private static final String REGION = "us-east-1";
+ private static final String NO_DUAL_STACK_REGION = "eu-isoe-west-1";
private S3Service s3;
private S3CfnProvisioner provisioner;
@@ -82,7 +84,9 @@ class S3CfnProvisionerTest {
"DomainName", "my-bucket.s3.amazonaws.com",
"RegionalDomainName", "my-bucket.s3.us-east-1.amazonaws.com",
"DualStackDomainName", "my-bucket.s3.dualstack.us-east-1.amazonaws.com",
- "WebsiteURL", "http://my-bucket.s3-website.us-east-1.amazonaws.com",
+ // us-east-1 is one of the nine regions that keep the legacy dash form, and AWS's
+ // WebsiteURL ends with a slash (the AWS::S3::Bucket schema example).
+ "WebsiteURL", "http://my-bucket.s3-website-us-east-1.amazonaws.com/",
"BucketName", "my-bucket"), r.getAttributes());
}
@@ -121,6 +125,32 @@ class S3CfnProvisionerTest {
verify(s3).createBucket("renamed", REGION);
}
+ /** ISO-E publishes no S3 dual-stack endpoint, so the attribute is absent rather than invented. */
+ @Test
+ void aBucketInARegionWithoutS3DualStackHasNoDualStackDomainName() {
+ StackResource r = resource("Bucket", "AWS::S3::Bucket");
+ provisioner.provision(r, props("{\"BucketName\": \"my-bucket\"}"),
+ new ProvisionContext(ctx.engine(), NO_DUAL_STACK_REGION, "000000000000", "my-stack"));
+
+ assertEquals("my-bucket.s3.eu-isoe-west-1.cloud.adc-e.uk", r.getAttributes().get("RegionalDomainName"));
+ assertFalse(r.getAttributes().containsKey("DualStackDomainName"));
+ }
+
+ /**
+ * An update arrives with the prior attributes already on the resource, so a dual-stack host
+ * recorded before the region's availability was known has to be removed, not just not written.
+ */
+ @Test
+ void anUpdateInARegionWithoutS3DualStackDropsAStaleDualStackDomainName() {
+ StackResource r = resource("Bucket", "AWS::S3::Bucket");
+ r.setPhysicalId("my-bucket");
+ r.getAttributes().put("DualStackDomainName", "my-bucket.s3.dualstack.eu-isoe-west-1.cloud.adc-e.uk");
+ provisioner.provision(r, props("{\"BucketName\": \"my-bucket\"}"),
+ new ProvisionContext(ctx.engine(), NO_DUAL_STACK_REGION, "000000000000", "my-stack", "my-bucket"));
+
+ assertFalse(r.getAttributes().containsKey("DualStackDomainName"), "attributes: " + r.getAttributes());
+ }
+
@Test
void anUnnamedBucketGetsALowerCasedStackScopedName() {
StackResource r = provisionBucket("{}");
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontRequestRouterTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontRequestRouterTest.java
index 9f799a80e7..0222aa1f99 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontRequestRouterTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudfront/CloudFrontRequestRouterTest.java
@@ -225,6 +225,14 @@ class CloudFrontRequestRouterTest {
assertEquals("foo.s3-website-bar",
CloudFrontRequestRouter.bucketFromS3Domain(
"foo.s3-website-bar.s3.us-east-1.amazonaws.com"));
+ assertEquals("my-bucket",
+ CloudFrontRequestRouter.bucketFromS3Domain("my-bucket.s3.cn-north-1.amazonaws.com.cn"));
+ assertEquals("my-bucket",
+ CloudFrontRequestRouter.bucketFromS3Domain("my-bucket.s3.us-iso-east-1.c2s.ic.gov"));
+ assertEquals("my-bucket",
+ CloudFrontRequestRouter.bucketFromS3Domain("my-bucket.s3-fips.dualstack.us-gov-west-1.amazonaws.com"));
+ assertEquals("my-bucket",
+ CloudFrontRequestRouter.bucketFromS3Domain("my-bucket.s3-website.eusc-de-east-1.amazonaws.eu"));
assertNull(CloudFrontRequestRouter.bucketFromS3Domain("sensitive.attacker.invalid"));
assertNull(CloudFrontRequestRouter.bucketFromS3Domain("sensitive.s3.attacker.invalid"));
assertNull(CloudFrontRequestRouter.bucketFromS3Domain("sensitive.s3-attacker.invalid"));
diff --git a/src/test/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailSelfDeliveryTest.java b/src/test/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailSelfDeliveryTest.java
index 190ab20bc1..745be19885 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailSelfDeliveryTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailSelfDeliveryTest.java
@@ -2,11 +2,15 @@ package io.github.hectorvent.floci.services.cloudtrail;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
+import io.github.hectorvent.floci.testing.PartitionCleanup;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
+import io.github.hectorvent.floci.testutil.S3RequestSigner;
import io.quarkus.test.junit.QuarkusTest;
+import io.restassured.response.Response;
import jakarta.inject.Inject;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
@@ -15,6 +19,8 @@ import java.util.UUID;
import java.util.zip.GZIPInputStream;
import static io.restassured.RestAssured.given;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
@@ -34,23 +40,68 @@ class CloudTrailSelfDeliveryTest {
@Inject
CloudTrailLogWriter writer;
+ @RegisterExtension
+ final PartitionCleanup cleanup = new PartitionCleanup();
+
@Test
void trailWithBlanketSelectorCapturesItsOwnLogDeliveryAsDataEvent() throws Exception {
+ List<JsonNode> selfDeliveries = selfDeliveryPutRecords("us-east-1", "arn:aws:s3:::");
+
+ assertFalse(selfDeliveries.isEmpty(),
+ "Expected a PutObject record for the trail's own CloudTrail log delivery "
+ + "(self-referential / circular-logging reproduction) but found none");
+ }
+
+ /**
+ * The log writer emits its own deliveries from the flush thread, outside any request, so the
+ * record's hosts and ARNs must come from the event's region: a China trail's delivery names a
+ * China host and ARN, not the deployment default's.
+ */
+ @Test
+ void selfDeliveryRecordNamesTheEventRegionsHostAndPartition() throws Exception {
+ List<JsonNode> selfDeliveries = selfDeliveryPutRecords("cn-north-1", "arn:aws-cn:s3:::");
+
+ assertFalse(selfDeliveries.isEmpty(), "no self-delivery record in cn-north-1");
+ for (JsonNode record : selfDeliveries) {
+ assertEquals("cn-north-1", record.path("awsRegion").asText());
+ String bucket = record.path("requestParameters").path("bucketName").asText();
+ assertEquals(bucket + ".s3.amazonaws.com.cn", record.path("requestParameters").path("Host").asText());
+ assertEquals(bucket + ".s3.amazonaws.com.cn",
+ record.path("tlsDetails").path("clientProvidedHostHeader").asText());
+ for (JsonNode resource : record.path("resources")) {
+ assertTrue(resource.path("ARN").asText().startsWith("arn:aws-cn:s3:::" + bucket),
+ "resource ARN: " + resource);
+ }
+ }
+ }
+
+ /**
+ * Creates a trail in {@code region} whose blanket S3 data-event selector matches its own
+ * destination bucket (the pathological "before" config, uc-build-loop: s3DataEvents true, no
+ * exclusions), flushes twice, and returns the PutObject records that describe the trail's own
+ * log-file writes. Delivery #1 writes a log file into the bucket; under the fix that write is
+ * itself a matching PutObject, so delivery #2 carries a record of it.
+ */
+ private List<JsonNode> selfDeliveryPutRecords(String region, String selectorArnPrefix) throws Exception {
String suffix = UUID.randomUUID().toString().substring(0, 8);
String bucket = "loop-logs-" + suffix;
String trailName = "loop-trail-" + suffix;
+ S3RequestSigner s3 = S3RequestSigner.signedAs("test", "test").inRegion(region);
- createBucket(bucket);
+ createBucket(bucket, s3);
+ // Runs last: the emulator is shared, and a leftover bucket shows up in every later
+ // cross-region listing (ResourceExplorer scans all resources).
+ cleanup.register(() -> deleteBucketAndObjects(bucket, s3));
- invokeCloudTrail("CreateTrail", String.format("""
+ invokeCloudTrail(region, "CreateTrail", String.format("""
{"Name":"%s","S3BucketName":"%s"}
""", trailName, bucket))
.then().statusCode(200);
+ // Runs first, so the writer stops delivering into the bucket before it is emptied.
+ cleanup.register(() -> invokeCloudTrail(region, "DeleteTrail",
+ String.format("{\"Name\":\"%s\"}", trailName)).then().statusCode(200));
- // Blanket selector: every S3 object in every bucket, including the
- // trail's own delivery bucket. This is the pathological "before"
- // config (uc-build-loop): s3DataEvents true, no exclusions.
- invokeCloudTrail("PutEventSelectors", String.format("""
+ invokeCloudTrail(region, "PutEventSelectors", String.format("""
{
"TrailName": "%s",
"EventSelectors": [
@@ -58,90 +109,79 @@ class CloudTrailSelfDeliveryTest {
"ReadWriteType": "All",
"IncludeManagementEvents": false,
"DataResources": [
- {"Type": "AWS::S3::Object", "Values": ["arn:aws:s3:::"]}
+ {"Type": "AWS::S3::Object", "Values": ["%s"]}
]
}
]
}
- """, trailName))
+ """, trailName, selectorArnPrefix))
.then().statusCode(200);
- invokeCloudTrail("StartLogging",
+ invokeCloudTrail(region, "StartLogging",
String.format("{\"Name\":\"%s\"}", trailName))
.then().statusCode(200);
- // Seed one real data event so the first flush has something to
- // deliver.
- putObject(bucket, "seed.txt", "seed");
+ // Seed one real data event so the first flush has something to deliver.
+ putObject(bucket, "seed.txt", "seed", s3);
- // Delivery #1: writes a log file into `bucket`. Under the fix, that
- // write is itself a PutObject matching the blanket selector, so it
- // must be queued for delivery #2.
writer.flushNow();
-
- // Delivery #2: should contain a record describing delivery #1's own
- // log-file write, the self-referential loop.
writer.flushNow();
- List<String> keys = new ArrayList<>();
- for (String key : listKeys(bucket)) {
- if (key.contains("/CloudTrail/") && key.endsWith(".json.gz")) {
- keys.add(key);
- }
- }
- assertTrue(keys.size() >= 2,
- "Expected at least 2 delivered log files (seed delivery + self-referential delivery), got: "
- + keys);
-
- boolean sawSelfReferentialPut = false;
ObjectMapper mapper = new ObjectMapper();
- for (String key : keys) {
- byte[] gz = given().when().get("/" + bucket + "/" + key)
+ List<JsonNode> selfDeliveries = new ArrayList<>();
+ for (String key : listKeys(bucket, s3)) {
+ if (!key.contains("/CloudTrail/") || !key.endsWith(".json.gz")) {
+ continue;
+ }
+ byte[] gz = given().filter(s3).when().get("/" + bucket + "/" + key)
.then().statusCode(200).extract().asByteArray();
byte[] json;
try (GZIPInputStream gzin = new GZIPInputStream(new ByteArrayInputStream(gz))) {
json = gzin.readAllBytes();
}
- JsonNode records = mapper.readTree(json).get("Records");
- for (JsonNode rec : records) {
- String eventName = rec.path("eventName").asText();
- String recBucket = rec.path("requestParameters").path("bucketName").asText(null);
- String recKey = rec.path("requestParameters").path("key").asText("");
- if ("PutObject".equals(eventName) && bucket.equals(recBucket)
+ for (JsonNode record : mapper.readTree(json).get("Records")) {
+ String recBucket = record.path("requestParameters").path("bucketName").asText(null);
+ String recKey = record.path("requestParameters").path("key").asText("");
+ if ("PutObject".equals(record.path("eventName").asText()) && bucket.equals(recBucket)
&& recKey.contains("/CloudTrail/")) {
- sawSelfReferentialPut = true;
+ selfDeliveries.add(record);
}
}
}
-
- assertTrue(sawSelfReferentialPut,
- "Expected a PutObject record for the trail's own CloudTrail log delivery "
- + "(self-referential / circular-logging reproduction) but found none in "
- + keys.size() + " delivered files");
+ return selfDeliveries;
}
// --- Helpers ---
- private static io.restassured.response.Response invokeCloudTrail(String action, String body) {
+ private static Response invokeCloudTrail(String region, String action, String body) {
return given()
.header("X-Amz-Target", CT_TARGET + action)
+ .header("Authorization", "AWS4-HMAC-SHA256 Credential=test/20260101/" + region
+ + "/cloudtrail/aws4_request, SignedHeaders=host, Signature=abc")
.contentType(JSON11)
.body(body)
.when().post("/");
}
- private static void createBucket(String name) {
- given().when().put("/" + name).then().statusCode(200);
+ private static void createBucket(String name, S3RequestSigner signer) {
+ given().filter(signer).when().put("/" + name).then().statusCode(200);
}
- private static void putObject(String bucket, String key, String body) {
- given().body(body)
+ private static void putObject(String bucket, String key, String body, S3RequestSigner signer) {
+ given().filter(signer).body(body)
.when().put("/" + bucket + "/" + key)
.then().statusCode(200);
}
- private static List<String> listKeys(String bucket) {
- String xml = given().when().get("/" + bucket + "?list-type=2")
+ private static void deleteBucketAndObjects(String bucket, S3RequestSigner signer) {
+ for (String key : listKeys(bucket, signer)) {
+ given().filter(signer).when().delete("/" + bucket + "/" + key).then().statusCode(204);
+ }
+ given().filter(signer).when().delete("/" + bucket).then().statusCode(204);
+ }
+
+ private static List<String> listKeys(String bucket, S3RequestSigner signer) {
+ String xml = given().filter(signer).when().get("/" + bucket + "?list-type=2")
.then().statusCode(200).extract().asString();
List<String> keys = new ArrayList<>();
int from = 0;
diff --git a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoServiceTest.java b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoServiceTest.java
index 4e8c7bb11f..3dd8e09710 100644
--- a/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoServiceTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/cognito/CognitoServiceTest.java
@@ -82,6 +82,7 @@ class CognitoServiceTest {
groupStore,
revokedTokenStore,
"http://localhost:4566",
+ "cloudfront.net",
regionResolver,
null,
acmService
@@ -1798,6 +1799,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
+ "cloudfront.net",
regionResolver,
null,
acmService,
@@ -1838,6 +1840,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
+ "cloudfront.net",
regionResolver,
null,
acmService,
@@ -1959,6 +1962,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
+ "cloudfront.net",
regionResolver,
null,
acmService,
@@ -2022,6 +2026,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
+ "cloudfront.net",
regionResolver,
null,
acmService,
@@ -2132,6 +2137,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
+ "cloudfront.net",
regionResolver,
null,
acmService,
@@ -2660,6 +2666,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
+ "cloudfront.net",
regionResolver,
null,
acmService,
@@ -2715,6 +2722,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
+ "cloudfront.net",
regionResolver,
null,
acmService,
@@ -2772,6 +2780,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
+ "cloudfront.net",
regionResolver,
null,
acmService,
@@ -2824,6 +2833,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
+ "cloudfront.net",
regionResolver,
null,
acmService,
@@ -2865,6 +2875,7 @@ class CognitoServiceTest {
new InMemoryStorage<>(),
new InMemoryStorage<>(),
"http://localhost:4566",
+ "cloudfront.net",
regionResolver,
null,
acmService,
diff --git a/src/test/java/io/github/hectorvent/floci/services/ecr/registry/EcrRegistryManagerTest.java b/src/test/java/io/github/hectorvent/floci/services/ecr/registry/EcrRegistryManagerTest.java
index b51b25c824..9091b8fa00 100644
--- a/src/test/java/io/github/hectorvent/floci/services/ecr/registry/EcrRegistryManagerTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/ecr/registry/EcrRegistryManagerTest.java
@@ -346,6 +346,16 @@ class EcrRegistryManagerTest {
assertEquals("http://floci-aws-run-one-test-ecr-registry:5000", manager.httpClient().baseUrl());
}
+ @Test
+ void rewriteImageUri_matchesAChinaEcrUri_rewritesToLocalRegistry() {
+ when(lifecycleManager.createAndStart(any())).thenReturn(
+ new ContainerLifecycleManager.ContainerInfo("container-id", Map.of()));
+
+ String rewritten = manager.rewriteImageUri("123456789012.dkr.ecr.cn-north-1.amazonaws.com.cn/backend-user:1");
+
+ assertEquals("123456789012.dkr.ecr.cn-north-1.localhost:4566/backend-user:1", rewritten);
+ }
+
@Test
void rewriteImageUri_matchesAwsEcrUri_rewritesToLocalRegistryAndStartsIt() {
when(lifecycleManager.createAndStart(any())).thenReturn(
diff --git a/src/test/java/io/github/hectorvent/floci/services/resourceexplorer2/ResourceExplorer2IntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/resourceexplorer2/ResourceExplorer2IntegrationTest.java
index d5c144e9d1..0ecbe1f59d 100644
--- a/src/test/java/io/github/hectorvent/floci/services/resourceexplorer2/ResourceExplorer2IntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/resourceexplorer2/ResourceExplorer2IntegrationTest.java
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.resourceexplorer2;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsArnUtils.Arn;
+import io.github.hectorvent.floci.core.common.AwsPartitions;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
@@ -1507,8 +1508,13 @@ class ResourceExplorer2IntegrationTest {
String arn = (String) resource.get("Arn");
String service = (String) resource.get("Service");
Arn parsed = AwsArnUtils.parse(arn);
- assertEquals(AwsRegions.partitionFor(parsed.region()), parsed.partition(),
- "ARN partition must be the one its region belongs to, got: " + arn);
+ // A regionless ARN (an S3 bucket) is in the partition of the region the resource
+ // lives in, which the listing reports; a global one ("global") says nothing.
+ String region = parsed.region().isEmpty() ? (String) resource.get("Region") : parsed.region();
+ if (AwsPartitions.isPublishedRegion(region)) {
+ assertEquals(AwsRegions.partitionFor(region), parsed.partition(),
+ "ARN partition must be the one its region belongs to, got: " + arn);
+ }
assertTrue(arn.contains(service),
"ARN should contain service '" + service + "', got: " + arn);
}
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3PartitionBucketPolicyIamEnforcementIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3PartitionBucketPolicyIamEnforcementIntegrationTest.java
index f048af1c86..81254b1497 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3PartitionBucketPolicyIamEnforcementIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3PartitionBucketPolicyIamEnforcementIntegrationTest.java
@@ -131,7 +131,7 @@ class S3PartitionBucketPolicyIamEnforcementIntegrationTest {
.formParam("Action", action)
.header("Authorization", "AWS4-HMAC-SHA256 Credential=" + ACCOUNT
+ "/20260629/us-east-1/iam/aws4_request, SignedHeaders=host, Signature=abc");
- for (int i = 0; i < params.length; i += 2) {
+ for (int i = 0; i + 1 < params.length; i += 2) {
request = request.formParam(params[i], params[i + 1]);
}
return request.when().post("/").then().statusCode(200).extract();
diff --git a/src/test/java/io/github/hectorvent/floci/services/s3/S3VirtualHostFilterTest.java b/src/test/java/io/github/hectorvent/floci/services/s3/S3VirtualHostFilterTest.java
index 5894fd22c2..caac9fedc2 100644
--- a/src/test/java/io/github/hectorvent/floci/services/s3/S3VirtualHostFilterTest.java
+++ b/src/test/java/io/github/hectorvent/floci/services/s3/S3VirtualHostFilterTest.java
@@ -67,6 +67,12 @@ class S3VirtualHostFilterTest {
"my-bucket.s3.amazonaws.com:443, localhost, my-bucket",
"my-bucket.s3.us-east-1.amazonaws.com, localhost, my-bucket",
"my-bucket.s3.eu-west-1.amazonaws.com:443, localhost, my-bucket",
+ // The same in every other partition: the longest published suffix wins, so .cn survives
+ "my-bucket.s3.cn-north-1.amazonaws.com.cn, localhost, my-bucket",
+ "my-bucket.s3.amazonaws.com.cn, localhost, my-bucket",
+ "my-bucket.s3.us-gov-west-1.amazonaws.com, localhost, my-bucket",
+ "my-bucket.s3.us-iso-east-1.c2s.ic.gov, localhost, my-bucket",
+ "my-bucket.s3.eusc-de-east-1.amazonaws.eu, localhost, my-bucket",
// LocalStack-compatible domains (*.localhost.localstack.cloud resolves to 127.0.0.1 via public DNS)
"my-bucket.s3.localhost.localstack.cloud, localhost, my-bucket",
"my-bucket.s3.localhost.localstack.cloud:4566, localhost, my-bucket",
diff --git a/tools/aws/regen_partitions.py b/tools/aws/regen_partitions.py
index 4a83113ccb..1be86167b8 100644
--- a/tools/aws/regen_partitions.py
+++ b/tools/aws/regen_partitions.py
@@ -12,6 +12,9 @@ from two sources and a rule:
the `local/aws/botocore` checkout (the reference corpus everything else in this repo is
grounded on), then the installed `botocore` package, which `requirements.txt` pins to the
version the vendored file was generated from so CI regenerates the same bytes.
+- `s3DualStackRegions` per partition: the regions whose S3 endpoint publishes a `dualstack`
+ variant in `endpoints.json` (the service defaults cover every region in the commercial, China
+ and GovCloud partitions; the ISO partitions list them per region and the EUSC one has none).
- The AWS CDK's `region-info/lib/aws-entities.ts` (Apache-2.0), whose ordered region list
carries two rule markers: regions before `RULE_S3_WEBSITE_REGIONAL_SUBDOMAIN` use the
legacy `s3-website-<region>` endpoint form, and commercial regions after
@@ -164,6 +167,12 @@ def build(partitions_doc: dict, endpoints_doc: dict, entities: list[str] | None,
"s3WebsiteDashForm": dash,
})
services = endpoints_partition.get("services", {})
+ s3 = services.get("s3", {})
+ s3_defaults_dualstack = any("dualstack" in v.get("tags", []) for v in s3.get("defaults", {}).get("variants", []))
+ s3_dualstack_regions = sorted(
+ region_id for region_id, endpoint in s3.get("endpoints", {}).items()
+ if region_id in descriptions and (s3_defaults_dualstack
+ or any("dualstack" in v.get("tags", []) for v in endpoint.get("variants", []))))
global_services = {}
for service_key in sorted(services):
service = services[service_key]
@@ -195,6 +204,7 @@ def build(partitions_doc: dict, endpoints_doc: dict, entities: list[str] | None,
"regions": regions,
"services": sorted(services),
"globalServices": global_services,
+ "s3DualStackRegions": s3_dualstack_regions,
})
result_partitions.sort(key=lambda p: (p["id"] != COMMERCIAL, p["id"]))
return {
diff --git a/tools/aws/test_regen_partitions.py b/tools/aws/test_regen_partitions.py
index 31d083e6fe..e08d4c5c4c 100644
--- a/tools/aws/test_regen_partitions.py
+++ b/tools/aws/test_regen_partitions.py
@@ -84,6 +84,8 @@ ENDPOINTS = {
"nohost": {"endpoints": {"aws-global": {"credentialScope": {"region": "us-east-1"}}},
"isRegionalized": False, "partitionEndpoint": "aws-global"},
"sqs": {"endpoints": {"us-east-1": {}}},
+ "s3": {"defaults": {"variants": [{"hostname": "{service}.dualstack.{region}.{dnsSuffix}", "tags": ["dualstack"]}]},
+ "endpoints": {"us-east-1": {}, "eu-north-1": {}, "aws-global": {"hostname": "s3.amazonaws.com"}}},
},
},
{
@@ -98,6 +100,8 @@ ENDPOINTS = {
"hostname": "iam.cn-north-1.amazonaws.com.cn"}},
"isRegionalized": False, "partitionEndpoint": "aws-cn-global"},
"sqs": {"endpoints": {"cn-north-1": {}}},
+ "s3": {"endpoints": {"cn-north-1": {"variants": [{"hostname": "s3.dualstack.cn-north-1.amazonaws.com.cn", "tags": ["dualstack"]}]},
+ "cn-northwest-1": {}}},
},
},
{
@@ -177,7 +181,14 @@ def test_build_carries_partition_outputs_and_names():
assert cn["implicitGlobalRegion"] == "cn-northwest-1"
assert cn["regionRegex"] == "^cn\\-\\w+\\-\\d+$"
assert cn["supportsDualStack"] is True and cn["supportsFips"] is True
- assert cn["services"] == ["iam", "sqs"]
+ assert cn["services"] == ["iam", "s3", "sqs"]
+
+
+def test_build_lists_the_regions_with_an_s3_dualstack_variant():
+ document = r.build(PARTITIONS, ENDPOINTS, r.parse_cdk_entities(ENTITIES), None, "test")
+ assert by_id(document, "aws")["s3DualStackRegions"] == ["eu-north-1", "us-east-1"]
+ assert by_id(document, "aws-cn")["s3DualStackRegions"] == ["cn-north-1"]
+ assert by_id(document, "aws-eusc")["s3DualStackRegions"] == []
def test_build_derives_global_services_from_partition_endpoint():
diff --git a/tools/partition/baseline.tsv b/tools/partition/baseline.tsv
index d118070ae4..41ca8099a0 100644
--- a/tools/partition/baseline.tsv
+++ b/tools/partition/baseline.tsv
@@ -3,32 +3,17 @@
arn-literal src/main/java/io/github/hectorvent/floci/services/iam/AwsManagedPolicies.java 1
arn-literal src/main/java/io/github/hectorvent/floci/services/kinesisanalytics/container/FlinkContainerManager.java 1
arn-literal src/main/java/io/github/hectorvent/floci/services/rds/proxy/RdsSigV4Validator.java 1
-dns-suffix src/main/java/io/github/hectorvent/floci/config/EmulatorConfig.java 2
-dns-suffix src/main/java/io/github/hectorvent/floci/core/common/AwsRegions.java 1
dns-suffix src/main/java/io/github/hectorvent/floci/services/account/AccountService.java 1
-dns-suffix src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayExecuteApiHostFilter.java 1
-dns-suffix src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayExecuteController.java 4
-dns-suffix src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayService.java 1
-dns-suffix src/main/java/io/github/hectorvent/floci/services/apigatewayv2/ApiGatewayV2Service.java 2
-dns-suffix src/main/java/io/github/hectorvent/floci/services/apigatewayv2/websocket/WebSocketProxyEventBuilder.java 1
dns-suffix src/main/java/io/github/hectorvent/floci/services/applicationautoscaling/ApplicationAutoScalingService.java 1
-dns-suffix src/main/java/io/github/hectorvent/floci/services/appsync/AppSyncService.java 1
-dns-suffix src/main/java/io/github/hectorvent/floci/services/aps/ApsService.java 1
-dns-suffix src/main/java/io/github/hectorvent/floci/services/bedrockagentcorecontrol/BedrockAgentCoreCredentialProviderService.java 1
-dns-suffix src/main/java/io/github/hectorvent/floci/services/bedrockagentcorecontrol/BedrockAgentCoreGatewayService.java 1
dns-suffix src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java 1
dns-suffix src/main/java/io/github/hectorvent/floci/services/cloudformation/SamTransformProcessor.java 4
dns-suffix src/main/java/io/github/hectorvent/floci/services/cloudformation/StackSetService.java 1
-dns-suffix src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/CognitoCfnProvisioner.java 1
-dns-suffix src/main/java/io/github/hectorvent/floci/services/cloudformation/provisioners/S3CfnProvisioner.java 4
dns-suffix src/main/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailLogWriter.java 1
-dns-suffix src/main/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailService.java 5
-dns-suffix src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java 1
+dns-suffix src/main/java/io/github/hectorvent/floci/services/cloudtrail/CloudTrailService.java 1
dns-suffix src/main/java/io/github/hectorvent/floci/services/connect/ConnectService.java 1
-dns-suffix src/main/java/io/github/hectorvent/floci/services/eks/EksOidcService.java 2
+dns-suffix src/main/java/io/github/hectorvent/floci/services/eks/EksOidcService.java 1
dns-suffix src/main/java/io/github/hectorvent/floci/services/eks/EksPodIdentityCredentialsController.java 1
dns-suffix src/main/java/io/github/hectorvent/floci/services/eks/EksPodIdentityWebhook.java 2
-dns-suffix src/main/java/io/github/hectorvent/floci/services/emr/EmrHandler.java 1
dns-suffix src/main/java/io/github/hectorvent/floci/services/guardduty/GuardDutyService.java 1
dns-suffix src/main/java/io/github/hectorvent/floci/services/iam/IamService.java 6
dns-suffix src/main/java/io/github/hectorvent/floci/services/iam/SAMLAssertionVerifier.java 1
@@ -37,11 +22,8 @@ dns-suffix src/main/java/io/github/hectorvent/floci/services/macie2/MacieControl
dns-suffix src/main/java/io/github/hectorvent/floci/services/ram/RamController.java 2
dns-suffix src/main/java/io/github/hectorvent/floci/services/redshift/proxy/S3CopySimulator.java 2
dns-suffix src/main/java/io/github/hectorvent/floci/services/s3/S3Service.java 1
-dns-suffix src/main/java/io/github/hectorvent/floci/services/s3/S3VirtualHostFilter.java 1
dns-suffix src/main/java/io/github/hectorvent/floci/services/signin/SigninService.java 1
dns-suffix src/main/java/io/github/hectorvent/floci/services/ssoportal/SsoPortalService.java 1
-dns-suffix src/main/java/io/github/hectorvent/floci/services/verifiedpermissions/VerifiedPermissionsService.java 1
-dns-suffix src/main/java/io/github/hectorvent/floci/tools/ami/AmiImageTool.java 1
hosted-zone-id src/main/java/io/github/hectorvent/floci/services/apigateway/ApiGatewayService.java 2
hosted-zone-id src/main/java/io/github/hectorvent/floci/services/elb/ElbClassicService.java 1
hosted-zone-id src/main/java/io/github/hectorvent/floci/services/elbv2/ElbV2Service.java 1