From 1d27a7f93d2ff495a555bc369b888a29ab27084c Mon Sep 17 00:00:00 2001 From: Mitsuhiro Tanda Date: Sat, 21 May 2016 16:02:04 +0900 Subject: [PATCH] (cloudwatch) fix wrong cache key of credentials (#5124) --- pkg/api/cloudwatch/cloudwatch.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pkg/api/cloudwatch/cloudwatch.go b/pkg/api/cloudwatch/cloudwatch.go index 5b4449b5c02..4e9c6cc9064 100644 --- a/pkg/api/cloudwatch/cloudwatch.go +++ b/pkg/api/cloudwatch/cloudwatch.go @@ -57,11 +57,12 @@ var awsCredentialCache map[string]cache = make(map[string]cache) var credentialCacheLock sync.RWMutex func getCredentials(profile string, region string, assumeRoleArn string) *credentials.Credentials { + cacheKey := profile + ":" + assumeRoleArn credentialCacheLock.RLock() - if _, ok := awsCredentialCache[profile]; ok { - if awsCredentialCache[profile].expiration != nil && - (*awsCredentialCache[profile].expiration).After(time.Now().UTC()) { - result := awsCredentialCache[profile].credential + if _, ok := awsCredentialCache[cacheKey]; ok { + if awsCredentialCache[cacheKey].expiration != nil && + (*awsCredentialCache[cacheKey].expiration).After(time.Now().UTC()) { + result := awsCredentialCache[cacheKey].credential credentialCacheLock.RUnlock() return result } @@ -118,7 +119,7 @@ func getCredentials(profile string, region string, assumeRoleArn string) *creden &ec2rolecreds.EC2RoleProvider{Client: ec2metadata.New(sess), ExpiryWindow: 5 * time.Minute}, }) credentialCacheLock.Lock() - awsCredentialCache[profile] = cache{ + awsCredentialCache[cacheKey] = cache{ credential: creds, expiration: expiration, }