@@ -23,9 +23,9 @@ resource "google_compute_security_policy" "cloud-armor" {
23
23
24
24
# apply rate limits
25
25
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)
29
29
# https://cloud.google.com/armor/docs/security-policy-overview#eval-order
30
30
priority = " 0"
31
31
@@ -39,28 +39,37 @@ resource "google_compute_security_policy" "cloud-armor" {
39
39
rate_limit_options {
40
40
conform_action = " allow"
41
41
exceed_action = " deny(429)"
42
-
43
42
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
45
45
rate_limit_threshold {
46
+ # NOTE: count cannot exceed 10,000
47
+ # https://cloud.google.com/armor/docs/rate-limiting-overview
46
48
count = 5000
47
49
interval_sec = 60
48
50
}
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
49
60
}
50
-
51
- preview = false
52
61
}
53
62
54
63
// 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
56
65
57
66
rule {
58
67
action = " deny(404)"
59
68
# apply this broad 404 for unexpected paths second
60
69
priority = " 1"
61
70
match {
62
71
expr {
63
- expression = " !request.path.match ('(?:^/$)|(?:^/privacy$)|(?:^/v2/)')"
72
+ expression = " !request.path.matches ('(?:^/$)|(?:^/privacy$)|(?:^/v2/)')"
64
73
}
65
74
}
66
75
}
0 commit comments