Reputation: 643
I have a problem with a Java Lettuce Redis client with ACL: I get an io.lettuce.core.RedisCommandExecutionException: WRONGPASS invalid username-password pair or user is disabled
exception.
I have a Redis Docker container configured as follows:
My Dockerfile
:
FROM redis:6.2.1
COPY redis.conf /usr/local/etc/redis/redis.conf
COPY users.acl /etc/redis/users.acl
EXPOSE 6379
CMD ["redis-server", "/usr/local/etc/redis/redis.conf"]
The redis.conf
file is:
aclfile /etc/redis/users.acl
and the users.acl
file is:
user myuser on +@all ~* >mypassword
user default off
I run the container with the command:
docker run -it -p 6379:6379 --name myredis myredis
My Java client is:
...
import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
public class Main {
public static void main(String... args) {
try {
RedisClient redisClient = RedisClient.create("redis://myuser:mypassword@localhost");
StatefulRedisConnection<String, String> connection = redisClient.connect();
System.out.println("Connected to Redis");
connection.close();
redisClient.shutdown();
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("End!");
}
}
}
When I try to run it, I get the error:
io.lettuce.core.RedisConnectionException: Unable to connect to localhost:6379
at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)
at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56)
at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:234)
at io.lettuce.core.RedisClient.connect(RedisClient.java:207)
at io.lettuce.core.RedisClient.connect(RedisClient.java:192)
at [MY_PACKAGE].Main.main(Main.java:16)
Caused by: io.lettuce.core.RedisCommandExecutionException: WRONGPASS invalid username-password pair or user is disabled.
at io.lettuce.core.ExceptionFactory.createExecutionException(ExceptionFactory.java:135)
at io.lettuce.core.ExceptionFactory.createExecutionException(ExceptionFactory.java:108)
at io.lettuce.core.protocol.AsyncCommand.completeResult(AsyncCommand.java:120)
at io.lettuce.core.protocol.AsyncCommand.complete(AsyncCommand.java:111)
at io.lettuce.core.protocol.CommandHandler.complete(CommandHandler.java:654)
at io.lettuce.core.protocol.CommandHandler.decode(CommandHandler.java:614)
at io.lettuce.core.protocol.CommandHandler.channelRead(CommandHandler.java:565)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:352)
at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1422)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:374)
at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:360)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:931)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:700)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:635)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:552)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:514)
at io.netty.util.concurrent.SingleThreadEventExecutor$6.run(SingleThreadEventExecutor.java:1050)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:834)
What am I doing wrong? Thanks in advance.
Upvotes: 1
Views: 7526
Reputation: 76
this works for me (lettuce 6.0.4), but it's pure magic:
change
user default off
into
user default off -@all +hello
I read redis and lettuce docs but couldn't find a proper explanation, but this may sound more legit to you:
user default on nopass -@all +hello
which will enable the clients to use default user to run only hello command, then by some means, the clients would know to use the configured user (myuser
) for further commands.
hope this help, wait for the explanation from everyone :penguin:
Upvotes: 1