Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Commit

Permalink
fix: Include the profileARN for the session cache key (#237)
Browse files Browse the repository at this point in the history
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
ebabani authored and nickatsegment committed Oct 30, 2019
1 parent 3a97126 commit e5359bb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
33 changes: 33 additions & 0 deletions internal/sessioncache/key_profilearn.go
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])
}
3 changes: 2 additions & 1 deletion lib/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ func (p *Provider) Retrieve() (credentials.Value, error) {
if !ok {
return credentials.Value{}, fmt.Errorf("missing profile named %s", p.profile)
}
key := sessioncache.OrigKey{
key := sessioncache.KeyWithProfileARN{
ProfileName: source,
ProfileConf: profileConf,
Duration: p.SessionDuration,
ProfileARN: p.AssumeRoleArn,
}

var creds sts.Credentials
Expand Down

0 comments on commit e5359bb

Please sign in to comment.