-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail-security.tf
More file actions
230 lines (181 loc) · 7.01 KB
/
Copy pathemail-security.tf
File metadata and controls
230 lines (181 loc) · 7.01 KB
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# SPDX-License-Identifier: MPL-2.0
# Email security records: DKIM, DMARC, SPF, BIMI, ARC
# ============================================================================
# DKIM (DomainKeys Identified Mail)
# ============================================================================
resource "cloudflare_record" "dkim" {
for_each = { for k, v in local.domains : k => v if v.enable_mail && v.dkim_selector != "" }
zone_id = data.cloudflare_zones.all[each.key].zones[0].id
name = "${each.value.dkim_selector}._domainkey"
content = "v=DKIM1; k=rsa; p=${each.value.dkim_public_key}"
type = "TXT"
comment = "DKIM public key (${each.value.dkim_selector})"
}
# Multiple DKIM selectors (for rotation)
resource "cloudflare_record" "dkim_rotation" {
for_each = { for k, v in local.domains : k => v if v.enable_mail && v.dkim_selector_rotation != "" }
zone_id = data.cloudflare_zones.all[each.key].zones[0].id
name = "${each.value.dkim_selector_rotation}._domainkey"
content = "v=DKIM1; k=rsa; p=${each.value.dkim_public_key_rotation}"
type = "TXT"
comment = "DKIM rotation key"
}
# ============================================================================
# BIMI (Brand Indicators for Message Identification)
# ============================================================================
resource "cloudflare_record" "bimi" {
for_each = { for k, v in local.domains : k => v if v.enable_mail && v.bimi_logo_url != "" }
zone_id = data.cloudflare_zones.all[each.key].zones[0].id
name = "default._bimi"
content = "v=BIMI1; l=${each.value.bimi_logo_url}; a=${each.value.bimi_vmc_url}"
type = "TXT"
comment = "BIMI logo for email"
}
# ============================================================================
# ARC (Authenticated Received Chain)
# ============================================================================
resource "cloudflare_record" "arc" {
for_each = { for k, v in local.domains : k => v if v.enable_mail && v.arc_selector != "" }
zone_id = data.cloudflare_zones.all[each.key].zones[0].id
name = "${each.value.arc_selector}._arc"
content = "v=ARC1; k=rsa; p=${each.value.arc_public_key}"
type = "TXT"
comment = "ARC signing key"
}
# ============================================================================
# Enhanced CAA with Critical Flag (128)
# ============================================================================
resource "cloudflare_record" "caa_critical_letsencrypt" {
for_each = local.domains
zone_id = data.cloudflare_zones.all[each.key].zones[0].id
name = "@"
type = "CAA"
data {
flags = "128" # Critical flag
tag = "issue"
value = "letsencrypt.org"
}
comment = "CAA - Let's Encrypt (CRITICAL)"
}
resource "cloudflare_record" "caa_critical_digicert" {
for_each = local.domains
zone_id = data.cloudflare_zones.all[each.key].zones[0].id
name = "@"
type = "CAA"
data {
flags = "128" # Critical flag
tag = "issue"
value = "digicert.com"
}
comment = "CAA - DigiCert (CRITICAL)"
}
resource "cloudflare_record" "caa_wildcard" {
for_each = local.domains
zone_id = data.cloudflare_zones.all[each.key].zones[0].id
name = "@"
type = "CAA"
data {
flags = "128"
tag = "issuewild"
value = "letsencrypt.org"
}
comment = "CAA - Wildcard cert authorization (CRITICAL)"
}
# ============================================================================
# ADSP (Author Domain Signing Practices) - Legacy but some use
# ============================================================================
resource "cloudflare_record" "adsp" {
for_each = { for k, v in local.domains : k => v if v.enable_mail }
zone_id = data.cloudflare_zones.all[each.key].zones[0].id
name = "_adsp._domainkey"
content = "dkim=all"
type = "TXT"
comment = "ADSP - All mail must be DKIM signed"
}
# ============================================================================
# Sender Policy Framework (SPF) - Enhanced
# ============================================================================
# Already defined in main.tf, but here's the enhanced version if using mail:
resource "cloudflare_record" "spf_mail" {
for_each = { for k, v in local.domains : k => v if v.enable_mail && v.mx_primary != "" }
zone_id = data.cloudflare_zones.all[each.key].zones[0].id
name = "@"
content = "v=spf1 mx include:_spf.github.com include:${each.value.spf_include} ~all"
type = "TXT"
comment = "SPF - Enhanced for mail servers"
}
# ============================================================================
# Mail Submission (Submission port)
# ============================================================================
resource "cloudflare_record" "submission" {
for_each = { for k, v in local.domains : k => v if v.enable_mail && v.mx_primary != "" }
zone_id = data.cloudflare_zones.all[each.key].zones[0].id
name = "_submission._tcp"
type = "SRV"
data {
service = "_submission"
proto = "_tcp"
name = each.value.domain
priority = 0
weight = 1
port = 587
target = each.value.mx_primary
}
comment = "Mail submission (port 587)"
}
# ============================================================================
# IMAP/POP3 SRV Records
# ============================================================================
resource "cloudflare_record" "imaps" {
for_each = { for k, v in local.domains : k => v if v.enable_mail && v.mx_primary != "" }
zone_id = data.cloudflare_zones.all[each.key].zones[0].id
name = "_imaps._tcp"
type = "SRV"
data {
service = "_imaps"
proto = "_tcp"
name = each.value.domain
priority = 0
weight = 1
port = 993
target = each.value.mx_primary
}
comment = "IMAP over TLS (port 993)"
}
resource "cloudflare_record" "pop3s" {
for_each = { for k, v in local.domains : k => v if v.enable_mail && v.mx_primary != "" }
zone_id = data.cloudflare_zones.all[each.key].zones[0].id
name = "_pop3s._tcp"
type = "SRV"
data {
service = "_pop3s"
proto = "_tcp"
name = each.value.domain
priority = 0
weight = 1
port = 995
target = each.value.mx_primary
}
comment = "POP3 over TLS (port 995)"
}
# ============================================================================
# Autoconfig/Autodiscover (Email client configuration)
# ============================================================================
resource "cloudflare_record" "autoconfig" {
for_each = { for k, v in local.domains : k => v if v.enable_mail }
zone_id = data.cloudflare_zones.all[each.key].zones[0].id
name = "autoconfig"
content = each.value.domain
type = "CNAME"
proxied = true
comment = "Email autoconfig (Thunderbird, etc.)"
}
resource "cloudflare_record" "autodiscover" {
for_each = { for k, v in local.domains : k => v if v.enable_mail }
zone_id = data.cloudflare_zones.all[each.key].zones[0].id
name = "autodiscover"
content = each.value.domain
type = "CNAME"
proxied = true
comment = "Email autodiscover (Outlook, etc.)"
}