Blame SOURCES/bz1683548-redis-mute-password-warning.patch

b94b9d
From 6303448af77d2ed64c7436a84b30cf7fa4941e19 Mon Sep 17 00:00:00 2001
b94b9d
From: Michele Baldessari <michele@acksyn.org>
b94b9d
Date: Wed, 30 Jan 2019 21:36:17 +0100
b94b9d
Subject: [PATCH] redis: Filter warning from stderr when calling 'redis-cli -a'
b94b9d
b94b9d
In some versions of redis (starting with 4.0.10) we have commits [1] and
b94b9d
[2] which add a warning on stderr which will be printed out every single
b94b9d
time a monitor operation takes place:
b94b9d
b94b9d
  foo pacemaker-remoted[57563]:  notice: redis_monitor_20000:1930:stderr
b94b9d
  [ Warning: Using a password with '-a' option on the command line interface may not be safe. ]
b94b9d
b94b9d
Later on commit [3] (merged with 5.0rc4) was merged which added the option
b94b9d
'--no-auth-warning' to disable said warning since it broke a bunch of
b94b9d
scripts [4]. I tried to forcibly either try the command twice (first
b94b9d
with --no-auth-warning and then without in case of errors) but it is
b94b9d
impossible to distinguish between error due to missing param and other
b94b9d
errors.
b94b9d
b94b9d
So instead of inspecting the version of the redis-cli tool and do the following:
b94b9d
- >= 5.0.0 use --no-auth-warning all the time
b94b9d
- >= 4.0.10 & < 5.0.0 filter the problematic line from stderr only
b94b9d
- else do it like before
b94b9d
b94b9d
We simply filter out from stderr the 'Using a password' message
b94b9d
unconditionally while making sure we keep stdout just the same.
b94b9d
b94b9d
Tested on a redis 4.0.10 cluster and confirmed that it is working as
b94b9d
intended.
b94b9d
b94b9d
All this horror and pain is due to the fact that redis does not support
b94b9d
any other means to pass a password (we could in theory first connect to
b94b9d
the server and then issue an AUTH command, but that seems even more
b94b9d
complex and error prone). See [5] for more info (or [6] for extra fun)
b94b9d
b94b9d
[1] https://github.com/antirez/redis/commit/c082221aefbb2a472c7193dbdbb90900256ce1a2
b94b9d
[2] https://github.com/antirez/redis/commit/ef931ef93e909b4f504e8c6fbed350ed70c1c67c
b94b9d
[3] https://github.com/antirez/redis/commit/a4ef94d2f71a32f73ce4ebf154580307a144b48f
b94b9d
[4] https://github.com/antirez/redis/issues/5073
b94b9d
[5] https://github.com/antirez/redis/issues/3483
b94b9d
[6] https://github.com/antirez/redis/pull/2413
b94b9d
b94b9d
Signed-off-by: Michele Baldessari <michele@acksyn.org>
b94b9d
---
b94b9d
 heartbeat/redis.in | 4 +++-
b94b9d
 1 file changed, 3 insertions(+), 1 deletion(-)
b94b9d
b94b9d
diff --git a/heartbeat/redis.in b/heartbeat/redis.in
b94b9d
index 1dff067e9..e257bcc5e 100644
b94b9d
--- a/heartbeat/redis.in
b94b9d
+++ b/heartbeat/redis.in
b94b9d
@@ -302,7 +302,9 @@ set_score()
b94b9d
 redis_client() {
b94b9d
 	ocf_log debug "redis_client: '$REDIS_CLIENT' -s '$REDIS_SOCKET' $*"
b94b9d
 	if [ -n "$clientpasswd" ]; then
b94b9d
-		"$REDIS_CLIENT" -s "$REDIS_SOCKET" -a "$clientpasswd" "$@" | sed 's/\r//'
b94b9d
+		# Starting with 4.0.10 there is a warning on stderr when using a pass
b94b9d
+		# Once we stop supporting versions < 5.0.0 we can add --no-auth-warning here
b94b9d
+		("$REDIS_CLIENT" -s "$REDIS_SOCKET" -a "$clientpasswd" "$@" 2>&1 >&3 3>&- | grep -v "Using a password" >&2 3>&-) 3>&1 | sed 's/\r//'
b94b9d
 	else
b94b9d
 		"$REDIS_CLIENT" -s "$REDIS_SOCKET" "$@" | sed 's/\r//'
b94b9d
 	fi