question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SSL support for Redis Connector

See original GitHub issue

I tried Redis Connector with Spring Music. With a user-provided service instance like below, Spring Music can start and work well.

cf cups redis -p '{"uri":"redis://<redis-name>:<key>@<redis-name>.redis.cache.windows.net:6379"}'

But Spring Music can’t start with this (notice the port 6380 which is the SSL port of Azure Redis),

cf cups redis -p '{"uri":"redis://<redis-name>:<key>@<redis-name>.redis.cache.windows.net:6380"}'

Some logs:

   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:204) ~[spring-data-redis-1.8.4.RELEASE.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.getConnection(JedisConnectionFactory.java:348) ~[spring-data-redis-1.8.4.RELEASE.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:129) ~[spring-data-redis-1.8.4.RELEASE.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:92) ~[spring-data-redis-1.8.4.RELEASE.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:79) ~[spring-data-redis-1.8.4.RELEASE.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:194) ~[spring-data-redis-1.8.4.RELEASE.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:169) ~[spring-data-redis-1.8.4.RELEASE.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:91) ~[spring-data-redis-1.8.4.RELEASE.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.data.redis.core.DefaultHashOperations.keys(DefaultHashOperations.java:98) ~[spring-data-redis-1.8.4.RELEASE.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.cloudfoundry.samples.music.repositories.redis.RedisAlbumRepository.count(RedisAlbumRepository.java:69) ~[classes/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.cloudfoundry.samples.music.repositories.AlbumRepositoryPopulator.onApplicationEvent(AlbumRepositoryPopulator.java:45) ~[classes/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.cloudfoundry.samples.music.repositories.AlbumRepositoryPopulator.onApplicationEvent(AlbumRepositoryPopulator.java:20) ~[classes/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167) ~[spring-context-4.3.9.RELEASE.jar!/:4.3.9.RELEASE]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-4.3.9.RELEASE.jar!/:4.3.9.RELEASE]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393) ~[spring-context-4.3.9.RELEASE.jar!/:4.3.9.RELEASE]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347) ~[spring-context-4.3.9.RELEASE.jar!/:4.3.9.RELEASE]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883) ~[spring-context-4.3.9.RELEASE.jar!/:4.3.9.RELEASE]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) ~[spring-boot-1.5.4.RELEASE.jar!/:1.5.4.RELEASE]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-4.3.9.RELEASE.jar!/:4.3.9.RELEASE]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.4.RELEASE.jar!/:1.5.4.RELEASE]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) ~[spring-boot-1.5.4.RELEASE.jar!/:1.5.4.RELEASE]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) ~[spring-boot-1.5.4.RELEASE.jar!/:1.5.4.RELEASE]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) ~[spring-boot-1.5.4.RELEASE.jar!/:1.5.4.RELEASE]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.cloudfoundry.samples.music.Application.main(Application.java:15) [classes/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) [app/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) [app/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) [app/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) [app/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT Caused by: redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at redis.clients.util.Pool.getResource(Pool.java:53) ~[jedis-2.9.0.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at redis.clients.jedis.JedisPool.getResource(JedisPool.java:226) ~[jedis-2.9.0.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at redis.clients.jedis.JedisPool.getResource(JedisPool.java:16) ~[jedis-2.9.0.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.springframework.data.redis.connection.jedis.JedisConnectionFactory.fetchJedisConnector(JedisConnectionFactory.java:194) ~[spring-data-redis-1.8.4.RELEASE.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     ... 31 common frames omitted
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT Caused by: redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketTimeoutException: Read timed out
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:202) ~[jedis-2.9.0.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40) ~[jedis-2.9.0.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at redis.clients.jedis.Protocol.process(Protocol.java:151) ~[jedis-2.9.0.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at redis.clients.jedis.Protocol.read(Protocol.java:215) ~[jedis-2.9.0.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:340) ~[jedis-2.9.0.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at redis.clients.jedis.Connection.getStatusCodeReply(Connection.java:239) ~[jedis-2.9.0.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at redis.clients.jedis.BinaryJedis.auth(BinaryJedis.java:2139) ~[jedis-2.9.0.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at redis.clients.jedis.JedisFactory.makeObject(JedisFactory.java:108) ~[jedis-2.9.0.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:868) ~[commons-pool2-2.4.2.jar!/:2.4.2]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:435) ~[commons-pool2-2.4.2.jar!/:2.4.2]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:363) ~[commons-pool2-2.4.2.jar!/:2.4.2]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at redis.clients.util.Pool.getResource(Pool.java:49) ~[jedis-2.9.0.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     ... 34 common frames omitted
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT Caused by: java.net.SocketTimeoutException: Read timed out
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.8.0_181]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[na:1.8.0_181]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at java.net.SocketInputStream.read(SocketInputStream.java:171) ~[na:1.8.0_181]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[na:1.8.0_181]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at java.net.SocketInputStream.read(SocketInputStream.java:127) ~[na:1.8.0_181]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:196) ~[jedis-2.9.0.jar!/:na]
   2018-08-30T07:32:59.65+0000 [APP/PROC/WEB/0] OUT     ... 45 common frames omitted

It seems that the dependency spring-data-redis supports SSL: https://github.com/spring-projects/spring-data-redis/search?p=2&q=ssl&unscoped_q=ssl. So, is it an issue in connector side?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
norshteincommented, Aug 31, 2018

Hi @scottfrederick , in later development, both the meta azure service broker and open service broker for azure can guarantee two points:

  • Key redisUrl will be given
  • If the Redis cache is expected to use SSL, then the value of redisUrl will begin with rediss://.

After diving into the connector’s code, I found a possible fix: Add a new scheme rediss for RedisServiceInfoCreator and use it in the constructor, and do the validation as @zhongyi-zhang said above. Then the connector can enable SSL in underlying factory for Azure Redis. And for other IaaS providers who don’t have this feature (Redis with SSL), this won’t affect their usage, and if one day they develop this feature, it’s reasonable for them to use rediss://xxx in redisUrl field.

1reaction
norshteincommented, Aug 31, 2018

I think it should be caused by the code here. When constructing the underlying factory, a default configuration is used, in which useSsl is false by default. The same in below LettuceClientConfigurationBuilder. I think a judgement can be added here to fix this issue, a possible fix might be:

if(serviceInfo.getHost().contains("rediss")) {
	builder.useSsl();
}
JedisConnectionFactory connectionFactory = new JedisConnectionFactory(configuration, builder.build());
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use SSL/TLS With Redis Enterprise
Step 1. Run a Redis server​ · Step 2. Get the Certificate from Redis Cluster​ · Step 3. Generate a New Client Certificate​...
Read more >
TLS | Redis
TLS. Redis TLS support. SSL/TLS is supported by Redis starting with version 6 as an optional feature that needs to be enabled at...
Read more >
Secure SSL Redis connections - ServiceStack Docs
The SSL Support in the Redis Client also enables secure access to a redis-server instance over the Internet and public networks as well,...
Read more >
Enable SSL for Redis - OutSystems How to Guide
Open the Configuration Tool and select the Session tab. · Select the Redis Session Provider, if it's not selected. · Enable the Use...
Read more >
How To Connect to a Managed Redis Instance over TLS with ...
One way to establish a secure connection to a managed Redis instance is to create a tunnel that uses the TLS protocol.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found