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 wildcard hostnames on SSL passthrough config #187

Merged
merged 1 commit into from
Jul 15, 2018
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
17 changes: 17 additions & 0 deletions pkg/controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type haConfig struct {
userlists map[string]types.Userlist
haServers []*types.HAProxyServer
haDefaultServer *types.HAProxyServer
haPassthrough []*types.HAProxyPassthrough
haproxyConfig *types.HAProxyConfig
}

Expand All @@ -71,6 +72,7 @@ func newControllerConfig(ingressConfig *ingress.Configuration, haproxyController
TCPEndpoints: cfg.ingress.TCPEndpoints,
UDPEndpoints: cfg.ingress.UDPEndpoints,
PassthroughBackends: cfg.ingress.PassthroughBackends,
HAPassthrough: cfg.haPassthrough,
Cfg: cfg.haproxyConfig,
}, nil
}
Expand Down Expand Up @@ -172,7 +174,16 @@ func configForwardfor(conf *types.HAProxyConfig) {

func (cfg *haConfig) createHAProxyServers() {
haServers := make([]*types.HAProxyServer, 0, len(cfg.ingress.Servers))
haPassthrough := make([]*types.HAProxyPassthrough, 0, len(cfg.ingress.PassthroughBackends))
var haDefaultServer *types.HAProxyServer
for _, server := range cfg.ingress.PassthroughBackends {
haServer := &types.HAProxyPassthrough{
Hostname: server.Hostname,
Backend: server.Backend,
HostnameIsWildcard: idHasWildcard(server.Hostname),
}
haPassthrough = append(haPassthrough, haServer)
}
for _, server := range cfg.ingress.Servers {
if server.SSLPassthrough {
// remove SSLPassthrough hosts from haServers array
Expand Down Expand Up @@ -227,7 +238,13 @@ func (cfg *haConfig) createHAProxyServers() {
}
return a < b
})
sort.SliceStable(haPassthrough, func(i, j int) bool {
// Move hosts without wildcard to the top
// if not isWildcard means priority, if isWildcard means less priority
return !haPassthrough[i].HostnameIsWildcard && haPassthrough[j].HostnameIsWildcard
})
cfg.haServers = haServers
cfg.haPassthrough = haPassthrough
cfg.haDefaultServer = haDefaultServer
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type (
TCPEndpoints []ingress.L4Service
UDPEndpoints []ingress.L4Service
PassthroughBackends []*ingress.SSLPassthroughBackend
HAPassthrough []*HAProxyPassthrough
Cfg *HAProxyConfig
BackendSlots map[string]*HAProxyBackendSlots
}
Expand Down Expand Up @@ -146,6 +147,12 @@ type (
HAWhitelist string `json:"whitelist,omitempty"`
HARateLimitWhiteList string `json:"rateLimitWhiteList,omitempty"`
}
// HAProxyPassthrough has SSL passthrough configurations
HAProxyPassthrough struct {
Hostname string `json:"hostname"`
Backend string `json:"backend"`
HostnameIsWildcard bool `json:"hostnameIsWildcard"`
}
// HAProxyBackendSlots contains used and empty backend server definitions
HAProxyBackendSlots struct {
// map from ip:port to server name
Expand Down
6 changes: 5 additions & 1 deletion rootfs/etc/haproxy/template/haproxy.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,13 @@ frontend httpsfront
{{- end }}
{{- end }}

{{- range $server := $ing.PassthroughBackends }}
{{- range $server := $ing.HAPassthrough }}
{{- if $server.HostnameIsWildcard }}
use_backend {{ $server.Backend }} if { req.ssl_sni -m reg -i {{ hostnameRegex $server.Hostname }} }
{{- else }}
use_backend {{ $server.Backend }} if { req.ssl_sni -i {{ $server.Hostname }} }
{{- end }}
{{- end }}

{{- range $server := $ing.HAServers }}
{{- if $server.IsCACert }}
Expand Down