-
-
Notifications
You must be signed in to change notification settings - Fork 839
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
S3 Replication Improvements #93
Changes from 7 commits
241cb24
66ef539
9062254
9c6cb9d
9cc2a02
7c3a690
31d44aa
d6ee58c
53140de
4a7b2f1
a9a2744
489c536
bcc1b25
5fbdb0f
a101eea
3c79dd8
a681f1a
cc83775
6a03310
4f5d382
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,7 @@ | ||||||||
locals { | ||||||||
bucket_name = var.bucket_name != null && var.bucket_name != "" ? var.bucket_name : module.this.id | ||||||||
bucket_name = var.bucket_name != null && var.bucket_name != "" ? var.bucket_name : module.this.id | ||||||||
replication_enabled = length(var.replication_rules) > 0 | ||||||||
bucket_arn = "arn:${data.aws_partition.current.partition}:s3:::${join("", aws_s3_bucket.default.*.id)}" | ||||||||
} | ||||||||
alexjurkiewicz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
||||||||
resource "aws_s3_bucket" "default" { | ||||||||
|
@@ -139,7 +141,7 @@ resource "aws_s3_bucket" "default" { | |||||||
} | ||||||||
|
||||||||
dynamic "replication_configuration" { | ||||||||
for_each = var.s3_replication_enabled ? [1] : [] | ||||||||
for_each = local.replication_enabled ? [1] : [] | ||||||||
|
||||||||
content { | ||||||||
role = aws_iam_role.replication[0].arn | ||||||||
|
@@ -154,7 +156,7 @@ resource "aws_s3_bucket" "default" { | |||||||
status = try(rules.value.status, null) | ||||||||
|
||||||||
destination { | ||||||||
bucket = var.s3_replica_bucket_arn | ||||||||
bucket = rules.value.destination.bucket | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
storage_class = try(rules.value.destination.storage_class, "STANDARD") | ||||||||
replica_kms_key_id = try(rules.value.destination.replica_kms_key_id, null) | ||||||||
account_id = try(rules.value.destination.account_id, null) | ||||||||
|
@@ -229,7 +231,7 @@ data "aws_iam_policy_document" "bucket_policy" { | |||||||
sid = "DenyIncorrectEncryptionHeader" | ||||||||
effect = "Deny" | ||||||||
actions = ["s3:PutObject"] | ||||||||
resources = ["arn:${data.aws_partition.current.partition}:s3:::${join("", aws_s3_bucket.default.*.id)}/*"] | ||||||||
resources = ["${local.bucket_arn}/*"] | ||||||||
|
||||||||
principals { | ||||||||
identifiers = ["*"] | ||||||||
|
@@ -251,7 +253,7 @@ data "aws_iam_policy_document" "bucket_policy" { | |||||||
sid = "DenyUnEncryptedObjectUploads" | ||||||||
effect = "Deny" | ||||||||
actions = ["s3:PutObject"] | ||||||||
resources = ["arn:${data.aws_partition.current.partition}:s3:::${join("", aws_s3_bucket.default.*.id)}/*"] | ||||||||
resources = ["${local.bucket_arn}/*"] | ||||||||
|
||||||||
principals { | ||||||||
identifiers = ["*"] | ||||||||
|
@@ -270,13 +272,10 @@ data "aws_iam_policy_document" "bucket_policy" { | |||||||
for_each = var.allow_ssl_requests_only ? [1] : [] | ||||||||
|
||||||||
content { | ||||||||
sid = "ForceSSLOnlyAccess" | ||||||||
effect = "Deny" | ||||||||
actions = ["s3:*"] | ||||||||
resources = [ | ||||||||
"arn:${data.aws_partition.current.partition}:s3:::${join("", aws_s3_bucket.default.*.id)}", | ||||||||
"arn:${data.aws_partition.current.partition}:s3:::${join("", aws_s3_bucket.default.*.id)}/*" | ||||||||
] | ||||||||
sid = "ForceSSLOnlyAccess" | ||||||||
effect = "Deny" | ||||||||
actions = ["s3:*"] | ||||||||
resources = [local.bucket_arn, "${local.bucket_arn}/*"] | ||||||||
|
||||||||
principals { | ||||||||
identifiers = ["*"] | ||||||||
|
@@ -290,6 +289,39 @@ data "aws_iam_policy_document" "bucket_policy" { | |||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
dynamic "statement" { | ||||||||
for_each = length(var.replication_source_roles) > 0 ? [1] : [] | ||||||||
|
||||||||
content { | ||||||||
sid = "CrossAccountReplicationObjects" | ||||||||
actions = [ | ||||||||
"s3:ReplicateObject", | ||||||||
"s3:ReplicateDelete", | ||||||||
alexjurkiewicz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
"s3:ReplicateTags", | ||||||||
"s3:GetObjectVersionTagging", | ||||||||
"s3:ObjectOwnerOverrideToBucketOwner" | ||||||||
] | ||||||||
resources = ["${local.bucket_arn}/*"] | ||||||||
principals { | ||||||||
type = "AWS" | ||||||||
identifiers = var.replication_source_roles | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
dynamic "statement" { | ||||||||
for_each = length(var.replication_source_roles) > 0 ? [1] : [] | ||||||||
|
||||||||
content { | ||||||||
sid = "CrossAccountReplicationBucket" | ||||||||
actions = ["s3:List*", "s3:GetBucketVersioning", "s3:PutBucketVersioning"] | ||||||||
resources = [local.bucket_arn] | ||||||||
principals { | ||||||||
type = "AWS" | ||||||||
identifiers = var.replication_source_roles | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
data "aws_iam_policy_document" "aggregated_policy" { | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,25 +166,14 @@ variable "restrict_public_buckets" { | |
description = "Set to `false` to disable the restricting of making the bucket public" | ||
} | ||
|
||
variable "s3_replication_enabled" { | ||
type = bool | ||
default = false | ||
description = "Set this to true and specify `s3_replica_bucket_arn` to enable replication. `versioning_enabled` must also be `true`." | ||
} | ||
|
||
variable "s3_replica_bucket_arn" { | ||
type = string | ||
default = "" | ||
description = "The ARN of the S3 replica bucket (destination)" | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will need to weigh in on @Nuru and @osterman to decide on whether removing these outright is the best upgrade path for our module's users. In this particular case I feel like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me know. As someone who went through the change of lifecycle rules from individual variables to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add this to the bottom of # The variables below are DEPRECATED and should not be used anymore
variable "s3_replication_enabled" {
type = bool
default = null
description = "DEPRECATED. Use `replication_rules` instead."
}
variable "s3_replica_bucket_arn" {
type = string
default = null
description = "DEPRECATED. Use `replication_rules` instead."
} |
||
variable "replication_rules" { | ||
# type = list(object({ | ||
# id = string | ||
# priority = number | ||
# prefix = string | ||
# status = string | ||
# destination = object({ | ||
# bucket = string | ||
# storage_class = string | ||
# replica_kms_key_id = string | ||
# access_control_translation = object({ | ||
|
@@ -202,10 +191,8 @@ variable "replication_rules" { | |
# tags = map(string) | ||
# }) | ||
# })) | ||
|
||
type = list(any) | ||
default = null | ||
description = "Specifies the replication rules if S3 bucket replication is enabled" | ||
default = [] | ||
description = "S3 replication rules" | ||
} | ||
|
||
variable "bucket_name" { | ||
|
@@ -235,4 +222,10 @@ variable "website_inputs" { | |
default = null | ||
|
||
description = "Specifies the static website hosting configuration object." | ||
} | ||
} | ||
|
||
variable "replication_source_roles" { | ||
type = list(string) | ||
default = [] | ||
description = "Cross-account IAM Role ARNs that will be allowed to perform S3 replication to this bucket (for replication within the same AWS account, it's not necessary to adjust the bucket policy)." | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.