Skip to content

Commit

Permalink
fixes for whitelisting
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispsheehan committed Feb 26, 2024
1 parent 50fe525 commit 2f34489
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
15 changes: 8 additions & 7 deletions tf/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ data "aws_iam_policy_document" "assume_role" {

data "aws_iam_policy_document" "whitelist_ips" {
statement {
principals {
type = "AWS"
identifiers = ["*"]
}

effect = "Allow"
actions = ["execute-api:Invoke"]
resources = [aws_api_gateway_rest_api.this.execution_arn]
resources = ["${aws_api_gateway_rest_api.this.execution_arn}/*/*/*"]
}

statement {
effect = "Deny"
actions = ["execute-api:Invoke"]
resources = ["${aws_api_gateway_rest_api.this.execution_arn}/*/*/*"]

condition {
test = "IpAddress"
test = "NotIpAddress"
variable = "aws:SourceIp"
values = var.whitelist_ips
}
Expand Down
2 changes: 0 additions & 2 deletions tf/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ resource "aws_api_gateway_method_settings" "this" {
}

resource "aws_api_gateway_rest_api_policy" "whitelist" {
count = length(var.whitelist_ips) > 0 ? 1 : 0

rest_api_id = aws_api_gateway_rest_api.this.id
policy = data.aws_iam_policy_document.whitelist_ips.json
}
1 change: 0 additions & 1 deletion tf/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@ variable "lambda-zip-path" {
}

variable "whitelist_ips" {
//default = []
default = ["0.0.0.0/0"]
}

0 comments on commit 2f34489

Please sign in to comment.