-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Cache temporary STS credentials #1329
Comments
@fxaguessy thanks for reaching out to us. You are correct the aws-sdk-go does not implement support for a cross-process credentials cache. The only caching of credentials the SDK includes is in process via a Being able to cache credentials cross process for a CLI makes a lot of sense, especially for MFA. I could imagine that being painful to use with MFA and STS. The AWS SDKs do not support the AWS CLI's file based credential cache as that cache is owned as internal functionality of the CLI. None of the SDKs use this cache for that reason. I think the best approach to this problem would be to create a cache that is specific to the I think there is some work we can do on the type FileCacheProvider struct {
Creds *credentials.Credentials
}
func (f *FileCacheProvider) Retrieve() (credentials.Value, error) {
// TODO check file credential cache before looking at nested credentials.
// Fall back to underlying credentials, and repopulate the cache.
return f.Creds.Get()
}
func (f *FileCacheProvider) IsExpired() bool {
// TODO check file cache is expired? Fall back to underlying credentials
return f.Creds.IsExpired()
}
func main() {
sess := session.Must(session.NewSession())
// Inject cache able credential provider on top of the SDK's credentials loader
sess.Config.Credentials = credentials.NewCredentials(&FileCacheProvider{
Creds: sess.Config.Credentials,
})
// create service clients with sessions and make API calls.
} The way the SDK supports the shared config makes wrapping injecting the FileCacheProvider prior to creating the This is an area the SDK can be improved I think. At the minimum if the |
Many thanks @jasdel for this great answer. This confirms what I thought, but your mock will be a good start for the implementation of the cache of credentials in I'm not sure to have fully understood this:
But I will start the implementation and if I find problems, I will come back and discuss it here. |
Thanks for the update @fxaguessy, glad that was helpful.
Sure, let me clarify that. This is an error the SDK could improve with a minor optimization by exposing the credentials |
Hi @fxaguessy I created PR #1320 a earlier this week that adds support for Go 1.8's plugin to retrieve AWS credentials from. I think there are use cases where users of The PR includes example and documentation on how to use this new feature. This feature is opt in and needs to be explicitly configured by the application using the SDK. |
Thanks @jasdel for the suggestion. This is indeed a useful feature, and we might integrate that into |
Hi @jasdel, I started a POC implementation of the It is a good start, as it successfully caches MFA credentials during multiple Did I miss something or should I do a query to AWS, catching the |
From a Your application won't be able to know what time the credentials will expire on, it will know if they are expired or not. To handle this when credentials expire you'll need a way to lock the file cache so only a single cli instance will attempt to refresh the credentials from AWS. |
Oh i see part of the problem is determining if the cached credentials are expired correct? |
Yes exactly, the problem is for credentials that have been cached. |
hmm so I don't think the SDK's We'd probably want to create a new interface type Expirer interface {
ExpiresAt() time.Time
} In this case the stscreds Provider would be updated to satisfy the |
Yes, indeed, such an |
PR, comments and issues are welcome |
The aws-iam-authenticator seems like it could use an implementation of a disk based credentials cache. I'm unclear why they can't use ~/.aws/credentials, tho. Or why this isn't built in to the aws-sdk-go package. |
See PR #2375 for an implementation of the above discussed Expirer interface on Providers. I've implemented a persistent credential cache in the aws-iam-authenticator project built on aws-sdk-go using this functionality. |
See kubernetes-sigs/aws-iam-authenticator#193 for an example of writing an application level credential cache using aws-sdk-go. |
As far as I know, contrary to
awscli,
there is no caching of temporary STS credentials in aws-sdk-go, for example when using MFA.This feature was discussed in #841, but according to the MFA discussion in #842 and implementation in #1088, I don't think that this was implemented. Am I wrong ?
We are building a CLI relying on aws-sdk-go, and several users ask for this feature (cf wallix/awless#104 or wallix/awless#109). As in a CLI, the life of the process and session is very short, when using MFA, a code may be asked very often. Did I miss something or is it a new credential provider that we need to add ?
The text was updated successfully, but these errors were encountered: