Skip to content

Commit

Permalink
Add wildcard hostnames on ssl passthrough config
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmoraisjr committed Jul 15, 2018
1 parent dae1259 commit 23d9bfd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
15 changes: 15 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,11 @@ func (cfg *haConfig) createHAProxyServers() {
}
return a < b
})
sort.SliceStable(haPassthrough, func(i, j int) bool {
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

0 comments on commit 23d9bfd

Please sign in to comment.