From ecc1400486f3df9968d8337f2fef5fe90d77cd79 Mon Sep 17 00:00:00 2001 From: DongHyeonka Date: Thu, 12 Nov 2026 01:16:56 +0900 Subject: [PATCH] =?UTF-8?q?fix(objectstorage):=20Minio=20TLS=20=EC=8B=9C?= =?UTF-8?q?=ED=97=98=EC=9D=B4=20CI=20job=20=EC=95=88=EC=97=90=EC=84=9C?= =?UTF-8?q?=EB=8F=84=20=EC=BB=A8=ED=85=8C=EC=9D=B4=EB=84=88=EC=97=90=20?= =?UTF-8?q?=EB=8B=BF=EB=8A=94=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문제: MinioS3ManagedObjectProviderContractTest는 endpoint를 `https://localhost:<포트>`로 고정했다. Gitea runner의 job 컨테이너 안에서 localhost는 job 컨테이너 자신이고, Testcontainers가 띄운 MinIO는 dind daemon 쪽에 있다. 그래서 main의 integration job이 run 52·63·79 세 번 모두 이 시험의 연결 거부로 빨갛다. desktop에서는 둘이 같아 통과한다. 시험 인증서도 localhost와 127.0.0.1만 이름으로 가졌다. 고른 방법: 같은 lane의 평문 시험(MinioManagedObjectContractTest)처럼 Testcontainers가 알려 주는 Docker 호스트 주소로 붙고, 그 주소를 인증서 SAN에 더한다(IP면 ip:, 이름이면 dns:). 인증서는 컨테이너보다 먼저 만들어야 하므로 주소는 DockerClientFactory에서 받는다. 버린 대안: 인증서 검증을 끄는 것. 이 시험은 운영 클라이언트 그대로 HTTPS로 붙는 것이 목적이라 검증을 끄면 시험이 다른 경로를 본다. 위험·한계: IPv6 호스트는 URI에 대괄호를 씌우는 것만 넣었고 그 환경에서 돌려 보지 않았다. 검증: desktop integrationCheck, runner main 수동 실행(이 PR 본문에 적는다). --- ...ioS3ManagedObjectProviderContractTest.java | 19 +++++++++++++-- .../s3/SelfSignedServerCertificate.java | 23 +++++++++++++++---- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/MinioS3ManagedObjectProviderContractTest.java b/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/MinioS3ManagedObjectProviderContractTest.java index f4409a48..c1547434 100644 --- a/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/MinioS3ManagedObjectProviderContractTest.java +++ b/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/MinioS3ManagedObjectProviderContractTest.java @@ -15,6 +15,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; +import org.testcontainers.DockerClientFactory; import org.testcontainers.containers.GenericContainer; import org.testcontainers.utility.MountableFile; import software.amazon.awssdk.services.s3.S3AsyncClient; @@ -53,7 +54,11 @@ class MinioS3ManagedObjectProviderContractTest extends ObjectStorageProviderCont String secretKey = UUID.randomUUID().toString().replace("-", "") + UUID.randomUUID(); byte[] keyBytes = new byte[32]; SECURE_RANDOM.nextBytes(keyBytes); - Path certificates = SelfSignedServerCertificate.writeTo(Files.createTempDirectory("minio-tls")); + // The host the mapped port is published on: localhost on a workstation, the Docker daemon's + // address inside a CI job container. The certificate has to name it. + String containerHost = DockerClientFactory.instance().dockerHostIpAddress(); + Path certificates = + SelfSignedServerCertificate.writeTo(Files.createTempDirectory("minio-tls"), containerHost); trustStoreBefore = SelfSignedServerCertificate.trustForThisJvm(certificates); minio = new GenericContainer<>(QualificationImages.minio()) @@ -90,7 +95,12 @@ class MinioS3ManagedObjectProviderContractTest extends ObjectStorageProviderCont .retryBaseDelay(Duration.ofMillis(10)) .retryMaximumBackoff(Duration.ofMillis(20)) .shutdownGrace(Duration.ofSeconds(2)) - .endpointOverride(URI.create("https://localhost:" + minio.getMappedPort(9000))) + .endpointOverride( + URI.create( + "https://" + + endpointHost(containerHost) + + ":" + + minio.getMappedPort(9000))) .pathStyleAccess(true) .staticCredentials(accessKey, secretKey) .build()); @@ -138,4 +148,9 @@ class MinioS3ManagedObjectProviderContractTest extends ObjectStorageProviderCont protected ObjectStorageProvider provider() { return provider; } + + // An IPv6 literal needs brackets in a URI authority. + private static String endpointHost(String containerHost) { + return containerHost.contains(":") ? "[" + containerHost + "]" : containerHost; + } } diff --git a/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/SelfSignedServerCertificate.java b/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/SelfSignedServerCertificate.java index 35624b4b..c02a22fb 100644 --- a/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/SelfSignedServerCertificate.java +++ b/src/adapter/outbound/objectstorage/src/integrationTest/java/dev/caskeleton/adapter/outbound/objectstorage/s3/SelfSignedServerCertificate.java @@ -11,10 +11,14 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; /** - * A throwaway localhost server certificate for one lane run, made with the running JDK's keytool so - * no key material is committed. MinIO reads {@code public.crt} and {@code private.key} (PKCS#8 PEM) - * from its certs directory; the JVM trusts the same certificate through its default trust store + * A throwaway server certificate for one lane run, made with the running JDK's keytool so no key + * material is committed. MinIO reads {@code public.crt} and {@code private.key} (PKCS#8 PEM) from + * its certs directory; the JVM trusts the same certificate through its default trust store * properties, which the SDK's Netty client reads. + * + *

The certificate names localhost and the host the test reaches the container on. They differ + * when the tests run inside a CI job container: there the Docker daemon is another host, and {@code + * localhost} is the job container itself. */ final class SelfSignedServerCertificate { @@ -23,7 +27,7 @@ final class SelfSignedServerCertificate { private SelfSignedServerCertificate() {} - static Path writeTo(Path directory) throws Exception { + static Path writeTo(Path directory, String containerHost) throws Exception { String password = password(directory); Path keytool = Path.of(System.getProperty("java.home"), "bin", "keytool"); Process process = @@ -44,7 +48,7 @@ final class SelfSignedServerCertificate { "-dname", "CN=localhost", "-ext", - "SAN=dns:localhost,ip:127.0.0.1", + subjectAlternativeNames(containerHost), "-storetype", "PKCS12", "-keystore", @@ -74,6 +78,15 @@ final class SelfSignedServerCertificate { return directory; } + private static String subjectAlternativeNames(String containerHost) { + String names = "SAN=dns:localhost,ip:127.0.0.1"; + if (containerHost.equals("localhost") || containerHost.equals("127.0.0.1")) { + return names; + } + boolean ipLiteral = containerHost.contains(":") || containerHost.matches("[0-9.]+"); + return names + (ipLiteral ? ",ip:" : ",dns:") + containerHost; + } + /** Points the JVM default trust store at the certificate; the returned action restores it. */ static Runnable trustForThisJvm(Path directory) throws Exception { String[] names = {