Skip to content

Commit 9be0041

Browse files
committed
MEDIUM: revise SSL redirection if redirecting to default HTTPS port
* The default for the controller is to generate redirects to port 8443, as this port can be bound to in a rootless container. * Running the container in a Kubernetes setting having a service port mapping to port 443 introduces the need to change this default configuration. * Having the default HTTPS port 443 appended to the redirect breaks certain caching behaviors and is thus not ideal. * This commit aims to purely switch the scheme from HTTP to HTTPS without changing anything else about the request, the only user visible change being that the :443 in the redirect URL is no longer visible. * fixes #642
1 parent 7915350 commit 9be0041

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

pkg/haproxy/rules/reqRequestRedirect.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type RequestRedirect struct {
1818
SSLRedirect bool
1919
}
2020

21+
const DefaultHTTPSPort = 443
22+
2123
func (r RequestRedirect) GetType() Type {
2224
return REQ_REDIRECT
2325
}
@@ -37,14 +39,18 @@ func (r RequestRedirect) Create(client api.HAProxyClient, frontend *models.Front
3739
}
3840

3941
func (r RequestRedirect) sslRedirect() models.HTTPRequestRule {
40-
rule := fmt.Sprintf("https://%%[hdr(host),field(1,:)]:%d%%[capture.req.uri]", r.RedirectPort)
4142
httpRule := models.HTTPRequestRule{
42-
Type: "redirect",
43-
RedirCode: utils.PtrInt64(r.RedirectCode),
44-
RedirValue: rule,
45-
RedirType: "location",
43+
Type: "redirect",
44+
RedirCode: utils.PtrInt64(r.RedirectCode),
45+
}
46+
if r.RedirectPort == DefaultHTTPSPort {
47+
httpRule.RedirType = "scheme"
48+
httpRule.RedirValue = "https"
49+
} else {
50+
rule := fmt.Sprintf("https://%%[hdr(host),field(1,:)]:%d%%[capture.req.uri]", r.RedirectPort)
51+
httpRule.RedirType = "location"
52+
httpRule.RedirValue = rule
4653
}
47-
4854
return httpRule
4955
}
5056

0 commit comments

Comments
 (0)