Skip to content

Commit

Permalink
Wait for newly set admin creds to be hashed in setup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nickva committed Nov 8, 2023
1 parent e68cbe2 commit be6124a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/setup/src/setup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit be6124a

Please sign in to comment.