spring-session: ERR unknown command 'CONFIG' when using Secured Redis
Redis security recommends disabling the CONFIG
command so that remote users cannot reconfigure an instance. The RedisHttpSessionConfiguration
requires access to this during its initialization. Hosted Redis services, like AWS ElastiCache disable this command by default, with no option to re-enable it.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 27 (15 by maintainers)
Commits related to this issue
- overload Spring's RedisHttpSessionConfiguration * https://github.com/spring-projects/spring-session/issues/124 — committed to spinnaker/gate by danveloper 9 years ago
- Fix doc dependencies for gh-124 — committed to spring-projects/spring-session by deleted user 9 years ago
I think it should be enabled by default, but fail gracefully with a warning. This would allow the same configuration to be used between dev and prod, where dev would JustWork™ and prod would require some manual intervention (which would be obvious from the warning).
I was able to work around the problem by subclassing the
RedisHttpSessionConfiguration
with an implementation that disables the keyspace notifications initializer, and bringing it in through normal configuration means:For posterity, here are the steps for enabling the keyspace notifications on AWS:
Log into the AWS console and choose the ElastiCache service
Choose the Cache Parameter Groups and click Create Parameter Group
Give the new group and name and description and click Create
With the new parameter group created, select it and click Edit Parameters
Page through the parameters until you find notify-keyspace-events and enter "eA" in the Value field and click Save Changes
Choose Cache Clusters from the context navigation and create a new Redis cache cluster
When specifying your cluster detail, choose the newly created parameter group
Thanks for the report @danveloper! This indeed seems to be a bug with the
RedisHttpSessionConfiguration
and thus the@EnableRedisHttpSession
annotation.UPDATE Fixing in 1.0.1
As of Spring Session 1.0.1 this can be disabled by exposing
ConfigureRedisAction.NO_OP
as a bean.An XML Configuration example
A Java Configuration example
Fixing the Issue
I’m debating what the best approach to fixing this would be though and wondering what your thoughts were @danveloper.
There is certainly a need for a fix, so I’m not debating that we need to fix something. However, I like the fact that it updates the Redis configuration by default for two reasons:
SessionDestroyedEvent
to be fired to clean up resources. In particular, this is important for WebSocket applications to ensure open WebSockets are closed when the HttpSession expires.My initial thoughts on how we should update the configuration is:
RedisHttpSessionConfiguration
should by default update the Redis configuration only if Spring WebSocket support is enabled.RedisHttpSessionConfiguration
should allow disabling updating the Redis configurationRedisHttpSessionConfiguration
should by default try to subscribe to keyspace notifications only if Spring WebSocket support is enabled. This will help increase performance for applications simply using Spring Session forHttpSession
which typically does not need to receive theSessionDestroyedEvent
RedisHttpSessionConfiguration
should allow explicitly configuring if the application should subscribe to keyspace notificationsWorkaround
In the meantime, a workaround is to remove
@EnableRedisHttpSession
from your configuration and then include a configuration with a fix. For example:If you are not using the
SessionDestroyedEvent
you can also disable subscribing to the notifications which should improve performance. For example:When I configured the elasticache (Redis on AWS) using the guide from previous post I fugured out that the
eA
parameter fornotify-keyspace-events
does not work correctly. Correct configuration isEA
(E with capital letter). In the documentation (https://redis.io/topics/notifications) you can see that theA
is an alias e.g. fore
which means, thateA
is effectively justA
. Redis Spring Session functionality needs thisE
because it consumes those key-events. So, specify thereEA
.That doesn’t sound right -
ConfigureRedisAction.NO_OP
is intended specifically as a configuration option for Spring Session’s Redis integration.If you’re not using Spring Session at all, you need something else to resolve the issue. I’d suggest taking a look at Spring Data Redis reference manual, or opening an issue over there if you don’t find anything.
@oak-tree See https://github.com/spring-projects/spring-session/issues/124#issuecomment-71490616 and http://docs.spring.io/spring-session/docs/current/reference/html5/#api-redisoperationssessionrepository-sessiondestroyedevent