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

Terraform not using STS regional endpoint #12727

Closed
ghost opened this issue Apr 8, 2020 · 8 comments · Fixed by #14077
Closed

Terraform not using STS regional endpoint #12727

ghost opened this issue Apr 8, 2020 · 8 comments · Fixed by #14077
Assignees
Milestone

Comments

@ghost
Copy link

ghost commented Apr 8, 2020

This issue was originally opened by @sanvipy as hashicorp/terraform#24592. It was migrated here as a result of the provider split. The original body of the issue is below.


Terraform Version

Terraform v0.12.20
+ provider.aws v2.35.0

Terraform Configuration Files

provider "aws" {
  region      = "ap-southeast-1"

 assume_role {
   role_arn = "role_arn"
}
  endpoints {
    sts = "sts.ap-southeast-1.amazonaws.com"
  }
}

~/.aws/config
[default]
region      = ap-southeast-1
sts_regional_endpoints = regional

>echo $AWS_STS_REGIONAL_ENDPOINT
>regional

Debug Output

2020/04/08 09:28:39 [INFO] Terraform version: 0.12.24
2020/04/08 09:28:39 [INFO] Go runtime version: go1.12.13
2020/04/08 09:28:39 [INFO] CLI args: []string{"/usr/bin/terraform", "plan", "--var-file=uat.tfvars"}
2020/04/08 09:28:39 [DEBUG] Attempting to open CLI config file: /root/.terraformrc
2020/04/08 09:28:39 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2020/04/08 09:28:39 [INFO] CLI command args: []string{"plan", "--var-file=uat.tfvars"}
2020/04/08 09:28:39 [TRACE] Meta.Backend: built configuration for "s3" backend with hash value 704415183
2020/04/08 09:28:39 [TRACE] Preserving existing state lineage "b273c1fd-f9bd-3803-0889-a7d64efe1dcf"
2020/04/08 09:28:39 [TRACE] Preserving existing state lineage "b273c1fd-f9bd-3803-0889-a7d64efe1dcf"
2020/04/08 09:28:39 [TRACE] Meta.Backend: working directory was previously initialized for "s3" backend
2020/04/08 09:28:39 [TRACE] Meta.Backend: using already-initialized, unchanged "s3" backend configuration
2020/04/08 09:28:39 [INFO] Setting AWS metadata API timeout to 100ms
2020/04/08 09:28:39 [INFO] AWS EC2 instance detected via default metadata API endpoint, EC2RoleProvider added to the auth chain
2020/04/08 09:28:39 [INFO] AWS Auth provider used: "EC2RoleProvider"
2020/04/08 09:28:39 [DEBUG] Trying to get account information via sts:GetCallerIdentity
2020/04/08 09:28:39 [DEBUG] [aws-sdk-go] DEBUG: Request sts/GetCallerIdentity Details:
---[ REQUEST POST-SIGN ]-----------------------------
POST / HTTP/1.1
Host: sts.amazonaws.com
User-Agent: aws-sdk-go/1.25.3 (go1.12.13; linux; amd64) APN/1.0 HashiCorp/1.0 Terraform/0.12.24
Content-Length: 43
Authorization: AWS4-HMAC-SHA256 Credential=XXXXXXXXXXXXXXXXXXX/20200408/us-east-1/sts/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date;x-amz-security-token, Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Content-Type: application/x-www-form-urlencoded; charset=utf-8
X-Amz-Date: 20200408T012839Z
X-Amz-Security-Token: XXXXXXXXXXXXXXXXXXX//////////XXXXXXXXXXXXXXXXXXX//////////XXXXXXXXXXXXXXXXXXX==
Accept-Encoding: gzip

Action=GetCallerIdentity&Version=2011-06-15

2020/04/08 09:28:42 [ERR] Checkpoint error: Get https://checkpoint-api.hashicorp.com/v1/check/terraform?arch=amd64&os=linux&signature=47f21672-90d8-81e4-0605-5c077c2c8166&version=0.12.24: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
2020/04/08 09:29:09 [DEBUG] [aws-sdk-go] DEBUG: Send Request sts/GetCallerIdentity failed, attempt 0/5, error RequestError: send request failed
caused by: Post https://sts.amazonaws.com/: dial tcp 52.46.134.192:443: i/o timeout
2020/04/08 09:29:09 [DEBUG] [aws-sdk-go] DEBUG: Retrying Request sts/GetCallerIdentity, attempt 1
2020/04/08 09:29:09 [DEBUG] [aws-sdk-go] DEBUG: Request sts/GetCallerIdentity Details:
---[ REQUEST POST-SIGN ]-----------------------------
POST / HTTP/1.1
Host: sts.amazonaws.com
User-Agent: aws-sdk-go/1.25.3 (go1.12.13; linux; amd64) APN/1.0 HashiCorp/1.0 Terraform/0.12.24
Content-Length: 43
Authorization: AWS4-HMAC-SHA256 Credential=XXXXXXXXXXXXXXXXXXX/20200408/us-east-1/sts/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date;x-amz-security-token, Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Content-Type: application/x-www-form-urlencoded; charset=utf-8
X-Amz-Date: 20200408T012909Z
X-Amz-Security-Token: XXXXXXXXXXXXXXXXXXX//////////XXXXXXXXXXXXXXXXXXX//////////XXXXXXXXXXXXXXXXXXX==
Accept-Encoding: gzip

