@@ -23,9 +23,11 @@ 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
- 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"
29
31
30
32
match {
31
33
config {
@@ -37,162 +39,39 @@ resource "google_compute_security_policy" "cloud-armor" {
37
39
rate_limit_options {
38
40
conform_action = " allow"
39
41
exceed_action = " deny(429)"
40
-
41
42
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
43
45
rate_limit_threshold {
46
+ # NOTE: count cannot exceed 10,000
47
+ # https://cloud.google.com/armor/docs/rate-limiting-overview
44
48
count = 5000
45
49
interval_sec = 60
46
50
}
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
140
58
}
59
+ ban_duration_sec = 1800
141
60
}
142
-
143
- preview = false
144
61
}
145
62
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
184
65
185
66
rule {
186
- action = " deny(403)"
187
- priority = " 1010"
67
+ action = " deny(404)"
68
+ # apply this broad 404 for unexpected paths second
69
+ priority = " 1"
188
70
match {
189
71
expr {
190
- expression = " evaluatePreconfiguredExpr('cve-canary ')"
72
+ expression = " !request.path.matches('(?:^/$)|(?:^/privacy$)|(?:^/v2/) ')"
191
73
}
192
74
}
193
- description = " CVEs and other vulnerabilities"
194
-
195
- preview = false
196
75
}
197
76
}
198
77
0 commit comments