fix(partition): hold escaped host regexes to the DNS suffix gate (#5232)

The partition literal gate's dns-suffix pattern matched amazonaws.com but
not a Java regex that escapes its dots (amazonaws\\.com), so hand-written
host patterns escaped it. With the dots allowed to be escaped, the gate
found two on main:

- ECR's pull-through cache recognised an ecr upstream only on the
  commercial and China suffixes, while Floci's own registry recognises an
  ECR image URI in every partition. The upstream host pattern is now
  built from AwsPartitions.dnsSuffixRegex() the same way.
- The console sign-in host pattern in SigninService has no published
  non-commercial form, so it carries a partition-literal escape like the
  console literals beside it.
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-10-06 22:49:23 -04:00
1 parent a0a2a5f0d6
commit 1b61945f28
5 files changed
+40 -3

No files matched your search

@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.ecr;
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.AwsPartitions;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.core.common.RegionResolver;
@@ -40,6 +41,13 @@ import java.util.regex.Pattern;
@ApplicationScoped
public class EcrService implements ResourceProvider {
/**
* A private ECR registry host in any partition, {@code <account>.dkr.ecr.<region>.<dnsSuffix>},
* matched the same way {@code EcrRegistryManager} recognises an ECR image URI.
*/
private static final Pattern ECR_UPSTREAM_HOST = Pattern.compile(
"[0-9]{12}\\.dkr\\.ecr\\.[a-z0-9-]+\\." + AwsPartitions.dnsSuffixRegex());
private static final Logger LOG = Logger.getLogger(EcrService.class);
private static final Pattern REPO_NAME = Pattern.compile(
"(?:[a-z0-9]+(?:[._-][a-z0-9]+)*/)*[a-z0-9]+(?:[._-][a-z0-9]+)*");
@@ -1023,7 +1031,7 @@ public class EcrService implements ResourceProvider {
if (host.equals("cgr.dev")) {
return "chainguard";
}
if (host.matches("[0-9]{12}\\.dkr\\.ecr\\.[a-z0-9-]+\\.amazonaws\\.com(?:\\.cn)?")) {
if (ECR_UPSTREAM_HOST.matcher(host).matches()) {
return "ecr";
}
throw unsupportedUpstreamRegistry(upstreamRegistryUrl);
@@ -50,7 +50,7 @@ public class SigninService {
private static final int MAX_STATE_LENGTH = 128;
private static final Pattern PKCE_VALUE_PATTERN = Pattern.compile("[A-Za-z0-9._~-]{43,128}");
private static final Pattern AWS_SIGNIN_HOST_PATTERN =
Pattern.compile("[a-z]{2}-[a-z-]+-\\d+\\.signin\\.aws\\.amazon\\.com");
Pattern.compile("[a-z]{2}-[a-z-]+-\\d+\\.signin\\.aws\\.amazon\\.com"); // partition-literal: console sign-in host, non-commercial host has no published source
private final IamService iamService;
private final RegionResolver regionResolver;