fix(objectstorage): Minio TLS 시험이 CI job 안에서도 컨테이너에 닿는다

문제: 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 본문에 적는다).
This commit is contained in:
DongHyeonka
2026-11-12 01:16:56 +09:00
parent 97798b5a35
commit ecc1400486
2 changed files with 35 additions and 7 deletions
@@ -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;
}
}
@@ -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.
*
* <p>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 = {