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

add acl validator to aws s3 bucket resource #15327

Merged
merged 2 commits into from
Nov 10, 2020

Conversation

NikolaeVarius
Copy link
Contributor

@NikolaeVarius NikolaeVarius commented Sep 24, 2020

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment 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 pull request followers and do not help prioritize the request

Closes #15304

Release note for CHANGELOG:


- Adds in canned acls that apply to buckets documented in https://docs.aws.amazon.com/AmazonS3/latest/dev/acl-overview.html#canned-acl specifically "aws-exec-read" and "log-delivery-write" as valid acls


Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccXXX'

...

@ghost ghost added size/XS Managed by automation to categorize the size of a PR. service/s3 Issues and PRs that pertain to the s3 service. dependencies Used to indicate dependency changes. labels Sep 24, 2020
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Sep 24, 2020
@github-actions
Copy link

Thank you for your contribution! 🚀

Please note that typically Go dependency changes are handled in this repository by Renovate Bot or the maintainers. This is to prevent pull request merge conflicts and further delay reviews of contributions. Remove any changes to the go.mod, go.sum, and vendor/ files and commit them into this pull request.

Additional details:

  • Check open pull requests with the dependencies label to view other dependency updates.
  • If this pull request includes an update the AWS Go SDK (or any other dependency) version, only updates submitted via Renovate Bot will be merged. This pull request will need to remove these changes and will need to be rebased after the existing dependency update via Renovate Bot has been merged for this pull request to be reviewed.
  • If this pull request is for supporting a new AWS service:
    • Ensure the new AWS service changes are following the Contributing Guide section on new services, in particular that the dependency addition and initial provider support are in a separate pull request from other changes (e.g. new resources). Contributions not following this item will not be reviewed until the changes are split.
    • If this pull request is already a separate pull request from the above item, you can ignore this message.

@@ -76,6 +76,14 @@ func resourceAwsS3Bucket() *schema.Resource {
Default: "private",
Optional: true,
ConflictsWith: []string{"grant"},
ValidateFunc: validation.StringInSlice([]string{
Copy link
Contributor

@reedloden reedloden Sep 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of hardcoding them, how about just using s3.BucketCannedACL_Values()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @NikolaeVarius. We've actually been changing over to the _Values() functions so that new values are automatically picked up when we update the AWS SDK. We're tracking this in #14601

The _Values() functions were actually added by one of our maintainers in aws/aws-sdk-go#3447 🙂

s3.BucketCannedACLPublicReadWrite,
s3.BucketCannedACLAWSExecRead,
s3.BucketCannedACLAuthenticatedRead,
s3.BucketCannedACLLogDeliveryWrite,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as in the other comment, yeah you're correct

s3.BucketCannedACLPrivate,
s3.BucketCannedACLPublicRead,
s3.BucketCannedACLPublicReadWrite,
s3.BucketCannedACLAWSExecRead,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this exists for buckets... For objects, there's ObjectCannedACLAwsExecRead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SDK doesn't seem to support it. See https://docs.aws.amazon.com/sdk-for-go/api/service/s3/#pkg-constants. Or if you look at the code directly (https://raw.githubusercontent.com/aws/aws-sdk-go/master/service/s3/api.go), you can take a look at the BucketCannedACL_Values() function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you're correct. Those values are exist at the ObjectCannedACL_Values() function. I dont know the behavior just yet, and would need to test, but in this case, would it be wise to add this validator in if the upstream SDK doesn't support all possible values for a bucket? Wouldn't want to return a validation error when the ACL is perfectly valid.

// ObjectCannedACL_Values returns all elements of the ObjectCannedACL enum
func ObjectCannedACL_Values() []string {
	return []string{
		ObjectCannedACLPrivate,
		ObjectCannedACLPublicRead,
		ObjectCannedACLPublicReadWrite,
		ObjectCannedACLAuthenticatedRead,
		ObjectCannedACLAwsExecRead,
		ObjectCannedACLBucketOwnerRead,
		ObjectCannedACLBucketOwnerFullControl,
	}
}

@NikolaeVarius
Copy link
Contributor Author

NikolaeVarius commented Sep 30, 2020

It seems the outdated canned acls in the go SDK are a known issue

aws/aws-sdk-go#2683

Further linked report terraform-linters/tflint#341 (comment)

Comment on lines +31317 to +31324
// BucketCannedACLAWSExecRead is a BucketCannedACL enum value
BucketCannedACLAWSExecRead = "aws-exec-read"

// BucketCannedACLAuthenticatedRead is a BucketCannedACL enum value
BucketCannedACLAuthenticatedRead = "authenticated-read"

// BucketCannedACLLogDeliveryWrite is a BucketCannedACL enum value
BucketCannedACLLogDeliveryWrite = "log-delivery-write"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, we can't make changes in the vendored dependencies, because they'll be wiped out the next time we update the AWS SDK. When we run into missing constants, the first thing to do is double-check that they haven't been added in a new version of the SDK. If they haven't, then we can define our own constants in the directory aws/internal/service/s3 and also file an issue with AWS either on the SDK or with support

@gdavison
Copy link
Contributor

HI @NikolaeVarius, this PR looks like a good start. Is there anything you need from us to move it forward?

@gdavison gdavison marked this pull request as ready for review November 10, 2020 20:33
@gdavison gdavison requested a review from a team as a code owner November 10, 2020 20:33
gdavison added a commit that referenced this pull request Nov 10, 2020
gdavison added a commit that referenced this pull request Nov 10, 2020
@gdavison gdavison merged commit 36c2a5c into hashicorp:master Nov 10, 2020
@gdavison gdavison removed the needs-triage Waiting for first response or review from a maintainer. label Nov 10, 2020
@gdavison gdavison added this to the v3.15.0 milestone Nov 10, 2020
@ghost
Copy link

ghost commented Nov 12, 2020

This has been released in version 3.15.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 11, 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 Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dependencies Used to indicate dependency changes. service/s3 Issues and PRs that pertain to the s3 service. size/XS Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"public" is an invalid value as acl for s3 resource
3 participants