-
Notifications
You must be signed in to change notification settings - Fork 55
feat: add support for account ID in IMDS credentials #1570
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
Conversation
|
A new generated diff is ready to view.
|
This comment has been minimized.
This comment has been minimized.
| client = ImdsClient { | ||
| platformProvider = this@DefaultChainCredentialsProvider.platformProvider | ||
| engine = this@DefaultChainCredentialsProvider.engine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ param client a preconfigured IMDS client with which to retrieve instance metadata. If an instance is passed, the caller is responsible for closing it.
Should we be closing this ImdsClient that the default chain creates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, we should be! Will fix.
| this.platformProvider = this@ImdsCredentialsProvider.platformProvider | ||
| } | ||
|
|
||
| // FIXME This only resolves from env vars and sys props but we need to resolve from profiles too |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you said you're working on a bigger refactor for profile keys, is that in progress now? I think we already have everything available that you'd need to read from profile here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not yet in progress so I'll add profile support now similarly to how we currently resolve other profile settings.
| override suspend fun resolve(attributes: Attributes): Credentials { | ||
| if (AwsSdkSetting.AwsEc2MetadataDisabled.resolve(platformProvider) == true) { | ||
| private suspend fun resolveUnderLock(): Credentials { | ||
| println("**** Resolving creds (instanceProfileName=$instanceProfileName; apiVersion=$apiVersion; urlBase=$urlBase)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove stray printlns
|
|
||
| override suspend fun resolve(attributes: Attributes): Credentials { | ||
| if (AwsSdkSetting.AwsEc2MetadataDisabled.resolve(platformProvider) == true) { | ||
| private suspend fun resolveUnderLock(): Credentials { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit/naming: There's no mutex used here, it seems strange to call it resolveUnderLock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was meant to describe the conditions under which the method must be called. 🤔 What's a better name for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a strong opinion, I think something like resolveSingleFlight or doResolve might be a bit clearer
| nextRefresh = if (resp.expiration != null && resp.expiration < clock.now()) { | ||
| coroutineContext.warn<ImdsCredentialsProvider> { | ||
| "Attempting credential expiration extension due to a credential service availability issue. " + | ||
| "A refresh of these credentials will be attempted again in " + | ||
| "${ DEFAULT_CREDENTIALS_REFRESH_SECONDS / 60 } minutes." | ||
| } | ||
| clock.now() + DEFAULT_CREDENTIALS_REFRESH_SECONDS.seconds |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we intentionally dropping this HOSM / static stability behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, we still mostly support the requirements of the static stability spec. This change removes some of the messaging around expiry but we'll still attempt to use expired credentials as required. We should update the CachedCredentialsProvider to handle messaging about expiry. I'll leave a TODO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The static stability SEP says we MUST log a message when using expired credentials
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having JSON test resources in a .kt file seems weird, is there any reason we can't use the resources folder like we do for other test resources? Is it because this test is common, not JVM-only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this test is common and there're no non-JVM resource facilities in Kotlin yet. This continues the pattern we use in other tests like EndpointUrlConfigNamesTest, DefaultRegionProviderChainTest, StandardRetryIntegrationTest, etc.
| @Deprecated("This constructor supports parameters which are no longer used in the implementation. It will be removed in version 1.5.") | ||
| public constructor( | ||
| profileOverride: String? = null, | ||
| client: Lazy<InstanceMetadataProvider> = lazy { ImdsClient() }, | ||
| platformProvider: PlatformEnvironProvider = PlatformProvider.System, | ||
| @Suppress("UNUSED_PARAMETER") clock: Clock = Clock.System, | ||
| ) : this(profileOverride, client.value, platformProvider = platformProvider as? PlatformProvider ?: PlatformProvider.System) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to merge this deprecation into main, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I originally planned to push this change to main directly but I've since added backwards incompatibilities beyond just deprecation so I'll split this change out now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I've realized now I can probably just merge this directly into main with a few tweaks. Updating PR...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...except this PR's branch upstream is already v1.5-main so I'll cherry pick the commits over to a new branch and new PR #1573.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the future, it's possible to change the destination branch if you edit the PR at the top
* close auto-created ImdsClient in default creds chain * adding support for profile settings * removing println calls leftover from debug * rename resolveUnderLock to resolveSingleFlight * add FIXME for static stability messaging/caching in CachedCredentialsProvider * re-adding removed/broken members for API compatibility
|
|
A new generated diff is ready to view.
|
|
Superseded by #1573 |
Affected ArtifactsChanged in size
|



Issue #
(none)
Description of changes
This change adds support for sourcing account ID from IMDS credentials. There are some breaking changes around the
ImdsCredentialsProviderconstructor to remove no-longer-necessary parameters/fields and forEC2MetadataErrorto more gracefully model HTTP status codes.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.