Skip to content

Commit 588e8d9

Browse files
authored
Merge pull request #6975 from BenTheElder/simplewaf2
simplify WAF rules
2 parents 315a356 + f2e99c5 commit 588e8d9

File tree

1 file changed

+23
-144
lines changed

1 file changed

+23
-144
lines changed

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

Lines changed: 23 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ resource "google_compute_security_policy" "cloud-armor" {
2323

2424
# apply rate limits
2525
rule {
26-
action = "throttle"
27-
description = "Default rule, throttle traffic"
28-
priority = "2147483647"
26+
action = "rate_based_ban"
27+
description = "Limit excessive usage"
28+
# apply rate limits first (rules are applied sequentially by priority)
29+
# https://cloud.google.com/armor/docs/security-policy-overview#eval-order
30+
priority = "0"
2931

3032
match {
3133
config {
@@ -37,162 +39,39 @@ resource "google_compute_security_policy" "cloud-armor" {
3739
rate_limit_options {
3840
conform_action = "allow"
3941
exceed_action = "deny(429)"
40-
4142
enforce_on_key = "IP"
42-
# This is comparable to the GCR limits from k8s.gcr.io
43+
# TODO: revisit these values
44+
# above this threshold we serve 429, currently ~83/sec in a 1 minute window
4345
rate_limit_threshold {
46+
# NOTE: count cannot exceed 10,000
47+
# https://cloud.google.com/armor/docs/rate-limiting-overview
4448
count = 5000
4549
interval_sec = 60
4650
}
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-
68-
69-
rule {
70-
action = "deny(403)"
71-
priority = "910"
72-
match {
73-
expr {
74-
expression = "evaluatePreconfiguredWaf('methodenforcement-v33-stable', {'sensitivity': 1})"
75-
}
76-
}
77-
description = "Method enforcement"
78-
79-
preview = false
80-
}
81-
82-
rule {
83-
action = "deny(403)"
84-
priority = "900"
85-
match {
86-
expr {
87-
expression = "evaluatePreconfiguredWaf('protocolattack-v33-stable', {'sensitivity': 3, 'opt_out_rule_ids': ['owasp-crs-v030301-id921170-protocolattack']})"
88-
}
89-
}
90-
description = "Protocol Attack"
91-
92-
preview = false
93-
}
94-
95-
rule {
96-
action = "deny(403)"
97-
priority = "920"
98-
match {
99-
expr {
100-
expression = "evaluatePreconfiguredWaf('scannerdetection-v33-stable', {'sensitivity': 1})"
101-
}
102-
}
103-
description = "Scanner detection"
104-
105-
preview = false
106-
}
107-
108-
rule {
109-
action = "deny(403)"
110-
priority = "990"
111-
match {
112-
expr {
113-
expression = "evaluatePreconfiguredWaf('xss-v33-stable', {'sensitivity': 1})"
114-
}
115-
}
116-
description = "Cross-site scripting (XSS)"
117-
118-
preview = false
119-
}
120-
121-
rule {
122-
action = "deny(403)"
123-
priority = "960"
124-
match {
125-
expr {
126-
expression = "evaluatePreconfiguredWaf('lfi-v33-stable', {'sensitivity': 1})"
127-
}
128-
}
129-
description = "Local file inclusion (LFI)"
130-
131-
preview = false
132-
}
133-
134-
rule {
135-
action = "deny(403)"
136-
priority = "930"
137-
match {
138-
expr {
139-
expression = "evaluatePreconfiguredExpr('rce-stable')"
51+
# if the user continues to exceed the rate limit, temp ban
52+
# otherwise users may ignore transient 429 and keep running right at the limit
53+
# clients that respect the 429 and backoff will not hit this
54+
# (or better yet, https://github.com/kubernetes/registry.k8s.io/blob/main/docs/mirroring/README.md)
55+
ban_threshold {
56+
count = 10000
57+
interval_sec = 120
14058
}
59+
ban_duration_sec = 1800
14160
}
142-
143-
preview = false
14461
}
14562

146-
rule {
147-
action = "deny(403)"
148-
priority = "940"
149-
match {
150-
expr {
151-
expression = "evaluatePreconfiguredWaf('rfi-v33-stable', {'sensitivity': 2})"
152-
}
153-
}
154-
description = "Remote file inclusion (RFI)"
155-
156-
preview = false
157-
}
158-
159-
rule {
160-
action = "deny(403)"
161-
priority = "950"
162-
match {
163-
expr {
164-
expression = "evaluatePreconfiguredWaf('sessionfixation-v33-stable', {'sensitivity': 1})"
165-
}
166-
}
167-
description = "Session fixation"
168-
169-
preview = false
170-
}
171-
172-
rule {
173-
action = "deny(403)"
174-
priority = "980"
175-
match {
176-
expr {
177-
expression = "evaluatePreconfiguredWaf('php-v33-stable', {'sensitivity': 3})"
178-
}
179-
}
180-
description = "PHP"
181-
182-
preview = false
183-
}
63+
// block all requests with obviously invalid paths at the edge
64+
// we support "/", "/privacy", and "/v2/.*" API, GET or HEAD
18465

18566
rule {
186-
action = "deny(403)"
187-
priority = "1010"
67+
action = "deny(404)"
68+
# apply this broad 404 for unexpected paths second
69+
priority = "1"
18870
match {
18971
expr {
190-
expression = "evaluatePreconfiguredExpr('cve-canary')"
72+
expression = "!request.path.matches('(?:^/$)|(?:^/privacy$)|(?:^/v2/)')"
19173
}
19274
}
193-
description = "CVEs and other vulnerabilities"
194-
195-
preview = false
19675
}
19776
}
19877

0 commit comments

Comments
 (0)