|
|
b4b3ce |
From c0b6356bbf5b9a1fb76b011486dfce258d395ef8 Mon Sep 17 00:00:00 2001
|
|
|
b4b3ce |
From: Peter Lemenkov <lemenkov@gmail.com>
|
|
|
b4b3ce |
Date: Fri, 6 Sep 2019 14:22:46 +0200
|
|
|
b4b3ce |
Subject: [PATCH] Restore users/perms/policies even if starting in a single
|
|
|
b4b3ce |
node mode
|
|
|
b4b3ce |
|
|
|
b4b3ce |
See https://bugzilla.redhat.com/1744467#c1
|
|
|
b4b3ce |
|
|
|
b4b3ce |
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
|
|
|
b4b3ce |
---
|
|
|
b4b3ce |
heartbeat/rabbitmq-cluster | 109 ++++++++++++++++++++-----------------
|
|
|
b4b3ce |
1 file changed, 58 insertions(+), 51 deletions(-)
|
|
|
b4b3ce |
|
|
|
b4b3ce |
diff --git a/heartbeat/rabbitmq-cluster b/heartbeat/rabbitmq-cluster
|
|
|
b4b3ce |
index cf8ca21a6..7837e9e3c 100755
|
|
|
b4b3ce |
--- a/heartbeat/rabbitmq-cluster
|
|
|
b4b3ce |
+++ b/heartbeat/rabbitmq-cluster
|
|
|
b4b3ce |
@@ -114,6 +114,62 @@ rmq_wipe_data()
|
|
|
b4b3ce |
rm -rf $RMQ_DATA_DIR > /dev/null 2>&1
|
|
|
b4b3ce |
}
|
|
|
b4b3ce |
|
|
|
b4b3ce |
+rmq_restore_users_perms_policies()
|
|
|
b4b3ce |
+{
|
|
|
b4b3ce |
+ # Restore users, user permissions, and policies (if any)
|
|
|
b4b3ce |
+ BaseDataDir=`dirname $RMQ_DATA_DIR`
|
|
|
b4b3ce |
+ $RMQ_EVAL "
|
|
|
b4b3ce |
+ %% Run only if Mnesia is ready.
|
|
|
b4b3ce |
+ lists:any(fun({mnesia,_,_}) -> true; ({_,_,_}) -> false end, application:which_applications()) andalso
|
|
|
b4b3ce |
+ begin
|
|
|
b4b3ce |
+ Restore = fun(Table, PostprocessFun, Filename) ->
|
|
|
b4b3ce |
+ case file:consult(Filename) of
|
|
|
b4b3ce |
+ {error, _} ->
|
|
|
b4b3ce |
+ ok;
|
|
|
b4b3ce |
+ {ok, [Result]} ->
|
|
|
b4b3ce |
+ lists:foreach(fun(X) -> mnesia:dirty_write(Table, PostprocessFun(X)) end, Result),
|
|
|
b4b3ce |
+ file:delete(Filename)
|
|
|
b4b3ce |
+ end
|
|
|
b4b3ce |
+ end,
|
|
|
b4b3ce |
+
|
|
|
b4b3ce |
+ %% Restore users
|
|
|
b4b3ce |
+
|
|
|
b4b3ce |
+ Upgrade = fun
|
|
|
b4b3ce |
+ ({internal_user, A, B, C}) -> {internal_user, A, B, C, rabbit_password_hashing_md5};
|
|
|
b4b3ce |
+ ({internal_user, A, B, C, D}) -> {internal_user, A, B, C, D}
|
|
|
b4b3ce |
+ end,
|
|
|
b4b3ce |
+
|
|
|
b4b3ce |
+ Downgrade = fun
|
|
|
b4b3ce |
+ ({internal_user, A, B, C}) -> {internal_user, A, B, C};
|
|
|
b4b3ce |
+ ({internal_user, A, B, C, rabbit_password_hashing_md5}) -> {internal_user, A, B, C};
|
|
|
b4b3ce |
+ %% Incompatible scheme, so we will loose user's password ('B' value) during conversion.
|
|
|
b4b3ce |
+ %% Unfortunately, this case will require manual intervention - user have to run:
|
|
|
b4b3ce |
+ %% rabbitmqctl change_password <somenewpassword>
|
|
|
b4b3ce |
+ ({internal_user, A, B, C, _}) -> {internal_user, A, B, C}
|
|
|
b4b3ce |
+ end,
|
|
|
b4b3ce |
+
|
|
|
b4b3ce |
+ %% Check db scheme first
|
|
|
b4b3ce |
+ [WildPattern] = ets:select(mnesia_gvar, [ { {{rabbit_user, wild_pattern}, '\\\$1'}, [], ['\\\$1'] } ]),
|
|
|
b4b3ce |
+ case WildPattern of
|
|
|
b4b3ce |
+ %% Version < 3.6.0
|
|
|
b4b3ce |
+ {internal_user,'_','_','_'} ->
|
|
|
b4b3ce |
+ Restore(rabbit_user, Downgrade, \"$BaseDataDir/users.erl\");
|
|
|
b4b3ce |
+ %% Version >= 3.6.0
|
|
|
b4b3ce |
+ {internal_user,'_','_','_','_'} ->
|
|
|
b4b3ce |
+ Restore(rabbit_user, Upgrade, \"$BaseDataDir/users.erl\")
|
|
|
b4b3ce |
+ end,
|
|
|
b4b3ce |
+
|
|
|
b4b3ce |
+ NoOp = fun(X) -> X end,
|
|
|
b4b3ce |
+
|
|
|
b4b3ce |
+ %% Restore user permissions
|
|
|
b4b3ce |
+ Restore(rabbit_user_permission, NoOp, \"$BaseDataDir/users_perms.erl\"),
|
|
|
b4b3ce |
+
|
|
|
b4b3ce |
+ %% Restore policies
|
|
|
b4b3ce |
+ Restore(rabbit_runtime_parameters, NoOp, \"$BaseDataDir/policies.erl\")
|
|
|
b4b3ce |
+ end.
|
|
|
b4b3ce |
+ "
|
|
|
b4b3ce |
+}
|
|
|
b4b3ce |
+
|
|
|
b4b3ce |
rmq_local_node()
|
|
|
b4b3ce |
{
|
|
|
b4b3ce |
|
|
|
b4b3ce |
@@ -411,6 +467,7 @@ rmq_try_start() {
|
|
|
b4b3ce |
if [ -z "$join_list" ]; then
|
|
|
b4b3ce |
rmq_start_first
|
|
|
b4b3ce |
rc=$?
|
|
|
b4b3ce |
+ rmq_restore_users_perms_policies
|
|
|
b4b3ce |
return $rc
|
|
|
b4b3ce |
fi
|
|
|
b4b3ce |
|
|
|
b4b3ce |
@@ -437,58 +494,8 @@ rmq_try_start() {
|
|
|
b4b3ce |
return $RMQ_TRY_RESTART_ERROR_CODE
|
|
|
b4b3ce |
fi
|
|
|
b4b3ce |
|
|
|
b4b3ce |
- # Restore users, user permissions, and policies (if any)
|
|
|
b4b3ce |
- BaseDataDir=`dirname $RMQ_DATA_DIR`
|
|
|
b4b3ce |
- $RMQ_EVAL "
|
|
|
b4b3ce |
- %% Run only if Mnesia is ready.
|
|
|
b4b3ce |
- lists:any(fun({mnesia,_,_}) -> true; ({_,_,_}) -> false end, application:which_applications()) andalso
|
|
|
b4b3ce |
- begin
|
|
|
b4b3ce |
- Restore = fun(Table, PostprocessFun, Filename) ->
|
|
|
b4b3ce |
- case file:consult(Filename) of
|
|
|
b4b3ce |
- {error, _} ->
|
|
|
b4b3ce |
- ok;
|
|
|
b4b3ce |
- {ok, [Result]} ->
|
|
|
b4b3ce |
- lists:foreach(fun(X) -> mnesia:dirty_write(Table, PostprocessFun(X)) end, Result),
|
|
|
b4b3ce |
- file:delete(Filename)
|
|
|
b4b3ce |
- end
|
|
|
b4b3ce |
- end,
|
|
|
b4b3ce |
+ rmq_restore_users_perms_policies
|
|
|
b4b3ce |
|
|
|
b4b3ce |
- %% Restore users
|
|
|
b4b3ce |
-
|
|
|
b4b3ce |
- Upgrade = fun
|
|
|
b4b3ce |
- ({internal_user, A, B, C}) -> {internal_user, A, B, C, rabbit_password_hashing_md5};
|
|
|
b4b3ce |
- ({internal_user, A, B, C, D}) -> {internal_user, A, B, C, D}
|
|
|
b4b3ce |
- end,
|
|
|
b4b3ce |
-
|
|
|
b4b3ce |
- Downgrade = fun
|
|
|
b4b3ce |
- ({internal_user, A, B, C}) -> {internal_user, A, B, C};
|
|
|
b4b3ce |
- ({internal_user, A, B, C, rabbit_password_hashing_md5}) -> {internal_user, A, B, C};
|
|
|
b4b3ce |
- %% Incompatible scheme, so we will loose user's password ('B' value) during conversion.
|
|
|
b4b3ce |
- %% Unfortunately, this case will require manual intervention - user have to run:
|
|
|
b4b3ce |
- %% rabbitmqctl change_password <somenewpassword>
|
|
|
b4b3ce |
- ({internal_user, A, B, C, _}) -> {internal_user, A, B, C}
|
|
|
b4b3ce |
- end,
|
|
|
b4b3ce |
-
|
|
|
b4b3ce |
- %% Check db scheme first
|
|
|
b4b3ce |
- [WildPattern] = ets:select(mnesia_gvar, [ { {{rabbit_user, wild_pattern}, '\\\$1'}, [], ['\\\$1'] } ]),
|
|
|
b4b3ce |
- case WildPattern of
|
|
|
b4b3ce |
- %% Version < 3.6.0
|
|
|
b4b3ce |
- {internal_user,'_','_','_'} ->
|
|
|
b4b3ce |
- Restore(rabbit_user, Downgrade, \"$BaseDataDir/users.erl\");
|
|
|
b4b3ce |
- %% Version >= 3.6.0
|
|
|
b4b3ce |
- {internal_user,'_','_','_','_'} ->
|
|
|
b4b3ce |
- Restore(rabbit_user, Upgrade, \"$BaseDataDir/users.erl\")
|
|
|
b4b3ce |
- end,
|
|
|
b4b3ce |
-
|
|
|
b4b3ce |
- NoOp = fun(X) -> X end,
|
|
|
b4b3ce |
-
|
|
|
b4b3ce |
- %% Restore user permissions
|
|
|
b4b3ce |
- Restore(rabbit_user_permission, NoOp, \"$BaseDataDir/users_perms.erl\"),
|
|
|
b4b3ce |
-
|
|
|
b4b3ce |
- %% Restore policies
|
|
|
b4b3ce |
- Restore(rabbit_runtime_parameters, NoOp, \"$BaseDataDir/policies.erl\")
|
|
|
b4b3ce |
- end.
|
|
|
b4b3ce |
- "
|
|
|
b4b3ce |
return $OCF_SUCCESS
|
|
|
b4b3ce |
}
|
|
|
b4b3ce |
|