Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep previous credentials when refresh fails #71

Merged

Conversation

dw-kihara
Copy link
Contributor

@dw-kihara dw-kihara commented May 21, 2024

The current version of aws_credentials seems to have a bug around refreshing credentials.

When refreshing fails, the stored credentials value is overwritten with true.

Reproduction:

$ rebar3 shell
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling aws_credentials
Erlang/OTP 26 [erts-14.1] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit:ns]

Eshell V14.1 (press Ctrl+G to abort, type help(). for help)
1> application:set_env(aws_credentials, provider_options, #{credential_path => "test/aws_credentials_providers_SUITE_data/"}). % ensures credentials to be loaded
ok
2> application:ensure_all_started(aws_credentials). % starts aws_credentials
{ok,[jsx,eini,iso8601,aws_credentials]}
3> application:set_env(aws_credentials, fail_if_unavailable, false). % overrides fail_if_unavailable (since it is set to true by rebar3 shell)
ok
4> aws_credentials:get_credentials(). % should show credentials
#{access_key_id => <<"dummy_access_key">>,
  credential_provider => aws_credentials_file,
  secret_access_key => <<"dummy_secret_access_key">>}
5> application:set_env(aws_credentials, provider_options, #{credential_path => "fail"}). % changes options to make refresh fail
ok
6> [{_, Pid, _, _}] = supervisor:which_children(aws_credentials_sup). % get pid
[{aws_credentials,<0.403.0>,worker,[aws_credentials]}]
7> Pid ! refresh_credentials. % manually cause refresh by sending message
refresh_credentials
8> aws_credentials:get_credentials(). % timeout.
** exception exit: {timeout,{gen_server,call,
                                        [aws_credentials,get_credentials]}}
     in function  gen_server:call/2 (gen_server.erl, line 386)
9> aws_credentials:get_credentials(). % again. credential becam `true'
true

I suggest keeping the previous credentials when automatic refresh fails.

@onno-vos-dev
Copy link
Member

@dw-kihara Wouldn't this result in the inability to invalidate file credentials? 🤔

@dw-kihara
Copy link
Contributor Author

Wouldn't this result in the inability to invalidate file credentials? 🤔

@onno-vos-dev Well, I overlooked that point.
However, I don't think it's a good idea to invalidate credentials, such as aws_credentials_ec2, just because an HTTP transport happens to fail once.

Maybe it whould be better to have a function to explicitly invalidate credentials, or an option to invalidate credentials for force_credentials_refresh.
What do you think?

@dw-kihara
Copy link
Contributor Author

an option to invalidate credentials for force_credentials_refresh

Hmm, I think this does not need tobe an option but mandatory behavior.
Because it says "force" it seems to be natural to lose current credentials if it fails.

I will modify this PR again.

@dw-kihara
Copy link
Contributor Author

@onno-vos-dev I have reverted behavior of force_credentials_refresh in order to invalidate credentials manually.

I wanted to prevent the automatic refresh from removing the credentials accidentaly, so the current pull request meets my requirements.

Thank you for suggestion.

@onno-vos-dev
Copy link
Member

This makes sense to me 👍 Would like to wait a day or two to see if any of the other maintainers have a different opinion than mine 👍

Copy link
Contributor

@jadeallenx jadeallenx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good behavioral change, thanks

@onno-vos-dev onno-vos-dev merged commit 62247a3 into aws-beam:master May 22, 2024
8 checks passed
@onno-vos-dev
Copy link
Member

Thank you @dw-kihara

Tagged and released as 0.2.4: https://hex.pm/packages/aws_credentials/0.2.4

@dw-kihara dw-kihara deleted the fix/keep_prev_when_refresh_fails branch May 22, 2024 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants