mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(core): vendor the per-region hosted zones, SAML URLs and VPC endpoint prefixes (#4545)
* feat(core): vendor the per-region hosted zones, SAML URLs and VPC endpoint prefixes tools/aws/regen_region_facts.py transcribes the per-region and per-partition constants AWS publishes only as prose tables into src/main/resources/aws/region-facts.json: the Terraform provider's load balancer and S3 website hosted-zone maps, the CloudFront hosted zone per partition (cross-checked against the CDK), and the CDK's SAML sign-on URLs and VPC endpoint service-name exceptions. AwsRegionFacts serves them, as Optionals where a partition publishes nothing (the ISO and EUSC partitions have no hosted zones). make aws-data-check regenerates and compares where the local reference checkouts exist, and verifies the file's shape where they do not. Behaviour this changes: network load balancers report their own hosted zone per region instead of the Application one, Classic and Application load balancers report their region's zone, API Gateway EDGE domains carry the CloudFront zone of their partition, SAML assertions are checked against the sign-on URL of the provider's partition, and the AWS-managed S3 and DynamoDB prefix lists carry the partition's service-name prefix. Also carries the follow-ups from the #4494 review: bucketRegionForCreate cites the S3 model for the us-east-1 rules, docs/services/s3.md gains a Bucket Regions section, and the Marketplace files are gated per line with stated reasons instead of being allowlisted by path, so a new region literal there is caught. Part of #4272 * fix(core): harden the region facts against restarts, partitions without CloudFront, and CI without sources The source-free data check rejected real twelve-character hosted zone ids such as ap-southeast-1's NLB zone ZKVM4W9LS7TM, which failed the vendored-data job. It now accepts Route 53's id length range and checks substance: every partition has an entry whose VPC endpoint prefix is its reversed DNS suffix, every region is published in partitions.json, SAML URLs are https sign-on URLs, and unknown fields are refused. Load balancers restored from storage take the hosted zone of their region and type again, so balancers stored before the per-region lookup stop reporting the old fixed zone. An EDGE API Gateway custom domain is refused where the partition has no CloudFront, since it would have no distribution zone to alias to. A customer prefix list may not take the prefix of the AWS-managed lists its region carries, cn.com.amazonaws. in China. The partitions doc now says which ISO hosted zones exist. * fix(core): hold only a changed endpoint type to the partition, and name malformed region facts UpdateDomainName checked the partition for EDGE on every patch, so an EDGE custom domain stored in GovCloud before the rule could no longer take a certificate or security-policy update; only a patch that changes the endpoint type is held to the partition now. The source-free region-facts check reports a partition or region entry that is not an object by name instead of failing with a traceback, and its test asserts on computed results rather than on calls that write the fixture. * fix(core): keep gateway endpoint names on com.amazonaws, allow EDGE only in the commercial partition, and keep SAML working where no sign-on URL is published The AWS-managed prefix lists belong to the S3 and DynamoDB gateway endpoints, which the CDK names com.amazonaws.<region>.<service> in every partition (GatewayVpcEndpointAwsService); the reversed-suffix table applies to interface endpoints only. The managed lists are back to that name and the cn.com.amazonaws. reservation is gone; DescribeVpcEndpointServices now names the interface services through the table instead, keeping the S3 gateway entry on com.amazonaws. Edge-optimized API Gateway exists only in the commercial partition: China has CloudFront but no edge-optimized APIs or domains (its API Gateway documentation says so), so EDGE custom domains are refused everywhere else. Where the CDK publishes no SAML sign-on URL (aws-iso-e, aws-iso-f, aws-eusc) assertions keep being checked against the commercial URL, as every partition was before, instead of all being refused. applyEndpointType has its javadoc back.
This commit is contained in:
1 parent
0a786207d6
commit
833a43bfa7
33 files changed
+1738
-68
No files matched your search
@@ -0,0 +1,141 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The per-region and per-partition constants AWS publishes only as prose tables, vendored in
|
||||
* {@code aws/region-facts.json} by {@code tools/aws/regen_region_facts.py} from the Terraform
|
||||
* provider and the CDK: load balancer and S3 website hosted zone ids, the CloudFront hosted
|
||||
* zone per partition, the SAML sign-on URL per partition and the VPC endpoint service-name
|
||||
* prefixes. Every accessor is {@link Optional}: the ISO and EUSC partitions have no published
|
||||
* hosted zones, and a service that needs one there has nothing faithful to answer.
|
||||
*/
|
||||
public final class AwsRegionFacts {
|
||||
|
||||
static final String RESOURCE_NAME = "aws/region-facts.json";
|
||||
private static final String DEFAULT_VPC_ENDPOINT_PREFIX = "com.amazonaws";
|
||||
|
||||
private static final class Holder {
|
||||
static final JsonNode FACTS = load();
|
||||
}
|
||||
|
||||
private AwsRegionFacts() {
|
||||
}
|
||||
|
||||
/** Classic load balancers share the Application load balancer hosted zone. */
|
||||
public static Optional<String> classicElbHostedZoneId(String region) {
|
||||
return regionText(region, "classicElbHostedZoneId");
|
||||
}
|
||||
|
||||
public static Optional<String> albHostedZoneId(String region) {
|
||||
return regionText(region, "albHostedZoneId");
|
||||
}
|
||||
|
||||
/** Network load balancers have their own hosted zone in every region, distinct from the ALB one. */
|
||||
public static Optional<String> nlbHostedZoneId(String region) {
|
||||
return regionText(region, "nlbHostedZoneId");
|
||||
}
|
||||
|
||||
public static Optional<String> s3WebsiteHostedZoneId(String region) {
|
||||
return regionText(region, "s3WebsiteHostedZoneId");
|
||||
}
|
||||
|
||||
/** Published for {@code aws} and {@code aws-cn} only, where CloudFront exists. */
|
||||
public static Optional<String> cloudFrontHostedZoneId(String partition) {
|
||||
return partitionText(partition, "cloudfrontHostedZoneId");
|
||||
}
|
||||
|
||||
/** The console's SAML endpoint; absent for {@code aws-iso-e}, {@code aws-iso-f} and {@code aws-eusc}. */
|
||||
public static Optional<String> samlSignOnUrl(String partition) {
|
||||
return partitionText(partition, "samlSignOnUrl");
|
||||
}
|
||||
|
||||
/** {@code com.amazonaws.vpce}, {@code cn.com.amazonaws.vpce}, ...: the reversed DNS suffix plus {@code .vpce}. */
|
||||
public static Optional<String> vpcEndpointServiceNamePrefix(String partition) {
|
||||
return partitionText(partition, "vpcEndpointServiceNamePrefix");
|
||||
}
|
||||
|
||||
/**
|
||||
* The AWS-owned VPC endpoint service name for {@code service} in {@code region}, e.g.
|
||||
* {@code com.amazonaws.us-east-1.s3} or {@code cn.com.amazonaws.cn-north-1.s3}. The reversed
|
||||
* prefix applies only to the (region, service) pairs the CDK lists; every other pair keeps
|
||||
* {@code com.amazonaws}, GovCloud included. China's {@code transcribe} also carries a
|
||||
* trailing {@code .cn}.
|
||||
*/
|
||||
public static String vpcEndpointServiceName(String region, String service) {
|
||||
JsonNode entry = regionNode(region);
|
||||
String prefix = DEFAULT_VPC_ENDPOINT_PREFIX;
|
||||
String suffix = "";
|
||||
if (entry != null) {
|
||||
if (contains(entry.path("vpcEndpointPrefixServices"), service)) {
|
||||
prefix = entry.path("vpcEndpointExceptionPrefix").asText(DEFAULT_VPC_ENDPOINT_PREFIX);
|
||||
}
|
||||
if (contains(entry.path("vpcEndpointCnSuffixServices"), service)) {
|
||||
suffix = ".cn";
|
||||
}
|
||||
}
|
||||
return prefix + "." + region + "." + service + suffix;
|
||||
}
|
||||
|
||||
/** The services whose endpoint name in {@code region} uses the reversed-suffix prefix. */
|
||||
public static Set<String> vpcEndpointPrefixServices(String region) {
|
||||
Set<String> services = new LinkedHashSet<>();
|
||||
JsonNode entry = regionNode(region);
|
||||
if (entry != null) {
|
||||
entry.path("vpcEndpointPrefixServices").forEach(node -> services.add(node.asText()));
|
||||
}
|
||||
return services;
|
||||
}
|
||||
|
||||
private static boolean contains(JsonNode array, String value) {
|
||||
for (JsonNode node : array) {
|
||||
if (node.asText().equals(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Optional<String> regionText(String region, String field) {
|
||||
JsonNode entry = regionNode(region);
|
||||
return entry == null || !entry.hasNonNull(field) ? Optional.empty() : Optional.of(entry.get(field).asText());
|
||||
}
|
||||
|
||||
private static Optional<String> partitionText(String partition, String field) {
|
||||
if (partition == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
JsonNode entry = Holder.FACTS.path("partitions").get(partition.trim().toLowerCase(Locale.ROOT));
|
||||
return entry == null || !entry.hasNonNull(field) ? Optional.empty() : Optional.of(entry.get(field).asText());
|
||||
}
|
||||
|
||||
private static JsonNode regionNode(String region) {
|
||||
if (region == null || region.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
return Holder.FACTS.path("regions").get(region.trim().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
private static JsonNode load() {
|
||||
try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(RESOURCE_NAME)) {
|
||||
if (in == null) {
|
||||
throw new IllegalStateException("Region facts resource not found: " + RESOURCE_NAME);
|
||||
}
|
||||
JsonNode root = new ObjectMapper().readTree(in);
|
||||
if (!root.path("regions").isObject() || !root.path("partitions").isObject()) {
|
||||
throw new IllegalStateException(RESOURCE_NAME + " lacks the regions or partitions object");
|
||||
}
|
||||
return root;
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Failed to read the region facts " + RESOURCE_NAME, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+36
-9
@@ -7,6 +7,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.config.TlsCertificateManager;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsPartition;
|
||||
import io.github.hectorvent.floci.core.common.AwsPartitions;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegionFacts;
|
||||
import io.github.hectorvent.floci.core.common.ReservedTags;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -65,6 +68,9 @@ import java.util.regex.Pattern;
|
||||
@ApplicationScoped
|
||||
public class ApiGatewayService {
|
||||
|
||||
/** The only partition where API Gateway offers edge-optimized APIs and custom domain names. */
|
||||
private static final Set<String> EDGE_OPTIMIZED_PARTITIONS = Set.of("aws");
|
||||
|
||||
private static final ObjectMapper JSON = new ObjectMapper();
|
||||
|
||||
/** Documented default page size for GetUsage. */
|
||||
@@ -1886,6 +1892,7 @@ public class ApiGatewayService {
|
||||
// neither regional nor edge-optimized, which nothing here could route or describe.
|
||||
throw new AwsException("BadRequestException", "Invalid value for endpoint type: " + endpointType, 400);
|
||||
}
|
||||
requireEndpointTypeAvailable(endpointType, region);
|
||||
|
||||
CustomDomain domain = new CustomDomain();
|
||||
domain.setDomainName(domainName);
|
||||
@@ -1894,8 +1901,8 @@ public class ApiGatewayService {
|
||||
domain.setRegionalCertificateName((String) request.get("regionalCertificateName"));
|
||||
domain.setRegionalCertificateArn((String) request.get("regionalCertificateArn"));
|
||||
domain.setRegionalDomainName(domainName + ".regional.local");
|
||||
domain.setRegionalHostedZoneId("Z2FDTNDATAQYL2");
|
||||
applyEndpointType(domain, endpointType);
|
||||
domain.setRegionalHostedZoneId("Z2FDTNDATAQYL2"); // partition-literal: no published per-region source for the regional zone
|
||||
applyEndpointType(domain, endpointType, region);
|
||||
domain.setSecurityPolicy((String) request.getOrDefault("securityPolicy", "TLS_1_2"));
|
||||
// Nothing is provisioned behind the domain, so it is usable as soon as it exists.
|
||||
domain.setDomainNameStatus("AVAILABLE");
|
||||
@@ -1922,12 +1929,26 @@ public class ApiGatewayService {
|
||||
}
|
||||
|
||||
/**
|
||||
* An edge-optimized domain fronts a CloudFront distribution, and a DNS alias points at the
|
||||
* distribution's name in the fixed CloudFront hosted zone AWS documents for every region. A
|
||||
* 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.
|
||||
* Edge-optimized APIs and domains exist only in the commercial partition: GovCloud and the
|
||||
* ISO partitions have no CloudFront, and China has CloudFront but no edge-optimized API Gateway
|
||||
* (https://docs.amazonaws.cn/en_us/aws/latest/userguide/api-gateway.html). No source shows
|
||||
* AWS's message for the refusal, so the wording is Floci's own.
|
||||
*/
|
||||
private void applyEndpointType(CustomDomain domain, String endpointType) {
|
||||
private static void requireEndpointTypeAvailable(String endpointType, String region) {
|
||||
AwsPartition partition = AwsPartitions.forRegionOrCommercial(region);
|
||||
if ("EDGE".equals(endpointType) && !EDGE_OPTIMIZED_PARTITIONS.contains(partition.id())) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"Endpoint type EDGE is not available in partition " + partition.id() + ".", 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An edge-optimized domain fronts a CloudFront distribution, and a DNS alias points at the
|
||||
* distribution's name in the CloudFront hosted zone of its partition. A 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 void applyEndpointType(CustomDomain domain, String endpointType, String region) {
|
||||
domain.setEndpointConfigurationType(endpointType);
|
||||
if (!"EDGE".equals(endpointType)) {
|
||||
domain.setDistributionDomainName(null);
|
||||
@@ -1936,7 +1957,8 @@ public class ApiGatewayService {
|
||||
domain.setDistributionDomainName(
|
||||
"d" + UUID.randomUUID().toString().replace("-", "").substring(0, 13) + "."
|
||||
+ config.services().cloudfront().domainSuffix());
|
||||
domain.setDistributionHostedZoneId("Z2FDTNDATAQYW2");
|
||||
domain.setDistributionHostedZoneId(AwsRegionFacts.cloudFrontHostedZoneId(
|
||||
AwsPartitions.forRegionOrCommercial(region).id()).orElse(null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2050,12 +2072,17 @@ public class ApiGatewayService {
|
||||
throw new AwsException("BadRequestException", "Unsupported path: " + path, 400);
|
||||
}
|
||||
}
|
||||
// Only a change of type is held to the partition: an EDGE domain stored before the rule
|
||||
// existed must still take certificate or security-policy updates.
|
||||
if (!Objects.equals(newEndpointConfigurationType, domain.getEndpointConfigurationType())) {
|
||||
requireEndpointTypeAvailable(newEndpointConfigurationType, region);
|
||||
}
|
||||
domain.setCertificateName(newCertificateName);
|
||||
domain.setCertificateArn(newCertificateArn);
|
||||
domain.setRegionalCertificateName(newRegionalCertificateName);
|
||||
domain.setRegionalCertificateArn(newRegionalCertificateArn);
|
||||
domain.setSecurityPolicy(newSecurityPolicy);
|
||||
applyEndpointType(domain, newEndpointConfigurationType);
|
||||
applyEndpointType(domain, newEndpointConfigurationType, region);
|
||||
domainStore.put(domainKey, domain);
|
||||
return domain;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsNamespaces;
|
||||
import io.github.hectorvent.floci.core.common.AwsPartition;
|
||||
import io.github.hectorvent.floci.core.common.AwsPartitions;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegionFacts;
|
||||
import io.github.hectorvent.floci.core.common.XmlBuilder;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.services.ec2.model.*;
|
||||
@@ -1584,9 +1585,11 @@ public class Ec2QueryHandler {
|
||||
return xmlResponse(xml.build());
|
||||
}
|
||||
|
||||
// The common AWS interface-endpoint services, as short names. Rendered as
|
||||
// com.amazonaws.<region>.<name>. CDK's InterfaceVpcEndpoint (lookupSupportedAzs)
|
||||
// calls DescribeVpcEndpointServices at synth time; an empty set aborts synth.
|
||||
// The common AWS interface-endpoint services, as short names. Rendered with the
|
||||
// region's interface-endpoint prefix: com.amazonaws.<region>.<name>, or the reversed
|
||||
// suffix for the (region, service) pairs AwsRegionFacts lists (cn.com.amazonaws in
|
||||
// China). CDK's InterfaceVpcEndpoint (lookupSupportedAzs) calls
|
||||
// DescribeVpcEndpointServices at synth time; an empty set aborts synth.
|
||||
private static final List<String> INTERFACE_ENDPOINT_SERVICES = List.of(
|
||||
"ec2", "ec2messages", "ssm", "ssmmessages", "logs", "monitoring", "sts",
|
||||
"secretsmanager", "kms", "ecr.api", "ecr.dkr", "ecs", "ecs-agent", "ecs-telemetry",
|
||||
@@ -1612,8 +1615,9 @@ public class Ec2QueryHandler {
|
||||
} else {
|
||||
// S3 has both a Gateway and an Interface offering; keep it in the set.
|
||||
for (String name : INTERFACE_ENDPOINT_SERVICES) {
|
||||
fullNames.add("com.amazonaws." + region + "." + name);
|
||||
fullNames.add(AwsRegionFacts.vpcEndpointServiceName(region, name));
|
||||
}
|
||||
// The S3 gateway service keeps com.amazonaws in every partition.
|
||||
fullNames.add("com.amazonaws." + region + ".s3");
|
||||
}
|
||||
for (String full : fullNames) {
|
||||
|
||||
@@ -1224,6 +1224,11 @@ public class Ec2Service implements ContainerTeardown, ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The managed lists belong to the S3 and DynamoDB gateway endpoints, which are named
|
||||
* {@code com.amazonaws.<region>.<service>} in every partition (the CDK's
|
||||
* {@code GatewayVpcEndpointAwsService}); the reversed-suffix names apply to interface endpoints only.
|
||||
*/
|
||||
private List<ManagedPrefixList> awsManagedPrefixLists(String region) {
|
||||
return List.of(
|
||||
awsManagedPrefixList(region, "pl-63a5400a", "com.amazonaws." + region + ".s3",
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.elb;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegionFacts;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackedMap;
|
||||
@@ -46,9 +47,6 @@ import java.util.stream.Collectors;
|
||||
@ApplicationScoped
|
||||
public class ElbClassicService {
|
||||
|
||||
/** The hosted zone ID AWS reports for Classic load balancers; fixed per region on AWS too. */
|
||||
private static final String CANONICAL_HOSTED_ZONE_ID = "Z35SXDOTRQ7X7K";
|
||||
|
||||
private static final SecureRandom RANDOM = new SecureRandom();
|
||||
|
||||
private final Ec2Service ec2Service;
|
||||
@@ -101,6 +99,18 @@ public class ElbClassicService {
|
||||
* nothing reachable from {@link #initializeStorage()} may touch an injected collaborator.
|
||||
*/
|
||||
public void restorePersistedRuntime() {
|
||||
// A balancer stored before the zone was looked up per region still carries the one fixed
|
||||
// zone every balancer used to report; take the region's zone again and store it back.
|
||||
for (String region : List.copyOf(loadBalancers.keySet())) {
|
||||
Map<String, ClassicLoadBalancer> regionLbs = loadBalancers.get(region);
|
||||
if (regionLbs == null) {
|
||||
continue;
|
||||
}
|
||||
for (ClassicLoadBalancer lb : regionLbs.values()) {
|
||||
lb.setCanonicalHostedZoneNameId(AwsRegionFacts.classicElbHostedZoneId(region).orElse(null));
|
||||
}
|
||||
loadBalancers.put(region, regionLbs);
|
||||
}
|
||||
for (Map<String, ClassicLoadBalancer> regionLbs : loadBalancers.values()) {
|
||||
for (ClassicLoadBalancer lb : regionLbs.values()) {
|
||||
healthChecker.startMonitoring(lb);
|
||||
@@ -148,7 +158,7 @@ public class ElbClassicService {
|
||||
}
|
||||
lb.setDnsName(dnsName);
|
||||
lb.setCanonicalHostedZoneName(dnsName);
|
||||
lb.setCanonicalHostedZoneNameId(CANONICAL_HOSTED_ZONE_ID);
|
||||
lb.setCanonicalHostedZoneNameId(AwsRegionFacts.classicElbHostedZoneId(region).orElse(null));
|
||||
lb.setScheme(scheme != null && !scheme.isBlank() ? scheme : "internet-facing");
|
||||
lb.setCreatedTime(Instant.now());
|
||||
lb.setListeners(new ArrayList<>(listeners));
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegionFacts;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.SsrfProtection;
|
||||
import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;
|
||||
@@ -51,8 +52,6 @@ public class ElbV2Service implements ResourceProvider {
|
||||
@Inject
|
||||
EmulatorConfig config;
|
||||
|
||||
private static final String CANONICAL_HOSTED_ZONE_ID = "Z35SXDOTRQ7X7K";
|
||||
|
||||
// region → ARN → resource
|
||||
private Map<String, Map<String, LoadBalancer>> loadBalancers = new ConcurrentHashMap<>();
|
||||
private Map<String, Map<String, TargetGroup>> targetGroups = new ConcurrentHashMap<>();
|
||||
@@ -163,6 +162,7 @@ public class ElbV2Service implements ResourceProvider {
|
||||
*/
|
||||
public void restorePersistedRuntime()
|
||||
{
|
||||
refreshCanonicalHostedZones();
|
||||
if (healthChecker != null) {
|
||||
for (Map<String, TargetGroup> regionTargetGroups : targetGroups.values()) {
|
||||
for (TargetGroup targetGroup : regionTargetGroups.values()) {
|
||||
@@ -210,7 +210,7 @@ public class ElbV2Service implements ResourceProvider {
|
||||
LoadBalancer lb = new LoadBalancer();
|
||||
lb.setLoadBalancerArn(arn);
|
||||
lb.setDnsName(dnsName);
|
||||
lb.setCanonicalHostedZoneId(CANONICAL_HOSTED_ZONE_ID);
|
||||
lb.setCanonicalHostedZoneId(canonicalHostedZoneId(lbType, region));
|
||||
lb.setCreatedTime(Instant.now());
|
||||
lb.setLoadBalancerName(name);
|
||||
lb.setScheme(lbScheme);
|
||||
@@ -1101,6 +1101,37 @@ public class ElbV2Service implements ResourceProvider {
|
||||
return UUID.randomUUID().toString().replace("-", "").substring(0, 16);
|
||||
}
|
||||
|
||||
/**
|
||||
* A load balancer stored before the hosted zones were looked up per region and type still
|
||||
* carries the one fixed zone every balancer used to report, so restored balancers take the
|
||||
* zone of their region and type again, written back so the stored copy agrees.
|
||||
*/
|
||||
private void refreshCanonicalHostedZones() {
|
||||
for (String region : List.copyOf(loadBalancers.keySet())) {
|
||||
Map<String, LoadBalancer> regionLoadBalancers = loadBalancers.get(region);
|
||||
if (regionLoadBalancers == null) {
|
||||
continue;
|
||||
}
|
||||
for (LoadBalancer lb : regionLoadBalancers.values()) {
|
||||
String lbType = lb.getType() != null ? lb.getType() : "application";
|
||||
lb.setCanonicalHostedZoneId(canonicalHostedZoneId(lbType, region));
|
||||
}
|
||||
loadBalancers.put(region, regionLoadBalancers);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Network load balancers have their own hosted zone per region, distinct from the one
|
||||
* Application (and Classic) load balancers share; a gateway load balancer has none.
|
||||
*/
|
||||
private static String canonicalHostedZoneId(String type, String region) {
|
||||
return switch (type) {
|
||||
case "network" -> AwsRegionFacts.nlbHostedZoneId(region).orElse(null);
|
||||
case "gateway" -> null;
|
||||
default -> AwsRegionFacts.albHostedZoneId(region).orElse(null);
|
||||
};
|
||||
}
|
||||
|
||||
private static String lbTypePrefix(String type) {
|
||||
return switch (type) {
|
||||
case "network" -> "net";
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.iam;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegionFacts;
|
||||
import io.github.hectorvent.floci.services.iam.model.SAMLProvider;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
@@ -130,7 +131,7 @@ final class SAMLAssertionVerifier {
|
||||
}
|
||||
String recipient = confirmationData.getAttribute("Recipient");
|
||||
Instant confirmationExpiry = instant(confirmationData.getAttribute("NotOnOrAfter"));
|
||||
if ("https://signin.aws.amazon.com/saml".equals(recipient)
|
||||
if (expectedRecipient(provider).equals(recipient)
|
||||
&& confirmationExpiry != null && now.isBefore(confirmationExpiry)) {
|
||||
validBearer = true;
|
||||
break;
|
||||
@@ -238,4 +239,17 @@ final class SAMLAssertionVerifier {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The console sign-on URL a bearer assertion must name, in the provider's partition. The CDK
|
||||
* publishes none for {@code aws-iso-e}, {@code aws-iso-f} and {@code aws-eusc}; there the
|
||||
* commercial URL is kept, as every partition used before the per-partition table, rather than
|
||||
* refusing every assertion.
|
||||
*/
|
||||
// Package-private for unit testing.
|
||||
static String expectedRecipient(SAMLProvider provider) {
|
||||
String partition = AwsArnUtils.parse(provider.getArn()).partition();
|
||||
return AwsRegionFacts.samlSignOnUrl(partition)
|
||||
.or(() -> AwsRegionFacts.samlSignOnUrl("aws"))
|
||||
.orElseThrow();
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -25,7 +25,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
@ApplicationScoped
|
||||
public class MarketplaceAgreementService implements Resettable {
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String REGION = "us-east-1"; // partition-literal: AWS Marketplace is commercial-only and AWS pins its APIs to these regions
|
||||
private static final String CATALOG = "AWSMarketplace";
|
||||
private static final Pattern PROPOSAL_ID = Pattern.compile("(at-|ap-)[A-Za-z0-9]+");
|
||||
private static final Pattern CLIENT_TOKEN = Pattern.compile("[a-zA-Z0-9-]{1,64}");
|
||||
@@ -782,7 +782,7 @@ public class MarketplaceAgreementService implements Resettable {
|
||||
|
||||
private static void validateRegion(String region) {
|
||||
if (!REGION.equals(region)) {
|
||||
throw validation("AWS Marketplace Agreement API is available only in us-east-1.");
|
||||
throw validation("AWS Marketplace Agreement API is available only in us-east-1."); // partition-literal: AWS's message text
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -138,7 +138,7 @@ public class MarketplaceCatalogController {
|
||||
}
|
||||
|
||||
private String region() {
|
||||
return context.getRegion() == null ? "us-east-1" : context.getRegion();
|
||||
return context.getRegion() == null ? "us-east-1" : context.getRegion(); // partition-literal: fallback to Marketplace's own region when the request carries none
|
||||
}
|
||||
|
||||
private static Response ok(JsonNode node) {
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class MarketplaceDeploymentController {
|
||||
}
|
||||
|
||||
private String region() {
|
||||
return requestContext.getRegion() == null ? "us-east-1" : requestContext.getRegion();
|
||||
return requestContext.getRegion() == null ? "us-east-1" : requestContext.getRegion(); // partition-literal: fallback to Marketplace's own region when the request carries none
|
||||
}
|
||||
|
||||
private String accountId() {
|
||||
|
||||
+2
-2
@@ -307,8 +307,8 @@ public class MarketplaceDeploymentService implements Resettable {
|
||||
}
|
||||
|
||||
private static void validateRegion(String region) {
|
||||
if (region != null && !region.isBlank() && !"us-east-1".equals(region)) {
|
||||
throw validation("AWS Marketplace Deployment Service is available only in us-east-1.");
|
||||
if (region != null && !region.isBlank() && !"us-east-1".equals(region)) { // partition-literal: AWS Marketplace is commercial-only and AWS pins its APIs to these regions
|
||||
throw validation("AWS Marketplace Deployment Service is available only in us-east-1."); // partition-literal: AWS's message text
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ public class MarketplaceDiscoveryController {
|
||||
} catch (AwsException e) { throw e; }
|
||||
catch (Exception e) { throw validation("Request body is not valid JSON."); }
|
||||
}
|
||||
private String region() { return context.getRegion() == null ? "us-east-1" : context.getRegion(); }
|
||||
private String region() { return context.getRegion() == null ? "us-east-1" : context.getRegion(); } // partition-literal: fallback to Marketplace's own region when the request carries none
|
||||
private Response ok(JsonNode node) { return Response.ok(node).build(); }
|
||||
private static AwsException validation(String message) { return new AwsException("ValidationException", message, 400); }
|
||||
}
|
||||
+2
-2
@@ -23,7 +23,7 @@ import java.util.Set;
|
||||
|
||||
@ApplicationScoped
|
||||
public class MarketplaceDiscoveryService implements Resettable {
|
||||
private static final Set<String> REGIONS = Set.of("us-east-1", "us-west-2", "eu-west-1");
|
||||
private static final Set<String> REGIONS = Set.of("us-east-1", "us-west-2", "eu-west-1"); // partition-literal: AWS Marketplace is commercial-only and AWS pins its APIs to these regions
|
||||
private static final Set<String> FACET_TYPES = Set.of("AVERAGE_CUSTOMER_RATING", "CATEGORY", "PUBLISHER", "FULFILLMENT_OPTION_TYPE", "PRICING_MODEL", "PRICING_UNIT", "DEPLOYED_ON_AWS", "NUMBER_OF_PRODUCTS");
|
||||
private static final Set<String> SEARCH_FILTER_TYPES = Set.of("MIN_AVERAGE_CUSTOMER_RATING", "MAX_AVERAGE_CUSTOMER_RATING", "CATEGORY", "PUBLISHER", "FULFILLMENT_OPTION_TYPE", "PRICING_MODEL", "PRICING_UNIT", "DEPLOYED_ON_AWS", "NUMBER_OF_PRODUCTS");
|
||||
private final ObjectMapper mapper;
|
||||
@@ -412,7 +412,7 @@ public class MarketplaceDiscoveryService implements Resettable {
|
||||
throw validation(f+" is required and must match [\\w-]+.");
|
||||
}return v;}
|
||||
private static void validateRegion(String region){if(!REGIONS.contains(region)){
|
||||
throw validation("Marketplace Discovery is available only in us-east-1, us-west-2, and eu-west-1.");
|
||||
throw validation("Marketplace Discovery is available only in us-east-1, us-west-2, and eu-west-1."); // partition-literal: AWS's message text
|
||||
}}
|
||||
private static AwsException validation(String m){return new AwsException("ValidationException",m,400);}
|
||||
private static AwsException notFound(String k,String id){return new AwsException("ResourceNotFoundException",k+" "+id+" was not found.",404);}
|
||||
|
||||
+2
-2
@@ -39,9 +39,9 @@ public class MarketplaceEntitlementService implements Resettable {
|
||||
}
|
||||
|
||||
ObjectNode getEntitlements(JsonNode request, String region) {
|
||||
if (region != null && !region.isBlank() && !"us-east-1".equals(region)) {
|
||||
if (region != null && !region.isBlank() && !"us-east-1".equals(region)) { // partition-literal: AWS Marketplace is commercial-only and AWS pins its APIs to these regions
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"AWS Marketplace Entitlement Service is available only in us-east-1.", 400);
|
||||
"AWS Marketplace Entitlement Service is available only in us-east-1.", 400); // partition-literal: AWS's message text
|
||||
}
|
||||
String productCode = requireText(request, "ProductCode", 1, 255);
|
||||
JsonNode filter = request == null ? null : request.get("Filter");
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ public class MarketplaceReportingService {
|
||||
}
|
||||
String token = UUID.randomUUID().toString().replace("-", "");
|
||||
String dashboardName = dashboard.substring(dashboard.lastIndexOf('/') + 1);
|
||||
String embedUrl = "https://us-east-1.quicksight.aws.amazon.com/sn/embed/share/accounts/"
|
||||
String embedUrl = "https://us-east-1.quicksight.aws.amazon.com/sn/embed/share/accounts/" // partition-literal: Marketplace reporting dashboards embed from QuickSight in us-east-1
|
||||
+ accountId + "/dashboards/" + URLEncoder.encode(dashboardName, StandardCharsets.UTF_8)
|
||||
+ "?code=" + token;
|
||||
MarketplaceBuyerDashboard result = new MarketplaceBuyerDashboard(
|
||||
|
||||
+2
-2
@@ -32,7 +32,7 @@ import java.util.regex.Pattern;
|
||||
@ApplicationScoped
|
||||
public class MarketplaceService implements Resettable {
|
||||
private static final String CATALOG = "AWSMarketplace";
|
||||
private static final String REGION = "us-east-1";
|
||||
private static final String REGION = "us-east-1"; // partition-literal: AWS Marketplace is commercial-only and AWS pins its APIs to these regions
|
||||
private static final Pattern CLIENT_TOKEN = Pattern.compile("[!-~]{1,64}");
|
||||
private static final Pattern CHANGE_SET_NAME = Pattern.compile("[\\w\\s+=.:@-]{1,100}");
|
||||
private static final Set<String> SUPPORTED_CHANGE_TYPES = Set.of(
|
||||
@@ -789,7 +789,7 @@ public class MarketplaceService implements Resettable {
|
||||
|
||||
private static void validateRegion(String region) {
|
||||
if (!REGION.equals(region)) {
|
||||
throw validation("AWS Marketplace Catalog API is available only in us-east-1.");
|
||||
throw validation("AWS Marketplace Catalog API is available only in us-east-1."); // partition-literal: AWS's message text
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2061,12 +2061,15 @@ public class S3Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* S3's CreateBucket region rules, the same in every partition (moto's {@code aws_verified}
|
||||
* matrix): every regional endpoint but {@code us-east-1} requires a constraint naming exactly
|
||||
* its region and answers {@code IllegalLocationConstraintException} otherwise, including for a
|
||||
* {@code us-east-1} constraint, so in a China or GovCloud deployment the constraint is de facto
|
||||
* required; the {@code us-east-1} endpoint takes any constraint but its own, which is
|
||||
* {@code InvalidLocationConstraint}.
|
||||
* S3's CreateBucket region rules, the same in every partition: every regional endpoint but
|
||||
* {@code us-east-1} requires a constraint naming exactly its region and answers
|
||||
* {@code IllegalLocationConstraintException} otherwise, including for a {@code us-east-1}
|
||||
* constraint, so in a China or GovCloud deployment the constraint is de facto required; the
|
||||
* {@code us-east-1} endpoint takes any constraint but its own, which is
|
||||
* {@code InvalidLocationConstraint}. The S3 model backs the us-east-1 rules on its own:
|
||||
* {@code us-east-1} is the one region missing from the {@code BucketLocationConstraint} enum,
|
||||
* and {@code GetBucketLocationOutput} gives buckets in {@code us-east-1} a null constraint. The
|
||||
* exact error codes and messages come from moto's {@code aws_verified} CreateBucket tests.
|
||||
*/
|
||||
static String bucketRegionForCreate(String locationConstraint, String endpointRegion) {
|
||||
boolean globalEndpoint = US_EAST_1.equals(endpointRegion);
|
||||
|
||||
@@ -278,7 +278,7 @@ public class SigninService {
|
||||
long now = issuedAt.getEpochSecond();
|
||||
String header = encodeJson(Map.of("alg", "none", "typ", "JWT"));
|
||||
String payload = encodeJson(Map.of(
|
||||
"iss", "https://signin.amazonaws.com",
|
||||
"iss", "https://signin.amazonaws.com", // partition-literal: floci's own issuer; the console issuer has no published source
|
||||
"sub", principalArn,
|
||||
"aud", clientId,
|
||||
"aws_account_id", accountId,
|
||||
|
||||
Reference in new issue
Block a user