Skip to content

Commit a79102d

Browse files
rexscariaRex Scariamaxvp
authored andcommitted
add doc on handling categories and app types in gateway via terraform (#21983)
Co-authored-by: Rex Scaria <[email protected]> Co-authored-by: Max Phillips <[email protected]>
1 parent e06d941 commit a79102d

File tree

4 files changed

+120
-15
lines changed

4 files changed

+120
-15
lines changed

src/content/docs/cloudflare-one/policies/gateway/application-app-types.mdx

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ When you choose the _Application_ selector in a Gateway policy builder, the **Va
1515

1616
## App types
1717

18+
Gateway sorts applications into the following app type groups:
19+
1820
| Value | Definition |
1921
| ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
2022
| Artificial Intelligence | AI assistance applications |
@@ -43,20 +45,9 @@ When you choose the _Application_ selector in a Gateway policy builder, the **Va
4345
| Video Streaming | Video streaming applications |
4446
| [Do Not Inspect](#do-not-inspect-applications) | Applications incompatible with the TLS certificate required by the [Gateway proxy](/cloudflare-one/policies/gateway/proxy/) |
4547

46-
### Do Not Inspect applications
47-
48-
#### TLS decryption limitations
49-
50-
Applications can be incompatible with [TLS decryption](/cloudflare-one/policies/gateway/http-policies/tls-decryption/) for various reasons:
51-
52-
<GlossaryDefinition
53-
term="certificate pinning"
54-
prepend="Certificate pinning is "
55-
/>
56-
57-
- **Non-web traffic**: Some applications send non-web traffic, such as Session Initiation Protocol (SIP) and Extensible Messaging and Presence Protocol (XMPP), over TLS. Gateway cannot inspect these protocols.
48+
## Usage
5849

59-
#### Application grouping
50+
### Do Not Inspect applications
6051

6152
Gateway automatically groups applications incompatible with TLS decryption into the _Do Not Inspect_ app type. As Cloudflare identifies incompatible applications, Gateway will periodically update this app type to add new applications. To ensure Gateway does not intercept any current or future incompatible traffic, you can [create a Do Not Inspect HTTP policy](/cloudflare-one/policies/gateway/http-policies/#do-not-inspect) with the entire _Do Not Inspect_ app type selected.
6253

@@ -65,6 +56,17 @@ Gateway automatically groups applications incompatible with TLS decryption into
6556
Instead of creating a Do Not Inspect policy for an application, you may be able to configure the application to [trust a Cloudflare certificate](/cloudflare-one/connections/connect-devices/user-side-certificates/manual-deployment/#add-the-certificate-to-applications). Doing so will allow the application to function without losing visibility into your traffic.
6657
:::
6758

59+
#### TLS decryption limitations
60+
61+
Applications can be incompatible with [TLS decryption](/cloudflare-one/policies/gateway/http-policies/tls-decryption/) for various reasons:
62+
63+
- <GlossaryDefinition
64+
term="certificate pinning"
65+
prepend="**Certificate pinning**: Certificate pinning is "
66+
/>
67+
68+
- **Non-web traffic**: Some applications send non-web traffic, such as Session Initiation Protocol (SIP) and Extensible Messaging and Presence Protocol (XMPP), over TLS. Gateway cannot inspect these protocols.
69+
6870
#### Microsoft 365 integration
6971

7072
To optimize performance for Microsoft 365 applications and services, you can bypass TLS decryption by turning on the Microsoft 365 traffic integration. This will create a [Do Not Inspect policy](/cloudflare-one/policies/gateway/http-policies/#do-not-inspect) for all [Microsoft 365 domains and IP addresses](https://docs.microsoft.com/en-us/microsoft-365/enterprise/microsoft-365-ip-web-service) specified by Microsoft. This policy also uses Cloudflare intelligence to identify other Microsoft 365 traffic not explicitly defined.
@@ -76,3 +78,33 @@ To turn on the Microsoft 365 integration:
7678
3. To verify the policy was created, select **View policy**. Alternatively, go to **Gateway** > **Firewall policies** > **HTTP**. A policy named Microsoft 365 Auto Generated will be enabled in your list.
7779

7880
All future Microsoft 365 traffic will bypass Gateway logging and filtering. To disable this behavior, turn off or delete the policy.
81+
82+
### Terraform
83+
84+
Terraform users can retrieve the app types list with the `cloudflare_zero_trust_gateway_app_types_list` data source. This allows you to create Gateway policies with the application's name rather than its numeric UUID. For example:
85+
86+
```tf
87+
data "cloudflare_zero_trust_gateway_app_types_list" "gateway_apptypes" {
88+
account_id = var.cloudflare_account_id
89+
}
90+
91+
locals {
92+
apptypes_map = merge([
93+
for c in data.cloudflare_zero_trust_gateway_app_types_list.gateway_apptypes.result :
94+
{ (c.name) = c.id }
95+
]...)
96+
}
97+
98+
resource "cloudflare_zero_trust_gateway_policy" "zt_block_dns_apps" {
99+
account_id = var.cloudflare_account_id
100+
name = "DNS Blocked apps"
101+
action = "block"
102+
traffic = "any(app.ids[*] in {${join(" ", [
103+
local.apptypes_map["Discord"],
104+
local.apptypes_map["GoToMeeting"],
105+
local.apptypes_map["Greenhouse"],
106+
local.apptypes_map["Zelle"],
107+
local.apptypes_map["Microsoft Visual Studio"]
108+
])}})"
109+
}
110+
```

src/content/docs/cloudflare-one/policies/gateway/domain-categories.mdx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,40 @@ Then, the initial categorization is refined via:
229229
3. Machine learning models. Our algorithms, including DGA Domains, DNS tunneling, and phishing detection models analyze patterns and behaviors to detect new and evolving threats.
230230

231231
4. Community feedback. Through a review process, Cloudflare assesses feedback by both our internal models and threat analysts. This ensures that our categorizations reflect the most current and accurate threat intelligence.
232+
233+
## Terraform
234+
235+
Terraform users can retrieve the category list with the `cloudflare_zero_trust_gateway_categories_list` data source. This allows you to create Gateway policies with the category's name rather than its numeric UUID. For example:
236+
237+
```tf
238+
data "cloudflare_zero_trust_gateway_categories_list" "categories" {
239+
account_id = var.cloudflare_account_id
240+
}
241+
242+
locals {
243+
main_categories_map = {
244+
for idx, c in data.cloudflare_zero_trust_gateway_categories_list.categories[0].result :
245+
c.name => c.id
246+
}
247+
248+
subcategories_map = merge(flatten([
249+
for idx, c in data.cloudflare_zero_trust_gateway_categories_list.categories[0].result : {
250+
for k, v in coalesce(c.subcategories, []) :
251+
v.name => v.id
252+
}
253+
])...)
254+
}
255+
256+
resource "cloudflare_zero_trust_gateway_policy" "zt_block_dns_tech_categories" {
257+
account_id = var.cloudflare_account_id
258+
name = "DNS Blocked"
259+
action = "block"
260+
traffic = "any(dns.content_category[*] in {${join(" ", [
261+
local.main_categories_map["Technology"],
262+
local.subcategories_map["APIs"],
263+
local.subcategories_map["Artificial Intelligence"],
264+
local.subcategories_map["Content Servers"],
265+
local.subcategories_map["Translator"]
266+
])}})"
267+
}
268+
```

src/content/partials/cloudflare-one/gateway/order-of-enforcement.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,37 @@ When a user goes to `https://test.example.com`, Gateway performs the following o
180180
3. Policy #3 is not evaluated because there has already been an explicit match.
181181

182182
Therefore, the user is able to connect to `https://test.example.com`.
183+
184+
## Precedence calculations
185+
186+
When arranging policies in Zero Trust, Gateway automatically calculates the precedence for rearranged policies.
187+
188+
When using the API to create a policy, unless the precedence is explicitly defined in the policy, Gateway will assign precedence to policies starting at `1000`. Every time a new policy is added to the bottom of the order, Gateway will calculate the current highest precedence in the account and add a random integer between 1 and 100 to `1000` so that it now claims the maximum precedence in the account. To manually update a policy's precedence, use the [Update a Zero Trust Gateway rule](/api/resources/zero_trust/subresources/gateway/subresources/rules/methods/update/) endpoint. You can set a policy's precedence to any value that is not already in use.
189+
190+
Changing the order within the Zero Trust dashboard or API may result in configuration issues when using [Terraform](#manage-precedence-with-terraform).
191+
192+
## Manage precedence with Terraform
193+
194+
You can manage a the order of execution of your Gateway policies using Terraform. With version 5 of the Terraform Cloudflare provider, Gateway users can list their policies in a Terraform file with any desired integer precedence value. Cloudflare recommends starting with a precedence of `1000` and adding extra space between each policy's precedence for any future policies. For example:
195+
196+
```tf
197+
resource "cloudflare_zero_trust_gateway_policy" "policy_1" {
198+
account_id = var.cloudflare_account_id
199+
# other attributes...
200+
precedence = 1000
201+
}
202+
203+
resource "cloudflare_zero_trust_gateway_policy" "policy_2" {
204+
account_id = var.cloudflare_account_id
205+
# other attributes...
206+
precedence = 2000
207+
}
208+
209+
resource "cloudflare_zero_trust_gateway_policy" "policy_3" {
210+
account_id = var.cloudflare_account_id
211+
# other attributes...
212+
precedence = 3000
213+
}
214+
```
215+
216+
To avoid precedence calculation errors, you should move one policy at a time before running `terraform plan` and `terraform apply`. If you use both Terraform and the Zero Trust dashboard or API, sync your polices with `terraform plan` before reordering policies in Terraform. Alternatively, you can set your account to [read-only in the Zero Trust dashboard](/cloudflare-one/api-terraform/#set-dashboard-to-read-only), only allowing changes using the API or Terraform.

src/content/partials/cloudflare-one/gateway/terraform-precedence-warning.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
{}
33
---
44

5-
:::caution[Terraform precedence limitation]
6-
To avoid conflicts, Terraform applies a hash calculation to policy precedence. For example, a precedence of `1000` may become `1000901`. This can cause errors when reordering policies. To avoid this issue, manually set the precedence of policies created with Terraform using the [Update a Zero Trust Gateway rule](/api/resources/zero_trust/subresources/gateway/subresources/rules/methods/update/) endpoint.
5+
:::caution[Terraform provider v4 precedence limitation]
6+
To avoid conflicts, version 4 of the Terraform Cloudflare provider applies a hash calculation to policy precedence. For example, a precedence of `1000` may become `1000901`. This can cause errors when reordering policies. To avoid this issue, manually set the precedence of policies created with Terraform using the [Update a Zero Trust Gateway rule](/api/resources/zero_trust/subresources/gateway/subresources/rules/methods/update/) endpoint.
7+
8+
To ensure your precedence is set correctly, Cloudflare recommends [upgrading your Terraform provider to version 5](https://registry.terraform.io/providers/cloudflare/cloudflare/latest/docs/guides/version-5-upgrade).
79
:::

0 commit comments

Comments
 (0)