@@ -162,6 +162,7 @@ typedef struct sentinelRedisInstance {
162
162
dict * slaves ; /* Slaves for this master instance. */
163
163
int quorum ; /* Number of sentinels that need to agree on failure. */
164
164
int parallel_syncs ; /* How many slaves to reconfigure at same time. */
165
+ char * auth_pass ; /* Password to use for AUTH against master & slaves. */
165
166
166
167
/* Slave specific. */
167
168
mstime_t master_link_down_time ; /* Slave replication link down time. */
@@ -326,6 +327,7 @@ void sentinelEvent(int level, char *type, sentinelRedisInstance *ri, const char
326
327
sentinelRedisInstance * sentinelSelectSlave (sentinelRedisInstance * master );
327
328
void sentinelScheduleScriptExecution (char * path , ...);
328
329
void sentinelStartFailover (sentinelRedisInstance * master , int state );
330
+ void sentinelDiscardReplyCallback (redisAsyncContext * c , void * reply , void * privdata );
329
331
330
332
/* ========================= Dictionary types =============================== */
331
333
@@ -874,6 +876,7 @@ sentinelRedisInstance *createSentinelRedisInstance(char *name, int flags, char *
874
876
ri -> down_after_period = master ? master -> down_after_period :
875
877
SENTINEL_DOWN_AFTER_PERIOD ;
876
878
ri -> master_link_down_time = 0 ;
879
+ ri -> auth_pass = NULL ;
877
880
ri -> slave_priority = SENTINEL_DEFAULT_SLAVE_PRIORITY ;
878
881
ri -> slave_reconf_sent_time = 0 ;
879
882
ri -> slave_master_host = NULL ;
@@ -921,6 +924,7 @@ void releaseSentinelRedisInstance(sentinelRedisInstance *ri) {
921
924
sdsfree (ri -> client_reconfig_script );
922
925
sdsfree (ri -> slave_master_host );
923
926
sdsfree (ri -> leader );
927
+ sdsfree (ri -> auth_pass );
924
928
releaseSentinelAddr (ri -> addr );
925
929
926
930
/* Clear state into the master if needed. */
@@ -1205,6 +1209,11 @@ char *sentinelHandleConfiguration(char **argv, int argc) {
1205
1209
return "Client reconfiguration script seems non existing or "
1206
1210
"non executable." ;
1207
1211
ri -> client_reconfig_script = sdsnew (argv [2 ]);
1212
+ } else if (!strcasecmp (argv [0 ],"auth-pass" ) && argc == 3 ) {
1213
+ /* auth-pass <name> <password> */
1214
+ ri = sentinelGetMasterByName (argv [1 ]);
1215
+ if (!ri ) return "No such master with specified name." ;
1216
+ ri -> auth_pass = sdsnew (argv [2 ]);
1208
1217
} else {
1209
1218
return "Unrecognized sentinel configuration statement." ;
1210
1219
}
@@ -1263,6 +1272,21 @@ void sentinelDisconnectCallback(const redisAsyncContext *c, int status) {
1263
1272
sentinelDisconnectInstanceFromContext (c );
1264
1273
}
1265
1274
1275
+ /* Send the AUTH command with the specified master password if needed.
1276
+ * Note that for slaves the password set for the master is used.
1277
+ *
1278
+ * We don't check at all if the command was successfully transmitted
1279
+ * to the instance as if it fails Sentinel will detect the instance down,
1280
+ * will disconnect and reconnect the link and so forth. */
1281
+ void sentinelSendAuthIfNeeded (sentinelRedisInstance * ri , redisAsyncContext * c ) {
1282
+ char * auth_pass = (ri -> flags & SRI_MASTER ) ? ri -> auth_pass :
1283
+ ri -> master -> auth_pass ;
1284
+
1285
+ if (auth_pass )
1286
+ redisAsyncCommand (c , sentinelDiscardReplyCallback , NULL , "AUTH %s" ,
1287
+ auth_pass );
1288
+ }
1289
+
1266
1290
/* Create the async connections for the specified instance if the instance
1267
1291
* is disconnected. Note that the SRI_DISCONNECTED flag is set even if just
1268
1292
* one of the two links (commands and pub/sub) is missing. */
@@ -1284,6 +1308,7 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) {
1284
1308
sentinelLinkEstablishedCallback );
1285
1309
redisAsyncSetDisconnectCallback (ri -> cc ,
1286
1310
sentinelDisconnectCallback );
1311
+ sentinelSendAuthIfNeeded (ri ,ri -> cc );
1287
1312
}
1288
1313
}
1289
1314
/* Pub / Sub */
@@ -1303,6 +1328,7 @@ void sentinelReconnectInstance(sentinelRedisInstance *ri) {
1303
1328
sentinelLinkEstablishedCallback );
1304
1329
redisAsyncSetDisconnectCallback (ri -> pc ,
1305
1330
sentinelDisconnectCallback );
1331
+ sentinelSendAuthIfNeeded (ri ,ri -> pc );
1306
1332
/* Now we subscribe to the Sentinels "Hello" channel. */
1307
1333
retval = redisAsyncCommand (ri -> pc ,
1308
1334
sentinelReceiveHelloMessages , NULL , "SUBSCRIBE %s" ,
0 commit comments