Skip to content

Commit 444d8b0

Browse files
cescoffiergsmet
authored andcommitted
Redis Client - Enable TLS/SSL Only with rediss:// Scheme
Previously, if `quarkus.tls.trust-all` was set, the Redis client would automatically use TLS. This commit ensures that TLS is only enabled when the host scheme is rediss://, aligning the behavior with expected usage patterns. Fix #41548 (cherry picked from commit 0fdf12c)
1 parent 2c0b79b commit 444d8b0

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

extensions/redis-client/runtime/src/main/java/io/quarkus/redis/runtime/client/VertxRedisClientFactory.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static Redis create(String name, Vertx vertx, RedisClientConfig config, T
9494
config.replicas().ifPresent(options::setUseReplicas);
9595

9696
options.setNetClientOptions(toNetClientOptions(config));
97-
configureTLS(name, config, tlsRegistry, options.getNetClientOptions());
97+
configureTLS(name, config, tlsRegistry, options.getNetClientOptions(), hosts);
9898

9999
options.setPoolName(name);
100100
// Use the convention defined by Quarkus Micrometer Vert.x metrics to create metrics prefixed with redis.
@@ -180,10 +180,18 @@ public static RedisHostsProvider findProvider(String name) {
180180
}
181181

182182
private static void configureTLS(String name, RedisClientConfig config, TlsConfigurationRegistry tlsRegistry,
183-
NetClientOptions net) {
183+
NetClientOptions net, List<URI> hosts) {
184184
TlsConfiguration configuration = null;
185185
boolean defaultTrustAll = false;
186186

187+
boolean tlsFromHosts = false;
188+
for (URI uri : hosts) {
189+
if ("rediss".equals(uri.getScheme())) {
190+
tlsFromHosts = true;
191+
break;
192+
}
193+
}
194+
187195
// Check if we have a named TLS configuration or a default configuration:
188196
if (config.tlsConfigurationName().isPresent()) {
189197
Optional<TlsConfiguration> maybeConfiguration = tlsRegistry.get(config.tlsConfigurationName().get());
@@ -200,10 +208,15 @@ private static void configureTLS(String name, RedisClientConfig config, TlsConfi
200208
}
201209
}
202210

211+
if (configuration != null && !tlsFromHosts) {
212+
LOGGER.warnf("The Redis client %s is configured with a named TLS configuration but the hosts are not " +
213+
"using the `rediss://` scheme - Disabling TLS", name);
214+
}
215+
203216
// Apply the configuration
204217
if (configuration != null) {
205218
// This part is often the same (or close) for every Vert.x client:
206-
net.setSsl(true);
219+
net.setSsl(tlsFromHosts);
207220

208221
if (configuration.getTrustStoreOptions() != null) {
209222
net.setTrustOptions(configuration.getTrustStoreOptions());
@@ -244,7 +257,7 @@ private static void configureTLS(String name, RedisClientConfig config, TlsConfi
244257
} else {
245258
net.setHostnameVerificationAlgorithm(verificationAlgorithm);
246259
}
247-
net.setSsl(config.tls().enabled() || defaultTrustAll);
260+
net.setSsl(config.tls().enabled() || tlsFromHosts);
248261
net.setTrustAll(config.tls().trustAll() || defaultTrustAll);
249262

250263
configurePemTrustOptions(net, config.tls().trustCertificatePem());

0 commit comments

Comments
 (0)