Skip to content
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

Add an optional list of IP CIDRs which can access the S3 website. #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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"
}
Loading