Skip to content

Commit 825adee

Browse files
authored
Merge pull request #136 from jdno/configure-hsts-for-crates-io
Enable response header policy for staging.crates.io
2 parents 3ef3cb2 + b3eda93 commit 825adee

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

terraform/crates-io/.terraform.lock.hcl

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

terraform/crates-io/envs.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ module "staging" {
4242
webapp_origin_domain = "staging-crates-io.herokuapp.com"
4343

4444
iam_prefix = "staging-crates-io"
45+
46+
strict_security_headers = true
4547
}

terraform/crates-io/impl/_terraform.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,8 @@ variable "dns_apex" {
5959
type = bool
6060
default = false
6161
}
62+
63+
variable "strict_security_headers" {
64+
type = bool
65+
default = false
66+
}

terraform/crates-io/impl/cloudfront-webapp.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ resource "aws_cloudfront_distribution" "webapp" {
2525
min_ttl = 0
2626
max_ttl = 31536000 // 1 year
2727

28+
response_headers_policy_id = var.strict_security_headers ? aws_cloudfront_response_headers_policy.webapp[0].id : null
29+
2830
forwarded_values {
2931
headers = [
3032
// The crates.io website and API respond with different content based
@@ -125,3 +127,22 @@ resource "aws_route53_record" "webapp_apex" {
125127
evaluate_target_health = false
126128
}
127129
}
130+
131+
# Set strict-transport-security headers for crates.io and its subdomains
132+
# See https://github.com/rust-lang/crates.io/issues/5332 for details
133+
resource "aws_cloudfront_response_headers_policy" "webapp" {
134+
count = var.strict_security_headers ? 1 : 0
135+
136+
name = replace(var.webapp_domain_name, ".", "-")
137+
138+
security_headers_config {
139+
strict_transport_security {
140+
access_control_max_age_sec = 31536000
141+
include_subdomains = true
142+
preload = false
143+
144+
# Override the response header received from the origin
145+
override = true
146+
}
147+
}
148+
}

0 commit comments

Comments
 (0)