Skip to content

Commit edb6867

Browse files
authored
Merge pull request #6969 from BenTheElder/simple-waf
oci-proxy: block most irrelevant requests at the edge with a simple path based rule
2 parents f3a0b17 + 9e329d0 commit edb6867

File tree

1 file changed

+44
-28
lines changed

1 file changed

+44
-28
lines changed

infra/gcp/terraform/modules/oci-proxy/cloud-armor.tf

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,50 @@ resource "google_compute_security_policy" "cloud-armor" {
2121
project = var.project_id
2222
name = "security-policy-oci-proxy"
2323

24+
# apply rate limits
25+
rule {
26+
action = "throttle"
27+
description = "Default rule, throttle traffic"
28+
priority = "2147483647"
29+
30+
match {
31+
config {
32+
src_ip_ranges = ["*"]
33+
}
34+
versioned_expr = "SRC_IPS_V1"
35+
}
36+
37+
rate_limit_options {
38+
conform_action = "allow"
39+
exceed_action = "deny(429)"
40+
41+
enforce_on_key = "IP"
42+
# This is comparable to the GCR limits from k8s.gcr.io
43+
rate_limit_threshold {
44+
count = 5000
45+
interval_sec = 60
46+
}
47+
}
48+
49+
preview = false
50+
}
51+
52+
// block all requests with obviously invalid paths at the edge
53+
// we support "/", "/privacy", and "/v2/.*" API
54+
55+
rule {
56+
action = "deny(404)"
57+
priority = "2147483646"
58+
match {
59+
expr {
60+
expression = "!request.path.match('(?:^/$)|(?:^/privacy$)|(?:^/v2/)')"
61+
}
62+
}
63+
}
64+
65+
66+
# TODO: remove these other rules?
67+
2468

2569
rule {
2670
action = "deny(403)"
@@ -150,33 +194,5 @@ resource "google_compute_security_policy" "cloud-armor" {
150194

151195
preview = false
152196
}
153-
154-
# Permit all other traffic, with rate limits
155-
rule {
156-
action = "throttle"
157-
description = "Default rule, throttle traffic"
158-
priority = "2147483647"
159-
160-
match {
161-
config {
162-
src_ip_ranges = ["*"]
163-
}
164-
versioned_expr = "SRC_IPS_V1"
165-
}
166-
167-
rate_limit_options {
168-
conform_action = "allow"
169-
exceed_action = "deny(429)"
170-
171-
enforce_on_key = "IP"
172-
# This is comparable to the GCR limits from k8s.gcr.io
173-
rate_limit_threshold {
174-
count = 5000
175-
interval_sec = 60
176-
}
177-
}
178-
179-
preview = false
180-
}
181197
}
182198

0 commit comments

Comments
 (0)