Linux/Haproxy

Haproxy - SNI TLS 통한 Backend 분기 처리

투명인간 2021. 2. 6. 00:52
728x90

테스트 환경 : Haproxy version 2.34

 

HTTPS (SSL) 서비스를 로드밸런싱할 경우, 통신 구간 암호화로 도메인 정보를 확인할 수 없기 때문에 이를 기반으로한 서비스 라우팅을 할 수 없음, 따라서 1개의 아이피로 1개의 서비스를 해야는 제약이 있음

 

대신에 과거 SSL 통신 규약에서 확장된 TLS 통신(2003, RFC 3546)에서 지원하는 SNI (Server Name Indication) 을 통해 서버 이름을 통한 라우팅이 가능함

 

이를 적용하기 위해서는 TCP mode를 SSL Passthrough 방식으로 로드밸런싱을 구현해야하며 IP별 접근 권한 또한 TCP mode에서 동작하는 응답 방식을 사용해야함

 

적용 예제

frontend  TCP_Service
    bind 192.168.60.102:443 v4v6
    mode tcp
    
    # 테스트 결과 아래 두줄을 추가하지 않으면 최초 접근시 TLS 통신 미지원 오류 메시지가 뜸
    tcp-request inspect-delay 5s
    tcp-request content accept if { req_ssl_hello_type 1 }

    log-format "%ci:%cp [%t] %ft %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq"
    
    # TCP mode에서는 http-request 방식으로 접근 통제를 사용할 수없음 -> tcp-request 사용
    acl network_allowed src -f /etc/haproxy/ip-whitelist.txt
    tcp-request connection reject if !network_allowed

    # DNS 호스트 명으로 백엔드 라우팅 처리
    # HTTP mode에서는 hdr을 사용하나, TCP mode에서는 위에서 언급한 SNI를 써야함
    acl apache  req.ssl_sni -i apache.testlab.net
    acl apache2  req.ssl_sni -i apache2.testlab.net
    use_backend backend_apache_tcp if apache
    use_backend backend_apache_tcp2 if apache2
    #default_backend backend_apache_tcp

backend backend_apache_tcp
    mode tcp
    balance roundrobin
    server  server2 192.168.60.11:443 check

backend backend_apache_tcp2
    mode tcp
    balance roundrobin
    server  server2 192.168.60.13:443 check

 참고 사이트

Enhanced SSL Load Balancing with Server Name Indication (SNI) TLS Extension - HAProxy Technologies

 

Enhanced SSL Load Balancing with Server Name Indication (SNI) TLS Extension - HAProxy Technologies

In this blog post we show how to enable enhanced SSL load balancing with the Server Name Indication (SNI) TLS Extension in HAProxy and HAProxy ALOHA.

www.haproxy.com

 

반응형