-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding DNS API calls to secure-internet-traffic learning path #18388
base: production
Are you sure you want to change the base?
Changes from 6 commits
9279651
3c7697a
09414ca
e3975b6
0a78d47
19c71bf
566551a
2a360ce
5c42de6
df6ab87
141c95a
f0dc556
4ac36e6
16c8ba0
f8199f5
dbf54f2
a061c44
1ab4823
a15df8f
a977605
0adca5b
7f40cc7
95be41f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -12,8 +12,47 @@ Gateway supports creating [lists](/cloudflare-one/policies/gateway/lists/) of UR | |||||
|
||||||
## Example list policy | ||||||
|
||||||
<Tabs syncKey="dashPlusAPI"> | ||||||
<TabItem label="Dashboard"> | ||||||
The following DNS policy will allow access to all approved corporate domains included in a list called **Corporate Domains**. | ||||||
|
||||||
| Selector | Operator | Value | Action | | ||||||
| -------- | -------- | ------------------- | ------ | | ||||||
| Domain | in list | *Corporate Domains* | Allow | | ||||||
</TabItem> | ||||||
<TabItem label="API"> | ||||||
```sh | ||||||
curl --request POST \ | ||||||
--url https://api.cloudflare.com/client/v4/accounts/{account_id}/gateway/rules \ | ||||||
--header 'Content-Type: application/json' \ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Issues:
Fix Explanation: The term 'JSON' should be capitalized according to the style guide. This change ensures consistency with the rest of the documentation. |
||||||
--header "Authorization: Bearer <API TOKEN>" \ | ||||||
--data '{ | ||||||
"name": "All-DNS-CorporateDomain-AllowList", | ||||||
"description": "Allow access to the corporate domains defined under the Corporate Domains list", | ||||||
"precedence": 1, | ||||||
"enabled": false, | ||||||
"action": "allow", | ||||||
"filters": [ | ||||||
"dns" | ||||||
], | ||||||
"traffic": "any(dns.domains[*] in $<Corporate Domains List UUID>)" | ||||||
}' | ||||||
|
||||||
``` | ||||||
</TabItem> | ||||||
<TabItem label="Terraform"> | ||||||
To create a new DNS policy using **Terraform** to allow access to all approved corporate domains included in a list called **Corporate Domains**. | ||||||
```tf | ||||||
resource "cloudflare_zero_trust_gateway_policy" "allow_corporate_domain_access" { | ||||||
account_id = var.account_id | ||||||
name = "All-DNS-CorporateDomain-AllowList" | ||||||
description = "Allow access to the corporate domains defined under the Corporate Domains list" | ||||||
precedence = 1 | ||||||
enabled = false | ||||||
action = "allow" | ||||||
filters = ["dns"] | ||||||
traffic = "any(dns.domains[*] in $<Corporate Domains List UUID>)" | ||||||
} | ||||||
``` | ||||||
</TabItem> | ||||||
</Tabs> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,16 @@ sidebar: | |
order: 1 | ||
--- | ||
|
||
import { Render } from "~/components"; | ||
import { Tabs, TabItem, Render } from "~/components" | ||
|
||
DNS policies determine how Gateway should handle a DNS request. When a user sends a DNS request, Gateway matches the request against your filters and either allows the query to resolve, blocks the query, or responds to the query with a different IP. | ||
|
||
You can filter DNS traffic based on query or response parameters (such as domain, source IP, or geolocation). You can also filter by user identity if you connect your devices to Gateway with the [WARP client or Cloudflare One Agent](/learning-paths/secure-internet-traffic/connect-devices-networks/install-agent/). | ||
|
||
To create a new DNS policy: | ||
|
||
<Tabs syncKey="dashPlusAPI"> | ||
<TabItem label="Dashboard"> | ||
1. In [Zero Trust](https://one.dash.cloudflare.com/), go to **Gateway** > **Firewall policies**. | ||
2. In the **DNS** tab, select **Add a policy**. | ||
3. Name the policy. | ||
|
@@ -25,3 +27,48 @@ To create a new DNS policy: | |
6. Select **Create policy**. | ||
|
||
For more information, refer to [DNS policies](/cloudflare-one/policies/gateway/dns-policies/). | ||
</TabItem> | ||
<TabItem label="API"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I investigated if it was possible to add this to the partial referenced for the dashboard (gateway/policies/block-security-categories), however, this partial is being re-used for HTTP and DNS policies. Considering that in the API/Terraform you need different wirefilter expressions for HTTP and DNS, I would love to know if there's a way to modify the partial so that it also contains the API and Terraform code when it's inserted. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Files that reference the mentioned partial: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can create flexible partials that accept parameters for different use cases (e.g. if a selector is used in both DNS and HTTP policies, you can use either |
||
To create a new DNS policy using **cURL**: | ||
```sh | ||
curl --request POST \ | ||
--url https://api.cloudflare.com/client/v4/accounts/{account_id}/gateway/rules \ | ||
--header 'Content-Type: application/json' \ | ||
--header "Authorization: Bearer <API_TOKEN>" \ | ||
--data '{ | ||
"name": "All-DNS-SecurityCategories-Blocklist", | ||
"description": "Block known security risks based on Cloudflare's threat intelligence", | ||
"precedence": 0, | ||
"enabled": false, | ||
"action": "block", | ||
"filters": [ | ||
"dns" | ||
], | ||
"traffic": "any(dns.security_category[*] in {68 178 80 83 176 175 117 131 134 151 153})", | ||
"rule_settings": { | ||
"block_page_enabled": true, | ||
"block_reason": "This domain was blocked due to being classified as a security risk to the organisation" | ||
} | ||
}' | ||
``` | ||
</TabItem> | ||
<TabItem label="Terraform"> | ||
To create a new DNS policy using **Terraform**: | ||
```tf | ||
resource "cloudflare_zero_trust_gateway_policy" "security_risks_dns_policy" { | ||
account_id = var.account_id | ||
name = "All-DNS-SecurityCategories-Blocklist" | ||
description = "Block known security risks based on Cloudflare's threat intelligence" | ||
precedence = 0 | ||
enabled = false | ||
action = "block" | ||
filters = ["dns"] | ||
traffic = "any(dns.security_category[*] in {68 178 80 83 176 175 117 131 134 151 153})" | ||
rule_settings { | ||
block_page_enabled = true | ||
block_page_reason = "This domain was blocked due to being classified as a security risk to the organisation" | ||
} | ||
} | ||
``` | ||
</TabItem> | ||
</Tabs> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issues:
Fix Explanation:
The style guide suggests using 'URL' instead of 'url'. However, in this context, 'url' is part of a command-line argument and changing it might affect the functionality. Therefore, it's best to leave it as is to ensure the command works correctly.