This repository has been archived by the owner on May 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Include the profileARN for the session cache key (#237)
The profileARN can be overriden as part of the exec call. This fixes a bug with the following commands: - aws-okta exec profile --assume-role-arn role1 -- command - aws-okta exec profile --assume-role-arn role2 -- command The second command would be run using role1 since the session cache thinks there's already a valid session. The cache lookup logic does not take the assume role override into account when looking for a session.
- Loading branch information
1 parent
3a97126
commit e5359bb
Showing
2 changed files
with
35 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package sessioncache | ||
|
||
import ( | ||
"crypto/md5" | ||
"encoding/hex" | ||
"encoding/json" | ||
"fmt" | ||
"time" | ||
) | ||
|
||
type KeyWithProfileARN struct { | ||
ProfileName string | ||
ProfileConf map[string]string | ||
Duration time.Duration | ||
ProfileARN string | ||
} | ||
|
||
// Key returns a key for the keyring item. For all purposes it behaves the same way as | ||
// OrigKey but also takes the ProfileARN into account when generating the key value. | ||
func (k KeyWithProfileARN) Key() string { | ||
var source string | ||
if source = k.ProfileConf["source_profile"]; source == "" { | ||
source = k.ProfileName | ||
} | ||
hasher := md5.New() | ||
hasher.Write([]byte(k.Duration.String())) | ||
hasher.Write([]byte(k.ProfileARN)) | ||
|
||
enc := json.NewEncoder(hasher) | ||
enc.Encode(k.ProfileConf) | ||
|
||
return fmt.Sprintf("%s session (%x)", source, hex.EncodeToString(hasher.Sum(nil))[0:10]) | ||
} |
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