Skip to content

Commit

Permalink
Fix AccessControlListNotSupported: The bucket does not allow ACLs e…
Browse files Browse the repository at this point in the history
…rror (#141)

* apply fix from slack thread

* acl or ownership control

* defaults

* object writer

* test

* depends on

* terraform-docs: automated action

* switch back to allowing any canned acl

* terraform-docs: automated action

* update readme

* terraform-docs: automated action

* allow custom ownership policy

* terraform-docs: automated action

* use ownership_controls as overriding var

* terraform-docs: automated action

* correct readme

* terraform-docs: automated action

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
georgepstaylor and github-actions[bot] authored Apr 26, 2023
1 parent a534481 commit 189a156
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ module "s3-bucket" {
bucket_prefix = "s3-bucket"
versioning_enabled = false
# to disable ACLs in preference of BucketOwnership controls as per https://aws.amazon.com/blogs/aws/heads-up-amazon-s3-security-changes-are-coming-in-april-of-2023/ set:
# ownership_controls = "BucketOwnerEnforced"
# Refer to the below section "Replication" before enabling replication
replication_enabled = false
# Below three variables and providers configuration are only relevant if 'replication_enabled' is set to true
Expand Down Expand Up @@ -103,6 +106,7 @@ No modules.
| [aws_s3_bucket_lifecycle_configuration.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration) | resource |
| [aws_s3_bucket_lifecycle_configuration.replication](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_lifecycle_configuration) | resource |
| [aws_s3_bucket_logging.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_logging) | resource |
| [aws_s3_bucket_ownership_controls.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_ownership_controls) | resource |
| [aws_s3_bucket_policy.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource |
| [aws_s3_bucket_policy.replication](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_policy) | resource |
| [aws_s3_bucket_public_access_block.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_public_access_block) | resource |
Expand All @@ -121,7 +125,7 @@ No modules.

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| <a name="input_acl"></a> [acl](#input\_acl) | Canned ACL to use on the bucket | `string` | `"private"` | no |
| <a name="input_acl"></a> [acl](#input\_acl) | Use canned ACL on the bucket instead of BucketOwnerEnforced ownership controls. var.ownership\_controls must be set to corresponding value below. | `string` | `"private"` | no |
| <a name="input_bucket_name"></a> [bucket\_name](#input\_bucket\_name) | Please use bucket\_prefix instead of bucket\_name to ensure a globally unique name. | `string` | `null` | no |
| <a name="input_bucket_policy"></a> [bucket\_policy](#input\_bucket\_policy) | JSON for the bucket policy | `list(string)` | <pre>[<br> "{}"<br>]</pre> | no |
| <a name="input_bucket_policy_v2"></a> [bucket\_policy\_v2](#input\_bucket\_policy\_v2) | Alternative to bucket\_policy. Define policies directly without needing to know the bucket ARN | <pre>list(object({<br> effect = string<br> actions = list(string)<br> principals = optional(object({<br> type = string<br> identifiers = list(string)<br> }))<br> conditions = optional(list(object({<br> test = string<br> variable = string<br> values = list(string)<br> })), [])<br> }))</pre> | `[]` | no |
Expand All @@ -132,6 +136,7 @@ No modules.
| <a name="input_lifecycle_rule"></a> [lifecycle\_rule](#input\_lifecycle\_rule) | List of maps containing configuration of object lifecycle management. | `any` | <pre>[<br> {<br> "enabled": "Enabled",<br> "expiration": {<br> "days": 730<br> },<br> "id": "main",<br> "noncurrent_version_expiration": {<br> "days": 730<br> },<br> "noncurrent_version_transition": [<br> {<br> "days": 90,<br> "storage_class": "STANDARD_IA"<br> },<br> {<br> "days": 365,<br> "storage_class": "GLACIER"<br> }<br> ],<br> "prefix": "",<br> "tags": {<br> "autoclean": "true",<br> "rule": "log"<br> },<br> "transition": [<br> {<br> "days": 90,<br> "storage_class": "STANDARD_IA"<br> },<br> {<br> "days": 365,<br> "storage_class": "GLACIER"<br> }<br> ]<br> }<br>]</pre> | no |
| <a name="input_log_bucket"></a> [log\_bucket](#input\_log\_bucket) | Bucket for server access logging, if applicable | `string` | `""` | no |
| <a name="input_log_prefix"></a> [log\_prefix](#input\_log\_prefix) | Prefix to use for server access logging, if applicable | `string` | `""` | no |
| <a name="input_ownership_controls"></a> [ownership\_controls](#input\_ownership\_controls) | Bucket Ownership Controls - for use WITH acl var above options are 'BucketOwnerPreferred' or 'ObjectWriter'. To disable ACLs and use new AWS recommended controls set this to 'BucketOwnerEnforced' and which will disabled ACLs and ignore var.acl | `string` | `"ObjectWriter"` | no |
| <a name="input_replication_enabled"></a> [replication\_enabled](#input\_replication\_enabled) | Activate S3 bucket replication | `bool` | `false` | no |
| <a name="input_replication_region"></a> [replication\_region](#input\_replication\_region) | Region to create S3 replication bucket | `string` | `"eu-west-2"` | no |
| <a name="input_replication_role_arn"></a> [replication\_role\_arn](#input\_replication\_role\_arn) | Role ARN to access S3 and replicate objects | `string` | `""` | no |
Expand Down
11 changes: 11 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@ resource "aws_s3_bucket" "default" {
tags = var.tags
}

resource "aws_s3_bucket_ownership_controls" "default" {
bucket = aws_s3_bucket.default.id
rule {
object_ownership = var.ownership_controls
}
}

# Configure bucket ACL
resource "aws_s3_bucket_acl" "default" {
count = var.ownership_controls == "BucketOwnerEnforced" ? 0 : 1
bucket = aws_s3_bucket.default.id
acl = var.acl
depends_on = [
aws_s3_bucket_ownership_controls.default
]
}

# Configure bucket lifecycle rules
Expand Down
8 changes: 7 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
variable "acl" {
type = string
description = "Canned ACL to use on the bucket"
description = "Use canned ACL on the bucket instead of BucketOwnerEnforced ownership controls. var.ownership_controls must be set to corresponding value below."
default = "private"
}

variable "ownership_controls" {
type = string
description = "Bucket Ownership Controls - for use WITH acl var above options are 'BucketOwnerPreferred' or 'ObjectWriter'. To disable ACLs and use new AWS recommended controls set this to 'BucketOwnerEnforced' and which will disabled ACLs and ignore var.acl"
default = "ObjectWriter"
}

variable "versioning_enabled" {
type = bool
description = "Activate S3 bucket versioning"
Expand Down

0 comments on commit 189a156

Please sign in to comment.