mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(s3): preserve configured endpoint roots (#8323)
Signed-off-by: Andre Kurait <akurait@amazon.com> Signed-off-by: Jackson Price <jxnprice@amazon.com> Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
f665d5f5e7
commit
5df26c5135
7 files changed
+208
-2
No files matched your search
@@ -149,6 +149,7 @@ public class S3Controller {
|
||||
private final IamService iamService;
|
||||
private final IamEnforcementFilter iamEnforcementFilter;
|
||||
private final EmulatorConfig config;
|
||||
private final S3VirtualHostFilter virtualHostFilter;
|
||||
private final Clock clock;
|
||||
|
||||
@Inject
|
||||
@@ -163,6 +164,7 @@ public class S3Controller {
|
||||
IamService iamService,
|
||||
IamEnforcementFilter iamEnforcementFilter,
|
||||
EmulatorConfig config,
|
||||
S3VirtualHostFilter virtualHostFilter,
|
||||
Clock clock) {
|
||||
this.s3Service = s3Service;
|
||||
this.s3SelectService = s3SelectService;
|
||||
@@ -176,6 +178,7 @@ public class S3Controller {
|
||||
this.iamService = iamService;
|
||||
this.iamEnforcementFilter = iamEnforcementFilter;
|
||||
this.config = config;
|
||||
this.virtualHostFilter = virtualHostFilter;
|
||||
this.clock = clock;
|
||||
}
|
||||
|
||||
@@ -4995,7 +4998,7 @@ public class S3Controller {
|
||||
httpHeaders.getHeaderString("Host"),
|
||||
httpHeaders.getHeaderString("X-Forwarded-Host"),
|
||||
uriInfo.getRequestUri());
|
||||
if (host == null) {
|
||||
if (host == null || virtualHostFilter.isEndpointRoot(host)) {
|
||||
return null;
|
||||
}
|
||||
String bucket = S3VirtualHostFilter.extractBucketFromExisting(host, s3Service);
|
||||
|
||||
@@ -151,6 +151,9 @@ public class S3VirtualHostFilter implements ContainerRequestFilter {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEndpointRoot(host)) {
|
||||
return;
|
||||
}
|
||||
String bucket = extractBucket(host, baseHostname, serviceHostSuffixes);
|
||||
if (bucket == null && signedForS3 && s3ServiceInstance != null && s3ServiceInstance.isResolvable()) {
|
||||
bucket = extractBucketFromExisting(host, s3ServiceInstance.get());
|
||||
@@ -270,6 +273,9 @@ public class S3VirtualHostFilter implements ContainerRequestFilter {
|
||||
|
||||
// Strip port if present
|
||||
String hostname = stripPort(host);
|
||||
if (isEndpointRoot(hostname, baseHostname, serviceHostSuffixes)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Need at least one dot for a subdomain to exist
|
||||
int firstDot = hostname.indexOf('.');
|
||||
@@ -319,6 +325,19 @@ public class S3VirtualHostFilter implements ContainerRequestFilter {
|
||||
return bucketBeforeS3Qualifier(hostname);
|
||||
}
|
||||
|
||||
/** Whether the host names a configured endpoint rather than a bucket, including controller fallback paths. */
|
||||
boolean isEndpointRoot(String host) {
|
||||
return isEndpointRoot(host, baseHostname, serviceHostSuffixes);
|
||||
}
|
||||
|
||||
private static boolean isEndpointRoot(String host, String baseHostname, Set<String> serviceHostSuffixes) {
|
||||
String withoutPort = stripPort(host);
|
||||
String hostname = withoutPort.endsWith(".")
|
||||
? withoutPort.substring(0, withoutPort.length() - 1) : withoutPort;
|
||||
return hostname.equalsIgnoreCase(baseHostname)
|
||||
|| serviceHostSuffixes.stream().anyMatch(hostname::equalsIgnoreCase);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the part of {@code hostname} preceding the longest known endpoint host it ends
|
||||
* with, or {@code null} if it ends with none of them. Candidates are the configured base
|
||||
|
||||
Reference in new issue
Block a user