Skip to content

Commit a79fdde

Browse files
committed
Update managed rulesets API examples
1 parent 24db0cf commit a79fdde

File tree

6 files changed

+419
-404
lines changed

6 files changed

+419
-404
lines changed

src/content/docs/ruleset-engine/managed-rulesets/override-examples/deploy-cmr-joomla-only.mdx

Lines changed: 127 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ head:
88
content: Use category overrides to enable Joomla rules
99
---
1010

11-
import { Details } from "~/components";
11+
import { Details, APIRequest } from "~/components";
1212

1313
Use the [Rulesets API](/ruleset-engine/rulesets-api/) to configure the execution of a managed ruleset and override its behavior. By default, enabled rules perform the actions defined by the managed ruleset issuer. This example uses overrides to ensure that only rules with a specific tag are enabled.
1414

@@ -22,73 +22,75 @@ Tag overrides take precedence over ruleset overrides. Only the rules with the sp
2222

2323
## Example 1
2424

25-
This example uses the [Update a zone entry point ruleset](/ruleset-engine/rulesets-api/update/) operation to deploy the Cloudflare Managed Ruleset to a phase with only Joomla rules enabled. The `name`, `kind`, and `phase` fields are omitted from the request because they are immutable.
25+
This example deploys the Cloudflare Managed Ruleset to a phase with only Joomla rules enabled. The `name`, `kind`, and `phase` fields are omitted from the request because they are immutable.
2626

2727
<Details header="Example: Enable only Joomla rules using category overrides at the zone level">
2828

29-
```bash
30-
curl --request PUT \
31-
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/phases/http_request_firewall_managed/entrypoint \
32-
--header "Authorization: Bearer <API_TOKEN>" \
33-
--header "Content-Type: application/json" \
34-
--data '{
35-
"rules": [
36-
{
37-
"action": "execute",
38-
"expression": "true",
39-
"action_parameters": {
40-
"id": "<MANAGED_RULESET_ID>",
41-
"overrides": {
42-
"enabled": false,
43-
"categories": [
44-
{
45-
"category": "joomla",
46-
"action": "block",
47-
"enabled": true
48-
}
49-
]
50-
}
51-
}
52-
}
53-
]
54-
}'
55-
```
56-
57-
- `"id": "<MANAGED_RULESET_ID>"` adds a rule to the ruleset of a phase that will apply the Cloudflare Managed Ruleset to requests for the specified zone (`{zone_id}`).
29+
<APIRequest
30+
path="/zones/{zone_id}/rulesets/phases/{ruleset_phase}/entrypoint"
31+
method="PUT"
32+
parameters={{
33+
ruleset_phase: "http_request_firewall_managed",
34+
}}
35+
json={{
36+
rules: [
37+
{
38+
action: "execute",
39+
expression: "true",
40+
action_parameters: {
41+
id: "<MANAGED_RULESET_ID>",
42+
overrides: {
43+
enabled: false,
44+
categories: [
45+
{
46+
category: "joomla",
47+
action: "block",
48+
enabled: true,
49+
},
50+
],
51+
},
52+
},
53+
},
54+
],
55+
}}
56+
/>
57+
58+
- `"id": "<MANAGED_RULESET_ID>"` adds a rule to the ruleset of a phase that will apply the Cloudflare Managed Ruleset to requests for the specified zone (`$ZONE_ID`).
5859
- `"enabled": false` defines an override at the ruleset level that disables all rules in the managed ruleset.
5960
- `"categories": [{"category": "joomla", "action": "block", "enabled": true}]` defines an override at the tag level that enables the Joomla rules and sets their action to `block`.
6061

6162
</Details>
6263

6364
<Details header="Example: Enable only Joomla rules using category overrides at the account level">
6465

65-
```bash
66-
curl --request PUT \
67-
https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets/phases/http_request_firewall_managed/entrypoint \
68-
--header "Authorization: Bearer <API_TOKEN>" \
69-
--header "Content-Type: application/json" \
70-
--data '{
71-
"rules": [
72-
{
73-
"action": "execute",
74-
"expression": "cf.zone.name eq \"example.com\" and cf.zone.plan eq \"ENT\"",
75-
"action_parameters": {
76-
"id": "<MANAGED_RULESET_ID>",
77-
"overrides": {
78-
"enabled": false,
79-
"categories": [
80-
{
81-
"category": "joomla",
82-
"action": "block",
83-
"enabled": true
84-
}
85-
]
86-
}
87-
}
88-
}
89-
]
90-
}'
91-
```
66+
<APIRequest
67+
path="/accounts/{account_id}/rulesets/phases/{ruleset_phase}/entrypoint"
68+
method="PUT"
69+
parameters={{
70+
ruleset_phase: "http_request_firewall_managed",
71+
}}
72+
json={{
73+
rules: [
74+
{
75+
action: "execute",
76+
expression: 'cf.zone.name eq "example.com" and cf.zone.plan eq "ENT"',
77+
action_parameters: {
78+
id: "<MANAGED_RULESET_ID>",
79+
overrides: {
80+
enabled: false,
81+
categories: [
82+
{
83+
category: "joomla",
84+
action: "block",
85+
enabled: true,
86+
},
87+
],
88+
},
89+
},
90+
},
91+
],
92+
}}
93+
/>
9294

