Skip to content

Commit 28f18f8

Browse files
authored
cloudflare: improve cloudflare security (#347)
1 parent 47e324b commit 28f18f8

File tree

6 files changed

+92
-12
lines changed

6 files changed

+92
-12
lines changed

aws/multi-stack/app/cloudflare.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ module "cloudflare" {
1414
# optional
1515
bastion_enabled = false
1616
tls_settings = var.tls_settings
17+
hsts_settings = var.hsts_settings
1718
bastion_public_dns = module.ecs.nlb_dns_name
1819
}

aws/multi-stack/app/variables.tf

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ variable "project_settings" {
4343
worker_script_name = string
4444
})), {})
4545
host_header = optional(list(string), null)
46-
health_check_path = optional(string, null)
46+
health_check_path = optional(string, "/livez")
4747
health_check_options = optional(
4848
object({
4949
healthy_threshold = optional(number, 2) # The number of consecutive health checks successes required before considering an unhealthy target healthy.
@@ -59,12 +59,39 @@ variable "project_settings" {
5959

6060
variable "tls_settings" {
6161
type = object({
62-
tls_1_3 = optional(string, "on") # "on/off"
62+
min_tls_version = optional(string, "1.2") # 1.0, 1.1, 1.2, 1.3
63+
tls_1_3 = optional(string, "off") # "on/off"
6364
automatic_https_rewrites = optional(string, "on") # "on/off"
6465
ssl = optional(string, "strict") # "strict"
6566
always_use_https = optional(string, "on") # "on/off"
6667
})
67-
default = null
68+
default = {
69+
min_tls_version = "1.2"
70+
tls_1_3 = "off"
71+
automatic_https_rewrites = "on"
72+
ssl = "strict"
73+
always_use_https = "on"
74+
}
75+
}
76+
77+
# HSTS protects HTTPS web servers from downgrade attacks.
78+
# These attacks redirect web browsers from an HTTPS web server to an attacker-controlled server, allowing bad actors to compromise user data and cookies.
79+
# https://developers.cloudflare.com/ssl/edge-certificates/additional-options/http-strict-transport-security/
80+
variable "hsts_settings" {
81+
type = object({
82+
enabled = optional(bool, null)
83+
preload = optional(bool, null)
84+
max_age = optional(number, null)
85+
include_subdomains = optional(bool, null)
86+
nosniff = optional(bool, null)
87+
})
88+
default = {
89+
enabled = true
90+
preload = true
91+
max_age = 31536000 # Set it to least value for validating functionality.
92+
include_subdomains = true
93+
nosniff = true
94+
}
6895
}
6996

7097
variable "kms_deletion_window_in_days" {

aws/stack/app/cloudflare.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@ module "cloudflare" {
1414
# optional
1515
bastion_enabled = true
1616
tls_settings = var.tls_settings
17+
hsts_settings = var.hsts_settings
1718
bastion_public_dns = module.ecs.nlb_dns_name
1819
}

aws/stack/app/variables.tf

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,39 @@ variable "s3_cloudflare_records" {
5050

5151
variable "tls_settings" {
5252
type = object({
53-
tls_1_3 = string # "on/off"
54-
automatic_https_rewrites = string # "on/off"
55-
ssl = string # "strict"
56-
always_use_https = string # "on/off"
53+
min_tls_version = optional(string, "1.2") # 1.0, 1.1, 1.2, 1.3
54+
tls_1_3 = optional(string, "off") # "on/off"
55+
automatic_https_rewrites = optional(string, "on") # "on/off"
56+
ssl = optional(string, "strict") # "strict"
57+
always_use_https = optional(string, "on") # "on/off"
5758
})
58-
default = null
59+
default = {
60+
min_tls_version = "1.2"
61+
tls_1_3 = "off"
62+
automatic_https_rewrites = "on"
63+
ssl = "strict"
64+
always_use_https = "on"
65+
}
66+
}
67+
68+
# HSTS protects HTTPS web servers from downgrade attacks.
69+
# These attacks redirect web browsers from an HTTPS web server to an attacker-controlled server, allowing bad actors to compromise user data and cookies.
70+
# https://developers.cloudflare.com/ssl/edge-certificates/additional-options/http-strict-transport-security/
71+
variable "hsts_settings" {
72+
type = object({
73+
enabled = optional(bool, null)
74+
preload = optional(bool, null)
75+
max_age = optional(number, null)
76+
include_subdomains = optional(bool, null)
77+
nosniff = optional(bool, null)
78+
})
79+
default = {
80+
enabled = true
81+
preload = true
82+
max_age = 31536000 # Set it to least value for validating functionality.
83+
include_subdomains = true
84+
nosniff = true
85+
}
5986
}
6087
# =============== Cloudflare ================ #
6188

cloudflare/tls.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ resource "cloudflare_zone_settings_override" "tls" {
99

1010
settings {
1111
tls_1_3 = var.tls_settings.tls_1_3
12+
min_tls_version = var.tls_settings.min_tls_version
1213
automatic_https_rewrites = var.tls_settings.automatic_https_rewrites
1314
ssl = var.tls_settings.ssl
1415
always_use_https = var.tls_settings.always_use_https
16+
17+
security_header {
18+
enabled = var.hsts_settings.enabled
19+
include_subdomains = var.hsts_settings.include_subdomains
20+
max_age = var.hsts_settings.max_age
21+
nosniff = var.hsts_settings.nosniff
22+
preload = var.hsts_settings.preload
23+
}
1524
}
1625
}

cloudflare/variables.tf

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,25 @@ variable "bastion_enabled" {
1414

1515
variable "tls_settings" {
1616
type = object({
17-
tls_1_3 = string # "on/off"
18-
automatic_https_rewrites = string # "on/off"
19-
ssl = string # "strict"
20-
always_use_https = string # "on/off"
17+
min_tls_version = optional(string, "1.2") # 1.0, 1.1, 1.2, 1.3
18+
tls_1_3 = string # "on/off"
19+
automatic_https_rewrites = string # "on/off"
20+
ssl = string # "strict"
21+
always_use_https = string # "on/off"
22+
})
23+
default = null
24+
}
25+
26+
# HSTS protects HTTPS web servers from downgrade attacks.
27+
# These attacks redirect web browsers from an HTTPS web server to an attacker-controlled server, allowing bad actors to compromise user data and cookies.
28+
# https://developers.cloudflare.com/ssl/edge-certificates/additional-options/http-strict-transport-security/
29+
variable "hsts_settings" {
30+
type = object({
31+
enabled = optional(bool, true)
32+
preload = optional(bool, true) # Initially disable until you are sure about your configuration
33+
max_age = optional(number, 31536000) # Set it to least value for validating functionality.
34+
include_subdomains = optional(bool, true)
35+
nosniff = optional(bool, true)
2136
})
2237
default = null
2338
}

0 commit comments

Comments
 (0)