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

fix: Better error messages for AWS auth #1557

Merged
merged 1 commit into from
Jul 6, 2022
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
22 changes: 19 additions & 3 deletions pkg/remote/aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package aws
import (
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/sts"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/snyk/driftctl/pkg/output"
"github.com/snyk/driftctl/pkg/remote/terraform"
tf "github.com/snyk/driftctl/pkg/terraform"
Expand All @@ -30,10 +32,10 @@ type awsConfig struct {
IgnoreTagsConfig map[string]string
Insecure bool

SkipCredsValidation bool
SkipCredsValidation bool `cty:"skip_credentials_validation"`
SkipGetEC2Platforms bool
SkipRegionValidation bool
SkipRequestingAccountId bool
SkipRequestingAccountId bool `cty:"skip_requesting_account_id"`
SkipMetadataApiCheck bool
S3ForcePathStyle bool
}
Expand Down Expand Up @@ -69,7 +71,12 @@ func NewAWSTerraformProvider(version string, progress output.Progress, configDir
DefaultAlias: *p.session.Config.Region,
GetProviderConfig: func(alias string) interface{} {
return awsConfig{
Region: alias,
Region: alias,
// Those two parameters are used to make sure that the credentials are not validated when calling
// Configure(). Credentials validation is now handled directly in driftctl
SkipCredsValidation: true,
SkipRequestingAccountId: true,

MaxRetries: 10, // TODO make this configurable
}
},
Expand Down Expand Up @@ -99,5 +106,14 @@ func (p *AWSTerraformProvider) CheckCredentialsExist() error {
if err != nil {
return err
}
// This call is to make sure that the credentials are valid
// A more complex logic exist in terraform provider, but it's probably not worth to implement it
// https://github.com/hashicorp/terraform-provider-aws/blob/e3959651092864925045a6044961a73137095798/aws/auth_helpers.go#L111
_, err = sts.New(p.session).GetCallerIdentity(&sts.GetCallerIdentityInput{})
if err != nil {
logrus.Debug(err)
return errors.New("Could not authenticate successfully on AWS with the provided credentials.\n" +
"Please refer to the AWS documentation: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html\n")
}
return nil
}