Bus reset uses admin account; disable default
authorBill Erickson <berickxx@gmail.com>
Thu, 11 May 2023 15:03:51 +0000 (11:03 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 11 May 2023 15:03:51 +0000 (11:03 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
bin/opensrf-perl.pl.in
examples/redis-accounts.txt.in

index 9103b8c..86f8148 100755 (executable)
@@ -621,16 +621,28 @@ sub do_reset_message_bus {
 
     my $routers = $conf->bootstrap->routers;
 
-    # TODO pull logins for all clients in the conf, including
-    # gateway and router.
-    for my $router (@{$conf->bootstrap->routers}) {
+    my $admin_pass = `grep 'ACL SETUSER admin on >' $opt_bus_accounts | cut -d'>' -f2`;
+
+    chomp($admin_pass);
+
+    die "No password for Redis 'admin' account found in $opt_bus_accounts\n"
+        unless $admin_pass;
 
+    # Redis prefers the password be passed via ENV.
+    $ENV{REDISCLI_AUTH} = $admin_pass;
+
+    # Apply the bus accounts to all of our domains.
+    for my $router (@{$conf->bootstrap->routers}) {
         my $domain = ref $router ? $router->{domain} : $router;
         my $port = $conf->bootstrap->port;
 
         msg("Resetting bus accounts for domain $domain");
 
-        system("cat $opt_bus_accounts | redis-cli -h $domain -p $port > /dev/null");
+        # Grep out some noise.  Avoid piping to /dev/null so we can 
+        # see failures.
+        my $command = "redis-cli --user admin -h $domain -p $port | grep -v OK | grep -v ^1";
+
+        system("cat $opt_bus_accounts | $command");
     }
 }
 
index bc98edf..04198a7 100644 (file)
@@ -25,12 +25,12 @@ ACL SETUSER gateway on >@GATEWAY_BUS_PASS@
 ACL SETUSER gateway -@all +lpop +blpop +rpush +del ~opensrf:router:* ~opensrf:client:*
 
 SET comment "admin can do anything"
+SET comment "avoid reseting admin since that would break the account mid-script"
 
-ACL SETUSER admin reset
 ACL SETUSER admin on >@ADMIN_BUS_PASS@
 ACL SETUSER admin +@all ~*
 
-SET comment "disable the 'default' account"
+SET comment "disable the 'default' passwordless account"
 
 ACL SETUSER default off