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

Allow specifying aws_s3_bucket_ownership_controls #109

Merged
merged 9 commits into from
Oct 29, 2021

Conversation

max-lobur
Copy link
Contributor

@max-lobur max-lobur commented Oct 13, 2021

what

  • Allow setting aws_s3_bucket_ownership_controls

why

  • Per docs this setting will let object uploader decide ownership. If bucket-owner-full-control ACL is specified, the bucket account take ownership, otherwise the writer account keeps ownership. Bucket on its side may enforce presence of the bucket-owner-full-control ACL which we already do when needed. So this setting was the only missing piece to make ownership work like we expected
  • I found no use cases for the other value of this resource: ObjectWriter. It corresponds to legacy S3 behavior which was broken for us.
  • However, giving the broad use of this module, I suspect there might be use cases that rely on previous S3 behavior: They set the ACL bucket-owner-full-control in their request and then still expect to own the object. To preserve legacy behavior I made this a variable, and the default corresponds to S3 legacy behavior. This is a new feature of AWS and we should wait for some time before enforcing the new default.

references

@max-lobur max-lobur requested review from a team as code owners October 13, 2021 14:23
@max-lobur max-lobur force-pushed the ownership branch 5 times, most recently from 8bed945 to 237146d Compare October 14, 2021 18:06
@max-lobur max-lobur force-pushed the ownership branch 5 times, most recently from 66d3987 to a60ff28 Compare October 28, 2021 12:34
@max-lobur
Copy link
Contributor Author

/test all

versions.tf Outdated Show resolved Hide resolved
versions.tf Outdated Show resolved Hide resolved
max-lobur and others added 2 commits October 29, 2021 14:22
Co-authored-by: nitrocode <[email protected]>
Co-authored-by: nitrocode <[email protected]>
}

# Workaround S3 eventual consistency for settings objects
resource "time_sleep" "wait_for_aws_s3_bucket_settings" {
Copy link
Member

Choose a reason for hiding this comment

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

can we set the name as default like all the others?

Suggested change
resource "time_sleep" "wait_for_aws_s3_bucket_settings" {
resource "time_sleep" "default" {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will leave as is, as its more readable. Also I'm afraid there will be more sleeps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

S3 went a weird way introducing a separate api/resource for every setting, which then get merged on the backend and races occur


# Per https://docs.aws.amazon.com/AmazonS3/latest/userguide/about-object-ownership.html
resource "aws_s3_bucket_ownership_controls" "default" {
count = local.enabled ? 1 : 0
Copy link
Member

Choose a reason for hiding this comment

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

what if users do not want to specify the s3 bucket ownership controls? can we make this toggleable and default it to false to maintain backwards compatibility?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's always specified implicitly to the value which is the default here. So creating this with default is equal to not creating at all

# Workaround S3 eventual consistency for settings objects
resource "time_sleep" "wait_for_aws_s3_bucket_settings" {
count = local.enabled ? 1 : 0
depends_on = [aws_s3_bucket_public_access_block.default, aws_s3_bucket_policy.default]
Copy link
Member

Choose a reason for hiding this comment

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

what happens when the sleep is removed? does s3 bucket ownership controls resource error out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes S3 api race condition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also when destroying, the aws_s3_bucket_public_access_block resource errors out - a reverse race

count = local.enabled ? 1 : 0
depends_on = [aws_s3_bucket_public_access_block.default, aws_s3_bucket_policy.default]
create_duration = "30s"
destroy_duration = "30s"
Copy link
Member

Choose a reason for hiding this comment

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

if time sleep has to be used here, can we make these configurable?

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 have doubts it's needed. The test covers this pretty well, if it ever fails we'd notice that. In my own tests even 3s was enough to avoid it, this should be bulletproof. I crashes when you have two near-simultaneous requests

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 wouldn't want people to experiment with increasing timeouts if they have errors related to this. 99% this will be another new resource race in S3, not the timeout itself.

@max-lobur
Copy link
Contributor Author

/test all

nitrocode
nitrocode previously approved these changes Oct 29, 2021
@max-lobur
Copy link
Contributor Author

/test all

@mergify mergify bot dismissed nitrocode’s stale review October 29, 2021 11:50

This Pull Request has been updated, so we're dismissing all reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants