fix(ec2): list the request partition's regions in DescribeRegions (#5550)

With floci.partitions.allow-unknown-regions on, a request signed for a
region no partition publishes is served in the deployment's partition,
and its ARNs are minted there. DescribeRegions picked its partition
with forRegionOrCommercial instead, so on a China deployment such a
request listed the commercial regions, and disagreed with the Step
Functions aws-sdk:ec2:describeRegions integration.

The handler now asks RegionResolver for the partition the request is
scoped to. A published region still lists its own partition.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-10-12 22:59:08 -04:00
1 parent d55b830a39
commit b4758b0018
5 files changed
+112 -5

No files matched your search

@@ -7,6 +7,7 @@ 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.RegionResolver;
import io.github.hectorvent.floci.core.common.XmlBuilder;
import io.github.hectorvent.floci.services.ec2.model.*;
import jakarta.enterprise.context.ApplicationScoped;
@@ -45,18 +46,20 @@ public class Ec2QueryHandler {
private final Ec2EbsEncryptionService ebsEncryptionService;
private final Ec2SnapshotBlockPublicAccessService snapshotBlockPublicAccessService;
private final Ec2IpamService ipamService;
private final RegionResolver regionResolver;
@Inject
public Ec2QueryHandler(Ec2Service service, EmulatorConfig config, FlowLogService flowLogService,
Ec2EbsEncryptionService ebsEncryptionService,
Ec2SnapshotBlockPublicAccessService snapshotBlockPublicAccessService,
Ec2IpamService ipamService) {
Ec2IpamService ipamService, RegionResolver regionResolver) {
this.service = service;
this.config = config;
this.flowLogService = flowLogService;
this.ebsEncryptionService = ebsEncryptionService;
this.snapshotBlockPublicAccessService = snapshotBlockPublicAccessService;
this.ipamService = ipamService;
this.regionResolver = regionResolver;
}
public Response handle(String action, MultivaluedMap<String, String> params, String region) {
@@ -4408,7 +4411,9 @@ public class Ec2QueryHandler {
}
private Response handleDescribeRegions(MultivaluedMap<String, String> p, String region) {
AwsPartition partition = AwsPartitions.forRegionOrCommercial(region);
// The partition the request is scoped to, not the region's own: a region no partition
// publishes is served in the deployment's partition, where its ARNs are minted too.
AwsPartition partition = AwsPartitions.byId(regionResolver.partitionForRegion(region));
boolean allRegions = Boolean.parseBoolean(p.getFirst("AllRegions"));
Set<String> requested = new HashSet<>(getList(p, "RegionName"));
XmlBuilder xml = new XmlBuilder()