
ATUALIZAÇÃO ABAIXO
________________Decidi usar o HAProxy como proxy reverso para sites do SharePoint e sem SSL tudo funciona bem, mas com SSL não consigo iniciar o haproxy.service. Eu estava tentando com muitas configurações, mas não consigo descobrir...
Tentando iniciar o serviço:
$ sudo systemctl start haproxy.service
Job for haproxy.service failed because the control process exited with error code.
See "systemctl status haproxy.service" and "journalctl -xe" for details.
Status do haproxy.service:
$ sudo systemctl status haproxy.service
haproxy.service - HAProxy Load Balancer
Loaded: loaded (/lib/systemd/system/haproxy.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since date CEST;
Docs: man:haproxy(1)
file:/usr/share/doc/haproxy/configuration.txt.gz
Process: ExecStart=/usr/sbin/haproxy-systemd-wrapper -f $CONFIG -p $PIDFILE $EXTRAOPTS (code=exited, status=0/SUCCESS)
Process: ExecStartPre=/usr/sbin/haproxy -f $CONFIG -c -q $EXTRAOPTS (code=exited, status=1/FAILURE)
Main PID: (code=exited, status=0/SUCCESS)
systemd[1]: haproxy.service: Failed with result 'exit-code'.
systemd[1]: haproxy.service: Service hold-off time over, scheduling restart.
systemd[1]: Stopped HAProxy Load Balancer.
systemd[1]: haproxy.service: Start request repeated too quickly.
systemd[1]: Failed to start HAProxy Load Balancer.
systemd[1]: haproxy.service: Unit entered failed state.
systemd[1]: haproxy.service: Failed with result 'exit-code'.
systemd[1]: haproxy.service: Start request repeated too quickly.
systemd[1]: Failed to start HAProxy Load Balancer.
systemd[1]: haproxy.service: Failed with result 'exit-code'.
Verificando problemas no arquivo de configuração:
$ sudo haproxy -c -f haproxy.cfg
Enter PEM pass phrase:
[ALERT]: parsing [haproxy.cfg:31] : 'bind *:443' : unable to load SSL private key from PEM file './cert.pem'.
[ALERT]: Error(s) found in configuration file : haproxy.cfg
[ALERT]: Proxy 'http_id': no SSL certificate specified for bind '*:443' at [haproxy.cfg:31] (use 'crt').
[ALERT]: Fatal errors found in configuration.
HAProxy -vv:
$ sudo haproxy -vv
HA-Proxy version 1.7.5-2
Encrypted password support via crypt(3): yes
Built with zlib version : 1.2.8
Running on zlib version : 1.2.8
Compression algorithms supported : identity("identity"), deflate("deflate"), raw-deflate("deflate"), gzip("gzip")
Built with OpenSSL version : OpenSSL 1.1.0e
Running on OpenSSL version : OpenSSL 1.1.0f
OpenSSL library supports TLS extensions : yes
OpenSSL library supports SNI : yes
OpenSSL library supports prefer-server-ciphers : yes
Built with PCRE version : 8.39
Running on PCRE version : 8.39
PCRE library supports JIT : no (USE_PCRE_JIT not set)
Built with Lua version : Lua 5.3.3
Built with transparent proxy support using: IP_TRANSPARENT IPV6_TRANSPARENT IP_FREEBIND
Built with network namespace support
Available polling systems :
epoll : pref=300, test result OK
poll : pref=200, test result OK
select : pref=150, test result OK
Total: 3 (3 usable), will use epoll.
Available filters :
[COMP] compression
[TRACE] trace
[SPOE] spoe
Histórico:
haproxy: [ALERT]: parsing [/etc/haproxy/haproxy.cfg:31] : 'bind *:443' : unable to load SSL certificate file './cert.pem' file does not exist.
haproxy: [ALERT]: Error(s) found in configuration file : /etc/haproxy/.cfg
haproxy: [ALERT]: Proxy 'http_id': no SSL certificate specified for bind '*:443' at [/etc/haproxy/haproxy.cfg:31] (use 'crt').
haproxy: [ALERT]: Fatal errors found in configuration.
Estou usando o mesmo certificado (mas dividido: certificado, chave, cadeia) para nginx em outro servidor e funciona. Criei este para HAProxy com cat cert.crt priv.key certchain.crt > cert.pem
comando e tentei em ordens diferentes, mas o erro é o mesmo. Também com haproxy -c -f haproxy.cfg
o servidor de comando está perguntando sobre a frase secreta, então acho que o certificado está correto (talvez eu esteja errado) e algo está errado com o arquivo de configuração. Obrigado pelo seu tempo e ajuda.
Meu haproxy.cfg:
global
tune.ssl.default-dh-param 2048
maxconn 4096
user haproxy
group haproxy
daemon
#ssl-server-verify none
defaults
mode http
option forwardfor
log 127.0.0.1 local0 notice
maxconn 2000
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
backend sharepoint
mode http
#balance roundrobin
option redispatch
cookie SERVERID insert nocache
server spsrv xxx.xxx.xxx.xxx:80
frontend http_id
#bind *:80
bind *:443 ssl crt ./cert.pem
mode http
reqadd X-Forwarded-Proto:\ https
acl hosts_sharepoint hdr_end(host) -i intranet.sharepoint.com:443
use_backend sharepoint if hosts_sharepoint
default_backend sharepoint
PRIMEIRA ATUALIZAÇÃO
Tentei passar e agora o SharePoint está solicitando credenciais (após desabilitar a função IIS) na porta 80 e o SharePoint está redirecionando para https com o erro "504 Gateway Time-out". Este é meu haproxy.cfg atual:
global
maxconn 4096
user haproxy
group haproxy
daemon
defaults
mode tcp
log 127.0.0.1 local0 notice
maxconn 2000
option tcplog
option dontlognull
timeout connect 20s
timeout client 10m
timeout server 10m
frontend httpid
mode tcp
bind *:443
acl hosts_sharepoint hdr_end(host) -i intranet.sharepoint.com
use_backend sharepoint if hosts_sharepoint
default_backend sharepoint
backend sharepoint
mode tcp
balance roundrobin
option redispatch
cookie SERVERID insert indirect nocache
server st1 xxx.xxx.xxx.xxx:443
option ssl-hello-chk
Comando também:
$ curl xxx.xxx.xxx.xxx:**80** --header 'Host: sharepoint.intranet.com' -vv
retorna 401 para que a conexão esteja funcionando, mas o comando com porta 443 $ url xxx.xxx.xxx.xxx:**443** --header 'Host: sharepoint.intranet.com' -vv
retorna curl: (56) Recv failure: Connection reset by peer
. Meu arquivo de configuração está correto? Ou talvez eu precise configurar o IIS?
SEGUNDA ATUALIZAÇÃO
Depois de reiniciar o servidor SharePoint com esta configuração está funcionandoatravessar:
global
maxconn 4096
user haproxy
group haproxy
daemon
defaults
mode tcp
log 127.0.0.1 local0 notice
maxconn 2000
option tcplog
option dontlognull
timeout connect 20s
timeout client 10m
timeout server 10m
frontend httpid
mode tcp
bind *:443
acl hosts_sharepoint hdr_end(host) -i intranet.sharepoint.com
use_backend sharepoint if hosts_sharepoint
default_backend sharepoint
backend sharepoint
mode tcp
balance roundrobin
option redispatch
cookie SERVERID insert indirect nocache
server st1 xxx.xxx.xxx.xxx:443
option ssl-hello-chk
Responder1
Você deve evitar usar caminhos relativos em arquivos de configuração como ./cert.pem
. Mude para um caminho absoluto como /etc/ssl/cert.pem
(ajuste ao caminho atual).
Além disso, verifique o cert.pem
próprio arquivo. Ele deve conter apenas texto imprimível (não binário) com pelo menos dois blocos -----BEGIN CERTIFICATE-----
, -----END CERTIFICATE-----
(seu certificado e uma CA da cadeia) e um bloco -----BEGIN PRIVATE KEY-----
, -----END PRIVATE KEY-----
(ou pode ser um -----BEGIN RSA PRIVATE KEY-----
, -----END RSA PRIVATE KEY-----
).
Se houvesse algum binário dentro do cert.pem
arquivo, você deveria converter os arquivos originais ( cert.crt
, priv.key
) para o formato PEM e recriar o cert.pem
arquivo novamente. A ordem correta para a concatenação deve ser certificado final, chave, emissor imediato, próximo emissor, etc. Você pode deixar de fora a CA raiz, pois é considerada uma boa prática não incluí-la (sem necessidade real, menos bytes trocados).
Você pode converter do formato binário (também conhecido como DER) para um formato de texto (também conhecido como PEM) usando openssl:
Para os certificados ( input.crt
seria o arquivo DER e output.crt
seria o novo arquivo no formato PEM):
openssl x509 -inform DER -in input.crt -out output.crt
Para a chave (presumo que seja uma chave RSA, que é a mais comum) NOTA: será solicitada uma (nova) senha para o output.key
, veja meus comentários sobre isso mais tarde.
openssl rsa -inform DER -in input.key -out output.key
NOTA: A maioria dos servidores assume que a chave não está cifrada (ou seja, a próxima linha do -----BEGIN PRIVATE KEY-----
contains ENCRYPTED
). Se for esse o caso e o seu servidor ainda não iniciar, tente converter a chave para um formato não criptografado (NOTA: neste comando, presumo que o inputcipher.key
arquivo já esteja no formato PEM):
openssl rsa -in inputcipher.key -nodes -out outputclear.key
Quanto à passagem com o 504
erro, na configuração posterior você está apontando, server st1 xxx.xxx.xxx.xxx:443
enquanto na configuração de interceptação você estava apontando server spsrv xxx.xxx.xxx.xxx:80
. Verifique novamente se o seu back-end está escutando na porta 80 ou na porta 443, mas parece que não há back-end escutando na 443.
Responder2
Talvez seja útil para alguém. No meu caso configurei dois adaptadores de rede no Linux - rede local e rede pública. No Windows tenho apenas rede local - o Windows está se conectando ao Linux na rede local e então através do HAProxy consigo abrir o site do SharePoint pela internet.
Esta é a configuração correta e no meu caso funciona (para SSL usei pass-through - redirecionamento e certificado está no Windows IIS):
global
maxconn 4096
user haproxy
group haproxy
daemon
defaults
mode tcp
log 127.0.0.1 local0 notice
maxconn 2000
option tcplog
option dontlognull
timeout connect 20s
timeout client 10m
timeout server 10m
frontend httpid
mode tcp
bind *:443
acl hosts_sharepoint hdr_end(host) -i intranet.sharepoint.com
use_backend sharepoint if hosts_sharepoint
default_backend sharepoint
backend sharepoint
mode tcp
balance roundrobin
option redispatch
server st1 xxx.xxx.xxx.xxx:443 #local address of the Windows server
option ssl-hello-chk