-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzero_trust.tf
194 lines (178 loc) · 6.13 KB
/
zero_trust.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// ==== Zero Trust ====
// TODO Access Policies
// ==== Gateway Policies ====
resource "cloudflare_teams_rule" "allowed" {
name = "Allowed"
description = ""
account_id = local.cf_account_id
precedence = 10000
action = "allow"
enabled = true
filters = ["dns"]
traffic = "any(dns.domains[*] in $b880f23bb11a45c29e8149401dd67592)"
}
resource "cloudflare_teams_rule" "block_content_categories" {
name = "Block Content Categories"
description = ""
account_id = local.cf_account_id
precedence = 12000
action = "block"
enabled = true
filters = ["dns"]
traffic = "any(dns.content_category[*] in {85 162 170})" # https://developers.cloudflare.com/cloudflare-one/policies/filtering/dns-policies/dns-categories/#category-and-subcategory-ids
rule_settings {
block_page_enabled = true
block_page_reason = "Access to this category of sites is blocked."
}
}
resource "cloudflare_teams_rule" "block_security_risks" {
name = "Block Security Risks"
description = ""
account_id = local.cf_account_id
precedence = 13000
action = "block"
enabled = true
filters = ["dns"]
traffic = "any(dns.security_category[*] in {178 80 83 176 175 117 131 134 151 153})" # https://developers.cloudflare.com/cloudflare-one/policies/filtering/dns-policies/dns-categories/#category-and-subcategory-ids
rule_settings {
block_page_enabled = true
block_page_reason = "This site is a security risk, and is therefor blocked."
}
}
resource "cloudflare_teams_rule" "block_manual_trackers_and_ads" {
name = "Block Manual Trackers & Ads"
description = ""
account_id = local.cf_account_id
precedence = 14000
action = "block"
enabled = true
filters = ["dns"]
traffic = "any(dns.domains[*] in $534bce67f20a4ac698fc003f6c139767)"
}
resource "cloudflare_teams_rule" "block_tor" {
name = "Block TOR"
description = ""
account_id = local.cf_account_id
precedence = 15000
action = "block"
enabled = true
filters = ["dns"]
traffic = "any(dns.dst.geo.continent[*] == \"T1\")"
rule_settings {
block_page_enabled = true
block_page_reason = "Access to TOR Sites is blocked."
}
}
resource "cloudflare_device_managed_networks" "seaview" {
account_id = local.cf_account_id
name = "Seaview"
type = "tls"
config {
tls_sockaddr = "10.0.10.220:443"
sha256 = lower("D693C2456E86E0535A2801F6335FD801BD1CF1ADCC51413E1946D1FA696655C6")
}
}
# Warp Client Policies
resource "cloudflare_device_settings_policy" "trusted_location_warp_policy" {
account_id = local.cf_account_id
name = "Disable when on trusted network"
description = ""
precedence = 10
match = "network in {\"Seaview\"}"
default = false
enabled = true
allow_mode_switch = false
allow_updates = true
allowed_to_leave = true
auto_connect = 0
captive_portal = 180
disable_auto_fallback = false
switch_locked = false
service_mode_v2_mode = "posture_only"
service_mode_v2_port = 0
exclude_office_ips = false
}
resource "cloudflare_device_settings_policy" "mobile_device_warp_policy" {
account_id = local.cf_account_id
name = "Mobile Client"
description = ""
precedence = 20
match = "os.name in {\"ios\" \"android\"}"
default = false
enabled = false # Disabled until trusted_location_warp_policy is actually working - test via `warp-cli debug alternate-network`
allow_mode_switch = false
allow_updates = true
allowed_to_leave = true
auto_connect = 180
captive_portal = 600
disable_auto_fallback = false
switch_locked = false
service_mode_v2_mode = "warp"
service_mode_v2_port = 0
exclude_office_ips = false
}
resource "cloudflare_device_settings_policy" "desktop_device_warp_policy" {
account_id = local.cf_account_id
name = "Desktops"
description = ""
precedence = 30
match = "os.name in {\"windows\" \"mac\" \"chromeos\" \"linux\"}"
default = false
enabled = false # Disabled until trusted_location_warp_policy is actually working - test via `warp-cli debug alternate-network`
allow_mode_switch = true
allow_updates = true
allowed_to_leave = true
auto_connect = 180
captive_portal = 600
disable_auto_fallback = false
switch_locked = false
service_mode_v2_mode = "warp"
service_mode_v2_port = 0
exclude_office_ips = false
}
resource "cloudflare_device_settings_policy" "default_warp_policy" {
account_id = local.cf_account_id
name = ""
description = ""
default = true
enabled = true
allow_mode_switch = true
allow_updates = true
allowed_to_leave = true
auto_connect = 0
captive_portal = 600
disable_auto_fallback = false
switch_locked = false
service_mode_v2_mode = "warp"
service_mode_v2_port = 0
exclude_office_ips = false
}
# Split Tunnel Configs
variable "zt_split_tunnel_file" {
default = "zt_split_tunnel.txt"
}
locals {
cidr_list = [
for cidr in split("\n", file(var.zt_split_tunnel_file)) : trimspace(cidr)
if cidr != "" && !startswith(trimspace(cidr), "#")
]
device_settings_policy_ids = [
cloudflare_device_settings_policy.trusted_location_warp_policy.id,
cloudflare_device_settings_policy.mobile_device_warp_policy.id,
cloudflare_device_settings_policy.desktop_device_warp_policy.id,
cloudflare_device_settings_policy.default_warp_policy.id,
]
}
resource "cloudflare_split_tunnel" "split_tunnel_exclude" {
for_each = toset(local.device_settings_policy_ids)
account_id = local.cf_account_id
policy_id = each.value
mode = "exclude"
dynamic "tunnels" {
for_each = local.cidr_list
content {
address = tunnels.value
description = ""
}
}
}