Action=GetCallerIdentity&Version=2011-06-15

2020/04/08 09:29:39 [DEBUG] [aws-sdk-go] DEBUG: Send Request sts/GetCallerIdentity failed, attempt 1/5, error RequestError: send request failed
caused by: Post https://sts.amazonaws.com/: dial tcp 54.239.29.25:443: i/o timeout
2020/04/08 09:29:39 [DEBUG] [aws-sdk-go] DEBUG: Retrying Request sts/GetCallerIdentity, attempt 2
2020/04/08 09:29:39 [DEBUG] [aws-sdk-go] DEBUG: Request sts/GetCallerIdentity Details:

Crash Output

Expected Behavior

Attempt to connect to STS regional endpoint- https://sts.ap-southeast-1.amazonaws.com which resolve to private IP of STS VPC endpoint

Actual Behavior

Attempt to connect to STS global endpoint- https://sts.amazonaws.com and its public IP

Steps to Reproduce

terraform plan

Additional Context

References

@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Apr 8, 2020
@ewbankkit
Copy link
Contributor

Related:

@sanvipy Thanks for opening this. Could you try setting AWS_STS_REGIONAL_ENDPOINTS=regional in your environment (if possible)?

@sanvipy
Copy link

sanvipy commented Apr 9, 2020

Thanks @ewbankkit , I did try setting both AWS_STS_REGIONAL_ENDPOINTS environment variable and sts_regional_endpoints configuration file options with no luck

[root@xxxxxxxxx xxxxxxxxx]# terraform plan --var-file=uat.tfvars
Error: error using credentials to get account ID: error calling sts:GetCallerIdentity: RequestError: send request failed
caused by: Post https://sts.amazonaws.com/: dial tcp 54.239.29.25:443: i/o timeout

[root@xxxxxxxxx xxxxxxxxx]# echo $AWS_STS_REGIONAL_ENDPOINTS
regional

@joelthompson
Copy link
Contributor

Hey @sanvipy -- can you try setting the AWS_SDK_LOAD_CONFIG=true in your environment?

@ewbankkit
Copy link
Contributor

ewbankkit commented Jun 12, 2020

Many issues in this area will be fixed with #13608. Revisit once that PR is merged.

@bflad
Copy link
Contributor

bflad commented Jul 7, 2020

Hi @sanvipy 👋 Are you also using the Terraform S3 Backend? The debug logs posted seem to indicate that you are. Please note that it has a separate configuration for STS endpoints (if explicitly configuring them) and that many of the unexpected behaviors were resolved in Terraform 0.13.0-beta2 (the ones that will be fixed in the AWS Provider in version 3.0.0). Are you able to see if running that version or later with terraform plan is successful?

@bflad bflad added waiting-response Maintainers are waiting on response from community or contributor. and removed needs-triage Waiting for first response or review from a maintainer. labels Jul 7, 2020
@bflad bflad self-assigned this Jul 7, 2020
@bflad bflad added this to the v3.0.0 milestone Jul 7, 2020
bflad added a commit that referenced this issue Jul 7, 2020
Reference: #5018
Reference: #6913
Reference: #7333
Reference: #9236
Reference: #9869
Reference: #9898
Reference: #9962
Reference: #9986
Reference: #10507
Reference: #11429
Reference: #12236
Reference: #12727
Reference: #12815
Reference: #13057

Changes:

