Haproxy istio-ingressgateway 作为 SSL 后端

Haproxy with istio-ingressgateway as SSL backend

最初我使用 tcp 模式进行测试,并且可以正常工作。 haproxy tcp passthru 配置如下:

frontend https_in
        bind *:443
        mode tcp
        option forwardfor
        option tcplog
        log global
        default_backend https_backend

backend https_backend
        mode tcp
        server s1 10.21.0.60:31390 check
        server s2 10.21.0.169:31390 check
        server s3 10.21.0.173:31390 check

模式 http 配置应该是什么样的?我需要解密流量,注入一些 headers(如 forwarded-for)并再次加密,将其发送到 ssl istio ingress-gateway 后端。

我的配置尝试很多(但都不成功)这里是一张快照:

frontend https_in
    mode http
    bind *:443 ssl crt /etc/haproxy/prod.pem crt /etc/haproxy/dev.pem crt /etc/haproxy/stg.pem no-sslv3

    option http-server-close
    option forwardfor
    reqadd X-Forwarded-Proto:\ https
    reqadd X-Forwarded-Port:\ 443

    rspadd  Strict-Transport-Security:\ max-age=15768000

    tcp-request inspect-delay 5s
    tcp-request content accept if { req_ssl_hello_type 1 }
    acl acl_app1 req_ssl_sni -i mydomain.test
    use_backend https_backend if acl_app1

backend https_backend
    mode http
    server s1 10.21.0.60:31390 check ssl verify none

我在 haproxy 日志中看到

haproxy[12734]: Server https_backend/s1 is DOWN, reason: Layer6 invalid response, info: "SSL handshake failure (Connection reset by peer)", check duration: 1ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
haproxy[12734]: Server https_backend/s1 is DOWN, reason: Layer6 invalid response, info: "SSL handshake failure (Connection reset by peer)", check duration: 1ms. 0 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
haproxy[12734]: backend https_backend has no server available!

如果我取消勾选,仍然尝试查询 haproxy:

haproxy[13381]: https_in~ https_in/<NOSRV> -1/-1/-1/-1/0 503 213 - - SC-- 1/1/0/0/0 0/0 "GET / HTTP/1.1"

我无法确定 SNI 设置从 haproxy 传递到 istio 以使其工作。

我在 envoyproxy 和 istio-ingressgateway 调试日志级别的日志中找不到任何有用的信息。

你发布这个问题已经有一段时间了,但我遇到了同样的问题。所以我能够使用 openssl s_client 命令验证 HAProxy 错误。

openssl s_client -connect ip:port 会 return 一个 write:errno=104 这意味着它是一个 Connection reset by peer 错误。

但是当我提供服务器名称时,我能够成功连接到后端:openssl s_client -connect ip:port -servername server.name

在 HAProxy 的后端选项中仔细研究后,我偶然发现了 check-sni 选项,其中提到:

This option allows you to specify the SNI to be used when doing health checks over SSL. It is only possible to use a string to set . ...

所以我使用这个选项来配置后端服务器如下

server lokomotive-contour ip:port ssl verify none check-sni server.name sni str(server.name) check

关键部分是前面提到的check-sni选项;这会在健康检查期间配置 SNI。

但我还发现 sni str() 选项对于让通过此后端的常规流量路由正常工作是必需的。

ps:确保您使用的是 HAProxy 1.8 或更高版本,因为 check-sni 仅从 1.8

开始受支持

希望我的回答对你以后有所帮助