mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ecr): pull rewritten ECS and Lambda images from localhost (#5882)
Floci rewrites an AWS-shaped ECR image of an ECS task or an image-backed
Lambda to its loopback registry and hands that address to the Docker
daemon, as <account>.dkr.ecr.<region>.localhost:<port>/<repo> in the
hostname style. A daemon with the containerd image store, the default
from Docker Engine 29, cannot pull from it. Measured on Docker 29.9.1:
against a plain HTTP registry:2, localhost:<port> and 127.0.0.1:<port>
are reached over HTTP, while any *.localhost name is tried over HTTPS
only ("server gave HTTP response to HTTPS client"), the 127.0.0.0/8
insecure CIDR notwithstanding. With Floci's TLS on, the same names reach
Floci's TLS port and fail on its certificate instead (unknown authority,
and *.localhost names are not in it). The containers never start: ECS
reports TaskFailedToStart.
So the rewrite now always gives localhost:<port>/<account>/<region>/<repo>,
path style, in either URI style and with or without TLS: the address
every daemon, classic or containerd store, pulls from over plain HTTP.
The data plane claims path-style requests on a loopback host (localhost,
127.0.0.0/8, ::1) in the hostname style too, so those pulls still go
through it and its repository name mapping. Nothing else changes: the
advertised repositoryUri, the login endpoint and pushes keep their style.
This commit is contained in:
1 parent
720f95bebe
commit
553411bc70
5 files changed
+59
-15
No files matched your search
+30
@@ -131,6 +131,36 @@ class EcrRegistryDataPlaneTest {
|
||||
assertEquals("/v2/000000000000/us-east-1/platform/api/manifests/v1", request.backendUri());
|
||||
}
|
||||
|
||||
/**
|
||||
* The address Floci hands the Docker daemon for the ECS and Lambda images it pulls is path
|
||||
* style on localhost in either URI style: a daemon with the containerd image store reaches
|
||||
* only localhost and 127.0.0.1 over plain HTTP, and takes {@code *.localhost} for HTTPS.
|
||||
*/
|
||||
@Test
|
||||
void pathStyleOnALoopbackHostIsClaimedInHostnameStyle() {
|
||||
EcrRegistryDataPlane.RegistryRequest request = EcrRegistryDataPlane.requestFor("localhost:4566",
|
||||
"/v2/000000000000/us-east-1/platform/api/manifests/v1", null, "hostname").orElseThrow();
|
||||
|
||||
assertEquals("000000000000", request.accountId());
|
||||
assertEquals("us-east-1", request.region());
|
||||
assertEquals("platform/api", request.repositoryName());
|
||||
assertEquals("v1", request.tag());
|
||||
assertEquals("/v2/000000000000/us-east-1/platform/api/manifests/v1", request.backendUri());
|
||||
assertTrue(EcrRegistryDataPlane.requestFor("127.0.0.1:443",
|
||||
"/v2/000000000000/us-east-1/platform/api/blobs/sha256:abc", null, "hostname").isPresent());
|
||||
assertTrue(EcrRegistryDataPlane.requestFor("[::1]:4566", "/v2/", null, "hostname").isPresent());
|
||||
assertTrue(EcrRegistryDataPlane.requestFor("localhost:4566", "/v2/", null, "hostname").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void pathStyleOnAnotherHostIsNotClaimedInHostnameStyle() {
|
||||
assertFalse(EcrRegistryDataPlane.requestFor("floci:4566",
|
||||
"/v2/000000000000/us-east-1/platform/api/manifests/v1", null, "hostname").isPresent());
|
||||
assertFalse(EcrRegistryDataPlane.requestFor("localhost.floci.io:4566",
|
||||
"/v2/000000000000/us-east-1/platform/api/manifests/v1", null, "hostname").isPresent());
|
||||
assertFalse(EcrRegistryDataPlane.requestFor("localhost:4566", "/v2/apis", null, "hostname").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void unrelatedV2RouteDoesNotClaimTheRequest() {
|
||||
assertFalse(EcrRegistryDataPlane.requestFor("localhost:4566", "/v2/apis", null, "hostname").isPresent());
|
||||
|
||||
+8
-8
@@ -392,7 +392,7 @@ class EcrRegistryManagerTest {
|
||||
|
||||
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);
|
||||
assertEquals("localhost:4566/123456789012/cn-north-1/backend-user:1", rewritten);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -402,7 +402,7 @@ class EcrRegistryManagerTest {
|
||||
|
||||
String rewritten = manager.rewriteImageUri("123456789012.dkr.ecr.us-east-1.amazonaws.com/backend-user:1");
|
||||
|
||||
assertEquals("123456789012.dkr.ecr.us-east-1.localhost:4566/backend-user:1", rewritten);
|
||||
assertEquals("localhost:4566/123456789012/us-east-1/backend-user:1", rewritten);
|
||||
verify(lifecycleManager).createAndStart(any());
|
||||
}
|
||||
|
||||
@@ -432,7 +432,7 @@ class EcrRegistryManagerTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"hostname, 123456789012.dkr.ecr.us-east-1.localhost:4566/backend-user:1",
|
||||
"hostname, localhost:4566/123456789012/us-east-1/backend-user:1",
|
||||
"path, localhost:4566/123456789012/us-east-1/backend-user:1"
|
||||
})
|
||||
void automaticImageRewritesKeepLoopbackWhenTlsUrisAreAdvertised(String style, String expectedImage) {
|
||||
@@ -494,7 +494,7 @@ class EcrRegistryManagerTest {
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"hostname, 123456789012.dkr.ecr.us-east-1.localhost:54321/backend-user:1",
|
||||
"hostname, localhost:54321/123456789012/us-east-1/backend-user:1",
|
||||
"path, localhost:54321/123456789012/us-east-1/backend-user:1"
|
||||
})
|
||||
void rewriteImageUri_flociPublishedOnAnotherHostPort_pointsTheDaemonAtThePublishedPort(String style,
|
||||
@@ -517,7 +517,7 @@ class EcrRegistryManagerTest {
|
||||
assertEquals("000000000000.dkr.ecr.us-east-1.localhost:4577/app",
|
||||
manager.getRepositoryUri("000000000000", "us-east-1", "app"));
|
||||
assertEquals("http://000000000000.dkr.ecr.us-east-1.localhost:4577", manager.getProxyEndpoint());
|
||||
assertEquals("123456789012.dkr.ecr.us-east-1.localhost:4577/backend-user:1",
|
||||
assertEquals("localhost:4577/123456789012/us-east-1/backend-user:1",
|
||||
manager.rewriteImageUri(AWS_ECR_IMAGE));
|
||||
verify(currentContainerNetworkResolver, Mockito.atLeastOnce()).resolvePublishedPort(4577);
|
||||
}
|
||||
@@ -576,7 +576,7 @@ class EcrRegistryManagerTest {
|
||||
|
||||
String rewritten = manager.rewriteImageUri(AWS_ECR_IMAGE);
|
||||
|
||||
assertEquals("123456789012.dkr.ecr.us-east-1.localhost:4566/backend-user:1", rewritten);
|
||||
assertEquals("localhost:4566/123456789012/us-east-1/backend-user:1", rewritten);
|
||||
verify(dockerClient, Mockito.never()).inspectImageCmd(anyString());
|
||||
}
|
||||
|
||||
@@ -606,7 +606,7 @@ class EcrRegistryManagerTest {
|
||||
|
||||
String rewritten = manager.rewriteImageUri(AWS_ECR_IMAGE);
|
||||
|
||||
assertEquals("123456789012.dkr.ecr.us-east-1.localhost:4566/backend-user:1", rewritten);
|
||||
assertEquals("localhost:4566/123456789012/us-east-1/backend-user:1", rewritten);
|
||||
verify(dockerClient).inspectImageCmd(mirrored);
|
||||
verify(lifecycleManager).createAndStart(any());
|
||||
}
|
||||
@@ -619,7 +619,7 @@ class EcrRegistryManagerTest {
|
||||
|
||||
String rewritten = manager.rewriteImageUri(AWS_ECR_IMAGE);
|
||||
|
||||
assertEquals("123456789012.dkr.ecr.us-east-1.localhost:4566/backend-user:1", rewritten);
|
||||
assertEquals("localhost:4566/123456789012/us-east-1/backend-user:1", rewritten);
|
||||
verify(lifecycleManager).createAndStart(any());
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user