Skip to content

Commit 8cb5028

Browse files
committed
feat(router): use one folder for all HSTS keys
1 parent b1a52f4 commit 8cb5028

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

docs/customizing_deis/router_settings.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ setting description
5959
/deis/router/gzipVary nginx gzipVary setting (default: on)
6060
/deis/router/gzipDisable nginx gzipDisable setting (default: "msie6")
6161
/deis/router/gzipTypes nginx gzipTypes setting (default: "application/x-javascript application/xhtml+xml application/xml application/xml+rss application/json text/css text/javascript text/plain text/xml")
62+
/deis/router/hsts/enabled enable HTTP Strict Transport Security headers for HTTPS requests (default: false)
63+
/deis/router/hsts/maxAge maximum number of seconds user agents should observe HSTS rewrites (default: 2628000)
64+
/deis/router/hsts/includeSubDomains enforce HSTS for requests on all subdomains (default: false)
65+
/deis/router/hsts/preload allow the domain to be included in the HSTS preload list (default: false)
6266
/deis/router/maxWorkerConnections maximum number of simultaneous connections that can be opened by a worker process (default: 768)
63-
/deis/router/secondsToEnforceHSTS maximum time to observe HSTS when enforceHTTPS is enabled (default: 2628000)
6467
/deis/router/serverNameHashMaxSize nginx server_names_hash_max_size setting (default: 512)
6568
/deis/router/serverNameHashBucketSize nginx server_names_hash_bucket_size (default: 64)
6669
/deis/router/sslCert cluster-wide SSL certificate

router/boot.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ func main() {
5959
mkdirEtcd(client, "/deis/builder")
6060
mkdirEtcd(client, "/deis/certs")
6161
mkdirEtcd(client, "/deis/router/hosts")
62+
mkdirEtcd(client, "/deis/router/hsts")
6263

6364
setDefaultEtcd(client, etcdPath+"/gzip", "on")
6465

router/image/templates/nginx.conf

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,18 @@ http {
6969
'' $scheme;
7070
}
7171

72-
{{ $enforceHTTPS := or (getv "/deis/router/enforceHTTPS") "false" }}
73-
74-
{{ $secondsToEnforceHSTS := or (getv "/deis/router/secondsToEnforceHSTS") "2628000" }}
72+
## HSTS instructs the browser to replace all HTTP links with HTTPS links for this domain until maxAge seconds from now
73+
{{ $enableHSTS := or (getv "/deis/router/hsts/enabled") "false" }}
74+
{{ $maxAgeHSTS := or (getv "/deis/router/hsts/maxAge") "2628000" }}
75+
{{ $includeSubdomainsHSTS := or (getv "/deis/router/hsts/includeSubDomains") "false" }}
76+
{{ $preloadHSTS := or (getv "/deis/router/hsts/preload") "false" }}
7577
map $access_scheme $sts {
76-
'https' 'max-age={{ $secondsToEnforceHSTS }}; preload';
78+
'https' 'max-age={{ $maxAgeHSTS }}{{ if eq $includeSubdomainsHSTS "true" }}; includeSubDomains{{ end }}{{ if eq $preloadHSTS "true" }}; preload{{ end }}';
7779
}
7880

81+
## since HSTS headers are not permitted on HTTP requests, 301 redirects to HTTPS resources are also necessary
82+
{{ $enforceHTTPS := or (getv "/deis/router/enforceHTTPS") $enableHSTS "false" }}
83+
7984
## start deis-controller
8085
{{ if exists "/deis/controller/host" }}
8186
upstream deis-controller {
@@ -119,6 +124,9 @@ http {
119124
if ($access_scheme != "https") {
120125
return 301 https://$host$request_uri;
121126
}
127+
{{ end }}
128+
129+
{{ if eq $enableHSTS "true" }}
122130
add_header Strict-Transport-Security $sts always;
123131
{{ end }}
124132
}
@@ -230,6 +238,9 @@ http {
230238
if ($access_scheme != "https") {
231239
return 301 https://$host$request_uri;
232240
}
241+
{{ end }}
242+
243+
{{ if eq $enableHSTS "true" }}
233244
add_header Strict-Transport-Security $sts always;
234245
{{ end }}
235246

@@ -289,6 +300,9 @@ http {
289300
if ($access_scheme != "https") {
290301
return 301 https://$host$request_uri;
291302
}
303+
{{ end }}
304+
305+
{{ if eq $enableHSTS "true" }}
292306
add_header Strict-Transport-Security $sts always;
293307
{{ end }}
294308

0 commit comments

Comments
 (0)