```
NOTES

* provider: Credential ordering has changed from static, environment, shared credentials, EC2 metadata, default AWS Go SDK (shared configuration, web identity, ECS, EC2 Metadata) to static, environment, shared credentials, default AWS Go SDK (shared configuration, web identity, ECS, EC2 Metadata)
* provider: The `AWS_METADATA_TIMEOUT` environment variable no longer has any effect as we now depend on the default AWS Go SDK EC2 Metadata client timeout of one second with two retries

ENHANCEMENTS

* provider: Always enable shared configuration file support (no longer require `AWS_SDK_LOAD_CONFIG` environment variable)
* provider: Add `assume_role` configuration block `duration_seconds`, `policy_arns`, `tags`, and `transitive_tag_keys` arguments

BUG FIXES

* provider: Ensure configured STS endpoint is used during `AssumeRole` API calls
* provider: Prefer AWS shared configuration over EC2 metadata credentials by default
* provider: Prefer CodeBuild, ECS, EKS credentials over EC2 metadata credentials by default
```

Output from acceptance testing:

```
--- PASS: TestAccAWSProvider_Region_AwsCommercial (3.89s)
--- PASS: TestAccAWSProvider_Region_AwsGovCloudUs (3.90s)
--- PASS: TestAccAWSProvider_Region_AwsChina (3.99s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_None (4.22s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_None (4.29s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_One (4.37s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_Multiple (4.38s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_One (4.39s)
--- PASS: TestAccAWSProvider_IgnoreTags_EmptyConfigurationBlock (4.40s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_Multiple (4.40s)
--- PASS: TestAccAWSProvider_Endpoints_Deprecated (4.42s)
--- PASS: TestAccAWSProvider_Endpoints (4.53s)
--- PASS: TestAccAWSProvider_AssumeRole_Empty (8.32s)
```
bflad added a commit that referenced this issue Jul 13, 2020
…14077)

* Update module hashicorp/aws-sdk-go-base to v0.5.0

* provider: Authentication updates for Terraform AWS Provider v3.0.0

Reference: #5018
Reference: #6913
Reference: #7333
Reference: #9236
Reference: #9869
Reference: #9898
Reference: #9962
Reference: #9986
Reference: #10507
Reference: #11429
Reference: #12236
Reference: #12727
Reference: #12815
Reference: #13057

Changes:

```
NOTES

* provider: Credential ordering has changed from static, environment, shared credentials, EC2 metadata, default AWS Go SDK (shared configuration, web identity, ECS, EC2 Metadata) to static, environment, shared credentials, default AWS Go SDK (shared configuration, web identity, ECS, EC2 Metadata)
* provider: The `AWS_METADATA_TIMEOUT` environment variable no longer has any effect as we now depend on the default AWS Go SDK EC2 Metadata client timeout of one second with two retries

ENHANCEMENTS

* provider: Always enable shared configuration file support (no longer require `AWS_SDK_LOAD_CONFIG` environment variable)
* provider: Add `assume_role` configuration block `duration_seconds`, `policy_arns`, `tags`, and `transitive_tag_keys` arguments

BUG FIXES

* provider: Ensure configured STS endpoint is used during `AssumeRole` API calls
* provider: Prefer AWS shared configuration over EC2 metadata credentials by default
* provider: Prefer CodeBuild, ECS, EKS credentials over EC2 metadata credentials by default
```

Output from acceptance testing:

```
--- PASS: TestAccAWSProvider_Region_AwsCommercial (3.89s)
--- PASS: TestAccAWSProvider_Region_AwsGovCloudUs (3.90s)
--- PASS: TestAccAWSProvider_Region_AwsChina (3.99s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_None (4.22s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_None (4.29s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_One (4.37s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_Multiple (4.38s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_One (4.39s)
--- PASS: TestAccAWSProvider_IgnoreTags_EmptyConfigurationBlock (4.40s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_Multiple (4.40s)
--- PASS: TestAccAWSProvider_Endpoints_Deprecated (4.42s)
--- PASS: TestAccAWSProvider_Endpoints (4.53s)
--- PASS: TestAccAWSProvider_AssumeRole_Empty (8.32s)
```

* docs/provider: Add authentication changes section to version 3 upgrade guide and remove pre-3.0 notes

Co-authored-by: Renovate Bot <bot@renovateapp.com>
@bflad
Copy link
Contributor

bflad commented Jul 13, 2020

The authentication changes applied to the Terraform S3 Backend as part of Terraform CLI 0.13.0-beta2 which should resolve this issue have also been merged into the Terraform AWS Provider and will release with version 3.0.0, likely in the next two weeks. Please follow the v3.0.0 milestone for tracking the progress of that release. If you are still having trouble after updating when its released, please file a new issue. Thanks!

@ghost
Copy link
Author

ghost commented Jul 31, 2020

This has been released in version 3.0.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link
Author

ghost commented Aug 12, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Aug 12, 2020
@breathingdust breathingdust removed the waiting-response Maintainers are waiting on response from community or contributor. label Sep 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants