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

reset provider creds on every invocation #401

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ammokhov
Copy link
Contributor

@ammokhov ammokhov commented Jul 22, 2022

Issue #, if available:

Description of changes:

Change

This change resets provider credentials during runtime initialization even when passed in provider creds are null. Previously, when a lambda container was reused and passed in credentials were null, we would use the same credentials from the previous request.

In the extensive logging I added to verify the issue and test the fix, I also found a bug whereby every time we invoke, we add the lambda logger to the platformProxyLogger, which causes us to log any messages on that logger X number of times, where X is the number of the times the lambda container was reused. I made the 1 line change to ensure that we only log messages once.

Testing

Verified issue and tested by uploading the jar to a function on the lambda console and logging the credentials used (those log statements have been removed from this PR of course).

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ammokhov ammokhov requested review from himanshs23 and rajdivya July 22, 2022 18:27
@@ -151,10 +151,14 @@ public AbstractWrapper(final CredentialsProvider providerCredentialsProvider,
// Both are required parameters when LoggingConfig (optional) is provided when
// 'RegisterType'.
if (providerCredentials != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

the only concern i think is, if we want to reset it to null, we will not allow it right?

I can see three scenarios and curios on the third one

  1. initially it was null, second request we got a non null provider credential we refresh it - it will work
  2. initially it was non-null provider-credential, second request we got a new non-null provider credential - it will work for this case too
  3. initially it was non-null provider-credenial, second request we got a null provider credential - We will still use the old one?

Copy link
Contributor

@aygold92 aygold92 left a comment

Choose a reason for hiding this comment

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

how was this tested?

@aygold92 aygold92 changed the title CW client creds refresh reset provider creds on every invocation Aug 3, 2022
Comment on lines 153 to 161
if (providerCredentials == null) {
// reset provider credentials back to null to avoid reusing stale credentials
if (this.providerCredentialsProvider != null) {
this.providerCredentialsProvider.resetCredentials();
}
this.providerMetricsPublisher = null;
this.providerEventsLogger = null;
this.cloudWatchLogHelper = null;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why null check providerCredentials and providerCredentialsProvider before resetting the credentials? Cant we do it for every request? The next section will set it if credentials are provided anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because it does get refreshed when creds are non-null

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually that null check on providerCredentialsProvider seemed unnecessary to me. It's a final variable and instantiated in the constructor, but it was already there and I was just afraid to remove it and potentially cause an NPE for something I couldn't see.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. What exactly are providerCredentials and providerCredentialsProvider? Do the credentials not need to be reset if both providerCredentials and providerCredentialsProvider are null?

Copy link
Contributor

Choose a reason for hiding this comment

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

providerCredentials come directly from the request sent in by CloudFormation (or Cloud Control API). So if the credentials passed by CFN are null, then we want to reset everything.

ProviderCredentialsProvider is just a wrapper class which holds a reference to a credentials object. Like I said I don't think it's possible to be null, but if it was then it wouldn't hold any credentials anyway, which is what we want in this case. And even then, we still reset the other related objects metricsPublisher, eventsLogger, and cloudWatchLogHelper

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.

4 participants