Skip to content
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

Allow ExternalId to be supplied to STS AssumeRole API request #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions auth_assumerole.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ import (
// stsAuth object is used to authenticate to STS to fetch temporary credentials
// for the desired role.
func NewAuthWithAssumedRole(roleArn, sessionName, region string, stsAuth Auth) (Auth, error) {
return NewAuthWithAssumedRoleAndExternalID(roleArn, sessionName, region, "", stsAuth)
}

// NewAuthWithAssumedRoleAndExternalID works just like NewAuthWithAssumedRole, except
// that it includes the supplied externalID parameter as the 'ExternalId' parameter
// in the authentication request to STS.
func NewAuthWithAssumedRoleAndExternalID(roleArn, sessionName, region, externalID string, stsAuth Auth) (Auth, error) {
return newCachedMutexedWarmedUpAuth(&stsCreds{
RoleARN: roleArn,
SessionName: sessionName,
Region: region,
STSAuth: stsAuth,
ExternalID: externalID,
})
}

Expand All @@ -27,15 +35,20 @@ type stsCreds struct {
SessionName string
Region string
STSAuth Auth
ExternalID string
}

func (sts *stsCreds) ExpiringKeyForSigning(now time.Time) (*SigningKey, time.Time, error) {
r, err := http.NewRequest(http.MethodPost, fmt.Sprintf("https://sts.%s.amazonaws.com/?%s", sts.Region, (url.Values{
params := url.Values{
"Version": []string{"2011-06-15"},
"Action": []string{"AssumeRole"},
"RoleSessionName": []string{sts.SessionName},
"RoleArn": []string{sts.RoleARN},
}).Encode()), bytes.NewReader([]byte{}))
}
if sts.ExternalID != "" {
params["ExternalId"] = []string{sts.ExternalID}
}
r, err := http.NewRequest(http.MethodPost, fmt.Sprintf("https://sts.%s.amazonaws.com/?%s", sts.Region, params.Encode()), bytes.NewReader([]byte{}))
if err != nil {
return nil, time.Time{}, err
}
Expand Down