Skip to content

Commit 5f61617

Browse files
committed
Change haproxy router to use a certificate list/map file.
1 parent 01c20d0 commit 5f61617

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

images/router/haproxy/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUN INSTALL_PKGS="haproxy" && \
1616
yum clean all && \
1717
mkdir -p /var/lib/haproxy/router/{certs,cacerts} && \
1818
mkdir -p /var/lib/haproxy/{conf,run,bin,log} && \
19-
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} && \
19+
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} && \
2020
chmod -R 777 /var && \
2121
setcap 'cap_net_bind_service=ep' /usr/sbin/haproxy
2222

images/router/haproxy/conf/haproxy-config.template

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ backend be_sni
148148

149149
frontend fe_sni
150150
# terminate ssl on edge
151-
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
151+
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
152152
mode http
153153

154154
# Remove port from Host header
@@ -548,4 +548,21 @@ backend be_secure_{{$cfgIdx}}
548548
{{$cfg.Host}}{{$cfg.Path}} {{$idx}}
549549
{{ end }}
550550
{{ end }}
551-
{{ end }}{{/* end reencrypt passthrough map template */}}
551+
{{ end }}{{/* end reencrypt map template */}}
552+
553+
{{/*
554+
cert_config.map: contains a mapping of <cert-file> -> example.org
555+
This map is used to present the appropriate cert
556+
based on the sni header.
557+
Note: It is sort of a reverse map for our case but the order
558+
"<cert>: <domain-set>" is important as this allows us to use
559+
wildcards and/or use a deny set with !<domain> in the future.
560+
*/}}
561+
{{ define "/var/lib/haproxy/conf/cert_config.map" }}
562+
{{ $workingDir := .WorkingDir }}
563+
{{ range $idx, $cfg := .State }}
564+
{{ if and (ne $cfg.Host "") (or (eq $cfg.TLSTermination "edge") (eq $cfg.TLSTermination "reencrypt")) }}
565+
{{$workingDir}}/certs/{{$idx}}.pem {{$cfg.Host}}
566+
{{ end }}
567+
{{ end }}
568+
{{ end }}{{/* end cert_config map template */}}

0 commit comments

Comments
 (0)