diff --git a/Gopkg.lock b/Gopkg.lock index 4f0b5e723..b780fd489 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -1189,7 +1189,7 @@ branch = "v1" name = "github.com/unrolled/secure" packages = ["."] - revision = "88720c9cbecfcf2eceb9bb4311ad6e398a8381ed" + revision = "a1cf62cc2159fff407728f118c41aece76c397fa" [[projects]] name = "github.com/urfave/negroni" diff --git a/autogen/gentemplates/gen.go b/autogen/gentemplates/gen.go index ed97b4aa2..177802f1d 100644 --- a/autogen/gentemplates/gen.go +++ b/autogen/gentemplates/gen.go @@ -262,6 +262,7 @@ var _templatesConsul_catalogTmpl = []byte(`[backends] SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLHost = "{{ $headers.SSLHost }}" + SSLForceHost = {{ $headers.SSLForceHost }} STSSeconds = {{ $headers.STSSeconds }} STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }} STSPreload = {{ $headers.STSPreload }} @@ -670,6 +671,7 @@ var _templatesDockerTmpl = []byte(`{{$backendServers := .Servers}} SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLHost = "{{ $headers.SSLHost }}" + SSLForceHost = {{ $headers.SSLForceHost }} STSSeconds = {{ $headers.STSSeconds }} STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }} STSPreload = {{ $headers.STSPreload }} @@ -929,6 +931,7 @@ var _templatesEcsTmpl = []byte(`[backends] SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLHost = "{{ $headers.SSLHost }}" + SSLForceHost = {{ $headers.SSLForceHost }} STSSeconds = {{ $headers.STSSeconds }} STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }} STSPreload = {{ $headers.STSPreload }} @@ -1141,6 +1144,7 @@ var _templatesKubernetesTmpl = []byte(`[backends] SSLRedirect = {{ $frontend.Headers.SSLRedirect }} SSLTemporaryRedirect = {{ $frontend.Headers.SSLTemporaryRedirect }} SSLHost = "{{ $frontend.Headers.SSLHost }}" + SSLForceHost = {{ $frontend.Headers.SSLForceHost }} STSSeconds = {{ $frontend.Headers.STSSeconds }} STSIncludeSubdomains = {{ $frontend.Headers.STSIncludeSubdomains }} STSPreload = {{ $frontend.Headers.STSPreload }} @@ -1346,6 +1350,7 @@ var _templatesKvTmpl = []byte(`[backends] SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLHost = "{{ $headers.SSLHost }}" + SSLForceHost = {{ $headers.SSLForceHost }} STSSeconds = {{ $headers.STSSeconds }} STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }} STSPreload = {{ $headers.STSPreload }} @@ -1647,6 +1652,7 @@ var _templatesMarathonTmpl = []byte(`{{ $apps := .Applications }} SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLHost = "{{ $headers.SSLHost }}" + SSLForceHost = {{ $headers.SSLForceHost }} STSSeconds = {{ $headers.STSSeconds }} STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }} STSPreload = {{ $headers.STSPreload }} @@ -1892,6 +1898,7 @@ var _templatesMesosTmpl = []byte(`[backends] SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLHost = "{{ $headers.SSLHost }}" + SSLForceHost = {{ $headers.SSLForceHost }} STSSeconds = {{ $headers.STSSeconds }} STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }} STSPreload = {{ $headers.STSPreload }} @@ -2190,6 +2197,7 @@ var _templatesRancherTmpl = []byte(`{{ $backendServers := .Backends }} SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLHost = "{{ $headers.SSLHost }}" + SSLForceHost = {{ $headers.SSLForceHost }} STSSeconds = {{ $headers.STSSeconds }} STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }} STSPreload = {{ $headers.STSPreload }} diff --git a/docs/configuration/backends/consulcatalog.md b/docs/configuration/backends/consulcatalog.md index e72be4526..3c62f09c1 100644 --- a/docs/configuration/backends/consulcatalog.md +++ b/docs/configuration/backends/consulcatalog.md @@ -161,11 +161,13 @@ Additional settings can be defined using Consul Catalog tags. | `.frontend.headers.SSLRedirect=true` | Forces the frontend to redirect to SSL if a non-SSL request is sent. | | `.frontend.headers.SSLTemporaryRedirect=true` | Forces the frontend to redirect to SSL if a non-SSL request is sent, but by sending a 302 instead of a 301. | | `.frontend.headers.SSLHost=HOST` | This setting configures the hostname that redirects will be based on. Default is "", which is the same host as the request. | +| `.frontend.headers.SSLForceHost=true` | If `SSLForceHost` is `true` and `SSLHost` is set, requests will be forced to use `SSLHost` even the ones that are already using SSL. Default is false. | | `.frontend.headers.SSLProxyHeaders=EXPR` | Header combinations that would signify a proper SSL Request (Such as `X-Forwarded-For:https`).
Format: HEADER:value||HEADER2:value2 | | `.frontend.headers.STSSeconds=315360000` | Sets the max-age of the STS header. | | `.frontend.headers.STSIncludeSubdomains=true` | Adds the `IncludeSubdomains` section of the STS header. | | `.frontend.headers.STSPreload=true` | Adds the preload flag to the STS header. | + ### Examples If you want that Træfik uses Consul tags correctly you need to defined them like that: diff --git a/docs/configuration/backends/docker.md b/docs/configuration/backends/docker.md index 2143aa1b7..0db4c5f76 100644 --- a/docs/configuration/backends/docker.md +++ b/docs/configuration/backends/docker.md @@ -271,6 +271,7 @@ Or if your service references external network use it's name instead. | `traefik.frontend.headers.SSLRedirect=true` | Forces the frontend to redirect to SSL if a non-SSL request is sent. | | `traefik.frontend.headers.SSLTemporaryRedirect=true` | Forces the frontend to redirect to SSL if a non-SSL request is sent, but by sending a 302 instead of a 301. | | `traefik.frontend.headers.SSLHost=HOST` | This setting configures the hostname that redirects will be based on. Default is "", which is the same host as the request. | +| `traefik.frontend.headers.SSLForceHost=true` | If `SSLForceHost` is `true` and `SSLHost` is set, requests will be forced to use `SSLHost` even the ones that are already using SSL. Default is false. | | `traefik.frontend.headers.SSLProxyHeaders=EXPR` | Header combinations that would signify a proper SSL Request (Such as `X-Forwarded-For:https`).
Format: HEADER:value||HEADER2:value2 | | `traefik.frontend.headers.STSSeconds=315360000` | Sets the max-age of the STS header. | | `traefik.frontend.headers.STSIncludeSubdomains=true` | Adds the `IncludeSubdomains` section of the STS header. | @@ -337,6 +338,7 @@ Segment labels override the default behavior. | `traefik..frontend.headers.SSLRedirect=true` | Same as `traefik.frontend.headers.SSLRedirect` | | `traefik..frontend.headers.SSLTemporaryRedirect=true` | Same as `traefik.frontend.headers.SSLTemporaryRedirect` | | `traefik..frontend.headers.SSLHost=HOST` | Same as `traefik.frontend.headers.SSLHost` | +| `traefik..frontend.headers.SSLForceHost=true` | Same as `traefik.frontend.headers.SSLForceHost` | | `traefik..frontend.headers.SSLProxyHeaders=EXPR` | Same as `traefik.frontend.headers.SSLProxyHeaders=EXPR` | | `traefik..frontend.headers.STSSeconds=315360000` | Same as `traefik.frontend.headers.STSSeconds=315360000` | | `traefik..frontend.headers.STSIncludeSubdomains=true` | Same as `traefik.frontend.headers.STSIncludeSubdomains=true` | diff --git a/docs/configuration/backends/ecs.md b/docs/configuration/backends/ecs.md index 0d51affab..e53b8a94c 100644 --- a/docs/configuration/backends/ecs.md +++ b/docs/configuration/backends/ecs.md @@ -205,6 +205,7 @@ Labels can be used on task containers to override default behaviour: | `traefik.frontend.headers.SSLRedirect=true` | Forces the frontend to redirect to SSL if a non-SSL request is sent. | | `traefik.frontend.headers.SSLTemporaryRedirect=true` | Forces the frontend to redirect to SSL if a non-SSL request is sent, but by sending a 302 instead of a 301. | | `traefik.frontend.headers.SSLHost=HOST` | This setting configures the hostname that redirects will be based on. Default is "", which is the same host as the request. | +| `traefik.frontend.headers.SSLForceHost=true` | If `SSLForceHost` is `true` and `SSLHost` is set, requests will be forced to use `SSLHost` even the ones that are already using SSL. Default is false. | | `traefik.frontend.headers.SSLProxyHeaders=EXPR` | Header combinations that would signify a proper SSL Request (Such as `X-Forwarded-For:https`).
Format: HEADER:value||HEADER2:value2 | | `traefik.frontend.headers.STSSeconds=315360000` | Sets the max-age of the STS header. | | `traefik.frontend.headers.STSIncludeSubdomains=true` | Adds the `IncludeSubdomains` section of the STS header. | diff --git a/docs/configuration/backends/kubernetes.md b/docs/configuration/backends/kubernetes.md index dfb20adcc..21bbface6 100644 --- a/docs/configuration/backends/kubernetes.md +++ b/docs/configuration/backends/kubernetes.md @@ -235,6 +235,7 @@ The following security annotations are applicable on the Ingress object: | `ingress.kubernetes.io/ssl-redirect: "true"` | Forces the frontend to redirect to SSL if a non-SSL request is sent. | | `ingress.kubernetes.io/ssl-temporary-redirect: "true"` | Forces the frontend to redirect to SSL if a non-SSL request is sent, but by sending a 302 instead of a 301. | | `ingress.kubernetes.io/ssl-host: HOST` | This setting configures the hostname that redirects will be based on. Default is "", which is the same host as the request. | +| `ingress.kubernetes.io/ssl-force-host: "true"` | If `SSLForceHost` is `true` and `SSLHost` is set, requests will be forced to use `SSLHost` even the ones that are already using SSL. Default is false. | | `ingress.kubernetes.io/ssl-proxy-headers: EXPR` | Header combinations that would signify a proper SSL Request (Such as `X-Forwarded-For:https`). Format: HEADER:value||HEADER2:value2 | ### Authentication diff --git a/docs/configuration/backends/marathon.md b/docs/configuration/backends/marathon.md index b5c3a825d..5b4aa7ae7 100644 --- a/docs/configuration/backends/marathon.md +++ b/docs/configuration/backends/marathon.md @@ -242,6 +242,7 @@ The following labels can be defined on Marathon applications. They adjust the be | `traefik.frontend.headers.SSLRedirect=true` | Forces the frontend to redirect to SSL if a non-SSL request is sent. | | `traefik.frontend.headers.SSLTemporaryRedirect=true` | Forces the frontend to redirect to SSL if a non-SSL request is sent, but by sending a 302 instead of a 301. | | `traefik.frontend.headers.SSLHost=HOST` | This setting configures the hostname that redirects will be based on. Default is "", which is the same host as the request. | +| `traefik.frontend.headers.SSLForceHost=true` | If `SSLForceHost` is `true` and `SSLHost` is set, requests will be forced to use `SSLHost` even the ones that are already using SSL. Default is false. | | `traefik.frontend.headers.SSLProxyHeaders=EXPR` | Header combinations that would signify a proper SSL Request (Such as `X-Forwarded-For:https`).
Format: HEADER:value||HEADER2:value2 | | `traefik.frontend.headers.STSSeconds=315360000` | Sets the max-age of the STS header. | | `traefik.frontend.headers.STSIncludeSubdomains=true` | Adds the `IncludeSubdomains` section of the STS header. | @@ -309,6 +310,7 @@ Segment labels override the default behavior. | `traefik..frontend.headers.SSLRedirect=true` | Same as `traefik.frontend.headers.SSLRedirect` | | `traefik..frontend.headers.SSLTemporaryRedirect=true` | Same as `traefik.frontend.headers.SSLTemporaryRedirect` | | `traefik..frontend.headers.SSLHost=HOST` | Same as `traefik.frontend.headers.SSLHost` | +| `traefik..frontend.headers.SSLForceHost=true` | Same as `traefik.frontend.headers.SSLForceHost` | | `traefik..frontend.headers.SSLProxyHeaders=EXPR` | Same as `traefik.frontend.headers.SSLProxyHeaders=EXPR` | | `traefik..frontend.headers.STSSeconds=315360000` | Same as `traefik.frontend.headers.STSSeconds=315360000` | | `traefik..frontend.headers.STSIncludeSubdomains=true` | Same as `traefik.frontend.headers.STSIncludeSubdomains=true` | diff --git a/docs/configuration/backends/mesos.md b/docs/configuration/backends/mesos.md index 925db2894..1597f1b10 100644 --- a/docs/configuration/backends/mesos.md +++ b/docs/configuration/backends/mesos.md @@ -177,6 +177,7 @@ The following labels can be defined on Mesos tasks. They adjust the behavior for | `traefik.frontend.headers.SSLRedirect=true` | Forces the frontend to redirect to SSL if a non-SSL request is sent. | | `traefik.frontend.headers.SSLTemporaryRedirect=true` | Forces the frontend to redirect to SSL if a non-SSL request is sent, but by sending a 302 instead of a 301. | | `traefik.frontend.headers.SSLHost=HOST` | This setting configures the hostname that redirects will be based on. Default is "", which is the same host as the request. | +| `traefik.frontend.headers.SSLForceHost=true` | If `SSLForceHost` is `true` and `SSLHost` is set, requests will be forced to use `SSLHost` even the ones that are already using SSL. Default is false. | | `traefik.frontend.headers.SSLProxyHeaders=EXPR` | Header combinations that would signify a proper SSL Request (Such as `X-Forwarded-For:https`).
Format: HEADER:value||HEADER2:value2 | | `traefik.frontend.headers.STSSeconds=315360000` | Sets the max-age of the STS header. | | `traefik.frontend.headers.STSIncludeSubdomains=true` | Adds the `IncludeSubdomains` section of the STS header. | diff --git a/docs/configuration/backends/rancher.md b/docs/configuration/backends/rancher.md index f64cb5379..c8b689809 100644 --- a/docs/configuration/backends/rancher.md +++ b/docs/configuration/backends/rancher.md @@ -209,6 +209,7 @@ Labels can be used on task containers to override default behavior: | `traefik.frontend.headers.SSLRedirect=true` | Forces the frontend to redirect to SSL if a non-SSL request is sent. | | `traefik.frontend.headers.SSLTemporaryRedirect=true` | Forces the frontend to redirect to SSL if a non-SSL request is sent, but by sending a 302 instead of a 301. | | `traefik.frontend.headers.SSLHost=HOST` | This setting configures the hostname that redirects will be based on. Default is "", which is the same host as the request. | +| `traefik.frontend.headers.SSLForceHost=true` | If `SSLForceHost` is `true` and `SSLHost` is set, requests will be forced to use `SSLHost` even the ones that are already using SSL. Default is false. | | `traefik.frontend.headers.SSLProxyHeaders=EXPR` | Header combinations that would signify a proper SSL Request (Such as `X-Forwarded-For:https`).
Format: HEADER:value||HEADER2:value2 | | `traefik.frontend.headers.STSSeconds=315360000` | Sets the max-age of the STS header. | | `traefik.frontend.headers.STSIncludeSubdomains=true` | Adds the `IncludeSubdomains` section of the STS header. | @@ -275,6 +276,7 @@ Segment labels override the default behavior. | `traefik..frontend.headers.SSLRedirect=true` | overrides `traefik.frontend.headers.SSLRedirect` | | `traefik..frontend.headers.SSLTemporaryRedirect=true` | overrides `traefik.frontend.headers.SSLTemporaryRedirect` | | `traefik..frontend.headers.SSLHost=HOST` | overrides `traefik.frontend.headers.SSLHost` | +| `traefik..frontend.headers.SSLForceHost=true` | overrides `traefik.frontend.headers.SSLForceHost` | | `traefik..frontend.headers.SSLProxyHeaders=EXPR` | overrides `traefik.frontend.headers.SSLProxyHeaders` | | `traefik..frontend.headers.STSSeconds=315360000` | overrides `traefik.frontend.headers.STSSeconds` | | `traefik..frontend.headers.STSIncludeSubdomains=true` | overrides `traefik.frontend.headers.STSIncludeSubdomains` | diff --git a/middlewares/headers.go b/middlewares/headers.go index 0bc2cf997..741ba167a 100644 --- a/middlewares/headers.go +++ b/middlewares/headers.go @@ -1,6 +1,6 @@ package middlewares -//Middleware based on https://github.com/unrolled/secure +// Middleware based on https://github.com/unrolled/secure import ( "net/http" diff --git a/provider/consulcatalog/config_test.go b/provider/consulcatalog/config_test.go index 960f8a139..4e92f8682 100644 --- a/provider/consulcatalog/config_test.go +++ b/provider/consulcatalog/config_test.go @@ -3,7 +3,9 @@ package consulcatalog import ( "testing" "text/template" + "time" + "github.com/containous/flaeg" "github.com/containous/traefik/provider/label" "github.com/containous/traefik/types" "github.com/hashicorp/consul/api" @@ -113,6 +115,266 @@ func TestProviderBuildConfiguration(t *testing.T) { }, }, }, + { + desc: "when all labels are set", + nodes: []catalogUpdate{ + { + Service: &serviceUpdate{ + ServiceName: "test", + Attributes: []string{ + label.TraefikBackend + "=foobar", + + label.TraefikBackendCircuitBreakerExpression + "=NetworkErrorRatio() > 0.5", + label.TraefikBackendHealthCheckPath + "=/health", + label.TraefikBackendHealthCheckPort + "=880", + label.TraefikBackendHealthCheckInterval + "=6", + label.TraefikBackendHealthCheckHostname + "=foo.com", + label.TraefikBackendHealthCheckHeaders + "=Foo:bar || Bar:foo", + label.TraefikBackendLoadBalancerMethod + "=drr", + label.TraefikBackendLoadBalancerSticky + "=true", + label.TraefikBackendLoadBalancerStickiness + "=true", + label.TraefikBackendLoadBalancerStickinessCookieName + "=chocolate", + label.TraefikBackendMaxConnAmount + "=666", + label.TraefikBackendMaxConnExtractorFunc + "=client.ip", + label.TraefikBackendBufferingMaxResponseBodyBytes + "=10485760", + label.TraefikBackendBufferingMemResponseBodyBytes + "=2097152", + label.TraefikBackendBufferingMaxRequestBodyBytes + "=10485760", + label.TraefikBackendBufferingMemRequestBodyBytes + "=2097152", + label.TraefikBackendBufferingRetryExpression + "=IsNetworkError() && Attempts() <= 2", + + label.TraefikFrontendAuthBasic + "=test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/,test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0", + label.TraefikFrontendEntryPoints + "=http,https", + label.TraefikFrontendPassHostHeader + "=true", + label.TraefikFrontendPassTLSCert + "=true", + label.TraefikFrontendPriority + "=666", + label.TraefikFrontendRedirectEntryPoint + "=https", + label.TraefikFrontendRedirectRegex + "=nope", + label.TraefikFrontendRedirectReplacement + "=nope", + label.TraefikFrontendRedirectPermanent + "=true", + label.TraefikFrontendRule + "=Host:traefik.io", + label.TraefikFrontendWhiteListSourceRange + "=10.10.10.10", + label.TraefikFrontendWhiteListUseXForwardedFor + "=true", + + label.TraefikFrontendRequestHeaders + "=Access-Control-Allow-Methods:POST,GET,OPTIONS || Content-type: application/json; charset=utf-8", + label.TraefikFrontendResponseHeaders + "=Access-Control-Allow-Methods:POST,GET,OPTIONS || Content-type: application/json; charset=utf-8", + label.TraefikFrontendSSLProxyHeaders + "=Access-Control-Allow-Methods:POST,GET,OPTIONS || Content-type: application/json; charset=utf-8", + label.TraefikFrontendAllowedHosts + "=foo,bar,bor", + label.TraefikFrontendHostsProxyHeaders + "=foo,bar,bor", + label.TraefikFrontendSSLHost + "=foo", + label.TraefikFrontendCustomFrameOptionsValue + "=foo", + label.TraefikFrontendContentSecurityPolicy + "=foo", + label.TraefikFrontendPublicKey + "=foo", + label.TraefikFrontendReferrerPolicy + "=foo", + label.TraefikFrontendCustomBrowserXSSValue + "=foo", + label.TraefikFrontendSTSSeconds + "=666", + label.TraefikFrontendSSLForceHost + "=true", + label.TraefikFrontendSSLRedirect + "=true", + label.TraefikFrontendSSLTemporaryRedirect + "=true", + label.TraefikFrontendSTSIncludeSubdomains + "=true", + label.TraefikFrontendSTSPreload + "=true", + label.TraefikFrontendForceSTSHeader + "=true", + label.TraefikFrontendFrameDeny + "=true", + label.TraefikFrontendContentTypeNosniff + "=true", + label.TraefikFrontendBrowserXSSFilter + "=true", + label.TraefikFrontendIsDevelopment + "=true", + + label.Prefix + label.BaseFrontendErrorPage + "foo." + label.SuffixErrorPageStatus + "=404", + label.Prefix + label.BaseFrontendErrorPage + "foo." + label.SuffixErrorPageBackend + "=foobar", + label.Prefix + label.BaseFrontendErrorPage + "foo." + label.SuffixErrorPageQuery + "=foo_query", + label.Prefix + label.BaseFrontendErrorPage + "bar." + label.SuffixErrorPageStatus + "=500,600", + label.Prefix + label.BaseFrontendErrorPage + "bar." + label.SuffixErrorPageBackend + "=foobar", + label.Prefix + label.BaseFrontendErrorPage + "bar." + label.SuffixErrorPageQuery + "=bar_query", + + label.TraefikFrontendRateLimitExtractorFunc + "=client.ip", + label.Prefix + label.BaseFrontendRateLimit + "foo." + label.SuffixRateLimitPeriod + "=6", + label.Prefix + label.BaseFrontendRateLimit + "foo." + label.SuffixRateLimitAverage + "=12", + label.Prefix + label.BaseFrontendRateLimit + "foo." + label.SuffixRateLimitBurst + "=18", + label.Prefix + label.BaseFrontendRateLimit + "bar." + label.SuffixRateLimitPeriod + "=3", + label.Prefix + label.BaseFrontendRateLimit + "bar." + label.SuffixRateLimitAverage + "=6", + label.Prefix + label.BaseFrontendRateLimit + "bar." + label.SuffixRateLimitBurst + "=9", + }, + }, + Nodes: []*api.ServiceEntry{ + { + Service: &api.AgentService{ + Service: "test", + Address: "10.0.0.1", + Port: 80, + Tags: []string{ + label.TraefikProtocol + "=https", + label.TraefikWeight + "=12", + }, + }, + Node: &api.Node{ + Node: "localhost", + Address: "127.0.0.1", + }, + }, + { + Service: &api.AgentService{ + Service: "test", + Address: "10.0.0.2", + Port: 80, + Tags: []string{ + label.TraefikProtocol + "=https", + label.TraefikWeight + "=12", + }, + }, + Node: &api.Node{ + Node: "localhost", + Address: "127.0.0.1", + }, + }, + }, + }, + }, + expectedFrontends: map[string]*types.Frontend{ + "frontend-test": { + EntryPoints: []string{ + "http", + "https", + }, + Backend: "backend-test", + Routes: map[string]types.Route{ + "route-host-test": { + Rule: "Host:traefik.io", + }, + }, + PassHostHeader: true, + PassTLSCert: true, + Priority: 666, + BasicAuth: []string{ + "test:$apr1$H6uskkkW$IgXLP6ewTrSuBkTrqE8wj/", + "test2:$apr1$d9hr9HBB$4HxwgUir3HP4EsggP/QNo0", + }, + WhiteList: &types.WhiteList{ + SourceRange: []string{ + "10.10.10.10", + }, + UseXForwardedFor: true, + }, + Headers: &types.Headers{ + CustomRequestHeaders: map[string]string{ + "Access-Control-Allow-Methods": "POST,GET,OPTIONS", + "Content-Type": "application/json; charset=utf-8", + }, + CustomResponseHeaders: map[string]string{ + "Access-Control-Allow-Methods": "POST,GET,OPTIONS", + "Content-Type": "application/json; charset=utf-8", + }, + AllowedHosts: []string{ + "foo", + "bar", + "bor", + }, + HostsProxyHeaders: []string{ + "foo", + "bar", + "bor", + }, + SSLRedirect: true, + SSLTemporaryRedirect: true, + SSLForceHost: true, + SSLHost: "foo", + SSLProxyHeaders: map[string]string{ + "Access-Control-Allow-Methods": "POST,GET,OPTIONS", + "Content-Type": "application/json; charset=utf-8", + }, + STSSeconds: 666, + STSIncludeSubdomains: true, + STSPreload: true, + ForceSTSHeader: true, + FrameDeny: true, + CustomFrameOptionsValue: "foo", + ContentTypeNosniff: true, + BrowserXSSFilter: true, + CustomBrowserXSSValue: "foo", + ContentSecurityPolicy: "foo", + PublicKey: "foo", + ReferrerPolicy: "foo", + IsDevelopment: true, + }, + Errors: map[string]*types.ErrorPage{ + "foo": { + Status: []string{"404"}, + Query: "foo_query", + Backend: "backend-foobar", + }, + "bar": { + Status: []string{"500", "600"}, + Query: "bar_query", + Backend: "backend-foobar", + }, + }, + RateLimit: &types.RateLimit{ + ExtractorFunc: "client.ip", + RateSet: map[string]*types.Rate{ + "foo": { + Period: flaeg.Duration(6 * time.Second), + Average: 12, + Burst: 18, + }, + "bar": { + Period: flaeg.Duration(3 * time.Second), + Average: 6, + Burst: 9, + }, + }, + }, + Redirect: &types.Redirect{ + EntryPoint: "https", + Regex: "", + Replacement: "", + Permanent: true, + }, + }, + }, + expectedBackends: map[string]*types.Backend{ + "backend-test": { + Servers: map[string]types.Server{ + "test-0-N753CZ-JEP1SmRf5Wfe6S3-RuM": { + URL: "https://10.0.0.1:80", + Weight: 12, + }, + "test-1-u4RAIw2K4-PDJh41dqqB4kM2wy0": { + URL: "https://10.0.0.2:80", + Weight: 12, + }, + }, + CircuitBreaker: &types.CircuitBreaker{ + Expression: "NetworkErrorRatio() > 0.5", + }, + LoadBalancer: &types.LoadBalancer{ + Method: "drr", + Sticky: true, + Stickiness: &types.Stickiness{ + CookieName: "chocolate", + }, + }, + MaxConn: &types.MaxConn{ + Amount: 666, + ExtractorFunc: "client.ip", + }, + HealthCheck: &types.HealthCheck{ + Path: "/health", + Port: 880, + Interval: "6", + Hostname: "foo.com", + Headers: map[string]string{ + "Foo": "bar", + "Bar": "foo", + }, + }, + Buffering: &types.Buffering{ + MaxResponseBodyBytes: 10485760, + MemResponseBodyBytes: 2097152, + MaxRequestBodyBytes: 10485760, + MemRequestBodyBytes: 2097152, + RetryExpression: "IsNetworkError() && Attempts() <= 2", + }, + }, + }, + }, } for _, test := range testCases { diff --git a/provider/docker/config_container_docker_test.go b/provider/docker/config_container_docker_test.go index ed87dbb09..09c37d39b 100644 --- a/provider/docker/config_container_docker_test.go +++ b/provider/docker/config_container_docker_test.go @@ -140,6 +140,7 @@ func TestDockerBuildConfiguration(t *testing.T) { label.TraefikFrontendReferrerPolicy: "foo", label.TraefikFrontendCustomBrowserXSSValue: "foo", label.TraefikFrontendSTSSeconds: "666", + label.TraefikFrontendSSLForceHost: "true", label.TraefikFrontendSSLRedirect: "true", label.TraefikFrontendSSLTemporaryRedirect: "true", label.TraefikFrontendSTSIncludeSubdomains: "true", @@ -216,6 +217,7 @@ func TestDockerBuildConfiguration(t *testing.T) { SSLRedirect: true, SSLTemporaryRedirect: true, SSLHost: "foo", + SSLForceHost: true, SSLProxyHeaders: map[string]string{ "Access-Control-Allow-Methods": "POST,GET,OPTIONS", "Content-Type": "application/json; charset=utf-8", diff --git a/provider/docker/config_container_swarm_test.go b/provider/docker/config_container_swarm_test.go index 0a2206df0..751613049 100644 --- a/provider/docker/config_container_swarm_test.go +++ b/provider/docker/config_container_swarm_test.go @@ -148,6 +148,7 @@ func TestSwarmBuildConfiguration(t *testing.T) { label.TraefikFrontendReferrerPolicy: "foo", label.TraefikFrontendCustomBrowserXSSValue: "foo", label.TraefikFrontendSTSSeconds: "666", + label.TraefikFrontendSSLForceHost: "true", label.TraefikFrontendSSLRedirect: "true", label.TraefikFrontendSSLTemporaryRedirect: "true", label.TraefikFrontendSTSIncludeSubdomains: "true", @@ -221,6 +222,7 @@ func TestSwarmBuildConfiguration(t *testing.T) { }, SSLRedirect: true, SSLTemporaryRedirect: true, + SSLForceHost: true, SSLHost: "foo", SSLProxyHeaders: map[string]string{ "Access-Control-Allow-Methods": "POST,GET,OPTIONS", diff --git a/provider/docker/config_segment_test.go b/provider/docker/config_segment_test.go index 02e6c6311..f99060162 100644 --- a/provider/docker/config_segment_test.go +++ b/provider/docker/config_segment_test.go @@ -100,6 +100,7 @@ func TestSegmentBuildConfiguration(t *testing.T) { label.Prefix + "sauternes." + label.SuffixFrontendHeadersReferrerPolicy: "foo", label.Prefix + "sauternes." + label.SuffixFrontendHeadersCustomBrowserXSSValue: "foo", label.Prefix + "sauternes." + label.SuffixFrontendHeadersSTSSeconds: "666", + label.Prefix + "sauternes." + label.SuffixFrontendHeadersSSLForceHost: "true", label.Prefix + "sauternes." + label.SuffixFrontendHeadersSSLRedirect: "true", label.Prefix + "sauternes." + label.SuffixFrontendHeadersSSLTemporaryRedirect: "true", label.Prefix + "sauternes." + label.SuffixFrontendHeadersSTSIncludeSubdomains: "true", @@ -170,6 +171,7 @@ func TestSegmentBuildConfiguration(t *testing.T) { }, SSLRedirect: true, SSLTemporaryRedirect: true, + SSLForceHost: true, SSLHost: "foo", SSLProxyHeaders: map[string]string{ "Access-Control-Allow-Methods": "POST,GET,OPTIONS", diff --git a/provider/ecs/config_test.go b/provider/ecs/config_test.go index 796742cca..a27c37d21 100644 --- a/provider/ecs/config_test.go +++ b/provider/ecs/config_test.go @@ -175,6 +175,7 @@ func TestBuildConfiguration(t *testing.T) { label.TraefikFrontendReferrerPolicy: aws.String("foo"), label.TraefikFrontendCustomBrowserXSSValue: aws.String("foo"), label.TraefikFrontendSTSSeconds: aws.String("666"), + label.TraefikFrontendSSLForceHost: aws.String("true"), label.TraefikFrontendSSLRedirect: aws.String("true"), label.TraefikFrontendSSLTemporaryRedirect: aws.String("true"), label.TraefikFrontendSTSIncludeSubdomains: aws.String("true"), @@ -294,6 +295,7 @@ func TestBuildConfiguration(t *testing.T) { }, SSLRedirect: true, SSLTemporaryRedirect: true, + SSLForceHost: true, SSLHost: "foo", SSLProxyHeaders: map[string]string{ "Access-Control-Allow-Methods": "POST,GET,OPTIONS", diff --git a/provider/kubernetes/annotations.go b/provider/kubernetes/annotations.go index 4b254ef1a..17eb83f85 100644 --- a/provider/kubernetes/annotations.go +++ b/provider/kubernetes/annotations.go @@ -32,6 +32,7 @@ const ( annotationKubernetesBuffering = "ingress.kubernetes.io/buffering" annotationKubernetesAppRoot = "ingress.kubernetes.io/app-root" + annotationKubernetesSSLForceHost = "ingress.kubernetes.io/ssl-force-host" annotationKubernetesSSLRedirect = "ingress.kubernetes.io/ssl-redirect" annotationKubernetesHSTSMaxAge = "ingress.kubernetes.io/hsts-max-age" annotationKubernetesHSTSIncludeSubdomains = "ingress.kubernetes.io/hsts-include-subdomains" diff --git a/provider/kubernetes/kubernetes.go b/provider/kubernetes/kubernetes.go index 242b7e3f2..c7485a8b5 100644 --- a/provider/kubernetes/kubernetes.go +++ b/provider/kubernetes/kubernetes.go @@ -599,6 +599,7 @@ func getHeader(i *extensionsv1beta1.Ingress) *types.Headers { CustomResponseHeaders: getMapValue(i.Annotations, annotationKubernetesCustomResponseHeaders), AllowedHosts: getSliceStringValue(i.Annotations, annotationKubernetesAllowedHosts), HostsProxyHeaders: getSliceStringValue(i.Annotations, annotationKubernetesProxyHeaders), + SSLForceHost: getBoolValue(i.Annotations, annotationKubernetesSSLForceHost, false), SSLRedirect: getBoolValue(i.Annotations, annotationKubernetesSSLRedirect, false), SSLTemporaryRedirect: getBoolValue(i.Annotations, annotationKubernetesSSLTemporaryRedirect, false), SSLHost: getStringValue(i.Annotations, annotationKubernetesSSLHost, ""), diff --git a/provider/kubernetes/kubernetes_test.go b/provider/kubernetes/kubernetes_test.go index b86c795d2..d9b4f55b3 100644 --- a/provider/kubernetes/kubernetes_test.go +++ b/provider/kubernetes/kubernetes_test.go @@ -786,6 +786,7 @@ rateset: iAnnotation(annotationKubernetesAllowedHosts, "foo, fii, fuu"), iAnnotation(annotationKubernetesProxyHeaders, "foo, fii, fuu"), iAnnotation(annotationKubernetesHSTSMaxAge, "666"), + iAnnotation(annotationKubernetesSSLForceHost, "true"), iAnnotation(annotationKubernetesSSLRedirect, "true"), iAnnotation(annotationKubernetesSSLTemporaryRedirect, "true"), iAnnotation(annotationKubernetesHSTSIncludeSubdomains, "true"), @@ -1030,6 +1031,7 @@ rateset: AllowedHosts: []string{"foo", "fii", "fuu"}, HostsProxyHeaders: []string{"foo", "fii", "fuu"}, STSSeconds: 666, + SSLForceHost: true, SSLRedirect: true, SSLTemporaryRedirect: true, STSIncludeSubdomains: true, diff --git a/provider/kv/keynames.go b/provider/kv/keynames.go index 01a2d67e1..05fec79e4 100644 --- a/provider/kv/keynames.go +++ b/provider/kv/keynames.go @@ -53,6 +53,7 @@ const ( pathFrontendCustomResponseHeaders = "/headers/customresponseheaders/" pathFrontendAllowedHosts = "/headers/allowedhosts" pathFrontendHostsProxyHeaders = "/headers/hostsproxyheaders" + pathFrontendSSLForceHost = "/headers/sslforcehost" pathFrontendSSLRedirect = "/headers/sslredirect" pathFrontendSSLTemporaryRedirect = "/headers/ssltemporaryredirect" pathFrontendSSLHost = "/headers/sslhost" diff --git a/provider/kv/kv_config.go b/provider/kv/kv_config.go index ee962e515..6e373275e 100644 --- a/provider/kv/kv_config.go +++ b/provider/kv/kv_config.go @@ -226,6 +226,7 @@ func (p *Provider) getHeaders(rootPath string) *types.Headers { SSLProxyHeaders: p.getMap(rootPath, pathFrontendSSLProxyHeaders), AllowedHosts: p.getList("", rootPath, pathFrontendAllowedHosts), HostsProxyHeaders: p.getList(rootPath, pathFrontendHostsProxyHeaders), + SSLForceHost: p.getBool(false, rootPath, pathFrontendSSLForceHost), SSLRedirect: p.getBool(false, rootPath, pathFrontendSSLRedirect), SSLTemporaryRedirect: p.getBool(false, rootPath, pathFrontendSSLTemporaryRedirect), SSLHost: p.get("", rootPath, pathFrontendSSLHost), diff --git a/provider/kv/kv_config_test.go b/provider/kv/kv_config_test.go index 1bf28ac3f..3c99d0336 100644 --- a/provider/kv/kv_config_test.go +++ b/provider/kv/kv_config_test.go @@ -121,6 +121,7 @@ func TestProviderBuildConfiguration(t *testing.T) { withPair(pathFrontendPublicKey, "foo"), withPair(pathFrontendReferrerPolicy, "foo"), withPair(pathFrontendCustomBrowserXSSValue, "foo"), + withPair(pathFrontendSSLForceHost, "true"), withPair(pathFrontendSSLRedirect, "true"), withPair(pathFrontendSSLTemporaryRedirect, "true"), withPair(pathFrontendSTSIncludeSubdomains, "true"), @@ -254,6 +255,7 @@ func TestProviderBuildConfiguration(t *testing.T) { PublicKey: "foo", ReferrerPolicy: "foo", CustomBrowserXSSValue: "foo", + SSLForceHost: true, SSLRedirect: true, SSLTemporaryRedirect: true, STSIncludeSubdomains: true, diff --git a/provider/label/names.go b/provider/label/names.go index e34e6d5d8..e9533a38a 100644 --- a/provider/label/names.go +++ b/provider/label/names.go @@ -41,6 +41,7 @@ const ( SuffixFrontendResponseHeaders = SuffixFrontendHeaders + "customResponseHeaders" SuffixFrontendHeadersAllowedHosts = SuffixFrontendHeaders + "allowedHosts" SuffixFrontendHeadersHostsProxyHeaders = SuffixFrontendHeaders + "hostsProxyHeaders" + SuffixFrontendHeadersSSLForceHost = SuffixFrontendHeaders + "SSLForceHost" SuffixFrontendHeadersSSLRedirect = SuffixFrontendHeaders + "SSLRedirect" SuffixFrontendHeadersSSLTemporaryRedirect = SuffixFrontendHeaders + "SSLTemporaryRedirect" SuffixFrontendHeadersSSLHost = SuffixFrontendHeaders + "SSLHost" @@ -120,6 +121,7 @@ const ( TraefikFrontendResponseHeaders = Prefix + SuffixFrontendResponseHeaders TraefikFrontendAllowedHosts = Prefix + SuffixFrontendHeadersAllowedHosts TraefikFrontendHostsProxyHeaders = Prefix + SuffixFrontendHeadersHostsProxyHeaders + TraefikFrontendSSLForceHost = Prefix + SuffixFrontendHeadersSSLForceHost TraefikFrontendSSLRedirect = Prefix + SuffixFrontendHeadersSSLRedirect TraefikFrontendSSLTemporaryRedirect = Prefix + SuffixFrontendHeadersSSLTemporaryRedirect TraefikFrontendSSLHost = Prefix + SuffixFrontendHeadersSSLHost diff --git a/provider/label/partial.go b/provider/label/partial.go index 043f13652..067a5a8eb 100644 --- a/provider/label/partial.go +++ b/provider/label/partial.go @@ -190,6 +190,7 @@ func GetHeaders(labels map[string]string) *types.Headers { STSSeconds: GetInt64Value(labels, TraefikFrontendSTSSeconds, 0), SSLRedirect: GetBoolValue(labels, TraefikFrontendSSLRedirect, false), SSLTemporaryRedirect: GetBoolValue(labels, TraefikFrontendSSLTemporaryRedirect, false), + SSLForceHost: GetBoolValue(labels, TraefikFrontendSSLForceHost, false), STSIncludeSubdomains: GetBoolValue(labels, TraefikFrontendSTSIncludeSubdomains, false), STSPreload: GetBoolValue(labels, TraefikFrontendSTSPreload, false), ForceSTSHeader: GetBoolValue(labels, TraefikFrontendForceSTSHeader, false), diff --git a/provider/label/partial_test.go b/provider/label/partial_test.go index 33ad0d2b7..644c46e9f 100644 --- a/provider/label/partial_test.go +++ b/provider/label/partial_test.go @@ -606,6 +606,7 @@ func TestGetHeaders(t *testing.T) { TraefikFrontendCustomBrowserXSSValue: "foo", TraefikFrontendSTSSeconds: "666", TraefikFrontendSSLRedirect: "true", + TraefikFrontendSSLForceHost: "true", TraefikFrontendSSLTemporaryRedirect: "true", TraefikFrontendSTSIncludeSubdomains: "true", TraefikFrontendSTSPreload: "true", @@ -637,6 +638,7 @@ func TestGetHeaders(t *testing.T) { ReferrerPolicy: "foo", CustomBrowserXSSValue: "foo", STSSeconds: 666, + SSLForceHost: true, SSLRedirect: true, SSLTemporaryRedirect: true, STSIncludeSubdomains: true, diff --git a/provider/marathon/config_test.go b/provider/marathon/config_test.go index df5c8f1de..04dfffa33 100644 --- a/provider/marathon/config_test.go +++ b/provider/marathon/config_test.go @@ -209,6 +209,7 @@ func TestBuildConfiguration(t *testing.T) { withLabel(label.TraefikFrontendSSLProxyHeaders, "Access-Control-Allow-Methods:POST,GET,OPTIONS || Content-type: application/json; charset=utf-8"), withLabel(label.TraefikFrontendAllowedHosts, "foo,bar,bor"), withLabel(label.TraefikFrontendHostsProxyHeaders, "foo,bar,bor"), + withLabel(label.TraefikFrontendSSLForceHost, "true"), withLabel(label.TraefikFrontendSSLHost, "foo"), withLabel(label.TraefikFrontendCustomFrameOptionsValue, "foo"), withLabel(label.TraefikFrontendContentSecurityPolicy, "foo"), @@ -285,6 +286,7 @@ func TestBuildConfiguration(t *testing.T) { }, SSLRedirect: true, SSLTemporaryRedirect: true, + SSLForceHost: true, SSLHost: "foo", SSLProxyHeaders: map[string]string{ "Access-Control-Allow-Methods": "POST,GET,OPTIONS", @@ -581,6 +583,7 @@ func TestBuildConfigurationSegments(t *testing.T) { withSegmentLabel(label.TraefikFrontendSSLProxyHeaders, "Access-Control-Allow-Methods:POST,GET,OPTIONS || Content-type: application/json; charset=utf-8", "containous"), withSegmentLabel(label.TraefikFrontendAllowedHosts, "foo,bar,bor", "containous"), withSegmentLabel(label.TraefikFrontendHostsProxyHeaders, "foo,bar,bor", "containous"), + withSegmentLabel(label.TraefikFrontendSSLForceHost, "true", "containous"), withSegmentLabel(label.TraefikFrontendSSLHost, "foo", "containous"), withSegmentLabel(label.TraefikFrontendCustomFrameOptionsValue, "foo", "containous"), withSegmentLabel(label.TraefikFrontendContentSecurityPolicy, "foo", "containous"), @@ -657,6 +660,7 @@ func TestBuildConfigurationSegments(t *testing.T) { }, SSLRedirect: true, SSLTemporaryRedirect: true, + SSLForceHost: true, SSLHost: "foo", SSLProxyHeaders: map[string]string{ "Access-Control-Allow-Methods": "POST,GET,OPTIONS", diff --git a/provider/mesos/config_test.go b/provider/mesos/config_test.go index c8a8d7845..25c32e88d 100644 --- a/provider/mesos/config_test.go +++ b/provider/mesos/config_test.go @@ -158,6 +158,7 @@ func TestBuildConfiguration(t *testing.T) { withLabel(label.TraefikFrontendSSLProxyHeaders, "Access-Control-Allow-Methods:POST,GET,OPTIONS || Content-type:application/json; charset=utf-8"), withLabel(label.TraefikFrontendAllowedHosts, "foo,bar,bor"), withLabel(label.TraefikFrontendHostsProxyHeaders, "foo,bar,bor"), + withLabel(label.TraefikFrontendSSLForceHost, "true"), withLabel(label.TraefikFrontendSSLHost, "foo"), withLabel(label.TraefikFrontendCustomFrameOptionsValue, "foo"), withLabel(label.TraefikFrontendContentSecurityPolicy, "foo"), @@ -240,6 +241,7 @@ func TestBuildConfiguration(t *testing.T) { }, SSLRedirect: true, SSLTemporaryRedirect: true, + SSLForceHost: true, SSLHost: "foo", SSLProxyHeaders: map[string]string{ "Access-Control-Allow-Methods": "POST,GET,OPTIONS", diff --git a/provider/rancher/config_test.go b/provider/rancher/config_test.go index a62a49349..9db9ac6ba 100644 --- a/provider/rancher/config_test.go +++ b/provider/rancher/config_test.go @@ -83,6 +83,7 @@ func TestProviderBuildConfiguration(t *testing.T) { label.TraefikFrontendReferrerPolicy: "foo", label.TraefikFrontendCustomBrowserXSSValue: "foo", label.TraefikFrontendSTSSeconds: "666", + label.TraefikFrontendSSLForceHost: "true", label.TraefikFrontendSSLRedirect: "true", label.TraefikFrontendSSLTemporaryRedirect: "true", label.TraefikFrontendSTSIncludeSubdomains: "true", @@ -158,6 +159,7 @@ func TestProviderBuildConfiguration(t *testing.T) { }, SSLRedirect: true, SSLTemporaryRedirect: true, + SSLForceHost: true, SSLHost: "foo", SSLProxyHeaders: map[string]string{ "Access-Control-Allow-Methods": "POST,GET,OPTIONS", @@ -292,6 +294,7 @@ func TestProviderBuildConfiguration(t *testing.T) { label.Prefix + "sauternes." + label.SuffixFrontendHeadersReferrerPolicy: "foo", label.Prefix + "sauternes." + label.SuffixFrontendHeadersCustomBrowserXSSValue: "foo", label.Prefix + "sauternes." + label.SuffixFrontendHeadersSTSSeconds: "666", + label.Prefix + "sauternes." + label.SuffixFrontendHeadersSSLForceHost: "true", label.Prefix + "sauternes." + label.SuffixFrontendHeadersSSLRedirect: "true", label.Prefix + "sauternes." + label.SuffixFrontendHeadersSSLTemporaryRedirect: "true", label.Prefix + "sauternes." + label.SuffixFrontendHeadersSTSIncludeSubdomains: "true", @@ -356,6 +359,7 @@ func TestProviderBuildConfiguration(t *testing.T) { HostsProxyHeaders: []string{"foo", "bar", "bor"}, SSLRedirect: true, SSLTemporaryRedirect: true, + SSLForceHost: true, SSLHost: "foo", SSLProxyHeaders: map[string]string{ "Access-Control-Allow-Methods": "POST,GET,OPTIONS", diff --git a/templates/consul_catalog.tmpl b/templates/consul_catalog.tmpl index 49f5d1d49..a1c91805d 100644 --- a/templates/consul_catalog.tmpl +++ b/templates/consul_catalog.tmpl @@ -127,6 +127,7 @@ SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLHost = "{{ $headers.SSLHost }}" + SSLForceHost = {{ $headers.SSLForceHost }} STSSeconds = {{ $headers.STSSeconds }} STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }} STSPreload = {{ $headers.STSPreload }} diff --git a/templates/docker.tmpl b/templates/docker.tmpl index ab9eb3ba0..9df0f3e19 100644 --- a/templates/docker.tmpl +++ b/templates/docker.tmpl @@ -128,6 +128,7 @@ SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLHost = "{{ $headers.SSLHost }}" + SSLForceHost = {{ $headers.SSLForceHost }} STSSeconds = {{ $headers.STSSeconds }} STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }} STSPreload = {{ $headers.STSPreload }} diff --git a/templates/ecs.tmpl b/templates/ecs.tmpl index 8c5ba15f6..11c5e97d5 100644 --- a/templates/ecs.tmpl +++ b/templates/ecs.tmpl @@ -127,6 +127,7 @@ SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLHost = "{{ $headers.SSLHost }}" + SSLForceHost = {{ $headers.SSLForceHost }} STSSeconds = {{ $headers.STSSeconds }} STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }} STSPreload = {{ $headers.STSPreload }} diff --git a/templates/kubernetes.tmpl b/templates/kubernetes.tmpl index e6af7b43a..ef259d8a5 100644 --- a/templates/kubernetes.tmpl +++ b/templates/kubernetes.tmpl @@ -100,6 +100,7 @@ SSLRedirect = {{ $frontend.Headers.SSLRedirect }} SSLTemporaryRedirect = {{ $frontend.Headers.SSLTemporaryRedirect }} SSLHost = "{{ $frontend.Headers.SSLHost }}" + SSLForceHost = {{ $frontend.Headers.SSLForceHost }} STSSeconds = {{ $frontend.Headers.STSSeconds }} STSIncludeSubdomains = {{ $frontend.Headers.STSIncludeSubdomains }} STSPreload = {{ $frontend.Headers.STSPreload }} diff --git a/templates/kv.tmpl b/templates/kv.tmpl index 3faf1bcf3..cf77aee2a 100644 --- a/templates/kv.tmpl +++ b/templates/kv.tmpl @@ -127,6 +127,7 @@ SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLHost = "{{ $headers.SSLHost }}" + SSLForceHost = {{ $headers.SSLForceHost }} STSSeconds = {{ $headers.STSSeconds }} STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }} STSPreload = {{ $headers.STSPreload }} diff --git a/templates/marathon.tmpl b/templates/marathon.tmpl index 51f393c92..e8185be01 100644 --- a/templates/marathon.tmpl +++ b/templates/marathon.tmpl @@ -130,6 +130,7 @@ SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLHost = "{{ $headers.SSLHost }}" + SSLForceHost = {{ $headers.SSLForceHost }} STSSeconds = {{ $headers.STSSeconds }} STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }} STSPreload = {{ $headers.STSPreload }} diff --git a/templates/mesos.tmpl b/templates/mesos.tmpl index 7a7f0d486..a29f0d324 100644 --- a/templates/mesos.tmpl +++ b/templates/mesos.tmpl @@ -130,6 +130,7 @@ SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLHost = "{{ $headers.SSLHost }}" + SSLForceHost = {{ $headers.SSLForceHost }} STSSeconds = {{ $headers.STSSeconds }} STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }} STSPreload = {{ $headers.STSPreload }} diff --git a/templates/rancher.tmpl b/templates/rancher.tmpl index aaa611f65..8887ded47 100644 --- a/templates/rancher.tmpl +++ b/templates/rancher.tmpl @@ -128,6 +128,7 @@ SSLRedirect = {{ $headers.SSLRedirect }} SSLTemporaryRedirect = {{ $headers.SSLTemporaryRedirect }} SSLHost = "{{ $headers.SSLHost }}" + SSLForceHost = {{ $headers.SSLForceHost }} STSSeconds = {{ $headers.STSSeconds }} STSIncludeSubdomains = {{ $headers.STSIncludeSubdomains }} STSPreload = {{ $headers.STSPreload }} diff --git a/types/types.go b/types/types.go index e9c554830..1557e7272 100644 --- a/types/types.go +++ b/types/types.go @@ -119,14 +119,16 @@ type RateLimit struct { // Headers holds the custom header configuration type Headers struct { - CustomRequestHeaders map[string]string `json:"customRequestHeaders,omitempty"` - CustomResponseHeaders map[string]string `json:"customResponseHeaders,omitempty"` + CustomRequestHeaders map[string]string `json:"customRequestHeaders,omitempty"` + CustomResponseHeaders map[string]string `json:"customResponseHeaders,omitempty"` + AllowedHosts []string `json:"allowedHosts,omitempty"` HostsProxyHeaders []string `json:"hostsProxyHeaders,omitempty"` SSLRedirect bool `json:"sslRedirect,omitempty"` SSLTemporaryRedirect bool `json:"sslTemporaryRedirect,omitempty"` SSLHost string `json:"sslHost,omitempty"` SSLProxyHeaders map[string]string `json:"sslProxyHeaders,omitempty"` + SSLForceHost bool `json:"sslForceHost,omitempty"` STSSeconds int64 `json:"stsSeconds,omitempty"` STSIncludeSubdomains bool `json:"stsIncludeSubdomains,omitempty"` STSPreload bool `json:"stsPreload,omitempty"` @@ -154,6 +156,7 @@ func (h *Headers) HasSecureHeadersDefined() bool { len(h.HostsProxyHeaders) != 0 || h.SSLRedirect || h.SSLTemporaryRedirect || + h.SSLForceHost || h.SSLHost != "" || len(h.SSLProxyHeaders) != 0 || h.STSSeconds != 0 || diff --git a/vendor/github.com/unrolled/secure/secure.go b/vendor/github.com/unrolled/secure/secure.go index 29ca8d93a..0f8c58017 100644 --- a/vendor/github.com/unrolled/secure/secure.go +++ b/vendor/github.com/unrolled/secure/secure.go @@ -27,7 +27,7 @@ const ( cspNonceSize = 16 ) -// a type whose pointer is the type of field `SSLHostFunc` of `Options` struct +// SSLHostFunc a type whose pointer is the type of field `SSLHostFunc` of `Options` struct type SSLHostFunc func(host string) (newHost string) func defaultBadHostHandler(w http.ResponseWriter, r *http.Request) { @@ -36,16 +36,47 @@ func defaultBadHostHandler(w http.ResponseWriter, r *http.Request) { // Options is a struct for specifying configuration options for the secure.Secure middleware. type Options struct { + // If BrowserXssFilter is true, adds the X-XSS-Protection header with the value `1; mode=block`. Default is false. + BrowserXssFilter bool // nolint: golint + // If ContentTypeNosniff is true, adds the X-Content-Type-Options header with the value `nosniff`. Default is false. + ContentTypeNosniff bool + // If ForceSTSHeader is set to true, the STS header will be added even when the connection is HTTP. Default is false. + ForceSTSHeader bool + // If FrameDeny is set to true, adds the X-Frame-Options header with the value of `DENY`. Default is false. + FrameDeny bool + // When developing, the AllowedHosts, SSL, and STS options can cause some unwanted effects. Usually testing happens on http, not https, and on localhost, not your production domain... so set this to true for dev environment. + // If you would like your development environment to mimic production with complete Host blocking, SSL redirects, and STS headers, leave this as false. Default if false. + IsDevelopment bool + // nonceEnabled is used internally for dynamic nouces. + nonceEnabled bool + // If SSLRedirect is set to true, then only allow https requests. Default is false. + SSLRedirect bool + // If SSLForceHost is true and SSLHost is set, requests will be forced to use SSLHost even the ones that are already using SSL. Default is false. + SSLForceHost bool + // If SSLTemporaryRedirect is true, the a 302 will be used while redirecting. Default is false (301). + SSLTemporaryRedirect bool + // If STSIncludeSubdomains is set to true, the `includeSubdomains` will be appended to the Strict-Transport-Security header. Default is false. + STSIncludeSubdomains bool + // If STSPreload is set to true, the `preload` flag will be appended to the Strict-Transport-Security header. Default is false. + STSPreload bool + // ContentSecurityPolicy allows the Content-Security-Policy header value to be set with a custom value. Default is "". + ContentSecurityPolicy string + // CustomBrowserXssValue allows the X-XSS-Protection header value to be set with a custom value. This overrides the BrowserXssFilter option. Default is "". + CustomBrowserXssValue string // nolint: golint + // Passing a template string will replace `$NONCE` with a dynamic nonce value of 16 bytes for each request which can be later retrieved using the Nonce function. + // Eg: script-src $NONCE -> script-src 'nonce-a2ZobGFoZg==' + // CustomFrameOptionsValue allows the X-Frame-Options header value to be set with a custom value. This overrides the FrameDeny option. Default is "". + CustomFrameOptionsValue string + // PublicKey implements HPKP to prevent MITM attacks with forged certificates. Default is "". + PublicKey string + // ReferrerPolicy allows sites to control when browsers will pass the Referer header to other sites. Default is "". + ReferrerPolicy string + // SSLHost is the host name that is used to redirect http requests to https. Default is "", which indicates to use the same host. + SSLHost string // AllowedHosts is a list of fully qualified domain names that are allowed. Default is empty list, which allows any and all host names. AllowedHosts []string // HostsProxyHeaders is a set of header keys that may hold a proxied hostname value for the request. HostsProxyHeaders []string - // If SSLRedirect is set to true, then only allow https requests. Default is false. - SSLRedirect bool - // If SSLTemporaryRedirect is true, the a 302 will be used while redirecting. Default is false (301). - SSLTemporaryRedirect bool - // SSLHost is the host name that is used to redirect http requests to https. Default is "", which indicates to use the same host. - SSLHost string // SSLHostFunc is a function pointer, the return value of the function is the host name that has same functionality as `SSHost`. Default is nil. // If SSLHostFunc is nil, the `SSLHost` option will be used. SSLHostFunc *SSLHostFunc @@ -53,35 +84,6 @@ type Options struct { SSLProxyHeaders map[string]string // STSSeconds is the max-age of the Strict-Transport-Security header. Default is 0, which would NOT include the header. STSSeconds int64 - // If STSIncludeSubdomains is set to true, the `includeSubdomains` will be appended to the Strict-Transport-Security header. Default is false. - STSIncludeSubdomains bool - // If STSPreload is set to true, the `preload` flag will be appended to the Strict-Transport-Security header. Default is false. - STSPreload bool - // If ForceSTSHeader is set to true, the STS header will be added even when the connection is HTTP. Default is false. - ForceSTSHeader bool - // If FrameDeny is set to true, adds the X-Frame-Options header with the value of `DENY`. Default is false. - FrameDeny bool - // CustomFrameOptionsValue allows the X-Frame-Options header value to be set with a custom value. This overrides the FrameDeny option. Default is "". - CustomFrameOptionsValue string - // If ContentTypeNosniff is true, adds the X-Content-Type-Options header with the value `nosniff`. Default is false. - ContentTypeNosniff bool - // If BrowserXssFilter is true, adds the X-XSS-Protection header with the value `1; mode=block`. Default is false. - BrowserXssFilter bool - // CustomBrowserXssValue allows the X-XSS-Protection header value to be set with a custom value. This overrides the BrowserXssFilter option. Default is "". - CustomBrowserXssValue string - // ContentSecurityPolicy allows the Content-Security-Policy header value to be set with a custom value. Default is "". - // Passing a template string will replace `$NONCE` with a dynamic nonce value of 16 bytes for each request which can be later retrieved using the Nonce function. - // Eg: script-src $NONCE -> script-src 'nonce-a2ZobGFoZg==' - ContentSecurityPolicy string - // PublicKey implements HPKP to prevent MITM attacks with forged certificates. Default is "". - PublicKey string - // ReferrerPolicy allows sites to control when browsers will pass the Referer header to other sites. Default is "". - ReferrerPolicy string - // When developing, the AllowedHosts, SSL, and STS options can cause some unwanted effects. Usually testing happens on http, not https, and on localhost, not your production domain... so set this to true for dev environment. - // If you would like your development environment to mimic production with complete Host blocking, SSL redirects, and STS headers, leave this as false. Default if false. - IsDevelopment bool - // nonceEnabled is used internally for dynamic nouces. - nonceEnabled bool } // Secure is a middleware that helps setup a few basic security features. A single secure.Options struct can be @@ -266,6 +268,30 @@ func (s *Secure) processRequest(w http.ResponseWriter, r *http.Request) (http.He return nil, fmt.Errorf("redirecting to HTTPS") } + if s.opt.SSLForceHost { + var SSLHost = host; + if s.opt.SSLHostFunc != nil { + if h := (*s.opt.SSLHostFunc)(host); len(h) > 0 { + SSLHost = h + } + } else if len(s.opt.SSLHost) > 0 { + SSLHost = s.opt.SSLHost + } + if SSLHost != host { + url := r.URL + url.Scheme = "https" + url.Host = SSLHost + + status := http.StatusMovedPermanently + if s.opt.SSLTemporaryRedirect { + status = http.StatusTemporaryRedirect + } + + http.Redirect(w, r, url.String(), status) + return nil, fmt.Errorf("redirecting to HTTPS") + } + } + // Create our header container. responseHeader := make(http.Header)