Skip to content

Commit 3812cb5

Browse files
committed
feat: Add log delivery source organization variables
Allow S3 bucket access scoping to AWS Organizations in ALB/NLB/S3 access log bucket policies. Signed-off-by: szubersk <[email protected]>
1 parent 8b855f8 commit 3812cb5

File tree

5 files changed

+113
-56
lines changed

5 files changed

+113
-56
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ No modules.
183183
| <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 |
184184
| <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 |
185185
| <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 |
186+
| <a name="input_access_log_delivery_policy_source_organizations"></a> [access\_log\_delivery\_policy\_source\_organizations](#input\_access\_log\_delivery\_policy\_source\_organizations) | (Optional) List of AWS Organization IDs should be allowed to deliver access logs to this bucket. | `list(string)` | `[]` | no |
186187
| <a name="input_acl"></a> [acl](#input\_acl) | (Optional) The canned ACL to apply. Conflicts with `grant` | `string` | `null` | no |
187188
| <a name="input_allowed_kms_key_arn"></a> [allowed\_kms\_key\_arn](#input\_allowed\_kms\_key\_arn) | The ARN of KMS key which should be allowed in PutObject | `string` | `null` | no |
188189
| <a name="input_analytics_configuration"></a> [analytics\_configuration](#input\_analytics\_configuration) | Map containing bucket analytics configuration. | `any` | `{}` | no |
@@ -217,6 +218,7 @@ No modules.
217218
| <a name="input_inventory_self_source_destination"></a> [inventory\_self\_source\_destination](#input\_inventory\_self\_source\_destination) | Whether or not the inventory source bucket is also the destination bucket. | `bool` | `false` | no |
218219
| <a name="input_inventory_source_account_id"></a> [inventory\_source\_account\_id](#input\_inventory\_source\_account\_id) | The inventory source account id. | `string` | `null` | no |
219220
| <a name="input_inventory_source_bucket_arn"></a> [inventory\_source\_bucket\_arn](#input\_inventory\_source\_bucket\_arn) | The inventory source bucket ARN. | `string` | `null` | no |
221+
| <a name="input_lb_log_delivery_policy_source_organizations"></a> [lb\_log\_delivery\_policy\_source\_organizations](#input\_lb\_log\_delivery\_policy\_source\_organizations) | (Optional) List of AWS Organization IDs should be allowed to deliver ALB/NLB logs to this bucket. | `list(string)` | `[]` | no |
220222
| <a name="input_lifecycle_rule"></a> [lifecycle\_rule](#input\_lifecycle\_rule) | List of maps containing configuration of object lifecycle management. | `any` | `[]` | no |
221223
| <a name="input_logging"></a> [logging](#input\_logging) | Map containing access bucket logging configuration. | `any` | `{}` | no |
222224
| <a name="input_metric_configuration"></a> [metric\_configuration](#input\_metric\_configuration) | Map containing bucket metric configuration. | `any` | `[]` | no |

examples/complete/main.tf

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,10 @@ module "log_bucket" {
7676
attach_deny_insecure_transport_policy = true
7777
attach_require_latest_tls_policy = true
7878

79-
access_log_delivery_policy_source_accounts = [data.aws_caller_identity.current.account_id]
80-
access_log_delivery_policy_source_buckets = ["arn:aws:s3:::${local.bucket_name}"]
79+
access_log_delivery_policy_source_accounts = [data.aws_caller_identity.current.account_id]
80+
access_log_delivery_policy_source_buckets = ["arn:aws:s3:::${local.bucket_name}"]
81+
access_log_delivery_policy_source_organizations = ["o-123456"]
82+
lb_log_delivery_policy_source_organizations = ["o-123456"]
8183
}
8284

8385
module "cloudfront_log_bucket" {

main.tf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,16 @@ data "aws_iam_policy_document" "lb_log_delivery" {
675675
variable = "s3:x-amz-acl"
676676
values = ["bucket-owner-full-control"]
677677
}
678+
679+
dynamic "condition" {
680+
for_each = length(var.lb_log_delivery_policy_source_organizations) > 0 ? [true] : []
681+
682+
content {
683+
test = "StringEquals"
684+
variable = "aws:ResourceOrgID"
685+
values = var.lb_log_delivery_policy_source_organizations
686+
}
687+
}
678688
}
679689

680690
statement {
@@ -696,6 +706,15 @@ data "aws_iam_policy_document" "lb_log_delivery" {
696706
aws_s3_bucket.this[0].arn,
697707
]
698708

709+
dynamic "condition" {
710+
for_each = length(var.lb_log_delivery_policy_source_organizations) > 0 ? [true] : []
711+
712+
content {
713+
test = "StringEquals"
714+
variable = "aws:ResourceOrgID"
715+
values = var.lb_log_delivery_policy_source_organizations
716+
}
717+
}
699718
}
700719
}
701720

@@ -741,6 +760,16 @@ data "aws_iam_policy_document" "access_log_delivery" {
741760
}
742761
}
743762

763+
dynamic "condition" {
764+
for_each = length(var.access_log_delivery_policy_source_organizations) > 0 ? [true] : []
765+
766+
content {
767+
test = "StringEquals"
768+
variable = "aws:ResourceOrgID"
769+
values = var.access_log_delivery_policy_source_organizations
770+
}
771+
}
772+
744773
}
745774

746775
statement {
@@ -761,6 +790,16 @@ data "aws_iam_policy_document" "access_log_delivery" {
761790
aws_s3_bucket.this[0].arn,
762791
]
763792

793+
dynamic "condition" {
794+
for_each = length(var.access_log_delivery_policy_source_organizations) > 0 ? [true] : []
795+
796+
content {
797+
test = "StringEquals"
798+
variable = "aws:ResourceOrgID"
799+
values = var.access_log_delivery_policy_source_organizations
800+
}
801+
}
802+
764803
}
765804
}
766805

variables.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ variable "access_log_delivery_policy_source_accounts" {
166166
default = []
167167
}
168168

169+
variable "access_log_delivery_policy_source_organizations" {
170+
description = "(Optional) List of AWS Organization IDs should be allowed to deliver access logs to this bucket."
171+
type = list(string)
172+
default = []
173+
}
174+
175+
variable "lb_log_delivery_policy_source_organizations" {
176+
description = "(Optional) List of AWS Organization IDs should be allowed to deliver ALB/NLB logs to this bucket."
177+
type = list(string)
178+
default = []
179+
}
180+
169181
variable "grant" {
170182
description = "An ACL policy grant. Conflicts with `acl`"
171183
type = any

0 commit comments

Comments
 (0)