Skip to content

Commit 2a9fd6e

Browse files
committed
[WAF, Terraform] Add Terraform docs for leaked credentials
1 parent 377cc59 commit 2a9fd6e

File tree

5 files changed

+90
-17
lines changed

5 files changed

+90
-17
lines changed

src/content/docs/terraform/additional-configurations/waf-custom-rules.mdx

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ sidebar:
66
head:
77
- tag: title
88
content: Configure WAF custom rules with Terraform
9-
109
---
1110

12-
import { Render } from "~/components"
11+
import { Render } from "~/components";
1312

1413
This page provides examples of creating WAF custom rules in a zone or account using Terraform. The examples cover the following scenarios:
1514

16-
* Zone-level configurations:
15+
- Zone-level configurations:
1716

18-
* [Add a custom rule to a zone](#add-a-custom-rule-to-a-zone)
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)
1919

20-
* Account-level configurations:
20+
- Account-level configurations:
2121

22-
* [Create and deploy a custom ruleset](#create-and-deploy-a-custom-ruleset)
23-
* [Add a custom rule checking for exposed credentials](#add-a-custom-rule-checking-for-exposed-credentials)
22+
- [Create and deploy a custom ruleset](#create-and-deploy-a-custom-ruleset)
23+
- [Add a custom rule checking for exposed credentials](#add-a-custom-rule-checking-for-exposed-credentials)
2424

2525
For more information on custom rules, refer to [Custom rules](/waf/custom-rules/) in the Cloudflare WAF documentation.
2626

@@ -34,7 +34,7 @@ For more information on custom rules, refer to [Custom rules](/waf/custom-rules/
3434

3535
<Render file="import-delete-existing-rulesets" />
3636

37-
***
37+
---
3838

3939
## Zone-level configurations
4040

@@ -59,7 +59,34 @@ resource "cloudflare_ruleset" "zone_custom_firewall" {
5959
}
6060
```
6161

62-
<Render file="add-new-rule" params={{ one: "custom rule" }} /> <br/>
62+
<Render file="add-new-rule" params={{ one: "custom rule" }} /> <br />
63+
64+
### Add a custom rule challenging requests with leaked credentials
65+
66+
:::note
67+
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-leaked-credentials-detection) documentation.
68+
:::
69+
70+
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.
71+
72+
```tf
73+
resource "cloudflare_ruleset" "zone_custom_firewall_leaked_creds" {
74+
zone_id = "<ZONE_ID>"
75+
name = "Phase entry point ruleset for custom rules in my zone"
76+
description = ""
77+
kind = "zone"
78+
phase = "http_request_firewall_custom"
79+
80+
rules {
81+
action = "managed_challenge"
82+
expression = "(cf.waf.credential_check.username_and_password_leaked)"
83+
description = "Challenge requests with a leaked username and password"
84+
enabled = true
85+
}
86+
}
87+
```
88+
89+
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.
6390

6491
## Account-level configurations
6592

@@ -69,7 +96,7 @@ The following example creates a [custom ruleset](/ruleset-engine/custom-rulesets
6996

7097
:::caution
7198

72-
You can only create and deploy custom rulesets at the account level.
99+
You can only create and deploy custom rulesets at the account level.
73100
:::
74101

75102
The following configuration creates the custom ruleset with a single rule:
@@ -91,7 +118,10 @@ resource "cloudflare_ruleset" "account_firewall_custom_ruleset" {
91118
}
92119
```
93120

94-
<Render file="add-new-rule" params={{ one: "custom rule in the custom ruleset" }} /> <br/>
121+
<Render
122+
file="add-new-rule"
123+
params={{ one: "custom rule in the custom ruleset" }}
124+
/> <br />
95125

96126
The following configuration deploys the custom ruleset at the account level. It defines a dependency on the `account_firewall_custom_ruleset` resource and uses the ID of the created custom ruleset in `action_parameters`:
97127

@@ -121,12 +151,13 @@ For more information on configuring and deploying custom rulesets, refer to [Wor
121151

122152
### Add a custom rule checking for exposed credentials
123153

124-
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).
154+
<Render file="leaked-credentials-recommend-detection" product="waf" />
125155

126-
:::caution
156+
The following configuration creates a custom ruleset with a single rule that
157+
[checks for exposed
158+
credentials](/waf/managed-rules/check-for-exposed-credentials/configure-api/#create-a-custom-rule-checking-for-exposed-credentials).
127159

128-
You can only add exposed credential checks to rules in a custom ruleset (that is, a ruleset with `kind = "custom"`).
129-
:::
160+
You can only add exposed credential checks to rules in a custom ruleset (that is, a ruleset with `kind = "custom"`).
130161

131162
```tf
132163
resource "cloudflare_ruleset" "account_firewall_custom_ruleset_exposed_creds" {
@@ -156,7 +187,7 @@ resource "cloudflare_ruleset" "account_firewall_custom_ruleset_exposed_creds" {
156187
}
157188
```
158189

159-
<Render file="add-new-rule" params={{ one: "rule" }} /> <br/>
190+
<Render file="add-new-rule" params={{ one: "rule" }} /> <br />
160191

161192
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:
162193

src/content/docs/waf/detections/leaked-credentials/get-started.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ This pair of lookup expressions (for username and password) will scan incoming H
126126

127127
Refer to the [`lookup_json_string()`](/ruleset-engine/rules-language/functions/#lookup_json_string) documentation for more information on this function.
128128

129+
</TabItem> <TabItem label="Terraform">
130+
131+
Use the `cloudflare_leaked_credential_check_rules` resource to add custom detection locations. For example:
132+
133+
<Render file="leaked-credentials-detection-add-custom-location-terraform" />
134+
129135
</TabItem> </Tabs>
130136

131137
You only need to provide an expression for the username in custom detection locations.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
{}
3+
---
4+
5+
```terraform
6+
# Create user-defined detection locations for leaked credentials detection
7+
resource "cloudflare_leaked_credential_check_rules" "custom_location_example" {
8+
zone_id = "<ZONE_ID>"
9+
rule {
10+
username = "lookup_json_string(http.request.body.raw, \"user\")"
11+
password = "lookup_json_string(http.request.body.raw, \"secret\")"
12+
}
13+
}
14+
```
15+
16+
To create another custom detection location, add a new `rule` object to the same `cloudflare_leaked_credential_check_rules` resource.
17+
18+
For more information, refer to the [Terraform Cloudflare provider](https://registry.terraform.io/providers/cloudflare/cloudflare/4.48.0/docs/resources/leaked_credential_check_rules) documentation.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
{}
3+
---
4+
5+
```terraform
6+
resource "cloudflare_leaked_credential_check" "zone_lcc_example" {
7+
zone_id = "<ZONE_ID>"
8+
enabled = true
9+
}
10+
```
11+
12+
For more information, refer to the [Terraform Cloudflare provider](https://registry.terraform.io/providers/cloudflare/cloudflare/4.48.0/docs/resources/leaked_credential_check) documentation.

src/content/partials/waf/leaked-credentials-detection-enable.mdx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{}
33
---
44

5-
import { TabItem, Tabs } from "~/components";
5+
import { TabItem, Tabs, Render } from "~/components";
66

77
On Free plans, the leaked credentials detection is enabled by default, and no action is required. On paid plans, you can turn on the detection in the Cloudflare dashboard or via API.
88

@@ -24,4 +24,10 @@ curl "https://api.cloudflare.com/client/v4/zones/{zone_id}/leaked-credential-che
2424
--data '{ "enabled": true }'
2525
```
2626

27+
</TabItem> <TabItem label="Terraform">
28+
29+
Use the `cloudflare_leaked_credential_check` resource to enable leaked credentials detection for a zone. For example:
30+
31+
<Render file="leaked-credentials-detection-enable-terraform" />
32+
2733
</TabItem> </Tabs>

0 commit comments

Comments
 (0)