mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(ecr): advertise TLS registry URIs on opt-in (#4252)
This commit is contained in:
1 parent
eb039eb71c
commit
22c56157ee
13 files changed
+506
-19
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package io.github.hectorvent.floci.config;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@QuarkusTest
|
||||
@TestProfile(EcrTlsPathUriIntegrationTest.Profile.class)
|
||||
class EcrTlsPathUriIntegrationTest extends EcrTlsUriIntegrationTest {
|
||||
|
||||
@Override
|
||||
String expectedRepositoryUri(String repository) {
|
||||
return "localhost.floci.io:" + ADVERTISED_PORT + "/" + ACCOUNT + "/" + REGION + "/" + repository;
|
||||
}
|
||||
|
||||
public static final class Profile extends EcrTlsUriIntegrationTest.Profile {
|
||||
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
Map<String, String> overrides = new LinkedHashMap<>(super.getConfigOverrides());
|
||||
overrides.put("floci.services.ecr.uri-style", "path");
|
||||
return overrides;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
package io.github.hectorvent.floci.config;
|
||||
|
||||
import com.sun.net.httpserver.HttpServer;
|
||||
import io.github.hectorvent.floci.services.acm.CertificateGenerator.GeneratedCertificate;
|
||||
import io.github.hectorvent.floci.services.acm.model.KeyAlgorithm;
|
||||
import io.github.hectorvent.floci.services.ecr.registry.EcrRegistryManager;
|
||||
import io.github.hectorvent.floci.services.ecr.registry.RegistryHttpClient;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.QuarkusTestProfile;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import io.quarkus.test.junit.mockito.InjectSpy;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.vertx.core.Vertx;
|
||||
import io.vertx.core.http.HttpClient;
|
||||
import io.vertx.core.http.HttpClientOptions;
|
||||
import io.vertx.core.http.HttpMethod;
|
||||
import io.vertx.core.http.RequestOptions;
|
||||
import io.vertx.core.net.PemTrustOptions;
|
||||
import io.vertx.core.net.SocketAddress;
|
||||
import jakarta.inject.Inject;
|
||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
|
||||
@QuarkusTest
|
||||
@TestProfile(EcrTlsUriIntegrationTest.Profile.class)
|
||||
class EcrTlsUriIntegrationTest {
|
||||
|
||||
static final String ACCOUNT = "123456789012";
|
||||
static final String REGION = "eu-west-1";
|
||||
static final int ADVERTISED_PORT = 4566;
|
||||
private static final String MANIFEST = "{\"schemaVersion\":2}";
|
||||
private static final String DIGEST = "sha256:" + "1".repeat(64);
|
||||
|
||||
@ConfigProperty(name = "quarkus.http.test-ssl-port")
|
||||
int sslPort;
|
||||
|
||||
@Inject
|
||||
Vertx vertx;
|
||||
|
||||
@InjectSpy
|
||||
EcrRegistryManager registryManager;
|
||||
|
||||
private final BlockingQueue<String> backendRequests = new LinkedBlockingQueue<>();
|
||||
private HttpServer backend;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
void startRegistryBackend() throws IOException {
|
||||
backend = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
|
||||
backend.createContext("/v2/", exchange -> {
|
||||
backendRequests.add(exchange.getRequestMethod() + " " + exchange.getRequestURI());
|
||||
exchange.getResponseHeaders().set("Docker-Distribution-Api-Version", "registry/2.0");
|
||||
exchange.getResponseHeaders().set("Docker-Content-Digest", DIGEST);
|
||||
exchange.getResponseHeaders().set("Content-Type", "application/vnd.oci.image.manifest.v1+json");
|
||||
byte[] body = MANIFEST.getBytes(StandardCharsets.UTF_8);
|
||||
if ("HEAD".equals(exchange.getRequestMethod())) {
|
||||
exchange.sendResponseHeaders(200, -1);
|
||||
} else {
|
||||
exchange.sendResponseHeaders(200, body.length);
|
||||
exchange.getResponseBody().write(body);
|
||||
}
|
||||
exchange.close();
|
||||
});
|
||||
backend.start();
|
||||
// Only container startup and its HTTP endpoint are replaced. URI generation stays real.
|
||||
doNothing().when(registryManager).ensureStarted();
|
||||
doReturn(true).when(registryManager).tryEnsureStarted();
|
||||
doReturn(new RegistryHttpClient("http://127.0.0.1:" + backend.getAddress().getPort()))
|
||||
.when(registryManager).httpClient();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void stopRegistryBackend() {
|
||||
if (backend != null) {
|
||||
backend.stop(0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void advertisedRepositoryAndLoginEndpointReachTheRegistryWithVerifiedTls() throws Exception {
|
||||
String repository = "tls-uri/team-" + Long.toString(System.nanoTime(), 36);
|
||||
String expectedUri = expectedRepositoryUri(repository);
|
||||
String repositoryUri = request("CreateRepository", Map.of("repositoryName", repository))
|
||||
.body("repository.repositoryUri", equalTo(expectedUri))
|
||||
.body("repository.registryId", equalTo(ACCOUNT))
|
||||
.extract().path("repository.repositoryUri");
|
||||
request("DescribeRepositories", Map.of("repositoryNames", new String[]{repository}))
|
||||
.body("repositories[0].repositoryUri", equalTo(repositoryUri));
|
||||
|
||||
URI image = URI.create("https://" + repositoryUri);
|
||||
String proxyEndpoint = request("GetAuthorizationToken", Map.of())
|
||||
.body("authorizationData[0].proxyEndpoint", equalTo("https://" + image.getAuthority()))
|
||||
.extract().path("authorizationData[0].proxyEndpoint");
|
||||
URI login = URI.create(proxyEndpoint);
|
||||
assertEquals("", login.getPath(), "Docker login uses the registry authority without a repository path");
|
||||
assertEquals(ADVERTISED_PORT, image.getPort());
|
||||
|
||||
HttpClient client = vertx.createHttpClient(new HttpClientOptions()
|
||||
.setSsl(true)
|
||||
.setForceSni(true)
|
||||
.setTrustOptions(new PemTrustOptions().addCertPath(
|
||||
FlociCertificateAuthority.loadOrCreate(Profile.TLS_DIR).certificatePath().toString()))
|
||||
.setVerifyHost(true));
|
||||
try {
|
||||
RegistryResponse ping = execute(client, HttpMethod.GET, login, "/v2/");
|
||||
assertEquals(200, ping.status());
|
||||
assertEquals("GET /v2/", backendRequests.poll(5, TimeUnit.SECONDS));
|
||||
|
||||
String manifestPath = "/v2" + image.getPath() + "/manifests/latest";
|
||||
RegistryResponse manifest = execute(client, HttpMethod.GET, image, manifestPath);
|
||||
assertEquals(200, manifest.status());
|
||||
assertEquals(MANIFEST, manifest.body());
|
||||
assertEquals(DIGEST, manifest.digest());
|
||||
String storagePath = "/v2/" + ACCOUNT + "/" + REGION + "/" + repository + "/manifests/latest";
|
||||
assertEquals("GET " + storagePath, backendRequests.poll(5, TimeUnit.SECONDS));
|
||||
|
||||
RegistryResponse head = execute(client, HttpMethod.HEAD, image, manifestPath);
|
||||
assertEquals(200, head.status());
|
||||
assertEquals(DIGEST, head.digest());
|
||||
assertEquals("HEAD " + storagePath, backendRequests.poll(5, TimeUnit.SECONDS));
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
String expectedRepositoryUri(String repository) {
|
||||
return ACCOUNT + ".dkr.ecr." + REGION + ".localhost.floci.io:" + ADVERTISED_PORT + "/" + repository;
|
||||
}
|
||||
|
||||
private ValidatableResponse request(String action, Map<String, Object> body) {
|
||||
return given().contentType("application/x-amz-json-1.1")
|
||||
.header("X-Amz-Target", "AmazonEC2ContainerRegistry_V20150921." + action)
|
||||
.header("Authorization", "AWS4-HMAC-SHA256 Credential=" + ACCOUNT
|
||||
+ "/20260923/" + REGION + "/ecr/aws4_request")
|
||||
.body(body)
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
}
|
||||
|
||||
private RegistryResponse execute(HttpClient client, HttpMethod method, URI advertised, String path)
|
||||
throws Exception {
|
||||
// Quarkus tests bind a random TLS port, while the production proxy uses fixed backend ports.
|
||||
// Override only the transport destination; retain the advertised authority and TLS hostname.
|
||||
RequestOptions options = new RequestOptions()
|
||||
.setServer(SocketAddress.inetSocketAddress(sslPort, "127.0.0.1"))
|
||||
.setHost(advertised.getHost())
|
||||
.setPort(advertised.getPort())
|
||||
.setMethod(method)
|
||||
.setURI(path);
|
||||
return client.request(options)
|
||||
.compose(request -> request.send())
|
||||
.compose(response -> response.body().map(body -> new RegistryResponse(
|
||||
response.statusCode(), body.toString(), response.getHeader("Docker-Content-Digest"))))
|
||||
.toCompletionStage().toCompletableFuture().get(10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
private record RegistryResponse(int status, String body, String digest) {}
|
||||
|
||||
public static class Profile implements QuarkusTestProfile {
|
||||
|
||||
static final Path DATA_DIR = Path.of("target", "floci-ecr-tls-uri-test").toAbsolutePath();
|
||||
static final Path TLS_DIR = DATA_DIR.resolve("tls");
|
||||
|
||||
static {
|
||||
try {
|
||||
Files.createDirectories(TLS_DIR);
|
||||
FlociCertificateAuthority ca = FlociCertificateAuthority.loadOrCreate(TLS_DIR);
|
||||
GeneratedCertificate leaf = ca.issueServerCertificate(
|
||||
"localhost", TlsConfigSource.DEFAULT_SAN_HOSTNAMES, KeyAlgorithm.RSA_2048, null);
|
||||
Files.writeString(TLS_DIR.resolve("floci-server.crt"), leaf.certificatePem());
|
||||
Files.writeString(TLS_DIR.resolve("floci-server.key"), leaf.privateKeyPem());
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Could not prepare ECR TLS URI test certificates", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getConfigOverrides() {
|
||||
return Map.ofEntries(
|
||||
Map.entry("floci.services.ecr.tls-uri", "true"),
|
||||
Map.entry("floci.services.ecr.uri-style", "hostname"),
|
||||
Map.entry("floci.default-account-id", ACCOUNT),
|
||||
Map.entry("floci.default-region", "us-east-1"),
|
||||
Map.entry("floci.port", String.valueOf(ADVERTISED_PORT)),
|
||||
Map.entry("floci.tls.enabled", "true"),
|
||||
Map.entry("floci.tls.aws-https-port", "0"),
|
||||
Map.entry("floci.storage.persistent-path", DATA_DIR.toString()),
|
||||
Map.entry("quarkus.tls.key-store.pem.0.cert", TLS_DIR.resolve("floci-server.crt").toString()),
|
||||
Map.entry("quarkus.tls.key-store.pem.0.key", TLS_DIR.resolve("floci-server.key").toString()),
|
||||
Map.entry("quarkus.http.test-ssl-port", "0"),
|
||||
Map.entry("quarkus.http.insecure-requests", "enabled"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,6 +228,40 @@ class EcrServiceTest {
|
||||
assertEquals(REPO, repos.get(0).getRepositoryName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeRepositoriesRefreshesStoredUrisForTheCurrentConfiguration() {
|
||||
String namedRepository = REPO + "-named";
|
||||
String listedRepository = REPO + "-listed";
|
||||
service.createRepository(namedRepository, null, null, null, null, null, null, REGION);
|
||||
service.createRepository(listedRepository, null, null, null, null, null, null, REGION);
|
||||
when(registryManager.getRepositoryUri(anyString(), anyString(), anyString()))
|
||||
.thenAnswer(invocation -> invocation.getArgument(0) + ".dkr.ecr." + invocation.getArgument(1)
|
||||
+ ".localhost.floci.io:4566/" + invocation.getArgument(2));
|
||||
|
||||
Repository named = service.describeRepositories(List.of(namedRepository), null, REGION).getFirst();
|
||||
assertEquals(ACCOUNT + ".dkr.ecr." + REGION + ".localhost.floci.io:4566/" + namedRepository,
|
||||
named.getRepositoryUri());
|
||||
List<Repository> listed = service.describeRepositories(null, null, REGION);
|
||||
assertEquals(2, listed.size());
|
||||
assertTrue(listed.stream().allMatch(repository -> repository.getRepositoryUri()
|
||||
.equals(ACCOUNT + ".dkr.ecr." + REGION + ".localhost.floci.io:4566/"
|
||||
+ repository.getRepositoryName())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteRepositoryRefreshesItsResponseWithoutRecreatingMetadata() {
|
||||
service.createRepository(REPO, null, null, null, null, null, null, REGION);
|
||||
String tlsUri = ACCOUNT + ".dkr.ecr." + REGION + ".localhost.floci.io:4566/" + REPO;
|
||||
when(registryManager.getRepositoryUri(ACCOUNT, REGION, REPO)).thenReturn(tlsUri);
|
||||
when(registryManager.tryEnsureStarted()).thenReturn(false);
|
||||
|
||||
Repository deleted = service.deleteRepository(REPO, null, false, REGION);
|
||||
|
||||
assertEquals(tlsUri, deleted.getRepositoryUri());
|
||||
assertThrows(AwsException.class, () -> service.describeRepositories(List.of(REPO), null, REGION));
|
||||
assertTrue(service.describeRepositories(null, null, REGION).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeRepositories_emptyList_returnsAllInRegion() {
|
||||
service.createRepository("a/one", null, null, null, null, null, null, REGION);
|
||||
|
||||
+23
@@ -137,6 +137,29 @@ class EcrRegistryDataPlaneTest {
|
||||
"hostname").isPresent());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tlsMirrorNamespacePreservesTheAccountAndRegion() {
|
||||
EcrRegistryDataPlane.RegistryRequest request = EcrRegistryDataPlane.requestFor(
|
||||
"floci:4566", "/v2/team/app/manifests/v1",
|
||||
"ns=123456789012.dkr.ecr.eu-west-1.localhost.floci.io%3A4566", "hostname").orElseThrow();
|
||||
|
||||
assertEquals("123456789012", request.accountId());
|
||||
assertEquals("eu-west-1", request.region());
|
||||
assertEquals("/v2/123456789012/eu-west-1/team/app/manifests/v1", request.backendUri());
|
||||
}
|
||||
|
||||
@Test
|
||||
void tlsPathStyleMirrorPreservesTheRepositoryNamespace() {
|
||||
EcrRegistryDataPlane.RegistryRequest request = EcrRegistryDataPlane.requestFor(
|
||||
"floci:4566", "/v2/123456789012/eu-west-1/team/app/manifests/v1",
|
||||
"ns=localhost.floci.io%3A4566", "path").orElseThrow();
|
||||
|
||||
assertEquals("123456789012", request.accountId());
|
||||
assertEquals("eu-west-1", request.region());
|
||||
assertEquals("team/app", request.repositoryName());
|
||||
assertEquals("/v2/123456789012/eu-west-1/team/app/manifests/v1", request.backendUri());
|
||||
}
|
||||
|
||||
@Test
|
||||
void registryPingDoesNotAcquireARepositoryNamespace() {
|
||||
var hostnameRequest = EcrRegistryDataPlane.requestFor(
|
||||
|
||||
+57
-1
@@ -26,6 +26,8 @@ import com.github.dockerjava.api.model.ContainerPort;
|
||||
import com.github.dockerjava.api.model.Frame;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.io.Closeable;
|
||||
@@ -63,6 +65,7 @@ class EcrRegistryManagerTest {
|
||||
private ContainerLogStreamer logStreamer;
|
||||
private ContainerDetector containerDetector;
|
||||
private CurrentContainerNetworkResolver currentContainerNetworkResolver;
|
||||
private EmulatorConfig config;
|
||||
private EmulatorConfig.DockerConfig docker;
|
||||
private EmulatorConfig.EcrServiceConfig ecr;
|
||||
private EmulatorConfig.StorageConfig storage;
|
||||
@@ -97,7 +100,7 @@ class EcrRegistryManagerTest {
|
||||
currentContainerNetworkResolver = Mockito.mock(CurrentContainerNetworkResolver.class);
|
||||
RegionResolver regionResolver = new RegionResolver("us-east-1", "000000000000");
|
||||
|
||||
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
|
||||
config = Mockito.mock(EmulatorConfig.class);
|
||||
ecr = Mockito.mock(EmulatorConfig.EcrServiceConfig.class);
|
||||
docker = Mockito.mock(EmulatorConfig.DockerConfig.class);
|
||||
storage = Mockito.mock(EmulatorConfig.StorageConfig.class);
|
||||
@@ -353,6 +356,59 @@ class EcrRegistryManagerTest {
|
||||
verify(lifecycleManager).createAndStart(any());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"hostname, false, false, 000000000000.dkr.ecr.us-east-1.localhost:4566/app, http://000000000000.dkr.ecr.us-east-1.localhost:4566",
|
||||
"hostname, true, false, 000000000000.dkr.ecr.us-east-1.localhost:4566/app, http://000000000000.dkr.ecr.us-east-1.localhost:4566",
|
||||
"hostname, false, true, 000000000000.dkr.ecr.us-east-1.localhost:4566/app, http://000000000000.dkr.ecr.us-east-1.localhost:4566",
|
||||
"hostname, true, true, 000000000000.dkr.ecr.us-east-1.localhost.floci.io:4566/app, https://000000000000.dkr.ecr.us-east-1.localhost.floci.io:4566",
|
||||
"path, false, false, localhost:4566/000000000000/us-east-1/app, http://000000000000.dkr.ecr.us-east-1.localhost:4566",
|
||||
"path, true, false, localhost:4566/000000000000/us-east-1/app, http://000000000000.dkr.ecr.us-east-1.localhost:4566",
|
||||
"path, false, true, localhost:4566/000000000000/us-east-1/app, http://000000000000.dkr.ecr.us-east-1.localhost:4566",
|
||||
"path, true, true, localhost.floci.io:4566/000000000000/us-east-1/app, https://localhost.floci.io:4566"
|
||||
})
|
||||
void advertisedUrisRequireBothTlsAndOptIn(String style, boolean globalTls, boolean tlsUris,
|
||||
String repositoryUri, String proxyEndpoint) {
|
||||
EmulatorConfig.TlsConfig tls = Mockito.mock(EmulatorConfig.TlsConfig.class);
|
||||
when(config.tls()).thenReturn(tls);
|
||||
when(tls.enabled()).thenReturn(globalTls);
|
||||
when(ecr.uriStyle()).thenReturn(style);
|
||||
when(ecr.tlsUri()).thenReturn(tlsUris);
|
||||
|
||||
assertEquals(repositoryUri, manager.getRepositoryUri("000000000000", "us-east-1", "app"));
|
||||
assertEquals(proxyEndpoint, manager.getProxyEndpoint());
|
||||
verify(lifecycleManager, never()).createAndStart(any());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"hostname, 123456789012.dkr.ecr.us-east-1.localhost:4566/backend-user:1",
|
||||
"path, localhost:4566/123456789012/us-east-1/backend-user:1"
|
||||
})
|
||||
void automaticImageRewritesKeepLoopbackWhenTlsUrisAreAdvertised(String style, String expectedImage) {
|
||||
EmulatorConfig.TlsConfig tls = Mockito.mock(EmulatorConfig.TlsConfig.class);
|
||||
when(config.tls()).thenReturn(tls);
|
||||
when(tls.enabled()).thenReturn(true);
|
||||
when(ecr.uriStyle()).thenReturn(style);
|
||||
when(ecr.tlsUri()).thenReturn(true);
|
||||
when(lifecycleManager.createAndStart(any())).thenReturn(
|
||||
new ContainerLifecycleManager.ContainerInfo("container-id", Map.of()));
|
||||
|
||||
assertTrue(manager.getRepositoryUri("123456789012", "us-east-1", "backend-user")
|
||||
.contains("localhost.floci.io:"));
|
||||
assertEquals(expectedImage, manager.rewriteImageUri(AWS_ECR_IMAGE));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tlsUriOptInDoesNotReplaceTheLegacyEcrTlsSetting() {
|
||||
when(ecr.tlsEnabled()).thenReturn(true);
|
||||
|
||||
assertEquals("http://" + REGISTRY_NAME + ":5000", manager.internalEndpoint());
|
||||
assertEquals("000000000000.dkr.ecr.us-east-1.localhost:4566/app",
|
||||
manager.getRepositoryUri("000000000000", "us-east-1", "app"));
|
||||
assertEquals("https://000000000000.dkr.ecr.us-east-1.localhost:4566", manager.getProxyEndpoint());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rewriteImageUri_pathStyleConfig_usesPathStyleUri() {
|
||||
when(ecr.uriStyle()).thenReturn("path");
|
||||
|
||||
@@ -177,6 +177,43 @@ class EksClusterManagerTest {
|
||||
assertTrue(yaml.contains("- \"http://floci:4566\""));
|
||||
}
|
||||
|
||||
@Test
|
||||
void registriesYamlTlsAliasesPreserveLoopbackMirrorsAndInternalHttpEndpoint() {
|
||||
String endpoint = "http://host.docker.internal:4577";
|
||||
String yaml = EksClusterManager.buildRegistriesYaml(
|
||||
"111122223333", AwsRegions.ALL, 4577, endpoint, true);
|
||||
|
||||
for (String region : AwsRegions.ALL) {
|
||||
assertTrue(yaml.contains("\"111122223333.dkr.ecr." + region + ".localhost:4577\":"));
|
||||
assertTrue(yaml.contains("\"111122223333.dkr.ecr." + region + ".localhost.floci.io:4577\":"));
|
||||
}
|
||||
assertTrue(yaml.contains("\"localhost:4577\":"));
|
||||
assertTrue(yaml.contains("\"localhost.floci.io:4577\":"));
|
||||
assertFalse(yaml.contains("*"), "mirrors must not intercept unrelated registries");
|
||||
assertFalse(yaml.contains("amazonaws.com"));
|
||||
assertFalse(yaml.contains("docker.io"));
|
||||
assertFalse(yaml.contains("ghcr.io"));
|
||||
assertFalse(yaml.contains("https://"), "internal pulls still use the HTTP data plane");
|
||||
long endpoints = yaml.lines().filter(line -> line.contains("- \"" + endpoint + "\"")).count();
|
||||
assertEquals(2L * (AwsRegions.ALL.size() + 1), endpoints);
|
||||
}
|
||||
|
||||
@Test
|
||||
void registriesYamlKeepsTheExistingOutputWhenTlsUrisAreDisabled() {
|
||||
String yaml = EksClusterManager.buildRegistriesYaml(
|
||||
"111122223333", List.of("eu-central-1"), 4566, "http://floci:4566", false);
|
||||
|
||||
assertEquals("""
|
||||
mirrors:
|
||||
"111122223333.dkr.ecr.eu-central-1.localhost:4566":
|
||||
endpoint:
|
||||
- "http://floci:4566"
|
||||
"localhost:4566":
|
||||
endpoint:
|
||||
- "http://floci:4566"
|
||||
""", yaml);
|
||||
}
|
||||
|
||||
@Test
|
||||
void serverArgsOmitCniFlagsByDefault() {
|
||||
List<String> args = EksClusterManager.buildServerArgs(false);
|
||||
@@ -574,6 +611,7 @@ class EksClusterManagerTest {
|
||||
private DockerClient dockerClient;
|
||||
private CopyArchiveToContainerCmd copyCmd;
|
||||
private EcrRegistryManager registryManager;
|
||||
private EmulatorConfig config;
|
||||
private EmulatorConfig.EksServiceConfig eks;
|
||||
private EmulatorConfig.EcrServiceConfig ecr;
|
||||
private EksClusterManager manager;
|
||||
@@ -588,7 +626,7 @@ class EksClusterManagerTest {
|
||||
|
||||
registryManager = Mockito.mock(EcrRegistryManager.class);
|
||||
|
||||
EmulatorConfig config = Mockito.mock(EmulatorConfig.class);
|
||||
config = Mockito.mock(EmulatorConfig.class);
|
||||
eks = Mockito.mock(EmulatorConfig.EksServiceConfig.class);
|
||||
ecr = Mockito.mock(EmulatorConfig.EcrServiceConfig.class);
|
||||
when(config.services()).thenReturn(Mockito.mock(EmulatorConfig.ServicesConfig.class));
|
||||
@@ -611,12 +649,46 @@ class EksClusterManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void injectsTheMirrorIntoTheContainer() {
|
||||
void injectsTheMirrorIntoTheContainer() throws Exception {
|
||||
manager.injectEcrRegistryMirror("container-1", "demo");
|
||||
|
||||
verify(registryManager).ensureStarted();
|
||||
verify(copyCmd).withRemotePath("/etc");
|
||||
verify(copyCmd).exec();
|
||||
verify(config, never()).tls();
|
||||
String yaml = Files.readString(tempDir.resolve("registries/demo/registries.yaml"));
|
||||
assertFalse(yaml.contains("localhost.floci.io"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void injectsTlsAliasesWhenTlsAndTlsUrisAreEnabled() throws Exception {
|
||||
EmulatorConfig.TlsConfig tls = Mockito.mock(EmulatorConfig.TlsConfig.class);
|
||||
when(config.tls()).thenReturn(tls);
|
||||
when(tls.enabled()).thenReturn(true);
|
||||
when(ecr.tlsUri()).thenReturn(true);
|
||||
|
||||
manager.injectEcrRegistryMirror("container-1", "demo");
|
||||
|
||||
String yaml = Files.readString(tempDir.resolve("registries/demo/registries.yaml"));
|
||||
assertTrue(yaml.contains("\"000000000000.dkr.ecr.us-east-1.localhost.floci.io:4566\":"));
|
||||
assertTrue(yaml.contains("\"localhost.floci.io:4566\":"));
|
||||
assertTrue(yaml.contains("- \"http://floci:4566\""));
|
||||
assertFalse(yaml.contains("https://"));
|
||||
verify(copyCmd).exec();
|
||||
}
|
||||
|
||||
@Test
|
||||
void omitsTlsAliasesWhenTlsIsDisabled() throws Exception {
|
||||
EmulatorConfig.TlsConfig tls = Mockito.mock(EmulatorConfig.TlsConfig.class);
|
||||
when(config.tls()).thenReturn(tls);
|
||||
when(ecr.tlsUri()).thenReturn(true);
|
||||
|
||||
manager.injectEcrRegistryMirror("container-1", "demo");
|
||||
|
||||
String yaml = Files.readString(tempDir.resolve("registries/demo/registries.yaml"));
|
||||
assertFalse(yaml.contains("localhost.floci.io"));
|
||||
assertTrue(yaml.contains("\"localhost:4566\":"));
|
||||
verify(copyCmd).exec();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in new issue
Block a user