Skip to content

Commit f2e99c5

Browse files
committed
enable temp ban when continuing to exceed rate limit, fix path rule
1 parent a08e5f5 commit f2e99c5

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

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

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

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

@@ -39,28 +39,37 @@ resource "google_compute_security_policy" "cloud-armor" {
3939
rate_limit_options {
4040
conform_action = "allow"
4141
exceed_action = "deny(429)"
42-
4342
enforce_on_key = "IP"
44-
# 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
4545
rate_limit_threshold {
46+
# NOTE: count cannot exceed 10,000
47+
# https://cloud.google.com/armor/docs/rate-limiting-overview
4648
count = 5000
4749
interval_sec = 60
4850
}
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
58+
}
59+
ban_duration_sec = 1800
4960
}
50-
51-
preview = false
5261
}
5362

5463
// block all requests with obviously invalid paths at the edge
55-
// we support "/", "/privacy", and "/v2/.*" API
64+
// we support "/", "/privacy", and "/v2/.*" API, GET or HEAD
5665

5766
rule {
5867
action = "deny(404)"
5968
# apply this broad 404 for unexpected paths second
6069
priority = "1"
6170
match {
6271
expr {
63-
expression = "!request.path.match('(?:^/$)|(?:^/privacy$)|(?:^/v2/)')"
72+
expression = "!request.path.matches('(?:^/$)|(?:^/privacy$)|(?:^/v2/)')"
6473
}
6574
}
6675
}

0 commit comments

Comments
 (0)