Skip to content

Commit 82ffb32

Browse files
committed
Add DNS API example
1 parent 4844691 commit 82ffb32

File tree

1 file changed

+19
-35
lines changed

1 file changed

+19
-35
lines changed

src/content/partials/cloudflare-one/gateway/get-started/create-dns-policy.mdx

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import { Render, Tabs, TabItem } from "~/components";
66

7+
To create a new DNS policy:
8+
79
<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard">
810

911
1. In [Zero Trust](https://one.dash.cloudflare.com/), go to **Gateway** > **Firewall policies**.
@@ -21,51 +23,33 @@ import { Render, Tabs, TabItem } from "~/components";
2123

2224
<TabItem label="API">
2325

24-
1. Create a custom API token with the following permissions:
26+
1. [Create an API token](/fundamentals/api/get-started/create-token/) with the following permissions:
2527

26-
| Scope | Application | Action |
27-
| ------- | ----------- | ------ |
28-
| Account | Zero Trust | Edit |
28+
| Type | Item | Permission |
29+
| ------- | ---------- | ---------- |
30+
| Account | Zero Trust | Edit |
2931

30-
2. (Optional) Configure your API environment variables with your account ID, email address, and API token.
31-
3. Send a `POST` request to the [Create a Zero Trust Gateway rule](/api/operations/zero-trust-gateway-rules-create-zero-trust-gateway-rule) endpoint:
32+
2. (Optional) Configure your API environment variables to include your [account ID](/fundamentals/setup/find-account-and-zone-ids/), email address, and API token.
33+
3. Send a `POST` request to the [Create a Zero Trust Gateway rule](/api/operations/zero-trust-gateway-rules-create-zero-trust-gateway-rule) endpoint. For example, we recommend adding a policy to block all [security categories](/cloudflare-one/policies/gateway/domain-categories/#security-categories):
3234

33-
```bash
35+
```bash title="curl API example"
3436
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/gateway/rules \
35-
--header "X-Auth-Email: <EMAIL>" \
36-
--header "X-Auth-Key: <API_KEY>" \
37-
--header "Content-Type: application/json" \
38-
--data '{
39-
"action": "allow",
40-
"description": "Lisbon team access rule",
37+
--header "X-Auth-Email: <EMAIL>" \
38+
--header "X-Auth-Key: <API_KEY>" \
39+
--data '{
40+
"action": "allow",
41+
"name": "Block security risks",
42+
"description": "Block all default Cloudflare security categories",
4143
"device_posture": "any(device_posture.checks.passed[*] in {})",
4244
"enabled": true,
43-
"expiration": {
44-
"duration": 10,
45-
"expired": false,
46-
"expires_at": "2014-01-01T05:20:20Z"
47-
},
4845
"filters": [
49-
"http"
46+
"dns"
5047
],
51-
"identity": "any(identity.groups.name[*] in {\"Lisbon-team\"})",
52-
"name": "Lisbon Team Access Rule",
5348
"precedence": 0,
54-
"rule_settings": {
55-
"allow_child_bypass": false
56-
},
57-
"schedule": {
58-
"fri": "08:00-12:30,13:30-17:00",
59-
"mon": "08:00-12:30,13:30-17:00",
60-
"sat": "08:00-12:30,13:30-17:00",
61-
"sun": "08:00-12:30,13:30-17:00",
62-
"thu": "08:00-12:30,13:30-17:00",
63-
"time_zone": "America/New York",
64-
"tue": "08:00-12:30,13:30-17:00",
65-
"wed": "08:00-12:30,13:30-17:00"
66-
},
67-
"traffic": "http.request.uri matches \".*a/partial/uri.*\" and http.request.host in $01302951-49f9-47c9-a400-0297e60b6a10"
49+
"traffic": "any(dns.security_category[*] in {68 178 80 83 176 175 117 131 134 151 153})"
6850
}'
6951
```
7052

7153
</TabItem> </Tabs>
54+
55+
For more information, refer to [DNS policies](/cloudflare-one/policies/gateway/dns-policies/).

0 commit comments

Comments
 (0)