diff --git a/builtin/credential/aws/backend.go b/builtin/credential/aws/backend.go index 809beaefe403..7b2d5e3ff1e8 100644 --- a/builtin/credential/aws/backend.go +++ b/builtin/credential/aws/backend.go @@ -9,6 +9,7 @@ import ( "github.com/aws/aws-sdk-go/aws/endpoints" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/iam" + "github.com/hashicorp/vault/helper/awsutil" "github.com/hashicorp/vault/helper/consts" "github.com/hashicorp/vault/logical" "github.com/hashicorp/vault/logical/framework" @@ -233,14 +234,14 @@ func (b *backend) resolveArnToRealUniqueId(ctx context.Context, s logical.Storag } iamClient, err := b.clientIAM(ctx, s, region.ID(), entity.AccountNumber) if err != nil { - return "", err + return "", awsutil.AppendLogicalError(err) } switch entity.Type { case "user": userInfo, err := iamClient.GetUser(&iam.GetUserInput{UserName: &entity.FriendlyName}) if err != nil { - return "", err + return "", awsutil.AppendLogicalError(err) } if userInfo == nil { return "", fmt.Errorf("got nil result from GetUser") @@ -249,7 +250,7 @@ func (b *backend) resolveArnToRealUniqueId(ctx context.Context, s logical.Storag case "role": roleInfo, err := iamClient.GetRole(&iam.GetRoleInput{RoleName: &entity.FriendlyName}) if err != nil { - return "", err + return "", awsutil.AppendLogicalError(err) } if roleInfo == nil { return "", fmt.Errorf("got nil result from GetRole") @@ -258,7 +259,7 @@ func (b *backend) resolveArnToRealUniqueId(ctx context.Context, s logical.Storag case "instance-profile": profileInfo, err := iamClient.GetInstanceProfile(&iam.GetInstanceProfileInput{InstanceProfileName: &entity.FriendlyName}) if err != nil { - return "", err + return "", awsutil.AppendLogicalError(err) } if profileInfo == nil { return "", fmt.Errorf("got nil result from GetInstanceProfile") diff --git a/builtin/credential/aws/path_login.go b/builtin/credential/aws/path_login.go index 7bf3cd925673..0a4cec6569c4 100644 --- a/builtin/credential/aws/path_login.go +++ b/builtin/credential/aws/path_login.go @@ -24,6 +24,7 @@ import ( "github.com/hashicorp/errwrap" "github.com/hashicorp/go-cleanhttp" "github.com/hashicorp/go-uuid" + "github.com/hashicorp/vault/helper/awsutil" "github.com/hashicorp/vault/helper/jsonutil" "github.com/hashicorp/vault/helper/strutil" "github.com/hashicorp/vault/logical" @@ -132,7 +133,7 @@ func (b *backend) instanceIamRoleARN(iamClient *iam.IAM, instanceProfileName str InstanceProfileName: aws.String(instanceProfileName), }) if err != nil { - return "", err + return "", awsutil.AppendLogicalError(err) } if profile == nil { return "", fmt.Errorf("nil output while getting instance profile details") @@ -168,7 +169,8 @@ func (b *backend) validateInstance(ctx context.Context, s logical.Storage, insta }, }) if err != nil { - return nil, errwrap.Wrapf(fmt.Sprintf("error fetching description for instance ID %q: {{err}}", instanceID), err) + errW := errwrap.Wrapf(fmt.Sprintf("error fetching description for instance ID %q: {{err}}", instanceID), err) + return nil, awsutil.AppendLogicalError(errW) } if status == nil { return nil, fmt.Errorf("nil output from describe instances")