Reputation: 14385
I have a Redis server running with Node.JS version 10.4.2. I am using the NPM "redis" client with my app. I am using the following code to create the Redis client and to authenticate. (Note the code commented out below to see what else I tried):
var redis = require("redis");
// var redisClient = require('redis').createClient(process.env.REDIS_URL || redis);
var redisClient = redis.createClient(
{
port: process.env.REDIS_PORT,
host: process.env.REDIS_URL,
no_ready_check: true,
auth_pass: process.env.REDIS_AUTH
});
/*
// Authenticate with Redis.
redisClient.auth(process.env.REDIS_AUTH, function(err, reply) {
if (err) {
console.error(err);
}
else {
console.log(reply);
}
});
*/
However, I always get the error below:
ReplyError: ERR invalid password
When I used the code that is commented out, I did not use the "no_ready_check" property during createClient(). Some facts:
I triple-checked the value in process.env.REDIS_AUTH and it matches exactly what is in my Redis server conf file for the requirepass password value.
I can use the password to successfully authenticate when testing with the Redis command line client (redis-cli) so I know the Redis server is password protected and that the password works.
I know the password is getting through because when I use the code that is commented out, I can see the correct password in the arguments passed to the callback function.
Why isn't my password working with my Node.JS code and how can I fix this? Note, the password was generated using the SSL random password generator on Linux. I mention that in case it affects anything.
UPDATE: I got this working by using a much shorter password in the Redis server conf file. Apparently the Node.JS Redis package doesn't like the long random passwords generated by the Linux SSL utility, despite there being no strange characters in those passwords at all. I posted an issue on this subject on the package repo here:
https://github.com/NodeRedis/node_redis/issues/1411
Upvotes: 1
Views: 8195
Reputation: 14385
I was using the following commands to create the password using OpenSSL on my Linux box:
openssl rand 60 | openssl base64 -A
Unfortunately openssl
creates passwords with forward slashes in them "/". There may be other characters that are not healthy in this context, but I have not exhaustively tested them. Once I removed the forward slashes from the password, and after I restarted Redis server to register the changes, the client creation attempt worked from Node.JS.
Something is happening on the Node.JS side to those characters on the way to Redis. As I said, I had no problems when directly pasting the very same forward slash containing passwords into the Redis client when using the auth
command. But using them from Node.JS causes the authentication attempt to fail.
My best advice to anyone reading this post is if you are using the openssl command to generate redis passwords for your Node.JS app, remove any characters are that are not strictly 'a-zA-Z' from the generated password. Perhaps someone will give a better solution later as a reply.
Upvotes: 2