Skip to content

Commit 46f3d9e

Browse files
committed
EHD-1474: Prevent email spoofing
1 parent 9c1923f commit 46f3d9e

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

terraform/dev.tfvars

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ create_dns_record = true
66
dns_record_subdomain_including_dot = "dev."
77

88
create_redirect_from_www_domain = false
9-
dns_record_www_domain_including_dot = "www.dev."
9+
dns_record_www_domain_including_dot = "www.dev."
10+
11+
prevent_email_spoofing = false

terraform/prevent_email_spoofing.tf

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
locals {
3+
dns_zones_to_protect_against_email_spoofing = (
4+
var.prevent_email_spoofing ?
5+
tomap({
6+
zone_1 = data.aws_route53_zone.route_53_zone_for_our_domain,
7+
})
8+
: tomap({})
9+
)
10+
}
11+
12+
resource "aws_route53_record" "dns_record_to_protect_against_email_spoofing__SPF" {
13+
for_each = local.dns_zones_to_protect_against_email_spoofing
14+
15+
type = "TXT"
16+
name = each.value.name // No subdomain
17+
records = ["v=spf1 -all"]
18+
ttl = 60
19+
zone_id = each.value.zone_id
20+
}
21+
22+
resource "aws_route53_record" "dns_record_to_protect_against_email_spoofing__DMARC" {
23+
for_each = local.dns_zones_to_protect_against_email_spoofing
24+
25+
type = "TXT"
26+
name = "_dmarc.${each.value.name}"
27+
records = ["v=DMARC1;p=reject;sp=reject;adkim=s;aspf=s;fo=1;rua=mailto:[email protected]"]
28+
ttl = 60
29+
zone_id = each.value.zone_id
30+
}
31+
32+
resource "aws_route53_record" "dns_record_to_protect_against_email_spoofing__DKIM" {
33+
for_each = local.dns_zones_to_protect_against_email_spoofing
34+
35+
type = "TXT"
36+
name = "*._domainkey.${each.value.name}"
37+
records = ["v=DKIM1; p="]
38+
ttl = 60
39+
zone_id = each.value.zone_id
40+
}
41+
42+
resource "aws_route53_record" "dns_record_to_protect_against_email_spoofing__MX" {
43+
for_each = local.dns_zones_to_protect_against_email_spoofing
44+
45+
type = "MX"
46+
name = each.value.name // No subdomain
47+
records = ["0 ."]
48+
ttl = 60
49+
zone_id = each.value.zone_id
50+
}

terraform/prod.tfvars

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ dns_record_subdomain_including_dot = ""
77

88
create_redirect_from_www_domain = true
99
dns_record_www_domain_including_dot = "www."
10+
11+
prevent_email_spoofing = true

terraform/variables.tf

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ variable "dns_record_www_domain_including_dot" {
4242
description = "The www. domain (including dot - e.g. 'www.dev.' or just 'www.' for production) for the www domain redirect"
4343
}
4444

45+
variable "prevent_email_spoofing" {
46+
type = bool
47+
description = "Should terraform create DNS records to prevent email spoofing (only required for the prod environment)"
48+
default = false
49+
}
50+
51+
4552
// SECRETS
4653
// These variables are set in GitHub Actions environment-specific secrets
4754
// Most of these are passed to the application via Elastic Beanstalk environment variables

0 commit comments

Comments
 (0)