Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,34 @@ data "aws_iam_policy_document" "default" {
}
}

dynamic "statement" {
for_each = flatten(var.trusted_ips) != [] ? [1] : []

# https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_examples_aws_deny-ip.html
content {
sid = "AllowTrustedIPsOnly"
effect = "Deny"
actions = ["s3:*"]
resources = [local.bucket_arn, "${local.bucket_arn}/*"]

principals {
identifiers = ["*"]
type = "*"
}

condition {
test = "NotIpAddress"
values = var.trusted_ips
variable = "aws:SourceIp"
}
condition {
test = "Bool"
values = ["false"]
variable = "aws:ViaAWSService"
}
}
}

# Support replication ARNs
dynamic "statement" {
for_each = flatten(data.aws_iam_policy_document.replication.*.statement)
Expand Down
8 changes: 7 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,10 @@ variable "allow_ssl_requests_only" {
type = bool
default = false
description = "Set to `true` to require requests to use Secure Socket Layer (HTTPS/SSL). This will explicitly deny access to HTTP requests"
}
}

variable "trusted_ips" {
type = list(string)
default = []
description = "(Optional) List of IP CIDRs which can access the S3 website"
}