9395
- `"id": "<MANAGED_RULESET_ID>"` adds a rule to the ruleset of a phase that will apply the Cloudflare Managed Ruleset to requests for `example.com`.
9496
- `"enabled": false` defines an override at the ruleset level that disables all rules in the managed ruleset.
@@ -100,83 +102,85 @@ You can add more than one category override to a rule.
100102

101103
## Example 2
102104

103-
This example uses a `PUT` request to add two overrides to the rule that executes a managed ruleset (`<MANAGED_RULESET_ID>`) in the `http_request_firewall_managed` phase. Note that the `name`, `kind`, and `phase` fields are omitted from the request because they are immutable.
105+
This example adds two overrides to the rule that executes a managed ruleset (`<MANAGED_RULESET_ID>`) in the `http_request_firewall_managed` phase. Note that the `name`, `kind`, and `phase` fields are omitted from the request because they are immutable.
104106

105107
<Details header="Example: Add more than one category override at the zone level">
106108

107-
```bash
108-
curl --request PUT \
109-
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/phases/http_request_firewall_managed/entrypoint \
110-
--header "Authorization: Bearer <API_TOKEN>" \
111-
--header "Content-Type: application/json" \
112-
--data '{
113-
"rules": [
114-
{
115-
"action": "execute",
116-
"expression": "true",
117-
"action_parameters": {
118-
"id": "<MANAGED_RULESET_ID>",
119-
"overrides": {
120-
"enabled": false,
121-
"categories": [
122-
{
123-
"category": "joomla",
124-
"action": "log",
125-
"enabled": true
126-
},
127-
{
128-
"category": "wordpress",
129-
"enabled": false
130-
}
131-
]
132-
}
133-
}
134-
}
135-
]
136-
}'
137-
```
109+
<APIRequest
110+
path="/zones/{zone_id}/rulesets/phases/{ruleset_phase}/entrypoint"
111+
method="PUT"
112+
parameters={{
113+
ruleset_phase: "http_request_firewall_managed",
114+
}}
115+
json={{
116+
rules: [
117+
{
118+
action: "execute",
119+
expression: "true",
120+
action_parameters: {
121+
id: "<MANAGED_RULESET_ID>",
122+
overrides: {
123+
enabled: false,
124+
categories: [
125+
{
126+
category: "joomla",
127+
action: "log",
128+
enabled: true,
129+
},
130+
{
131+
category: "wordpress",
132+
enabled: false,
133+
},
134+
],
135+
},
136+
},
137+
},
138+
],
139+
}}
140+
/>
138141

139142
</Details>
140143

141144
<Details header="Example: Add more than one category override at the account level">
142145

143-
```bash
144-
curl --request PUT \
145-
https://api.cloudflare.com/client/v4/account/{account_id}/rulesets/phases/http_request_firewall_managed/entrypoint \
146-
--header "Authorization: Bearer <API_TOKEN>" \
147-
--header "Content-Type: application/json" \
148-
--data '{
149-
"rules": [
150-
{
151-
"action": "execute",
152-
"expression": "cf.zone.name eq \"example.com\" and cf.zone.plan eq \"ENT\"",
153-
"action_parameters": {
154-
"id": "<MANAGED_RULESET_ID>",
155-
"overrides": {
156-
"enabled": false,
157-
"categories": [
158-
{
159-
"category": "joomla",
160-
"action": "log",
161-
"enabled": true
162-
},
163-
{
164-
"category": "wordpress",
165-
"enabled": false
166-
}
167-
]
168-
}
169-
}
170-
}
171-
]
172-
}'
173-
```
146+
<APIRequest
147+
path="/accounts/{account_id}/rulesets/phases/{ruleset_phase}/entrypoint"
148+
method="PUT"
149+
parameters={{
150+
ruleset_phase: "http_request_firewall_managed",
151+
}}
152+
json={{
153+
rules: [
154+
{
155+
action: "execute",
156+
expression: 'cf.zone.name eq "example.com" and cf.zone.plan eq "ENT"',
157+
action_parameters: {
158+
id: "<MANAGED_RULESET_ID>",
159+
overrides: {
160+
enabled: false,
161+
categories: [
162+
{
163+
category: "joomla",
164+
action: "log",
165+
enabled: true,
166+
},
167+
{
168+
category: "wordpress",
169+
enabled: false,
170+
},
171+
],
172+
},
173+
},
174+
},
175+
],
176+
}}
177+
/>
174178

175179
</Details>
176180

177-
The order of the overrides in the root ruleset affects whether rules in the deployed managed ruleset are enabled or disabled. Overrides placed later in the list take precedence over earlier overrides. Consider four rules from the managed ruleset in the code above that have different combinations of `category` tags.
181+
The order of the overrides in the ruleset determines if rules in the deployed managed ruleset are enabled or disabled. Overrides placed later in the list take precedence over earlier overrides.
178182

179-
The following table shows the status of the rules after the overrides.
183+
Consider four rules from the managed ruleset in the code above that have different combinations of `category` tags. The following table shows the status of the rules after the overrides.
180184

181185
| Rule in managed ruleset | Tags | Rule status after overrides |
182186
| ----------------------- | ---------------------------- | --------------------------- |

0 commit comments

Comments
 (0)