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

China S3 bucket resource returning 401 for non-ICP accounts #15420

Closed
michaelfoley1 opened this issue Oct 1, 2020 · 13 comments · Fixed by #15481
Closed

China S3 bucket resource returning 401 for non-ICP accounts #15420

michaelfoley1 opened this issue Oct 1, 2020 · 13 comments · Fixed by #15481
Assignees
Labels
bug Addresses a defect in current functionality. partition/aws-cn Pertains to the aws-cn partition. service/s3 Issues and PRs that pertain to the s3 service.
Milestone

Comments

@michaelfoley1
Copy link

michaelfoley1 commented Oct 1, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Terraform 0.12.26
AWS Provider v3.5.0

Affected Resource(s)

  • aws_s3_bucket

Terraform Configuration Files

terraform {
  required_version = "0.12.26"
}

provider "aws" {
  version = "3.5.0"
  profile = "canva-network-cn"
  region = "cn-north-1"
  skip_metadata_api_check = true
}

resource "aws_s3_bucket" "b" {
  bucket = "my-tf-test-bucket-fdsajfkdslfjlk"
  acl    = "private"
}

Debug Output

https://gist.github.com/michaelfoley1/06d649284ac90fe467cce2defe839ed9

Expected Behavior

Terraform should create the bucket and exit gracefully.

Actual Behavior

Terraform creates the bucket and errors out with the error message:
Error: error getting S3 Bucket location: Unauthorized: Unauthorized

Steps to Reproduce

  1. terraform apply

Important Factoids

This only affects AWS account in the Chinese partiion that do not have ICP licenses associated to them.

If a Chinese account does have an ICP licence unauthenticated HEAD requests receive a 403 response which is gracefully handled.
It an Chinese account does not have an ICP license unauthenticated HEAD requests receive a 401 response which is not gracefully handled and errors out.

References

@ghost ghost added the service/s3 Issues and PRs that pertain to the s3 service. label Oct 1, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Oct 1, 2020
@ebabani
Copy link
Contributor

ebabani commented Oct 1, 2020

I'm assuming this is recent new behaviour? Getting this when updating some already existing buckets as well.

@michaelfoley1 michaelfoley1 changed the title China S3 unauthenticated HEADBucket returning 401 for non-ICP accounts China S3 bucket resource returning 401 for non-ICP accounts Oct 1, 2020
@michaelfoley1
Copy link
Author

michaelfoley1 commented Oct 1, 2020

I'm assuming this is recent new behaviour? Getting this when updating some already existing buckets as well.

The AWS change was made ~September 30,
My temp fix was to remove this LoC so HEAD requests are authenticated while I figure out the "correct" fix:
https://github.com/aws/aws-sdk-go/blob/master/service/s3/s3manager/bucket_region.go#L110

@bflad bflad added the partition/aws-cn Pertains to the aws-cn partition. label Oct 1, 2020
ebabani pushed a commit to autonomic-ai/terraform-provider-aws-1 that referenced this issue Oct 1, 2020
This fixes hashicorp#15420 where in aws-cn using anonymous credentials will cause the Head request to return Unauthorized. That error in turn fill cause terraform bucket operations to fail.
@OffCode
Copy link

OffCode commented Oct 2, 2020

It happens also in the terraform plan phase as well. As soon as terraform tries to check/evaluate the actual state of the S3 logging bucket, it raises the same error denoted above.
This is code snippet of our terraform module:
`

Create the data bucket

resource "aws_s3_bucket" "apr_s3_bucket" {
bucket = "${var.identifier}"
acl = "private"
provider = aws.aws_s3_provider

server_side_encryption_configuration {
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}

dynamic "logging" {
for_each = var.aws_s3_logging_enabled ? ["${aws_s3_bucket.app_log_bucket.id}"] : []

content {
  target_bucket = "${aws_s3_bucket.app_log_bucket.id}"
  target_prefix = "${var.identifier}"
}

}

...

Create the access log bucket

resource "aws_s3_bucket" "app_log_bucket" {
bucket = "access-log-${var.identifier}"
acl = "log-delivery-write"
provider = aws.aws_s3_provider

`

@ebabani
Copy link
Contributor

ebabani commented Oct 2, 2020

I'm using this change to work around the issue: autonomic-ai@64e2a4f

If that seems like an appropriate way to fix this I can clean it up and send a PR

ebabani pushed a commit to autonomic-ai/terraform-provider-aws-1 that referenced this issue Oct 5, 2020
This fixes hashicorp#15420 where in aws-cn using anonymous credentials will cause the Head request to return Unauthorized. That error in turn fill cause terraform bucket operations to fail.
@yogeek
Copy link

yogeek commented Oct 5, 2020

Hi @ebabani !

How can we test your fix please ?
Is it possible to override the AWS provider in terraform declaration to point to your github source... ?

@ebabani
Copy link
Contributor

ebabani commented Oct 5, 2020

You have to build the provider and override the AWS provider terraform uses locally. For more details see https://www.terraform.io/docs/extend/how-terraform-works.html#discovery

@yogeek
Copy link

yogeek commented Oct 5, 2020

@ebabani Thanks, I did that and your fix went well !

@yogeek
Copy link

yogeek commented Oct 12, 2020

Hello ! Do you have an idea of a potential date to merge this fix please ?

@ecktom
Copy link

ecktom commented Oct 30, 2020

Might be related to #15659

@josemdav
Copy link

josemdav commented Nov 4, 2020

I built the code from this PR and deployed locally overriding official AWS provider and it worked fine.

@bflad bflad added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Nov 17, 2020
@bflad bflad self-assigned this Nov 17, 2020
@bflad bflad added this to the v3.16.0 milestone Nov 17, 2020
bflad pushed a commit that referenced this issue Nov 17, 2020
… region (#15481)

This fixes #15420 where in aws-cn using anonymous credentials will cause the Head request to return Unauthorized. That error in turn fill cause terraform bucket operations to fail.
@bflad
Copy link
Member

bflad commented Nov 17, 2020

The fix for this has been merged and will release with version 3.16.0 of the Terraform AWS Provider, later this week. Thank you to @ebabani for the implementation. 👍

@ghost
Copy link

ghost commented Nov 18, 2020

This has been released in version 3.16.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

ghost commented Dec 17, 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!

@hashicorp hashicorp locked as resolved and limited conversation to collaborators Dec 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. partition/aws-cn Pertains to the aws-cn partition. service/s3 Issues and PRs that pertain to the s3 service.
Projects
None yet
7 participants