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

V1.7.0 aws sts endpoint error #1002

Merged
merged 8 commits into from
Jan 10, 2023
34 changes: 31 additions & 3 deletions mongodbatlas/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,32 @@ func configureCredentialsSTS(config *Config, secret, region, awsAccessKeyID, aws
return *config, err
}

sess := session.Must(session.NewSession(&aws.Config{
defaultResolver := endpoints.DefaultResolver()
stsCustResolverFn := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
if service == endpoints.StsServiceID {
if endpoint == "" {
return endpoints.ResolvedEndpoint{
URL: "https://sts.amazonaws.com",
SigningRegion: region,
}, nil
}
return endpoints.ResolvedEndpoint{
URL: endpoint,
SigningRegion: region,
}, nil
}

return defaultResolver.EndpointFor(service, region, optFns...)
}

cfg := aws.Config{
Region: aws.String(region),
Credentials: credentials.NewStaticCredentials(awsAccessKeyID, awsSecretAccessKey, awsSessionToken),
STSRegionalEndpoint: ep,
Endpoint: &endpoint,
}))
EndpointResolver: endpoints.ResolverFunc(stsCustResolverFn),
}

sess := session.Must(session.NewSession(&cfg))

creds := stscreds.NewCredentials(sess, config.AssumeRole.RoleARN)

Expand All @@ -342,6 +362,14 @@ func configureCredentialsSTS(config *Config, secret, region, awsAccessKeyID, aws
if err != nil {
return *config, err
}
if secretData.PrivateKey == "" {
return *config, fmt.Errorf("secret missing value for credential PrivateKey")
}

if secretData.PublicKey == "" {
return *config, fmt.Errorf("secret missing value for credential PublicKey")
}

config.PublicKey = secretData.PublicKey
config.PrivateKey = secretData.PrivateKey
return *config, nil
Expand Down