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

added AWS enpoint handling #3416

Merged
merged 4 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions builtin/logical/aws/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func getRootConfig(s logical.Storage) (*aws.Config, error) {
credsConfig.AccessKey = config.AccessKey
credsConfig.SecretKey = config.SecretKey
credsConfig.Region = config.Region
credsConfig.Endpoint = config.Endpoint
}

if credsConfig.Region == "" {
Expand All @@ -51,6 +52,7 @@ func getRootConfig(s logical.Storage) (*aws.Config, error) {
return &aws.Config{
Credentials: creds,
Region: aws.String(credsConfig.Region),
Endpoint: aws.String(credsConfig.Endpoint),
HTTPClient: cleanhttp.DefaultClient(),
}, nil
}
Expand All @@ -60,7 +62,13 @@ func clientIAM(s logical.Storage) (*iam.IAM, error) {
if err != nil {
return nil, err
}

client := iam.New(session.New(awsConfig))

if *awsConfig.Endpoint != "none" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See note about not using "none" as a placeholder, use ""

client = iam.New(session.New(awsConfig.WithEndpoint(*awsConfig.Endpoint)))
}

if client == nil {
return nil, fmt.Errorf("could not obtain iam client")
}
Expand All @@ -73,6 +81,9 @@ func clientSTS(s logical.Storage) (*sts.STS, error) {
return nil, err
}
client := sts.New(session.New(awsConfig))
if *awsConfig.Endpoint != "none" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same -- use ""

client = sts.New(session.New(awsConfig.WithEndpoint(*awsConfig.Endpoint)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're configuring STS and IAM clients with the same endpoints, and I doubt that will work. They likely need different endpoints.

}
if client == nil {
return nil, fmt.Errorf("could not obtain sts client")
}
Expand Down
11 changes: 11 additions & 0 deletions builtin/logical/aws/path_config_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func pathConfigRoot() *framework.Path {
Type: framework.TypeString,
Description: "Region for API calls.",
},
"endpoint": &framework.FieldSchema{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You probably want separate iam_endpoint and sts_endpoint here.

Type: framework.TypeString,
Description: "Endpoint to custom IAM server URL",
},
},

Callbacks: map[logical.Operation]framework.OperationFunc{
Expand All @@ -37,10 +41,16 @@ func pathConfigRoot() *framework.Path {
func pathConfigRootWrite(
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
region := data.Get("region").(string)
endpoint := data.Get("endpoint").(string)

if endpoint == "" {
endpoint = "none"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't use "none" as a placeholder value here. I'd just leave it as the empty string (which is the zero value for strings in golang) and compare against the empty string in client.go

}

entry, err := logical.StorageEntryJSON("config/root", rootConfig{
AccessKey: data.Get("access_key").(string),
SecretKey: data.Get("secret_key").(string),
Endpoint: endpoint,
Region: region,
})
if err != nil {
Expand All @@ -57,6 +67,7 @@ func pathConfigRootWrite(
type rootConfig struct {
AccessKey string `json:"access_key"`
SecretKey string `json:"secret_key"`
Endpoint string `json:"endpoint"`
Region string `json:"region"`
}

Expand Down
3 changes: 3 additions & 0 deletions helper/awsutil/generate_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type CredentialsConfig struct {
// the client elsewhere.
Region string

//Endpoint to custom IAM server URL
Endpoint string

// The filename for the shared credentials provider, if being used
Filename string

Expand Down