Skip to content

Commit 5d8da30

Browse files
Added "preconfiguredWafConfig" and "rateLimitOptions" support to region security policy rule (#10532) (#18039)
[upstream:bbeb3f6313cfe439e8cc9ddadf3ccb8b0c91b3f0] Signed-off-by: Modular Magician <[email protected]>
1 parent e809049 commit 5d8da30

File tree

1 file changed

+288
-0
lines changed

1 file changed

+288
-0
lines changed

website/docs/r/compute_region_security_policy_rule.html.markdown

+288
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,69 @@ resource "google_compute_region_security_policy_rule" "policy_rule_two" {
117117
preview = true
118118
}
119119
```
120+
<div class = "oics-button" style="float: right; margin: 0 0 -15px">
121+
<a href="https://console.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.jpy.wang%2Fterraform-google-modules%2Fdocs-examples.git&cloudshell_working_dir=region_security_policy_rule_with_preconfigured_waf_config&cloudshell_image=gcr.io%2Fcloudshell-images%2Fcloudshell%3Alatest&open_in_editor=main.tf&cloudshell_print=.%2Fmotd&cloudshell_tutorial=.%2Ftutorial.md" target="_blank">
122+
<img alt="Open in Cloud Shell" src="//gstatic.com/cloudssh/images/open-btn.svg" style="max-height: 44px; margin: 32px auto; max-width: 100%;">
123+
</a>
124+
</div>
125+
## Example Usage - Region Security Policy Rule With Preconfigured Waf Config
126+
127+
128+
```hcl
129+
resource "google_compute_region_security_policy" "default" {
130+
provider = google-beta
131+
132+
region = "asia-southeast1"
133+
name = "policyruletest"
134+
description = "basic region security policy"
135+
type = "CLOUD_ARMOR"
136+
}
137+
138+
resource "google_compute_region_security_policy_rule" "policy_rule" {
139+
provider = google-beta
140+
141+
region = "asia-southeast1"
142+
security_policy = google_compute_region_security_policy.default.name
143+
description = "new rule"
144+
priority = 100
145+
match {
146+
versioned_expr = "SRC_IPS_V1"
147+
config {
148+
src_ip_ranges = ["10.10.0.0/16"]
149+
}
150+
}
151+
preconfigured_waf_config {
152+
exclusion {
153+
request_uri {
154+
operator = "STARTS_WITH"
155+
value = "/admin"
156+
}
157+
target_rule_set = "rce-stable"
158+
}
159+
exclusion {
160+
request_query_param {
161+
operator = "CONTAINS"
162+
value = "password"
163+
}
164+
request_query_param {
165+
operator = "STARTS_WITH"
166+
value = "freeform"
167+
}
168+
request_query_param {
169+
operator = "EQUALS"
170+
value = "description"
171+
}
172+
target_rule_set = "xss-stable"
173+
target_rule_ids = [
174+
"owasp-crs-v030001-id941330-xss",
175+
"owasp-crs-v030001-id941340-xss",
176+
]
177+
}
178+
}
179+
action = "allow"
180+
preview = true
181+
}
182+
```
120183
## Example Usage - Region Security Policy Rule With Network Match
121184

122185

@@ -222,6 +285,17 @@ The following arguments are supported:
222285
If it evaluates to true, the corresponding 'action' is enforced.
223286
Structure is [documented below](#nested_match).
224287

288+
* `preconfigured_waf_config` -
289+
(Optional)
290+
Preconfigured WAF configuration to be applied for the rule.
291+
If the rule does not evaluate preconfigured WAF rules, i.e., if evaluatePreconfiguredWaf() is not used, this field will have no effect.
292+
Structure is [documented below](#nested_preconfigured_waf_config).
293+
294+
* `rate_limit_options` -
295+
(Optional)
296+
Must be specified if the action is "rate_based_ban" or "throttle". Cannot be specified for any other actions.
297+
Structure is [documented below](#nested_rate_limit_options).
298+
225299
* `preview` -
226300
(Optional)
227301
If set to true, the specified action is not enforced.
@@ -263,6 +337,220 @@ The following arguments are supported:
263337
(Optional)
264338
CIDR IP address range. Maximum number of srcIpRanges allowed is 10.
265339

340+
<a name="nested_preconfigured_waf_config"></a>The `preconfigured_waf_config` block supports:
341+
342+
* `exclusion` -
343+
(Optional)
344+
An exclusion to apply during preconfigured WAF evaluation.
345+
Structure is [documented below](#nested_exclusion).
346+
347+
348+
<a name="nested_exclusion"></a>The `exclusion` block supports:
349+
350+
* `target_rule_set` -
351+
(Required)
352+
Target WAF rule set to apply the preconfigured WAF exclusion.
353+
354+
* `target_rule_ids` -
355+
(Optional)
356+
A list of target rule IDs under the WAF rule set to apply the preconfigured WAF exclusion.
357+
If omitted, it refers to all the rule IDs under the WAF rule set.
358+
359+
* `request_header` -
360+
(Optional)
361+
Request header whose value will be excluded from inspection during preconfigured WAF evaluation.
362+
Structure is [documented below](#nested_request_header).
363+
364+
* `request_cookie` -
365+
(Optional)
366+
Request cookie whose value will be excluded from inspection during preconfigured WAF evaluation.
367+
Structure is [documented below](#nested_request_cookie).
368+
369+
* `request_uri` -
370+
(Optional)
371+
Request URI from the request line to be excluded from inspection during preconfigured WAF evaluation.
372+
When specifying this field, the query or fragment part should be excluded.
373+
Structure is [documented below](#nested_request_uri).
374+
375+
* `request_query_param` -
376+
(Optional)
377+
Request query parameter whose value will be excluded from inspection during preconfigured WAF evaluation.
378+
Note that the parameter can be in the query string or in the POST body.
379+
Structure is [documented below](#nested_request_query_param).
380+
381+
382+
<a name="nested_request_header"></a>The `request_header` block supports:
383+
384+
* `operator` -
385+
(Required)
386+
You can specify an exact match or a partial match by using a field operator and a field value.
387+
Available options:
388+
EQUALS: The operator matches if the field value equals the specified value.
389+
STARTS_WITH: The operator matches if the field value starts with the specified value.
390+
ENDS_WITH: The operator matches if the field value ends with the specified value.
391+
CONTAINS: The operator matches if the field value contains the specified value.
392+
EQUALS_ANY: The operator matches if the field value is any value.
393+
Possible values are: `CONTAINS`, `ENDS_WITH`, `EQUALS`, `EQUALS_ANY`, `STARTS_WITH`.
394+
395+
* `value` -
396+
(Optional)
397+
A request field matching the specified value will be excluded from inspection during preconfigured WAF evaluation.
398+
The field value must be given if the field operator is not EQUALS_ANY, and cannot be given if the field operator is EQUALS_ANY.
399+
400+
<a name="nested_request_cookie"></a>The `request_cookie` block supports:
401+
402+
* `operator` -
403+
(Required)
404+
You can specify an exact match or a partial match by using a field operator and a field value.
405+
Available options:
406+
EQUALS: The operator matches if the field value equals the specified value.
407+
STARTS_WITH: The operator matches if the field value starts with the specified value.
408+
ENDS_WITH: The operator matches if the field value ends with the specified value.
409+
CONTAINS: The operator matches if the field value contains the specified value.
410+
EQUALS_ANY: The operator matches if the field value is any value.
411+
Possible values are: `CONTAINS`, `ENDS_WITH`, `EQUALS`, `EQUALS_ANY`, `STARTS_WITH`.
412+
413+
* `value` -
414+
(Optional)
415+
A request field matching the specified value will be excluded from inspection during preconfigured WAF evaluation.
416+
The field value must be given if the field operator is not EQUALS_ANY, and cannot be given if the field operator is EQUALS_ANY.
417+
418+
<a name="nested_request_uri"></a>The `request_uri` block supports:
419+
420+
* `operator` -
421+
(Required)
422+
You can specify an exact match or a partial match by using a field operator and a field value.
423+
Available options:
424+
EQUALS: The operator matches if the field value equals the specified value.
425+
STARTS_WITH: The operator matches if the field value starts with the specified value.
426+
ENDS_WITH: The operator matches if the field value ends with the specified value.
427+
CONTAINS: The operator matches if the field value contains the specified value.
428+
EQUALS_ANY: The operator matches if the field value is any value.
429+
Possible values are: `CONTAINS`, `ENDS_WITH`, `EQUALS`, `EQUALS_ANY`, `STARTS_WITH`.
430+
431+
* `value` -
432+
(Optional)
433+
A request field matching the specified value will be excluded from inspection during preconfigured WAF evaluation.
434+
The field value must be given if the field operator is not EQUALS_ANY, and cannot be given if the field operator is EQUALS_ANY.
435+
436+
<a name="nested_request_query_param"></a>The `request_query_param` block supports:
437+
438+
* `operator` -
439+
(Required)
440+
You can specify an exact match or a partial match by using a field operator and a field value.
441+
Available options:
442+
EQUALS: The operator matches if the field value equals the specified value.
443+
STARTS_WITH: The operator matches if the field value starts with the specified value.
444+
ENDS_WITH: The operator matches if the field value ends with the specified value.
445+
CONTAINS: The operator matches if the field value contains the specified value.
446+
EQUALS_ANY: The operator matches if the field value is any value.
447+
Possible values are: `CONTAINS`, `ENDS_WITH`, `EQUALS`, `EQUALS_ANY`, `STARTS_WITH`.
448+
449+
* `value` -
450+
(Optional)
451+
A request field matching the specified value will be excluded from inspection during preconfigured WAF evaluation.
452+
The field value must be given if the field operator is not EQUALS_ANY, and cannot be given if the field operator is EQUALS_ANY.
453+
454+
<a name="nested_rate_limit_options"></a>The `rate_limit_options` block supports:
455+
456+
* `rate_limit_threshold` -
457+
(Optional)
458+
Threshold at which to begin ratelimiting.
459+
Structure is [documented below](#nested_rate_limit_threshold).
460+
461+
* `conform_action` -
462+
(Optional)
463+
Action to take for requests that are under the configured rate limit threshold.
464+
Valid option is "allow" only.
465+
466+
* `exceed_action` -
467+
(Optional)
468+
Action to take for requests that are above the configured rate limit threshold, to deny with a specified HTTP response code.
469+
Valid options are deny(STATUS), where valid values for STATUS are 403, 404, 429, and 502.
470+
471+
* `enforce_on_key` -
472+
(Optional)
473+
Determines the key to enforce the rateLimitThreshold on. Possible values are:
474+
* ALL: A single rate limit threshold is applied to all the requests matching this rule. This is the default value if "enforceOnKey" is not configured.
475+
* IP: The source IP address of the request is the key. Each IP has this limit enforced separately.
476+
* HTTP_HEADER: The value of the HTTP header whose name is configured under "enforceOnKeyName". The key value is truncated to the first 128 bytes of the header value. If no such header is present in the request, the key type defaults to ALL.
477+
* XFF_IP: The first IP address (i.e. the originating client IP address) specified in the list of IPs under X-Forwarded-For HTTP header. If no such header is present or the value is not a valid IP, the key defaults to the source IP address of the request i.e. key type IP.
478+
* HTTP_COOKIE: The value of the HTTP cookie whose name is configured under "enforceOnKeyName". The key value is truncated to the first 128 bytes of the cookie value. If no such cookie is present in the request, the key type defaults to ALL.
479+
* HTTP_PATH: The URL path of the HTTP request. The key value is truncated to the first 128 bytes.
480+
* SNI: Server name indication in the TLS session of the HTTPS request. The key value is truncated to the first 128 bytes. The key type defaults to ALL on a HTTP session.
481+
* REGION_CODE: The country/region from which the request originates.
482+
* TLS_JA3_FINGERPRINT: JA3 TLS/SSL fingerprint if the client connects using HTTPS, HTTP/2 or HTTP/3. If not available, the key type defaults to ALL.
483+
* USER_IP: The IP address of the originating client, which is resolved based on "userIpRequestHeaders" configured with the security policy. If there is no "userIpRequestHeaders" configuration or an IP address cannot be resolved from it, the key type defaults to IP.
484+
Possible values are: `ALL`, `IP`, `HTTP_HEADER`, `XFF_IP`, `HTTP_COOKIE`, `HTTP_PATH`, `SNI`, `REGION_CODE`, `TLS_JA3_FINGERPRINT`, `USER_IP`.
485+
486+
* `enforce_on_key_name` -
487+
(Optional)
488+
Rate limit key name applicable only for the following key types:
489+
HTTP_HEADER -- Name of the HTTP header whose value is taken as the key value.
490+
HTTP_COOKIE -- Name of the HTTP cookie whose value is taken as the key value.
491+
492+
* `enforce_on_key_configs` -
493+
(Optional)
494+
If specified, any combination of values of enforceOnKeyType/enforceOnKeyName is treated as the key on which ratelimit threshold/action is enforced.
495+
You can specify up to 3 enforceOnKeyConfigs.
496+
If enforceOnKeyConfigs is specified, enforceOnKey must not be specified.
497+
Structure is [documented below](#nested_enforce_on_key_configs).
498+
499+
* `ban_threshold` -
500+
(Optional)
501+
Can only be specified if the action for the rule is "rate_based_ban".
502+
If specified, the key will be banned for the configured 'banDurationSec' when the number of requests that exceed the 'rateLimitThreshold' also exceed this 'banThreshold'.
503+
Structure is [documented below](#nested_ban_threshold).
504+
505+
* `ban_duration_sec` -
506+
(Optional)
507+
Can only be specified if the action for the rule is "rate_based_ban".
508+
If specified, determines the time (in seconds) the traffic will continue to be banned by the rate limit after the rate falls below the threshold.
509+
510+
511+
<a name="nested_rate_limit_threshold"></a>The `rate_limit_threshold` block supports:
512+
513+
* `count` -
514+
(Optional)
515+
Number of HTTP(S) requests for calculating the threshold.
516+
517+
* `interval_sec` -
518+
(Optional)
519+
Interval over which the threshold is computed.
520+
521+
<a name="nested_enforce_on_key_configs"></a>The `enforce_on_key_configs` block supports:
522+
523+
* `enforce_on_key_type` -
524+
(Optional)
525+
Determines the key to enforce the rateLimitThreshold on. Possible values are:
526+
* ALL: A single rate limit threshold is applied to all the requests matching this rule. This is the default value if "enforceOnKeyConfigs" is not configured.
527+
* IP: The source IP address of the request is the key. Each IP has this limit enforced separately.
528+
* HTTP_HEADER: The value of the HTTP header whose name is configured under "enforceOnKeyName". The key value is truncated to the first 128 bytes of the header value. If no such header is present in the request, the key type defaults to ALL.
529+
* XFF_IP: The first IP address (i.e. the originating client IP address) specified in the list of IPs under X-Forwarded-For HTTP header. If no such header is present or the value is not a valid IP, the key defaults to the source IP address of the request i.e. key type IP.
530+
* HTTP_COOKIE: The value of the HTTP cookie whose name is configured under "enforceOnKeyName". The key value is truncated to the first 128 bytes of the cookie value. If no such cookie is present in the request, the key type defaults to ALL.
531+
* HTTP_PATH: The URL path of the HTTP request. The key value is truncated to the first 128 bytes.
532+
* SNI: Server name indication in the TLS session of the HTTPS request. The key value is truncated to the first 128 bytes. The key type defaults to ALL on a HTTP session.
533+
* REGION_CODE: The country/region from which the request originates.
534+
* TLS_JA3_FINGERPRINT: JA3 TLS/SSL fingerprint if the client connects using HTTPS, HTTP/2 or HTTP/3. If not available, the key type defaults to ALL.
535+
* USER_IP: The IP address of the originating client, which is resolved based on "userIpRequestHeaders" configured with the security policy. If there is no "userIpRequestHeaders" configuration or an IP address cannot be resolved from it, the key type defaults to IP.
536+
Possible values are: `ALL`, `IP`, `HTTP_HEADER`, `XFF_IP`, `HTTP_COOKIE`, `HTTP_PATH`, `SNI`, `REGION_CODE`, `TLS_JA3_FINGERPRINT`, `USER_IP`.
537+
538+
* `enforce_on_key_name` -
539+
(Optional)
540+
Rate limit key name applicable only for the following key types:
541+
HTTP_HEADER -- Name of the HTTP header whose value is taken as the key value.
542+
HTTP_COOKIE -- Name of the HTTP cookie whose value is taken as the key value.
543+
544+
<a name="nested_ban_threshold"></a>The `ban_threshold` block supports:
545+
546+
* `count` -
547+
(Optional)
548+
Number of HTTP(S) requests for calculating the threshold.
549+
550+
* `interval_sec` -
551+
(Optional)
552+
Interval over which the threshold is computed.
553+
266554
<a name="nested_network_match"></a>The `network_match` block supports:
267555

268556
* `user_defined_fields` -

0 commit comments

Comments
 (0)