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

Bad key value in s3 data source causes crash #14151

Closed
johnkeates opened this issue Jul 11, 2020 · 4 comments · Fixed by #14154
Closed

Bad key value in s3 data source causes crash #14151

johnkeates opened this issue Jul 11, 2020 · 4 comments · Fixed by #14154
Labels
bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. service/s3 Issues and PRs that pertain to the s3 service.
Milestone

Comments

@johnkeates
Copy link

johnkeates commented Jul 11, 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 Version

Terraform v0.12.21

  • provider.aws v2.69.0
  • provider.cloudflare v2.8.0
  • provider.template v2.1.2

Affected Resource(s)

  • aws_s3_bucket_object

Terraform Configuration Files

data "aws_s3_bucket_object" "placeholder" {
  bucket = "some_bucket_name"
  key    = "/" 
}

Debug Output

https://gist.github.com/johnkeates/6f16cce6357fa1c20c16c9077939b996

Expected Behavior

An error should have been shown, either passed down from the AWS SDK or from the provider as this input can never result in any correct result.

Actual Behavior

The provider crashed

Steps to Reproduce

  1. Create this:
data "aws_s3_bucket_object" "placeholder" {
  bucket = "some_bucket_name"
  key    = "/" 
}
  1. terraform apply

Factoid

I accidentally came across this because I was using the output of a resource to pipe via interpolation in to this data item, and the resource returned an empty string. Both the empty string and a slash cause this behaviour. While this is not valid use of the data item it should also not crash the provider and cause terraform to get a dropped RPC pipe. A true empty string returns an:

Error: Failed getting S3 object: InvalidParameter: 1 validation error(s) found.
- minimum field size of 1, HeadObjectInput.Key.

but if your string is "/" it crashes.

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

Relevant part of crash log:

 runtime error: invalid memory address or nil pointer dereference
2020-07-12T01:31:30.684+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x4714027]
2020-07-12T01:31:30.684+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: 
2020-07-12T01:31:30.684+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: goroutine 91 [running]:
2020-07-12T01:31:30.684+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: github.com/terraform-providers/terraform-provider-aws/aws.dataSourceAwsS3BucketObjectRead(0xc000c3f9d0, 0x5cadf60, 0xc0000d2000, 0xc000c3f9d0, 0x0)
2020-07-12T01:31:30.684+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/aws/data_source_aws_s3_bucket_object.go:168 +0x887
2020-07-12T01:31:30.684+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Resource).ReadDataApply(0xc0001bf830, 0xc00138f340, 0x5cadf60, 0xc0000d2000, 0xc000184b40, 0x1, 0x0)
2020-07-12T01:31:30.684+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/resource.go:403 +0x88
2020-07-12T01:31:30.684+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: github.com/hashicorp/terraform-plugin-sdk/helper/schema.(*Provider).ReadDataApply(0xc00015a580, 0xc001229a88, 0xc00138f340, 0xc00138f340, 0x0, 0x0)
2020-07-12T01:31:30.684+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/provider.go:451 +0x8f
2020-07-12T01:31:30.684+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin.(*GRPCProviderServer).ReadDataSource(0xc0001559f0, 0x72191e0, 0xc00149a1b0, 0xc00107ccc0, 0xc0001559f0, 0xc00149a1b0, 0xc000f80b30)
2020-07-12T01:31:30.684+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform-plugin-sdk/internal/helper/plugin/grpc_provider.go:1036 +0x44e
2020-07-12T01:31:30.685+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5._Provider_ReadDataSource_Handler(0x66838e0, 0xc0001559f0, 0x72191e0, 0xc00149a1b0, 0xc000c99aa0, 0x0, 0x72191e0, 0xc00149a1b0, 0xc000cf1500, 0x1a5)
2020-07-12T01:31:30.685+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/github.com/hashicorp/terraform-plugin-sdk/internal/tfplugin5/tfplugin5.pb.go:3341 +0x217
2020-07-12T01:31:30.685+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: google.golang.org/grpc.(*Server).processUnaryRPC(0xc000f6e000, 0x723da40, 0xc000f6ed80, 0xc0011b4300, 0xc000a5d7d0, 0xa6c01b0, 0x0, 0x0, 0x0)
2020-07-12T01:31:30.685+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc/server.go:1024 +0x4f4
2020-07-12T01:31:30.685+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: google.golang.org/grpc.(*Server).handleStream(0xc000f6e000, 0x723da40, 0xc000f6ed80, 0xc0011b4300, 0x0)
2020-07-12T01:31:30.685+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc/server.go:1313 +0xd97
2020-07-12T01:31:30.685+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: google.golang.org/grpc.(*Server).serveStreams.func1.1(0xc000a7c160, 0xc000f6e000, 0x723da40, 0xc000f6ed80, 0xc0011b4300)
2020-07-12T01:31:30.685+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc/server.go:722 +0xbb
2020-07-12T01:31:30.685+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: created by google.golang.org/grpc.(*Server).serveStreams.func1
2020-07-12T01:31:30.685+0200 [DEBUG] plugin.terraform-provider-aws_v2.69.0_x4: 	/opt/teamcity-agent/work/5d79fe75d4460a2f/src/github.com/terraform-providers/terraform-provider-aws/vendor/google.golang.org/grpc/server.go:720 +0xa1

Relevant code:
https://github.com/terraform-providers/terraform-provider-aws/blob/2a9f7ce734d23eb0357d7ae519682cb82a8e8061/aws/data_source_aws_s3_bucket_object.go#L167-L168

Related:

@ewbankkit ewbankkit added bug Addresses a defect in current functionality. crash Results from or addresses a Terraform crash or kernel panic. and removed needs-triage Waiting for first response or review from a maintainer. labels Jul 12, 2020
@bflad bflad added this to the v3.10.0 milestone Oct 6, 2020
@bflad
Copy link
Contributor

bflad commented Oct 6, 2020

The fix for this has been merged and will release with version 3.10.0 of the Terraform AWS Provider, later this week. Thanks to @ewbankkit for the implementation. 👍

@ghost
Copy link

ghost commented Oct 9, 2020

This has been released in version 3.10.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 Nov 6, 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 as resolved and limited conversation to collaborators Nov 6, 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. crash Results from or addresses a Terraform crash or kernel panic. service/s3 Issues and PRs that pertain to the s3 service.
Projects
None yet
3 participants