Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ssl-redirect-code global config key #511

Merged
merged 1 commit into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/content/en/docs/configuration/keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ The table below describes all supported configuration keys.
| [`ssl-passthrough`](#ssl-passthrough) | [true\|false] | Host | |
| [`ssl-passthrough-http-port`](#ssl-passthrough) | backend port | Host | |
| [`ssl-redirect`](#ssl-redirect) | [true\|false] | Backend | `true` |
| [`ssl-redirect-code`](#ssl-redirect) | http status code | Global | `302` |
| [`stats-auth`](#stats) | user:passwd | Global | no auth |
| [`stats-port`](#stats) | port number | Global | `1936` |
| [`stats-proxy-protocol`](#stats) | [true\|false] | Global | `false` |
Expand Down Expand Up @@ -1503,12 +1504,18 @@ If using SSL passthrough, only root `/` path is supported.
|-----------------------------|-----------|-------------------------------|-------|
| `no-tls-redirect-locations` | `Global` | `/.well-known/acme-challenge` | |
| `ssl-redirect` | `Backend` | `true` | |
| `ssl-redirect-code` | `Global` | `302` | v0.10 |

Configures if an encripted connection should be used.

* `ssl-redirect`: Defines if HAProxy should send a `302 redirect` response to requests made on unencripted connections. Note that this configuration will only make effect if TLS is [configured](https://github.com/jcmoraisjr/haproxy-ingress/tree/master/examples/tls-termination).
* `ssl-redirect-code`: Defines the HTTP status code used in the redirect. The default value is `302` if not declared. Supported values are `301`, `302`, `303`, `307` and `308`.
* `no-tls-redirect-locations`: Defines a comma-separated list of URLs that should be removed from the TLS redirect. Requests to `:80` http port and starting with one of the URLs from the list will not be redirected to https despite of the TLS redirect configuration. This option defaults to `/.well-known/acme-challenge`, used by ACME protocol.

See also:

* http://cbonte.github.io/haproxy-dconv/2.0/configuration.html#redirect

---

## Stats
Expand Down
1 change: 1 addition & 0 deletions pkg/converters/ingress/annotations/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func (c *updater) UpdateGlobalConfig(haproxyConfig haproxy.Config, mapper *Mappe
d.global.Cookie.Key = mapper.Get(ingtypes.GlobalCookieKey).Value
d.global.LoadServerState = mapper.Get(ingtypes.GlobalLoadServerState).Bool()
d.global.SSL.ALPN = mapper.Get(ingtypes.GlobalTLSALPN).Value
d.global.SSL.RedirectCode = mapper.Get(ingtypes.GlobalSSLRedirectCode).Int()
d.global.StrictHost = mapper.Get(ingtypes.GlobalStrictHost).Bool()
d.global.UseChroot = mapper.Get(ingtypes.GlobalUseChroot).Bool()
d.global.UseHAProxyUser = mapper.Get(ingtypes.GlobalUseHAProxyUser).Bool()
Expand Down
1 change: 1 addition & 0 deletions pkg/converters/ingress/types/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const (
GlobalSSLHeadersPrefix = "ssl-headers-prefix"
GlobalSSLModeAsync = "ssl-mode-async"
GlobalSSLOptions = "ssl-options"
GlobalSSLRedirectCode = "ssl-redirect-code"
GlobalStatsAuth = "stats-auth"
GlobalStatsPort = "stats-port"
GlobalStatsProxyProtocol = "stats-proxy-protocol"
Expand Down
11 changes: 10 additions & 1 deletion pkg/haproxy/instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,8 @@ func TestInstanceSSLRedirect(t *testing.T) {
h.AddPath(b, "/")
b.SSLRedirect = b.CreateConfigBool(true)

c.config.Global().SSL.RedirectCode = 301

c.Update()
c.checkConfig(`
<<global>>
Expand All @@ -1731,7 +1733,14 @@ backend d2_app-front_8080
mode http
server s21 172.17.0.121:8080 weight 100
<<backends-default>>
<<frontend-http>>
frontend _front_http
mode http
bind :80
http-request set-var(req.base) base,lower,regsub(:[0-9]+/,/)
http-request redirect scheme https code 301 if { var(req.base),map_beg(/etc/haproxy/maps/_global_https_redir.map) yes }
<<http-headers>>
http-request set-var(req.backend) var(req.base),map_beg(/etc/haproxy/maps/_global_http_front.map)
use_backend %[var(req.backend)] if { var(req.backend) -m found }
default_backend _error404
<<frontend-https>>
default_backend _error404
Expand Down
1 change: 1 addition & 0 deletions pkg/haproxy/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ type SSLConfig struct {
HeadersPrefix string
ModeAsync bool
Options string
RedirectCode int
}

// DHParamConfig ...
Expand Down
8 changes: 6 additions & 2 deletions rootfs/etc/haproxy/template/haproxy.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,9 @@ frontend _front_http

{{- /*------------------------------------*/}}
{{- if $hasFrontingProxy }}
http-request redirect scheme https if
{{- "" }} fronting-proxy !{ hdr(X-Forwarded-Proto) https }
http-request redirect scheme https
{{- if $global.SSL.RedirectCode }} code {{ $global.SSL.RedirectCode }}{{ end }}
{{- "" }} if fronting-proxy !{ hdr(X-Forwarded-Proto) https }
{{- end }}

{{- /*------------------------------------*/}}
Expand All @@ -722,16 +723,19 @@ frontend _front_http
{{- "" }} var(req.base),map_beg({{ $fgroup.HTTPSRedirMap.MatchFile }})
{{- if $hasFrontingProxy }} if !fronting-proxy{{ end }}
http-request redirect scheme https
{{- if $global.SSL.RedirectCode }} code {{ $global.SSL.RedirectCode }}{{ end }}
{{- "" }} if{{ if $acmeexclusive }} !acme-challenge{{ end }}
{{- if $hasFrontingProxy }} !fronting-proxy{{ end }}
{{- "" }} { var(req.redir) yes }
http-request redirect scheme https
{{- if $global.SSL.RedirectCode }} code {{ $global.SSL.RedirectCode }}{{ end }}
{{- "" }} if{{ if $acmeexclusive }} !acme-challenge{{ end }}
{{- if $hasFrontingProxy }} !fronting-proxy{{ end }}
{{- "" }} !{ var(req.redir) -m found }
{{- "" }} { var(req.base),map_reg({{ $fgroup.HTTPSRedirMap.RegexFile }}) yes }
{{- else }}
http-request redirect scheme https
{{- if $global.SSL.RedirectCode }} code {{ $global.SSL.RedirectCode }}{{ end }}
{{- "" }} if{{ if $acmeexclusive }} !acme-challenge{{ end }}
{{- if $hasFrontingProxy }} !fronting-proxy{{ end }}
{{- "" }} { var(req.base),map_beg({{ $fgroup.HTTPSRedirMap.MatchFile }}) yes }
Expand Down