Skip to content

Commit 2aeba2c

Browse files
committed
[C4Platforms] Update WAF for SaaS
1 parent 605eb10 commit 2aeba2c

File tree

4 files changed

+74
-88
lines changed

4 files changed

+74
-88
lines changed
-187 KB
Binary file not shown.
-38.3 KB
Binary file not shown.

src/content/docs/cloudflare-for-platforms/cloudflare-for-saas/security/waf-for-saas/index.mdx

Lines changed: 45 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ Before you can use WAF for SaaS, you need to create a custom hostname. Review [G
2121
You can also create a custom hostname through the API:
2222

2323
<APIRequest
24-
path="/zones/{zone_id}/custom_hostnames"
25-
method="POST"
26-
json={{
27-
"hostname": "<CUSTOM_HOSTNAME>",
28-
"ssl": {
29-
wildcard: false
24+
path="/zones/{zone_id}/custom_hostnames"
25+
method="POST"
26+
json={{
27+
hostname: "<CUSTOM_HOSTNAME>",
28+
ssl: {
29+
wildcard: false,
3030
},
3131
}}
3232
/>
@@ -41,28 +41,23 @@ To apply WAF to your custom hostname, you need to create an association between
4141

4242
3. Locate your custom hostname ID by making a `GET` call in the API:
4343

44-
<APIRequest
45-
path="/zones/{zone_id}/custom_hostnames"
46-
method="GET"
47-
/>
44+
<APIRequest path="/zones/{zone_id}/custom_hostnames" method="GET" />
4845

4946
4. Plan your [custom metadata](/cloudflare-for-platforms/cloudflare-for-saas/domain-support/custom-metadata/). It is fully customizable. In the example below, we have chosen the tag `"security_level"` to which we expect to assign three values (low, medium, and high).
5047

5148
:::note
52-
5349
One instance of low, medium, and high rules could be rate limiting. You can specify three different thresholds: low - 100 requests/minute, medium - 85 requests/minute, high - 50 requests/minute, for example. Another possibility is a WAF custom rule in which low challenges requests and high blocks them.
54-
5550
:::
5651

5752
5. Make an API call in the format below using your Cloudflare email and the IDs gathered above:
5853

5954
<APIRequest
60-
path="/zones/{zone_id}/custom_hostnames/{custom_hostname_id}"
61-
method="PATCH"
62-
json={{
63-
"custom_metadata": {
64-
"customer_id": "12345",
65-
"security_level": "low"
55+
path="/zones/{zone_id}/custom_hostnames/{custom_hostname_id}"
56+
method="PATCH"
57+
json={{
58+
custom_metadata: {
59+
customer_id: "12345",
60+
security_level: "low",
6661
},
6762
}}
6863
/>
@@ -73,41 +68,35 @@ This assigns custom metadata to your custom hostname so that it has a security t
7368

7469
1. Locate the custom metadata field in the Ruleset Engine where the WAF runs. This can be used to trigger different configurations of products such as [WAF custom rules](/waf/custom-rules/), [rate limiting rules](/waf/rate-limiting-rules/), and [Transform Rules](/rules/transform/).
7570

76-
2. Build your rules either [through the dashboard](/waf/custom-rules/create-dashboard/) or via the API. An example rate limiting rule, corresponding to `"security_level"` low, is shown below as an API call.
77-
78-
<APIRequest
79-
path="/zones/{zone_id}/rulesets/phases/{ruleset_phase}/entrypoint"
80-
method="PUT"
81-
json={{
82-
"rules": [
83-
{
84-
"action": "block",
85-
"ratelimit": {
86-
"characteristics": [
87-
"cf.colo.id",
88-
"ip.src"
89-
],
90-
"period": 10,
91-
"requests_per_period": 2,
92-
"mitigation_timeout": 60
93-
},
94-
"expression": "lookup_json_string(cf.hostname.metadata, \"security_level\") eq \"low\" and http.request.uri contains \"login\""
95-
}
96-
]
97-
}}
98-
parameters={{
99-
ruleset_phase: "http_ratelimit"
100-
}}
101-
/>
102-
103-
To build rules through the dashboard:
104-
105-
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and navigate to your account and website.
106-
107-
2. Select **Security** > **WAF**.
108-
109-
3. Follow the instructions on the dashboard specific to custom rules, rate limiting rules, or managed rules, depending on your security goal.
110-
111-
4. Once the rule is active, you should see it under the applicable tab (custom rules, rate limiting, or managed rules).
112-
113-
![Rule Active](~/assets/images/cloudflare-for-platforms/active-rule.png)
71+
2. Build your rules either through the dashboard or via the API.
72+
73+
To build rules through the dashboard, follow the instructions specific to [custom rules](/waf/custom-rules/create-dashboard/), [rate limiting rules](/waf/rate-limiting-rules/create-zone-dashboard/), or [managed rules](/waf/managed-rules/deploy-zone-dashboard/), depending on your security goal.
74+
75+
An example rate limiting rule, corresponding to `"security_level"` low, is shown below as an API call.
76+
77+
<APIRequest
78+
path="/zones/{zone_id}/rulesets/phases/{ruleset_phase}/entrypoint"
79+
method="PUT"
80+
json={{
81+
rules: [
82+
{
83+
action: "block",
84+
ratelimit: {
85+
characteristics: ["cf.colo.id", "ip.src"],
86+
period: 10,
87+
requests_per_period: 2,
88+
mitigation_timeout: 60,
89+
},
90+
expression:
91+
'lookup_json_string(cf.hostname.metadata, "security_level") eq "low" and http.request.uri contains "login"',
92+
},
93+
],
94+
}}
95+
parameters={{
96+
ruleset_phase: "http_ratelimit",
97+
}}
98+
/>
99+
100+
:::caution
101+
This API call will replace any existing rate limiting rules in the zone.
102+
:::
Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,81 @@
11
---
22
pcx_content_type: how-to
3-
title: Managed Rulesets
3+
title: Managed rulesets
44
sidebar:
55
order: 4
66
head:
77
- tag: title
8-
content: Managed Rulesets per Custom Hostname
9-
8+
content: Managed rulesets per custom hostname
109
---
1110

1211
import { DashButton } from "~/components";
1312

1413
If you are interested in [WAF for SaaS](/cloudflare-for-platforms/cloudflare-for-saas/security/waf-for-saas/) but unsure of where to start, Cloudflare recommends using WAF Managed Rules. The Cloudflare security team creates and manages a variety of rules designed to detect common attack vectors and protect applications from vulnerabilities. These rules are offered in [managed rulesets](/waf/managed-rules/), like Cloudflare Managed and OWASP, which can be deployed with different settings and sensitivity levels.
1514

16-
***
15+
---
1716

1817
## Prerequisites
1918

2019
WAF for SaaS is available for customers on an Enterprise plan.
2120

22-
If you would like to deploy a managed ruleset at the account level, refer to the [Ruleset Engine documentation](/ruleset-engine/managed-rulesets/deploy-managed-ruleset/).
21+
If you would like to deploy a managed ruleset at the account level, refer to the [WAF documentation](/waf/account/managed-rulesets/deploy-dashboard/).
2322

2423
Ensure you have reviewed [Get Started with Cloudflare for SaaS](/cloudflare-for-platforms/cloudflare-for-saas/start/getting-started/) and familiarize yourself with [WAF for SaaS](/cloudflare-for-platforms/cloudflare-for-saas/security/waf-for-saas/).
2524

2625
Customers can automate the [custom metadata](/cloudflare-for-platforms/cloudflare-for-saas/domain-support/custom-metadata/) tagging by adding it to the custom hostnames at creation. For more information on tagging a custom hostname with custom metadata, refer to the [API documentation](/api/resources/custom_hostnames/methods/edit/).
2726

28-
***
27+
---
2928

3029
## 1. Choose security tagging system
3130

3231
1. Outline `security_tag` buckets. These are fully customizable with no strict limit on quantity. For example, you can set `security_tag` to `low`,`medium`, and `high` as a default, with one tag per custom hostname.
3332

3433
2. If you have not already done so, [associate your custom metadata to custom hostnames](/cloudflare-for-platforms/cloudflare-for-saas/security/waf-for-saas/#1-associate-custom-metadata-to-a-custom-hostname) by including the `security_tag`in the custom metadata associated with the custom hostname. The JSON blob associated with the custom hostname is fully customizable.
3534

36-
:::note
37-
35+
After the association is complete, the JSON blob is added to the defined custom hostname. This blob is then associated to every incoming request and exposed in the WAF through the [`cf.hostname.metadata`](/ruleset-engine/rules-language/fields/reference/cf.hostname.metadata/) field. In the rule, you can access `cf.hostname.metadata` and get whatever data you need from that blob.
3836

39-
After the association is complete, the JSON blob is added to the defined custom hostname. This blob is then associated to every incoming request and exposed in the WAF through the new field `cf.hostname.metadata`. In the rule, you can access `cf.hostname.metadata` and get whatever data you need from that blob.
37+
---
4038

39+
## 2. Deploy rulesets
4140

41+
:::note
42+
Account-level WAF requires an Enterprise plan with a paid add-on.
4243
:::
4344

44-
***
45-
46-
## 2. Deploy Rulesets
47-
4845
1. In the Cloudflare dashboard, go to the **WAF** page.
4946

5047
<DashButton url="/?to=/:account/application-security/waf" />
5148

52-
:::note
53-
**WAF** at the account level will only be visible on Enterprise plans. If you do not see this option, contact your account manager.
54-
:::
49+
2. Go to the **Managed rulesets** tab.
5550

56-
2. Select **Managed rulesets**.
51+
3. Select **Deploy** > **Deploy managed ruleset**.
5752

58-
3. Select **Deploy a managed ruleset**.
53+
4. Next to **Cloudflare Managed Ruleset**, choose **Select ruleset**.
5954

60-
4. Under **Field**, Select *Hostname*. Set the operator as *equals*. The complete expression should look like this, plus any logic you would like to add:
55+
5. Give a name to the rule deploying the ruleset in **Execution name**.
6156

62-
![Rule expression](~/assets/images/cloudflare-for-platforms/rule-expression.png)
57+
6. Select **Edit scope** to execute the managed ruleset for a subset of incoming requests.
6358

64-
5. Beneath **Value**, add the custom hostname.
59+
7. Select **Custom filter expression**.
6560

66-
6. Select **Next**.
61+
8. Select **Edit expression** to switch to the [Expression Editor](/ruleset-engine/rules-language/expressions/edit-expressions/#expression-editor).
6762

68-
7. Find the **Cloudflare Managed Ruleset** card and select **Use this Ruleset**.
63+
9. The basic expression should look like this, plus any logic you would like to add (like filtering by a specific custom hostname with `http.host eq "<HOSTNAME>"`):
6964

70-
8. Click the checkbox next to each rule you want to deploy.
65+
```txt
66+
(lookup_json_string(cf.hostname.metadata, "security_tag") eq "low") and (cf.zone.plan eq "ENT")
67+
```
7168

72-
9. Toggle the **Status** button next to each rule to enable or disable it. Then select **Next**.
69+
:::note
70+
Rulesets deployed at the account level will only apply to incoming traffic of Enterprise domains on your account. When you define a custom expression using the Expression Editor, use parentheses to enclose any custom conditions and end your expression with `and (cf.zone.plan eq "ENT")` so that the rule only applies to domains on an Enterprise plan.
71+
:::
7372

74-
10. On the review page, give your rule a descriptive name. You can modify the ruleset configuration by changing, for example, what rules are enabled or what action should be the default.
73+
10. Select **Next**.
7574

76-
11. Select **Deploy**.
75+
11. (Optional) You can modify the ruleset configuration by changing, for example, what rules are enabled or what action should be the default.
7776

78-
:::note
77+
12. Select **Deploy**.
7978

79+
## Next steps
8080

81-
While this tutorial uses Cloudflare Managed Rulesets, you can also create a custom ruleset and deploy on your custom hostnames. To do this, select **Browse Rulesets** > **Create new ruleset**. For examples of a low/medium/high ruleset, refer to [WAF for SaaS](/cloudflare-for-platforms/cloudflare-for-saas/security/waf-for-saas/).
82-
83-
84-
:::
81+
While this guide uses the Cloudflare Managed Ruleset, you can also create a custom ruleset and deploy on your custom hostnames. To do this, go to the **Custom rulesets** tab and select **Create ruleset**. For examples of a low/medium/high ruleset, refer to [WAF for SaaS](/cloudflare-for-platforms/cloudflare-for-saas/security/waf-for-saas/).

0 commit comments

Comments
 (0)