From 0798be97ebdf6ce7fb60a08002d78b72f55ab0e7 Mon Sep 17 00:00:00 2001 From: John Sully Date: Mon, 15 Apr 2019 22:31:02 -0400 Subject: [PATCH] Fix replica authentication failure when masterauth is below replicaof in the config file Former-commit-id: c64ce7aa9c7783425430e08831f1c41346e315a9 --- src/config.cpp | 2 ++ src/replication.cpp | 19 +++++++++++++++++++ src/server.h | 1 + 3 files changed, 22 insertions(+) diff --git a/src/config.cpp b/src/config.cpp index bcd4052aa..a702a5645 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -399,6 +399,8 @@ void loadServerConfigFromString(char *config) { } else if (!strcasecmp(argv[0],"masterauth") && argc == 2) { zfree(server.default_masterauth); server.default_masterauth = argv[1][0] ? zstrdup(argv[1]) : NULL; + // Loop through all existing master infos and update them (in case this came after the replicaof config) + updateMasterAuth(); } else if ((!strcasecmp(argv[0],"slave-serve-stale-data") || !strcasecmp(argv[0],"replica-serve-stale-data")) && argc == 2) diff --git a/src/replication.cpp b/src/replication.cpp index e46d96d42..4e431cf73 100644 --- a/src/replication.cpp +++ b/src/replication.cpp @@ -3194,4 +3194,23 @@ void replicaReplayCommand(client *c) // call() will not propogate this for us, so we do so here alsoPropagate(server.rreplayCommand,c->db->id,c->argv,c->argc,PROPAGATE_AOF|PROPAGATE_REPL); return; +} + +void updateMasterAuth() +{ + listIter li; + listNode *ln; + + listRewind(server.masters, &li); + while ((ln = listNext(&li))) + { + redisMaster *mi = (redisMaster*)listNodeValue(ln); + zfree(mi->masterauth); mi->masterauth = nullptr; + zfree(mi->masteruser); mi->masteruser = nullptr; + + if (server.default_masterauth) + mi->masterauth = zstrdup(server.default_masterauth); + if (server.default_masteruser) + mi->masteruser = zstrdup(server.default_masteruser); + } } \ No newline at end of file diff --git a/src/server.h b/src/server.h index 069077c96..41c5b3eb7 100644 --- a/src/server.h +++ b/src/server.h @@ -1824,6 +1824,7 @@ void clearReplicationId2(void); void chopReplicationBacklog(void); void replicationCacheMasterUsingMyself(struct redisMaster *mi); void feedReplicationBacklog(const void *ptr, size_t len); +void updateMasterAuth(); /* Generic persistence functions */ void startLoading(FILE *fp);