-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cli): short-lived credentials are not refreshed (#32354)
The CLI immediately invokes credential *providers* to produce *credentials*, and passes the credentials around instead of the providers. This means that if short-lived credentials expire (like session credentials from roles), there is no way to refresh them. CLI calls will start to fail if that happens. To fix this, instead of resolving providers to credentials, pass providers around instead. Implications for auth plugins ------------- This widens the plugin protocol: the new plugin protocol *forced* a translation to V3 credentials, and had no way to return V3 providers. While it is now possible to return V3 Credential Providers from the plugin protocol, plugin writers cannot easily take advantage of that protocol because there have been ~8 CLI releases that only support V3 credentials and will fail at runtime of V3 providers are returned. To support this, pass a new options argument into `getProvider()`: this will indicate whether V3 Providers are supported or not. Plugins can return a provider if the CLI indicates that it supports V3 providers, and avoid doing that if the CLI indicates it won't. That way, plugins can be rewritten to take advantage of returning V3 providers without crashing on CLI versions `2.167.0..(this releases)`. This also affects #32111 in which the plugin contract is being moved. Closes #32287. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
19 changed files
with
462 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { memoize } from '@smithy/property-provider'; | ||
import { AwsCredentialIdentity, AwsCredentialIdentityProvider } from '@smithy/types'; | ||
|
||
/** | ||
* Wrap a credential provider in a cache | ||
* | ||
* Some credential providers in the SDKv3 are cached (the default Node | ||
* chain, specifically) but most others are not. | ||
* | ||
* Since we want to avoid duplicate calls to `AssumeRole`, or duplicate | ||
* MFA prompts or what have you, we are going to liberally wrap providers | ||
* in caches which will return the cached value until it expires. | ||
*/ | ||
export function makeCachingProvider(provider: AwsCredentialIdentityProvider): AwsCredentialIdentityProvider { | ||
return memoize( | ||
provider, | ||
credentialsAboutToExpire, | ||
(token) => token.expiration !== undefined); | ||
} | ||
|
||
export function credentialsAboutToExpire(token: AwsCredentialIdentity) { | ||
const expiryMarginSecs = 5; | ||
return token.expiration !== undefined && token.expiration.getTime() - Date.now() < expiryMarginSecs * 1000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.