Skip to content

Commit

Permalink
Generate host acl correctly for * host
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalsaha committed Dec 28, 2017
1 parent e89ad35 commit bea0796
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
7 changes: 4 additions & 3 deletions hack/docker/voyager/templates/http-frontend.cfg
Expand Up @@ -73,10 +73,11 @@ frontend {{ .FrontendName }}
acl is_proxy_https hdr(X-Forwarded-Proto) https

{{ range $host := .Hosts }}
{{ if and (or (eq $.Port 80) (eq $.Port 443)) ( or $.ForceMatchServicePort (not $.NodePort)) }}
{{ if $host.Host }}acl host_acl_{{ $host.Host | acl_name }} {{ $host.Host | host_name }}{{ end }}
{{ with $conditions := (host_acls $host.Host $.Port $.NodePort $.ForceMatchServicePort ) }}
{{ range $cond := $conditions }}
{{ if $cond }}acl host_acl_{{ $host.Host | acl_name }} {{ $cond }}{{ end }}
{{ end }}
{{ end }}
{{ if $host.Host }}acl host_acl_{{ $host.Host | acl_name }} {{ $host.Host | host_name }}{{ if and (not $.ForceMatchServicePort) $.NodePort }}:{{ $.NodePort }}{{ else }}:{{ $.Port }}{{ end }}{{ end }}
{{ range $path := $host.Paths }}
{{ if $path.Path }}acl url_acl_{{ $host.Host | acl_name }}_{{ $path.Path | acl_name }} path_beg {{ $path.Path }}{{ end }}
{{ if $path.SSLRedirect }}
Expand Down
31 changes: 31 additions & 0 deletions pkg/haproxy/template.go
Expand Up @@ -35,6 +35,36 @@ func HeaderName(v string) string {
return v[:index]
}

func HostACLs(host string, port, nodePort int, forceSvcPort bool) []string {
/*
{{ if and (or (eq $.Port 80) (eq $.Port 443)) ( or $.ForceMatchServicePort (not $.NodePort)) }}
{{ if $host.Host }}acl host_acl_{{ $host.Host | acl_name }} {{ $host.Host | host_name }}{{ end }}
{{ end }}
{{ if $host.Host }}acl host_acl_{{ $host.Host | acl_name }} {{ $host.Host | host_name }}{{ if and (not $.ForceMatchServicePort) $.NodePort }}:{{ $.NodePort }}{{ else }}:{{ $.Port }}{{ end }}{{ end }}
*/
var conditions []string

if (port == 80 || port == 443) && forceSvcPort {
hostname := hostName(host)
if hostname != "" {
conditions = append(conditions, hostname)
}
}
if forceSvcPort && port > 0 {
hostname := hostName(fmt.Sprintf("host:%d", port))
if hostname != "" {
conditions = append(conditions, hostname)
}
}
if !forceSvcPort && nodePort > 0 {
hostname := hostName(fmt.Sprintf("host:%d", nodePort))
if hostname != "" {
conditions = append(conditions, hostname)
}
}
return conditions
}

func HostName(v string) string {
v = strings.TrimSpace(v)
if v == "" || v == `*` {
Expand Down Expand Up @@ -64,6 +94,7 @@ var (
"acl_name": ACLName,
"header_name": HeaderName,
"host_name": HostName,
"host_acls": HostACLs,
"backend_hash": BackendHash,
}

Expand Down

0 comments on commit bea0796

Please sign in to comment.