Skip to content

Commit b297b4e

Browse files
osibandaosibanda
authored andcommitted
Support S3 bucket ABAC
1 parent 3170c8b commit b297b4e

File tree

8 files changed

+53
-0
lines changed

8 files changed

+53
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ These features of S3 bucket configurations are supported:
2020
- Account-level Public Access Block
2121
- S3 Directory Bucket
2222
- S3 Table Bucket
23+
- S3 Bucket ABAC (Attribute Based Access Control)
2324

2425
## Usage
2526

@@ -97,6 +98,20 @@ module "s3_bucket_for_waf_logs" {
9798
}
9899
```
99100

101+
### Bucket with ABAC enabled
102+
103+
```hcl
104+
module "s3_bucket" {
105+
source = "terraform-aws-modules/s3-bucket/aws"
106+
107+
bucket = "my-s3-bucket"
108+
109+
abac_status = {
110+
status = "Enabled"
111+
}
112+
}
113+
```
114+
100115
### Bucket with a custom policy attached
101116

102117
When you need to attach a custom policy to the bucket, you can use the `policy` argument. To keep bucket policy with correct S3 bucket and AWS account properties, you can use the placeholders `_S3_BUCKET_ID_`, `_S3_BUCKET_ARN_`, and `_AWS_ACCOUNT_ID_` in the policy document. Those values will be replaced with the actual values during the policy attachment. This is especially useful when using bucket prefixes.
@@ -173,6 +188,7 @@ No modules.
173188
| Name | Type |
174189
|------|------|
175190
| [aws_s3_bucket.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket) | resource |
191+
| [aws_s3_bucket_abac.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_abac) | resource |
176192
| [aws_s3_bucket_accelerate_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_accelerate_configuration) | resource |
177193
| [aws_s3_bucket_acl.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_acl) | resource |
178194
| [aws_s3_bucket_analytics_configuration.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket_analytics_configuration) | resource |
@@ -215,6 +231,7 @@ No modules.
215231

216232
| Name | Description | Type | Default | Required |
217233
|------|-------------|------|---------|:--------:|
234+
| <a name="input_abac_status"></a> [abac\_status](#input\_abac\_status) | Map containing ABAC (Attribute Based Access Control) configuration | `any` | `{}` | no |
218235
| <a name="input_acceleration_status"></a> [acceleration\_status](#input\_acceleration\_status) | (Optional) Sets the accelerate configuration of an existing bucket. Can be Enabled or Suspended. | `string` | `null` | no |
219236
| <a name="input_access_log_delivery_policy_source_accounts"></a> [access\_log\_delivery\_policy\_source\_accounts](#input\_access\_log\_delivery\_policy\_source\_accounts) | (Optional) List of AWS Account IDs should be allowed to deliver access logs to this bucket. | `list(string)` | `[]` | no |
220237
| <a name="input_access_log_delivery_policy_source_buckets"></a> [access\_log\_delivery\_policy\_source\_buckets](#input\_access\_log\_delivery\_policy\_source\_buckets) | (Optional) List of S3 bucket ARNs which should be allowed to deliver access logs to this bucket. | `list(string)` | `[]` | no |
@@ -292,6 +309,7 @@ No modules.
292309
| Name | Description |
293310
|------|-------------|
294311
| <a name="output_aws_s3_bucket_versioning_status"></a> [aws\_s3\_bucket\_versioning\_status](#output\_aws\_s3\_bucket\_versioning\_status) | The versioning status of the bucket. Will be 'Enabled', 'Suspended', or 'Disabled'. |
312+
| <a name="output_s3_bucket_abac_status"></a> [s3\_bucket\_abac\_status](#output\_s3\_bucket\_abac\_status) | The ABAC status of the bucket. |
295313
| <a name="output_s3_bucket_arn"></a> [s3\_bucket\_arn](#output\_s3\_bucket\_arn) | The ARN of the bucket. Will be of format arn:aws:s3:::bucketname. |
296314
| <a name="output_s3_bucket_bucket_domain_name"></a> [s3\_bucket\_bucket\_domain\_name](#output\_s3\_bucket\_bucket\_domain\_name) | The bucket domain name. Will be of format bucketname.s3.amazonaws.com. |
297315
| <a name="output_s3_bucket_bucket_regional_domain_name"></a> [s3\_bucket\_bucket\_regional\_domain\_name](#output\_s3\_bucket\_bucket\_regional\_domain\_name) | The bucket region-specific domain name. The bucket domain name including the region name, please refer here for format. Note: The AWS CloudFront allows specifying S3 region-specific endpoint when creating S3 origin, it will prevent redirect issues from CloudFront to S3 Origin URL. |

examples/complete/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ No inputs.
7070

7171
| Name | Description |
7272
|------|-------------|
73+
| <a name="output_s3_bucket_abac_status"></a> [s3\_bucket\_abac\_status](#output\_s3\_bucket\_abac\_status) | The ABAC status of the bucket. |
7374
| <a name="output_s3_bucket_arn"></a> [s3\_bucket\_arn](#output\_s3\_bucket\_arn) | The ARN of the bucket. Will be of format arn:aws:s3:::bucketname. |
7475
| <a name="output_s3_bucket_bucket_domain_name"></a> [s3\_bucket\_bucket\_domain\_name](#output\_s3\_bucket\_bucket\_domain\_name) | The bucket domain name. Will be of format bucketname.s3.amazonaws.com. |
7576
| <a name="output_s3_bucket_bucket_regional_domain_name"></a> [s3\_bucket\_bucket\_regional\_domain\_name](#output\_s3\_bucket\_bucket\_regional\_domain\_name) | The bucket region-specific domain name. The bucket domain name including the region name, please refer here for format. Note: The AWS CloudFront allows specifying S3 region-specific endpoint when creating S3 origin, it will prevent redirect issues from CloudFront to S3 Origin URL. |

examples/complete/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ module "s3_bucket" {
410410
# metadata_encryption_configuration = {
411411
# sse_algorithm = "AES256"
412412
# }
413+
414+
abac_status = {
415+
status = "Enabled"
416+
}
413417
}
414418

415419
module "disabled" {

examples/complete/outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,8 @@ output "s3_bucket_website_domain" {
4747
description = "The domain of the website endpoint, if the bucket is configured with a website. If not, this will be an empty string. This is used to create Route 53 alias records. "
4848
value = module.s3_bucket.s3_bucket_website_domain
4949
}
50+
51+
output "s3_bucket_abac_status" {
52+
description = "The ABAC status of the bucket."
53+
value = module.s3_bucket.s3_bucket_abac_status
54+
}

main.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,3 +1409,16 @@ resource "aws_s3_bucket_metadata_configuration" "this" {
14091409
}
14101410
}
14111411
}
1412+
1413+
resource "aws_s3_bucket_abac" "this" {
1414+
count = local.create_bucket && length(keys(var.abac_status)) > 0 && !var.is_directory_bucket ? 1 : 0
1415+
1416+
region = var.region
1417+
1418+
bucket = aws_s3_bucket.this[0].bucket
1419+
expected_bucket_owner = var.expected_bucket_owner
1420+
1421+
abac_status {
1422+
status = try(var.abac_status["status"], "Enabled")
1423+
}
1424+
}

outputs.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,8 @@ output "s3_bucket_tags" {
6767
description = "Tags of the bucket."
6868
value = try(aws_s3_bucket.this[0].tags, {})
6969
}
70+
71+
output "s3_bucket_abac_status" {
72+
description = "The ABAC status of the bucket."
73+
value = try(aws_s3_bucket_abac.this[0].abac_status[0].status, null)
74+
}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,12 @@ variable "metadata_journal_table_record_expiration" {
419419
default = null
420420
}
421421

422+
variable "abac_status" {
423+
description = "Map containing ABAC (Attribute Based Access Control) configuration"
424+
type = any
425+
default = {}
426+
}
427+
422428
variable "putin_khuylo" {
423429
description = "Do you agree that Putin doesn't respect Ukrainian sovereignty and territorial integrity? More info: https://en.wikipedia.org/wiki/Putin_khuylo!"
424430
type = bool

wrappers/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module "wrapper" {
33

44
for_each = var.items
55

6+
abac_status = try(each.value.abac_status, var.defaults.abac_status, {})
67
acceleration_status = try(each.value.acceleration_status, var.defaults.acceleration_status, null)
78
access_log_delivery_policy_source_accounts = try(each.value.access_log_delivery_policy_source_accounts, var.defaults.access_log_delivery_policy_source_accounts, [])
89
access_log_delivery_policy_source_buckets = try(each.value.access_log_delivery_policy_source_buckets, var.defaults.access_log_delivery_policy_source_buckets, [])

0 commit comments

Comments
 (0)