HAproxy REQ_SSL_SNI 和 SSL 終止

HAproxy REQ_SSL_SNI 和 SSL 終止

我正在嘗試讓 haproxy 與 REQ_SSL_SNI 和 SSL 終止一起使用。

我遵循的指南https://www.haproxy.com/blog/enhanced-ssl-load-balancing-with-server-name-inspiration-sni-tls-extension/ https://stuff-things.net/2016/11/30/haproxy-sni/

設定:HA-Proxy 版本 1.6.3 Ubuntu 16.04

日誌產生以下內容:

HTTP-in ~ http-in/NOSRV-1/-1/12 0 SC 0/0/0/0/0 0/0

frontend http-in
bind *:443 ssl crt /etc/haproxy/certs/
log global
reqadd X-Forwarded-Proto:\ https
mode tcp 
option tcplog
# wait up to 5 seconds from the time the tcp socket opens
# until the hello packet comes in (otherwise fallthru to the default)
tcp-request inspect-delay 5s
tcp-request content accept if { req.ssl_hello_type 1 }
acl is_site1 req_ssl_sni -i foo.foobar.com
acl is_site2 req_ssl_sni -i foobar.com
use_backend www-foo-foobar if is_site1
use_backend www-foobar if is_site2

backend www-foo-foobar
log global
mode tcp 
option tcplog
redirect scheme https if !{ ssl_fc }
server www-1 127.0.0.1:3030 check

backend www-foobar
log global
mode tcp 
option tcplog
redirect scheme https if !{ ssl_fc }
server www-1 127.0.0.1:5000 check

我缺什麼?

有人能指出我正確的方向嗎?

答案1

嘗試使用ssl_fc_sni

    acl is_site1 ssl_fc_sni foo.foobar.com
    acl is_site2 ssl_fc_sni foobar.com

基本上,當終止/解密 SSL 時,您必須使用ssl_fc_sni(從 OpenSSL API 取得 SNI)。

透過TCP方式傳遞時,必須使用req_ssl_sni(解析TCP封包中的SNI)。

來自文件:

ssl_fc_sni :字串

這會從透過 SSL/TLS 傳輸層建立並由 haproxy 本地解密的傳入連線中提取伺服器名稱指示 TLS 擴充 (SNI) 欄位。結果(如果存在)通常是與 HTTPS 主機名稱相符的字串(253 個字元或更少)。 SSL 函式庫必須在啟用 TLS 擴充支援的情況下建置(檢查 haproxy -vv)。

此獲取與上面的“req_ssl_sni”不同,它適用於 haproxy 解密的連接,而不適用於盲目轉發的 SSL 內容。另請參閱下面的“ssl_fc_sni_end”和“ssl_fc_sni_reg”。這要求在建置 SSL 庫時啟用 TLS 擴充支援(檢查 haproxy -vv)。

ACL 衍生物:

  • ssl_fc_sni_end :後綴匹配
  • ssl_fc_sni_reg :正規表示式匹配

https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#7.3.4-ssl_fc_sni

相關內容