fix(docker): pass the resolved TLS config to the Docker HTTP client (#4638)

* fix(docker): pass the resolved TLS config to the Docker HTTP client

The client config carried TLS material from DOCKER_TLS_VERIFY/DOCKER_CERT_PATH or the active context, but the ApacheDockerHttpClient was built without it, so TLS daemons were spoken to in plain HTTP. The HTTP client is now built in a package-private newHttpClient that passes clientConfig.getSSLConfig(); a TLS-verify config with unreadable certificates now fails the build, which the test uses to observe that the SSL config is actually consumed.

Fixes #4608

* test(docker): use explicit types and imports in the TLS client tests
This commit is contained in:
Sam Fakhreddine authored and GitHub committed 2026-10-04 20:45:20 -05:00
1 parent b2e3870c06
commit 728e000187
2 files changed
+42 -3

No files matched your search

@@ -489,14 +489,18 @@ public class DockerClientProducer {
LOG.infov("Creating {0} DockerClient pool (maxConnections={1}) for host: {2}",
role, maxConnections, clientConfig.getDockerHost());
ApacheDockerHttpClient httpClient = new ApacheDockerHttpClient.Builder()
return DockerClientImpl.getInstance(clientConfig,
wrapForRole(newHttpClient(clientConfig, maxConnections), role));
}
static ApacheDockerHttpClient newHttpClient(DefaultDockerClientConfig clientConfig, int maxConnections) {
return new ApacheDockerHttpClient.Builder()
.dockerHost(clientConfig.getDockerHost())
.sslConfig(clientConfig.getSSLConfig())
.maxConnections(maxConnections)
.connectionTimeout(Duration.ofSeconds(30))
.responseTimeout(Duration.ofMinutes(5))
.build();
return DockerClientImpl.getInstance(clientConfig, wrapForRole(httpClient, role));
}
/**
@@ -3,6 +3,8 @@ package io.github.hectorvent.floci.core.common.docker;
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.async.ResultCallback;
import com.github.dockerjava.api.model.Frame;
import com.github.dockerjava.core.DefaultDockerClientConfig;
import com.github.dockerjava.httpclient5.ApacheDockerHttpClient;
import io.github.hectorvent.floci.config.EmulatorConfig;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -723,4 +725,37 @@ class DockerClientProducerTest {
}
}
}
@Test
void newHttpClient_tlsVerifyConfig_loadsTheConfiguredCertificates(@TempDir Path certDir) throws IOException {
// Catches: TLS material resolved onto the client config but never handed to the HTTP transport
Files.writeString(certDir.resolve("ca.pem"), "not a certificate");
Files.writeString(certDir.resolve("cert.pem"), "not a certificate");
Files.writeString(certDir.resolve("key.pem"), "not a key");
DefaultDockerClientConfig tlsConfig =
DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("tcp://127.0.0.1:2376")
.withDockerTlsVerify(true)
.withDockerCertPath(certDir.toString())
.build();
// An HTTP client that actually uses the SSL config must read the certificates, so
// unreadable ones fail the build; one that ignores the config builds silently.
assertThrows(RuntimeException.class, () -> DockerClientProducer.newHttpClient(tlsConfig, 10));
}
@Test
void newHttpClient_plainTcpConfig_buildsWithoutTls() throws IOException {
// Catches: passing the SSL config breaking hosts that have no TLS material
DefaultDockerClientConfig plainConfig =
DefaultDockerClientConfig.createDefaultConfigBuilder()
.withDockerHost("tcp://127.0.0.1:2375")
.withDockerTlsVerify(false)
.build();
try (ApacheDockerHttpClient client = DockerClientProducer.newHttpClient(plainConfig, 10)) {
assertNull(plainConfig.getSSLConfig(), "a config without TLS verify carries no SSL config");
assertEquals("tcp://127.0.0.1:2375", plainConfig.getDockerHost().toString());
}
}
}