Skip to content

Commit

Permalink
Change haproxy router to use a certificate list/map file.
Browse files Browse the repository at this point in the history
  • Loading branch information
ramr committed Oct 6, 2016
1 parent 01c20d0 commit 5ce393c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion images/router/haproxy/Dockerfile
Expand Up @@ -16,7 +16,7 @@ RUN INSTALL_PKGS="haproxy" && \
yum clean all && \
mkdir -p /var/lib/haproxy/router/{certs,cacerts} && \
mkdir -p /var/lib/haproxy/{conf,run,bin,log} && \
touch /var/lib/haproxy/conf/{{os_http_be,os_edge_http_be,os_tcp_be,os_sni_passthrough,os_reencrypt,os_edge_http_expose,os_edge_http_redirect}.map,haproxy.config} && \
touch /var/lib/haproxy/conf/{{os_http_be,os_edge_http_be,os_tcp_be,os_sni_passthrough,os_reencrypt,os_edge_http_expose,os_edge_http_redirect,cert_config}.map,haproxy.config} && \
chmod -R 777 /var && \
setcap 'cap_net_bind_service=ep' /usr/sbin/haproxy

Expand Down
24 changes: 22 additions & 2 deletions images/router/haproxy/conf/haproxy-config.template
Expand Up @@ -148,7 +148,7 @@ backend be_sni

frontend fe_sni
# terminate ssl on edge
bind 127.0.0.1:{{env "ROUTER_SERVICE_SNI_PORT" "10444"}} ssl no-sslv3 {{ if (len .DefaultCertificate) gt 0 }}crt {{.DefaultCertificate}}{{ else }}crt /var/lib/haproxy/conf/default_pub_keys.pem{{ end }} crt {{ $workingDir }}/certs accept-proxy
bind 127.0.0.1:{{env "ROUTER_SERVICE_SNI_PORT" "10444"}} ssl no-sslv3 {{ if (len .DefaultCertificate) gt 0 }}crt {{.DefaultCertificate}}{{ else }}crt /var/lib/haproxy/conf/default_pub_keys.pem{{ end }} crt-list /var/lib/haproxy/conf/cert_config.map accept-proxy
mode http

# Remove port from Host header
Expand Down Expand Up @@ -548,4 +548,24 @@ backend be_secure_{{$cfgIdx}}
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
{{ end }}
{{ end }}
{{ end }}{{/* end reencrypt passthrough map template */}}
{{ end }}{{/* end reencrypt map template */}}

{{/*
cert_config.map: contains a mapping of <cert-file> -> example.org
This map is used to present the appropriate cert
based on the sni header.
Note: It is sort of a reverse map for our case but the order
"<cert>: <domain-set>" is important as this allows us to use
wildcards and/or use a deny set with !<domain> in the future.
*/}}
{{ define "/var/lib/haproxy/conf/cert_config.map" }}
{{ $workingDir := .WorkingDir }}
{{ range $idx, $cfg := .State }}
{{ if and (ne $cfg.Host "") (or (eq $cfg.TLSTermination "edge") (eq $cfg.TLSTermination "reencrypt")) }}
{{ $cert := index $cfg.Certificates $cfg.Host }}
{{ if ne $cert.Contents "" }}
{{$workingDir}}/certs/{{$idx}}.pem {{$cfg.Host}}
{{ end }}
{{ end }}
{{ end }}
{{ end }}{{/* end cert_config map template */}}

0 comments on commit 5ce393c

Please sign in to comment.