HAProxy als Loadbalancer mit SSL Offloading für Microsoft Exchange

Seit der Version 1.5 kann der schnelle und zuverlässige Load Balancer HAProxy auch als sogenannter SSL Offloader eingesetzt werden.
Hierbei terminiert der SSL- Datenstrom des Clients am Proxy, der sich um die komplette Zertifikatsarbeit kümmert. Die dahinter liegenden Systeme, in diesem Fall zwei Microsoft Exchange WebAccess Server, behandeln dann nur noch den unverschlüsselten HTTP- Datenstrom und werden somit nicht unerheblich entlastet.
In der gezeigten Beispielkonfiguration sind bewusst die einzelnen Bereiche der behandelten Daten (Outlook Anywhere, ActiveSync, AddressBook usw.) in separate Backends aufgeteilt um einen Überblick über die übertragene Datenmenge pro Microsoft Exchange Dienst zu erhalten und es zu ermöglichen die Dienste über unterschiedliche Server zu skalieren.
In der Beispielkonfiguration nicht enthalten sind empfehlenswerte Sicherheitsparameter, die HAProxy zu einem WAF System machen (Schutz vor DOS, DDOS, Slowloris, SYN-Flood Attacken usw.) - dies würde den Rahmen dieses Artikels sprengen, ist aber hier zu finden.
[root@exprox /usr/local/etc]# cat haproxy.conf
global
        daemon
        stats socket /var/run/haproxy.stat mode 600 level admin
        maxconn 40000
        ulimit-n 81000
        pidfile /var/run/haproxy.pid
        log /var/run/log local0
defaults
        mode http
        maxconn 50000
        contimeout 4000
        clitimeout 50000
        srvtimeout 50000
        balance roundrobin
        log global
        option tcplog
        option redispatch
        option contstats
        option dontlognull
        timeout connect 5s
        timeout queue 30s
        timeout client 300s
        timeout server 300s
        default-server inter 3s rise 2 fall 3
        backlog 10000

# START WebAccess/ActiveSync
frontend WebAccess
        maxconn 50000
        bind 172.17.86.273:443 ssl  crt /usr/local/etc/haproxy-certs/webmail.doma.in.pem
        mode http
        option httplog
        log global
        no option httpclose

        acl ACLActiveSync path_beg -i /Microsoft-Server-ActiveSync
        acl ACLRPC path_beg -i /rpc/rpcproxy.dll
        acl ACLEWS path_beg -i /ews
        acl ACLOAB path_beg -i /oab
        acl ACLAutoDiscover path_beg -i /autodiscover

        # modified for expired passwords
        rspirep ^Location:\ http:\/\/webmail\.doma\.in/owa/auth/expiredpassword.aspx\?url=/owa/auth\.owa        Location:\ https://webmail.doma.in/owa/auth/expiredpassword.aspx?url=/owa/auth.owa

        use_backend OutlookAnywhere if ACLRPC
        use_backend ExchangeEWS if ACLEWS
        use_backend ExchangeOAB if ACLOAB
        use_backend ExchangeAutoDiscover if ACLAutoDiscover
        use_backend ActiveSyncDirect if ACLActiveSync
        default_backend ExchangeOWA
        option forwardfor

backend ActiveSyncDirect
        option httpchk HEAD /Microsoft-Server-ActiveSync
        http-check expect status 401
        balance roundrobin
        server cas1 172.17.86.274:80 check port 80
        server cas2 172.17.86.276:80 check port 80

backend ExchangeOWA
        stick-table type ip size 10240k expire 60m
        stick on src
        option http-server-close
        balance roundrobin
        option redispatch
        option httpchk GET /owa
        http-check expect status 301
        server cas1 172.17.86.274:80 check port 80
        server cas2 172.17.86.276:80 check port 80

backend ExchangeEWS
        option httpchk GET /ews
        http-check expect status 401
        balance roundrobin
        server cas1 172.17.86.274:80 check port 80
        server cas2 172.17.86.276:80 check port 80

backend ExchangeAutoDiscover
        balance roundrobin
        server cas1 172.17.86.274:80 check port 80
        server cas2 172.17.86.276:80 check port 80

backend ExchangeOAB
        balance roundrobin
        server cas1 172.17.86.274:80 check port 80
        server cas2 172.17.86.276:80 check port 80

backend OutlookAnywhere
        stick-table type ip size 10240k expire 60m
        stick on src
        balance roundrobin
        option redispatch
        server cas1 172.17.86.274:80 check port 80
        server cas2 172.17.86.276:80 check port 80
# END WebAccess/ActiveSync

userlist UsersFor_HAProxyStatistics
        group admin users admin
        user admin insecure-password password
        user stats insecure-password password

listen  stats :7000
        stats enable
        stats uri /
        option httpclose
        acl AuthOkay_ReadOnly http_auth(UsersFor_HAProxyStatistics)
        acl AuthOkay_Admin http_auth_group(UsersFor_HAProxyStatistics) admin
        stats http-request auth realm HAProxy-Statistics unless AuthOkay_ReadOnly
        stats admin if AuthOkay_Admin
        stats show-node
        stats show-legends
Das SSL Zertifikat wird in die Konfiguration des sogenannten Frontends in Zeile 31 eingebunden.
Hier findet auch die "Aufteilung" der URLs je nach Exchange- Dienst mittels acl statt.
In jedem Backend werden die, in diesem Fall zwei, Microsoft Exchange CAS Server aufgeführt. Diese Trennung ermöglicht es auf einfachem Weg die Dienste auf mehrere unterschiedliche Systeme zu verteilen.
In den Zeilen 98-101 werden die Benutzeraccounts für den Zugang zur Webstatistik definiert. Hier sind es die Benutzer admin und stats, beide mit dem Passwort password, das hier als Plaintext definiert ist.
Die Zeilen 103-112 definieren dann noch auf welchem Port das Webfrontend erreichbar ist und welcher Benutzer welche Rechte hat- so kann der Benutzer stats nur lesen, admin hingegen darf das System, und damit einzelne Frontends oder Backends abschalten.

Einstellungen auf den Exchange Servern

Eine sehr gute Dokumentation der auf den Microsoft Exchange Servern notwendigen Änderungen findet sich unter diesem Link.