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

Add region parameter to AWS agent auto auth #7632

Merged
merged 2 commits into from
Oct 14, 2019
Merged
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
13 changes: 12 additions & 1 deletion command/agent/auth/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/hashicorp/vault/api"
awsauth "github.com/hashicorp/vault/builtin/credential/aws"
"github.com/hashicorp/vault/command/agent/auth"
"github.com/hashicorp/vault/helper/awsutil"
)

const (
Expand All @@ -45,6 +46,7 @@ type awsMethod struct {
mountPath string
role string
headerValue string
region string

// These are used to share the latest creds safely across goroutines.
credLock sync.Mutex
Expand All @@ -70,6 +72,7 @@ func NewAWSAuthMethod(conf *auth.AuthConfig) (auth.AuthMethod, error) {
mountPath: conf.MountPath,
credsFound: make(chan struct{}),
stopCh: make(chan struct{}),
region: awsutil.DefaultRegion,
}

typeRaw, ok := conf.Config["type"]
Expand Down Expand Up @@ -142,6 +145,14 @@ func NewAWSAuthMethod(conf *auth.AuthConfig) (auth.AuthMethod, error) {
}
}

regionRaw, ok := conf.Config["region"]
if ok {
a.region, ok = regionRaw.(string)
if !ok {
return nil, errors.New("could not convert 'region' value into string")
}
}

if a.authType == typeIAM {

// Check for an optional custom frequency at which we should poll for creds.
Expand Down Expand Up @@ -246,7 +257,7 @@ func (a *awsMethod) Authenticate(ctx context.Context, client *api.Client) (retTo
defer a.credLock.Unlock()

var err error
data, err = awsauth.GenerateLoginData(a.lastCreds, a.headerValue, "")
data, err = awsauth.GenerateLoginData(a.lastCreds, a.headerValue, a.region)
if err != nil {
retErr = errwrap.Wrapf("error creating login value: {{err}}", err)
return
Expand Down