You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[WAF] Improve linking between API and Terraform (#21741)
* Add links between API and Terraform sections
* Move Terraform examples of using traffic detections to WAF docs
* Move custom detection location examples to concept section
* Apply suggestions from PCX review
---------
Co-authored-by: Jun Lee <[email protected]>
This page provides examples of creating [WAF custom rules](/waf/custom-rules/) in a zone or account using Terraform. The examples cover the following scenarios:
15
15
16
-
- Zone-level configurations:
17
-
-[Add a custom rule to a zone](#add-a-custom-rule-to-a-zone)
18
-
-[Add a custom rule challenging requests with leaked credentials](#add-a-custom-rule-challenging-requests-with-leaked-credentials)
19
-
-[Add a custom rule blocking malicious uploads](#add-a-custom-rule-blocking-malicious-uploads)
20
-
- Account-level configurations:
21
-
-[Create and deploy a custom ruleset](#create-and-deploy-a-custom-ruleset)
22
-
-[Add a custom rule checking for exposed credentials](#add-a-custom-rule-checking-for-exposed-credentials)
16
+
-[Add a custom rule to a zone](#add-a-custom-rule-to-a-zone) (zone-level configuration)
17
+
-[Create and deploy a custom ruleset](#create-and-deploy-a-custom-ruleset) (account-level configuration)
18
+
19
+
The WAF documentation includes additional Terraform examples — refer to [More resources](#more-resources).
23
20
24
21
## Before you start
25
22
@@ -33,9 +30,7 @@ This page provides examples of creating [WAF custom rules](/waf/custom-rules/) i
33
30
34
31
---
35
32
36
-
## Zone-level configurations
37
-
38
-
### Add a custom rule to a zone
33
+
## Add a custom rule to a zone
39
34
40
35
The following example configures a custom rule in the zone entry point ruleset for the `http_request_firewall_custom` phase for zone with ID `<ZONE_ID>`. The rule will block all traffic on non-standard HTTP(S) ports:
### Add a custom rule challenging requests with leaked credentials
64
-
65
-
:::note
66
-
For more information on enabling leaked credentials detection using Terraform, refer to the [leaked credentials detection](/waf/detections/leaked-credentials/get-started/#1-turn-on-the-detection) documentation.
67
-
:::
68
-
69
-
This example adds a custom rule that challenges requests with leaked credentials by using one of the [leaked credentials fields](/waf/detections/leaked-credentials/#leaked-credentials-fields) in the rule expression.
For more information on configuring custom detection locations, refer to the [Terraform example](/waf/detections/leaked-credentials/get-started/#4-optional-configure-a-custom-detection-location) in the WAF documentation.
91
-
92
-
### Add a custom rule blocking malicious uploads
58
+
## Create and deploy a custom ruleset (account-level configuration) {/* create-and-deploy-a-custom-ruleset */}
93
59
94
60
:::note
95
-
For more information on enabling malicious uploads detection using Terraform, refer to the [malicious uploads detection](/waf/detections/malicious-uploads/get-started/#1-turn-on-the-detection) documentation.
61
+
Account-level WAF configuration requires an Enterprise plan with a paid add-on.
96
62
:::
97
63
98
-
This example adds a custom rule that blocks requests with one or more <GlossaryTooltipterm="content object">content objects</GlossaryTooltip> considered malicious by using one of the [content scanning fields](/waf/detections/malicious-uploads/#content-scanning-fields) in the rule expression.
expression = "(cf.waf.content_scan.has_malicious_obj and http.request.uri.path eq \"/upload.php\")"
114
-
action = "block"
115
-
}
116
-
}
117
-
```
118
-
119
-
For more information on configuring custom scan expressions, refer to the [Terraform example](/waf/detections/malicious-uploads/get-started/#4-optional-configure-a-custom-scan-expression) in the WAF documentation.
120
-
121
-
## Account-level configurations
122
-
123
-
### Create and deploy a custom ruleset
124
-
125
64
The following example creates a [custom ruleset](/ruleset-engine/custom-rulesets/) in the account with ID `<ACCOUNT_ID>` containing a single custom rule. This custom ruleset is then deployed using a separate `cloudflare_ruleset` Terraform resource. If you do not deploy a custom ruleset, it will not execute.
126
65
127
-
:::caution
128
66
You can only create and deploy custom rulesets at the account level.
129
-
:::
130
67
131
-
The following configuration creates the custom ruleset with a single rule:
68
+
The following configuration creates a custom ruleset with a single rule:
For more information on configuring and deploying custom rulesets, refer to [Work with custom rulesets](/ruleset-engine/custom-rulesets/) in the Ruleset Engine documentation.
185
122
186
-
### Add a custom rule checking for exposed credentials
The following configuration creates a custom ruleset with a single rule that [checks for exposed credentials](/waf/managed-rules/check-for-exposed-credentials/configure-api/#create-a-custom-rule-checking-for-exposed-credentials).
191
-
192
-
You can only add exposed credential checks to rules in a custom ruleset (that is, a ruleset with `kind = "custom"`).
The following configuration deploys the custom ruleset. It defines a dependency on the `account_firewall_custom_ruleset_exposed_creds` resource and obtains the ID of the created custom ruleset:
description = "Deploy custom ruleset for example.com"
243
-
expression = "(cf.zone.name eq \"example.com\")"
244
-
action = "execute"
245
-
action_parameters {
246
-
id = cloudflare_ruleset.account_firewall_custom_ruleset_exposed_creds.id
247
-
}
248
-
}
249
-
}
250
-
```
125
+
-[Malicious uploads detection: Add a custom rule to block malicious uploads](/waf/detections/malicious-uploads/terraform-examples/#add-a-custom-rule-to-block-malicious-uploads)
126
+
-[Leaked credentials detection: Add a custom rule to challenge requests with leaked credentials](/waf/detections/leaked-credentials/terraform-examples/#add-a-custom-rule-to-challenge-requests-with-leaked-credentials)
Copy file name to clipboardExpand all lines: src/content/docs/waf/analytics/security-analytics.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -92,7 +92,7 @@ To apply the filters for an insight to the data displayed in the Security Analyt
92
92
93
93
### Score-based analyses
94
94
95
-
The **Attack analysis**, **Bot analysis**, **Malicious uploads**, and **Account abuse detection** sections display statistics related to WAF attack scores, bot scores, WAF content scanning scores, and leaked credentials scanning of incoming requests for the selected time frame. All plans include access to the **Leaked credential check** under **Account abuse detection**. This feature detects login attempts using credentials that have been exposed online. For more information on what to do if you have credentials that have been leaked, refer to the [mitigation examples page](/waf/detections/leaked-credentials/examples/).
95
+
The **Attack analysis**, **Bot analysis**, **Malicious uploads**, and **Account abuse detection** sections display statistics related to WAF attack scores, bot scores, WAF content scanning scores, and leaked credentials scanning of incoming requests for the selected time frame. All plans include access to the **Leaked credential check** under **Account abuse detection**. This feature detects login attempts using credentials that have been exposed online. For more information on what to do if you have credentials that have been leaked, refer to the [example mitigation rules page](/waf/detections/leaked-credentials/examples/).
96
96
97
97
You can examine different traffic segments according to the current metric (attack score, bot score, or content scanning). To apply score filters for different segments, select the buttons below the traffic chart. For example, select **Likely attack** under **Attack analysis** to filter requests that are likely an attack (requests with WAF attack score values between 21 and 50).
Copy file name to clipboardExpand all lines: src/content/docs/waf/detections/attack-score.mdx
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -102,4 +102,4 @@ If you are an Enterprise customer and you created a rule with _Log_ action, chan
102
102
103
103
## Additional remarks
104
104
105
-
The WAF Attack Score is different from Bot Score. WAF Attack Score identifies variation of attacks that WAF Managed Rules do not catch, while Bot Score identifies bots.
105
+
The WAF attack score is different from [bot score](/bots/concepts/bot-score/). WAF attack score identifies variations of attacks that WAF Managed Rules do not catch, while bot score identifies bots.
Copy file name to clipboardExpand all lines: src/content/docs/waf/detections/leaked-credentials/api-calls.mdx
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,10 @@ head:
10
10
11
11
import { APIRequest } from"~/components";
12
12
13
+
The following examples address common scenarios of using the Cloudflare API to manage and configure leaked credentials detection.
14
+
15
+
If you are using Terraform, refer to [Terraform configuration examples](/waf/detections/leaked-credentials/terraform-examples/).
16
+
13
17
## General operations
14
18
15
19
The following API examples cover basic operations such as enabling and disabling the leaked credentials detection.
@@ -53,11 +57,11 @@ To obtain the current status of the leaked credentials detection, use a `GET` re
53
57
54
58
## Custom detection location operations
55
59
56
-
The following API examples cover operations on custom detection locations for leaked credentials detection.
60
+
The following API examples cover operations on [custom detection locations](/waf/detections/leaked-credentials/#custom-detection-locations) for leaked credentials detection.
57
61
58
62
### Add a custom detection location
59
63
60
-
Use a `POST` request similar to the following:
64
+
To add a custom detection location, use a `POST` request similar to the following:
Copy file name to clipboardExpand all lines: src/content/docs/waf/detections/leaked-credentials/get-started.mdx
+18-19Lines changed: 18 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,7 +72,7 @@ You can combine the previous expression with other [fields](/ruleset-engine/rule
72
72
73
73
</Details>
74
74
75
-
For additional examples, refer to [Mitigation examples](/waf/detections/leaked-credentials/examples/).
75
+
For additional examples, refer to [Example mitigation rules](/waf/detections/leaked-credentials/examples/).
76
76
77
77
### Handle detected leaked credentials at the origin server
78
78
@@ -84,22 +84,27 @@ Additionally, you may want to handle leaked credentials detected by Cloudflare a
84
84
85
85
## 4. (Optional) Configure a custom detection location
86
86
87
-
To check for leaked credentials in a way that is not covered by the default configuration, add a custom detection location.
87
+
To check for leaked credentials in a way that is not covered by the default configuration, add a [custom detection location](/waf/detections/leaked-credentials/#custom-detection-locations).
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/), and select your account and domain.
92
92
2. Go to **Security** > **Settings**.
93
93
3. Under **Incoming traffic detections**, select **Leaked credentials** and then select **Add custom username and password location**.
94
-
4. In **Username location** and **Password location** (optional), enter expressions for obtaining the username and the password from the HTTP request. Refer to the following example expressions:
94
+
4. In **Username location** and **Password location** (optional), enter expressions for obtaining the username and the password from the HTTP request. For example, you could use the following expressions:
95
95
96
-
| Request type | Username location / Password location |
Refer to the [`lookup_json_string()`](/ruleset-engine/rules-language/functions/#lookup_json_string) and [`url_decode()`](/ruleset-engine/rules-language/functions/#url_decode) documentation for more information on these functions.
101
+
This configuration will scan incoming HTTP requests containing a JSON body with a structure similar to the following:
102
+
103
+
```js
104
+
{"user":"<USERNAME>", "secret":"<PASSWORD>"}
105
+
```
106
+
107
+
Refer to the [`lookup_json_string()`](/ruleset-engine/rules-language/functions/#lookup_json_string) documentation for more information on this function.
103
108
104
109
5. Select **Save**.
105
110
@@ -126,22 +131,16 @@ Refer to the [`lookup_json_string()`](/ruleset-engine/rules-language/functions/#
126
131
127
132
</TabItem> <TabItemlabel="Terraform">
128
133
129
-
Use the `cloudflare_leaked_credential_check_rule` resource to add a custom detection location. For example:
For more information, refer to the [Terraform Cloudflare provider documentation](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs).
136
+
Refer to the [`lookup_json_string()`](/ruleset-engine/rules-language/functions/#lookup_json_string) documentation for more information on this function.
140
137
141
138
</TabItem> </Tabs>
142
139
143
140
You only need to provide an expression for the username in custom detection locations.
144
141
142
+
For more examples of custom detection locations for different request types, refer to [Custom detection locations](/waf/detections/leaked-credentials/#custom-detection-locations).
Copy file name to clipboardExpand all lines: src/content/docs/waf/detections/leaked-credentials/index.mdx
+9-1Lines changed: 9 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ Leaked credentials detection includes rules for identifying credentials in HTTP
47
47
48
48
Additionally, the scan includes generic rules for other common web authentication patterns.
49
49
50
-
You can also configure custom detection locations to address the specific authentication mechanism used in your web applications. A custom detection location tells the Cloudflare WAF where to find usernames and passwords in HTTP requests of your web application.
50
+
You can also configure [custom detection locations](#custom-detection-locations) to address the specific authentication mechanism used in your web applications. A custom detection location tells the Cloudflare WAF where to find usernames and passwords in HTTP requests of your web application.
51
51
52
52
## Custom detection locations
53
53
@@ -72,6 +72,14 @@ You could configure a custom detection location with the following settings:
72
72
73
73
When specifying a custom detection location, only the location of the username field is required.
74
74
75
+
The following table includes example detection locations for different request types:
76
+
77
+
| Request type | Username location / Password location |
0 commit comments