Skip to content

Commit

Permalink
MB-4114 retry 2 more times if the password is not accepted
Browse files Browse the repository at this point in the history
... so if you mistype you won't need to start the node again

Change-Id: I5de0a142a3e5a53c05e1736aa975b51c74355a96
Reviewed-on: http://review.couchbase.org/67321
Reviewed-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
Tested-by: Aliaksey Artamonau <aliaksiej.artamonau@gmail.com>
  • Loading branch information
vzasade authored and aartamonau committed Oct 12, 2016
1 parent 271771a commit 9c4d1bb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
3 changes: 3 additions & 0 deletions cbmaster_password
Expand Up @@ -60,6 +60,9 @@ def prompt_for_password(node, cookie):

if res == "ok":
print "Password accepted. Node started booting."
elif res == "retry":
print "Incorrect password."
prompt_for_password(node, cookie)
elif res == "{badrpc,nodedown}":
print "Either the node is down or password was already supplied"
else:
Expand Down
52 changes: 29 additions & 23 deletions deps/ns_babysitter/src/encryption_service.erl
Expand Up @@ -42,28 +42,34 @@ decrypt(Data) ->
start_link() ->
gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).

prompt_the_password(EncryptedDataKey, State) ->
?log_debug("Waiting for the master password to be supplied"),
{Resp, ReplyTo} =
receive
{'$gen_call', From, {set_password, P}} ->
ok = set_password(P, State),
case EncryptedDataKey of
undefined ->
{ok, From};
_ ->
Ret = call_gosecrets({set_data_key, EncryptedDataKey}, State),
case Ret of
ok ->
{ok, From};
Error ->
?log_error("Incorrect master password. Error: ~p", [Error]),
{auth_failure, From}
end
end
end,
gen_server:reply(ReplyTo, Resp),
Resp.
prompt_the_password(EncryptedDataKey, State, Try) ->
?log_debug("Waiting for the master password to be supplied. Attempt ~p", [Try]),
receive
{'$gen_call', From, {set_password, P}} ->
ok = set_password(P, State),
case EncryptedDataKey of
undefined ->
gen_server:reply(From, ok),
ok;
_ ->
Ret = call_gosecrets({set_data_key, EncryptedDataKey}, State),
case Ret of
ok ->
gen_server:reply(From, ok),
ok;
Error ->
?log_error("Incorrect master password. Error: ~p", [Error]),
maybe_retry_prompt_the_password(EncryptedDataKey, State, From, Try)
end
end
end.

maybe_retry_prompt_the_password(_EncryptedDataKey, _State, ReplyTo, 1) ->
gen_server:reply(ReplyTo, auth_failure),
auth_failure;
maybe_retry_prompt_the_password(EncryptedDataKey, State, ReplyTo, Try) ->
gen_server:reply(ReplyTo, retry),
prompt_the_password(EncryptedDataKey, State, Try - 1).

set_password(Password, State) ->
?log_debug("Sending password to gosecrets"),
Expand All @@ -83,7 +89,7 @@ init([]) ->
State = start_gosecrets(),
case os:getenv("CB_WAIT_FOR_MASTER_PASSWORD") of
"true" ->
case prompt_the_password(EncryptedDataKey, State) of
case prompt_the_password(EncryptedDataKey, State, 3) of
ok ->
ok;
auth_failure ->
Expand Down

0 comments on commit 9c4d1bb

Please sign in to comment.