This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/main by this push:
new be6124aab Wait for newly set admin creds to be hashed in setup
be6124aab is described below
commit be6124aab7f2ad8097a7a85b3e64123f8454ef15
Author: Nick Vatamaniuc <[email protected]>
AuthorDate: Wed Nov 8 12:24:36 2023 -0500
Wait for newly set admin creds to be hashed in setup
Previously, in the setup app, we set admin creds but didn't wait for them
to be
hashed. The next setup step then could fail with the 401 error.
Since we're doing setup, let's wait for the newly set creds to be hashed
before
continuing.
---
src/setup/src/setup.erl | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/src/setup/src/setup.erl b/src/setup/src/setup.erl
index 35830284d..7a38e69cb 100644
--- a/src/setup/src/setup.erl
+++ b/src/setup/src/setup.erl
@@ -169,7 +169,21 @@ enable_cluster_int(Options, false) ->
couch_log:debug("Enable Cluster: ~p~n",
[couch_util:remove_sensitive_data(Options)]).
set_admin(Username, Password) ->
- config:set("admins", binary_to_list(Username), binary_to_list(Password),
#{sensitive => true}).
+ config:set("admins", binary_to_list(Username), binary_to_list(Password),
#{sensitive => true}),
+ % 5 minutes
+ wait_admins_to_be_hashed(60 * 5).
+
+wait_admins_to_be_hashed(Tries) when is_integer(Tries), Tries > 0 ->
+ case couch_passwords:get_unhashed_admins() of
+ [] ->
+ ok;
+ [_ | _] ->
+ timer:sleep(1000),
+ couch_log:debug("Waiting for admins to be hashed. Seconds left:
~p", [Tries]),
+ wait_admins_to_be_hashed(Tries - 1)
+ end;
+wait_admins_to_be_hashed(0) ->
+ throw({setup_error, "Admin passwords could not be hashed"}).
setup_node(NewCredentials, NewBindAddress, NodeCount, Port) ->
case NewCredentials of