Skip to content

Commit 85e6220

Browse files
committed
Fix replica authentication failure when masterauth is below replicaof in the config file
1 parent e951386 commit 85e6220

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/config.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,8 @@ void loadServerConfigFromString(char *config) {
399399
} else if (!strcasecmp(argv[0],"masterauth") && argc == 2) {
400400
zfree(server.default_masterauth);
401401
server.default_masterauth = argv[1][0] ? zstrdup(argv[1]) : NULL;
402+
// Loop through all existing master infos and update them (in case this came after the replicaof config)
403+
updateMasterAuth();
402404
} else if ((!strcasecmp(argv[0],"slave-serve-stale-data") ||
403405
!strcasecmp(argv[0],"replica-serve-stale-data"))
404406
&& argc == 2)

src/replication.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,4 +3194,23 @@ void replicaReplayCommand(client *c)
31943194
// call() will not propogate this for us, so we do so here
31953195
alsoPropagate(server.rreplayCommand,c->db->id,c->argv,c->argc,PROPAGATE_AOF|PROPAGATE_REPL);
31963196
return;
3197+
}
3198+
3199+
void updateMasterAuth()
3200+
{
3201+
listIter li;
3202+
listNode *ln;
3203+
3204+
listRewind(server.masters, &li);
3205+
while ((ln = listNext(&li)))
3206+
{
3207+
redisMaster *mi = (redisMaster*)listNodeValue(ln);
3208+
zfree(mi->masterauth); mi->masterauth = nullptr;
3209+
zfree(mi->masteruser); mi->masteruser = nullptr;
3210+
3211+
if (server.default_masterauth)
3212+
mi->masterauth = zstrdup(server.default_masterauth);
3213+
if (server.default_masteruser)
3214+
mi->masteruser = zstrdup(server.default_masteruser);
3215+
}
31973216
}

src/server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,7 @@ void clearReplicationId2(void);
18241824
void chopReplicationBacklog(void);
18251825
void replicationCacheMasterUsingMyself(struct redisMaster *mi);
18261826
void feedReplicationBacklog(const void *ptr, size_t len);
1827+
void updateMasterAuth();
18271828

18281829
/* Generic persistence functions */
18291830
void startLoading(FILE *fp);

0 commit comments

Comments
 (0)