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

feat: DEVOPS-1640 Use Google Cloud Armor to protect the faucet #2080

Merged
merged 1 commit into from
Dec 26, 2024
Merged
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
52 changes: 36 additions & 16 deletions infra/tf/apps.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ resource "google_compute_firewall" "allow_apps_external_http" {
network = local.network_name

direction = "INGRESS"
source_ranges = ["0.0.0.0/0"]
source_ranges = local.google_load_balancer_ip_ranges

target_tags = [format("%s-%s", var.chain_name, "apps")]

Expand All @@ -17,21 +17,6 @@ resource "google_compute_firewall" "allow_apps_external_http" {
}
}

resource "google_compute_firewall" "allow_apps_external_https" {
name = "${var.chain_name}-apps-allow-external-https"
network = local.network_name

direction = "INGRESS"
source_ranges = ["0.0.0.0/0"]

target_tags = [format("%s-%s", var.chain_name, "apps")]

allow {
protocol = "tcp"
ports = ["443"]
}
}

module "apps" {
source = "./modules/node"

Expand Down Expand Up @@ -124,6 +109,9 @@ resource "google_compute_backend_service" "spout" {
capacity_scaler = 1.0
}
}

## Attach Cloud Armor policy to the backend service
security_policy = module.spout_security_policies.policy.self_link
}

resource "google_compute_url_map" "apps" {
Expand Down Expand Up @@ -213,3 +201,35 @@ resource "google_compute_global_forwarding_rule" "faucet_https" {
target = google_compute_target_https_proxy.apps.id
ip_address = data.google_compute_global_address.faucet.address
}

module "spout_security_policies" {
source = "./modules/google-cloud-armor"

project_id = var.project_id
name = "${var.chain_name}-apps-spout"
description = "Cloud Armor security policy for the ${var.chain_name} faucet"
default_rule_action = "deny(403)"
type = "CLOUD_ARMOR"

security_rules = {
allow_whitelisted_ip_ranges = {
action = "allow"
priority = 999
description = "Allow whitelisted IP address ranges"
src_ip_ranges = ["*"]
}
throttle = {
action = "throttle"
priority = 990
description = "Limit requests per IP"
src_ip_ranges = ["0.0.0.0/0"]

rate_limit_options = {
enforce_on_key = "IP"
exceed_action = "deny(429)"
rate_limit_http_request_count = var.apps.faucet_max_hourly_requests
rate_limit_http_request_interval_sec = 3600
}
}
}
}
48 changes: 48 additions & 0 deletions infra/tf/modules/google-cloud-armor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# OSX leaves these everywhere on SMB shares
._*

# OSX trash
.DS_Store

# Python
*.pyc

# Emacs save files
*~
\#*\#
.\#*

# Vim-related files
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist

### https://raw.github.com/github/gitignore/90f149de451a5433aebd94d02d11b0e28843a1af/Terraform.gitignore

# Local .terraform directories
**/.terraform/*
.terraform.lock.hcl

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log

# Kitchen files
**/inspec.lock
**/.kitchen
**/.kitchen.local.yml
**/Gemfile.lock

# Ignore any .tfvars files that are generated automatically for each Terraform run. Most
# .tfvars files are managed as part of configuration and so should be included in
# version control.
#
# example.tfvars
test/fixtures/shared/terraform.tfvars

credentials.json
801 changes: 801 additions & 0 deletions infra/tf/modules/google-cloud-armor/README.md

Large diffs are not rendered by default.

Loading
Loading