Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis Client - Enable TLS/SSL Only with rediss:// Scheme #41573

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public static Redis create(String name, Vertx vertx, RedisClientConfig config, T
config.replicas().ifPresent(options::setUseReplicas);

options.setNetClientOptions(toNetClientOptions(config));
configureTLS(name, config, tlsRegistry, options.getNetClientOptions());
configureTLS(name, config, tlsRegistry, options.getNetClientOptions(), hosts);

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

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

boolean tlsFromHosts = false;
for (URI uri : hosts) {
if ("rediss".equals(uri.getScheme())) {
tlsFromHosts = true;
break;
}
}

// Check if we have a named TLS configuration or a default configuration:
if (config.tlsConfigurationName().isPresent()) {
Optional<TlsConfiguration> maybeConfiguration = tlsRegistry.get(config.tlsConfigurationName().get());
Expand All @@ -200,10 +208,15 @@ private static void configureTLS(String name, RedisClientConfig config, TlsConfi
}
}

if (configuration != null && !tlsFromHosts) {
LOGGER.warnf("The Redis client %s is configured with a named TLS configuration but the hosts are not " +
"using the `rediss://` scheme - Disabling TLS", name);
}

// Apply the configuration
if (configuration != null) {
// This part is often the same (or close) for every Vert.x client:
net.setSsl(true);
net.setSsl(tlsFromHosts);

if (configuration.getTrustStoreOptions() != null) {
net.setTrustOptions(configuration.getTrustStoreOptions());
Expand Down Expand Up @@ -244,7 +257,7 @@ private static void configureTLS(String name, RedisClientConfig config, TlsConfi
} else {
net.setHostnameVerificationAlgorithm(verificationAlgorithm);
}
net.setSsl(config.tls().enabled() || defaultTrustAll);
net.setSsl(config.tls().enabled() || tlsFromHosts);
net.setTrustAll(config.tls().trustAll() || defaultTrustAll);

configurePemTrustOptions(net, config.tls().trustCertificatePem());
Expand Down
Loading