HAProxy + Squid

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

HAProxy + Squid

neok
Hello everyone, I would like to know if the configuration I want to do is viable:
1 Load Balancer HAProxy configured in TCP mode.
2 Squid servers 4.7.2 with negotiate kerberos authentication and LDAP group authorizations.
The idea is that the web clients of my lan point to the IP/Name of the Load Balancer and that this distributes the load between the proxy servers.
Attached is a link to a configuration diagram.
Thank you very much in advance for your comments.
Best regards

Gabriel


_______________________________________________
squid-users mailing list
[hidden email]
http://lists.squid-cache.org/listinfo/squid-users
Reply | Threaded
Open this post in threaded view
|

Re: HAProxy + Squid

Rafael Akchurin

Hello Gabriel,

 

We do exactly that in our lab, see docs at https://docs.diladele.com/administrator_guide_7_0/active_directory_extra/redundancy/haproxy_proxy_protocol.html

It works perfectly.

 

Best regards,

Rafael Akchurin

Diladele B.V.

 

 

 

From: squid-users [mailto:[hidden email]] On Behalf Of Service MV
Sent: Monday, July 22, 2019 4:37 PM
To: [hidden email]
Subject: [squid-users] HAProxy + Squid

 

Hello everyone, I would like to know if the configuration I want to do is viable:

1 Load Balancer HAProxy configured in TCP mode.
2 Squid servers 4.7.2 with negotiate kerberos authentication and LDAP group authorizations.

The idea is that the web clients of my lan point to the IP/Name of the Load Balancer and that this distributes the load between the proxy servers.

Attached is a link to a configuration diagram.

Thank you very much in advance for your comments.
Best regards

 

Gabriel

 


_______________________________________________
squid-users mailing list
[hidden email]
http://lists.squid-cache.org/listinfo/squid-users
Reply | Threaded
Open this post in threaded view
|

Re: HAProxy + Squid

neok
Hi, I finally did the configuration differently. It's working very well for
me.

In squid.conf configuring:
acl haproxy src x.x.x.x # HAProxy Load Balancer IP
follow_x_forwarded_for allow haproxy

In haproxy.cfg configuring:
defaults
        global log
        mode http
        option httplog
        option dontlognull
        timeout connect 5000
        timeout client 50000
        timeout server 50000
        errorfile 400 /etc/haproxy/errors/400.http
        errorfile 403 /etc/haproxy/errors/403.http
        errorfile 408 /etc/haproxy/errors/408.http
        errorfile 500 /etc/haproxy/errors/500.http
        errorfile 502 /etc/haproxy/errors/502.http
        errorfile 503 /etc/haproxy/errors/503.http
        errorfile 504 /etc/haproxy/errors/504.http

frontend squid
        bind *:3128
        default_backend squid_pool

backend squid_pool
        mode http
        SERVERID cookie insert indirect nocache
        balance source
        hash-type consistent
        option httpclose
        option forwardfor header X-Client
        option forwardfor
        server px1 x.x.x.1:3128 check inter 2000 rise 2 fall 3
        server px2 x.x.x.2:3128 check inter 2000 rise 2 fall 3

Greetings!

Gabriel


Rafael Akchurin wrote

> Hello Gabriel,
>
> We do exactly that in our lab, see docs at
> https://docs.diladele.com/administrator_guide_7_0/active_directory_extra/redundancy/haproxy_proxy_protocol.html
> It works perfectly.
>
> Best regards,
> Rafael Akchurin
> Diladele B.V.
>
>
>
> From: squid-users [mailto:

> squid-users-bounces@.squid-cache

> ] On Behalf Of Service MV
> Sent: Monday, July 22, 2019 4:37 PM
> To:

> squid-users@.squid-cache

> Subject: [squid-users] HAProxy + Squid
>
> Hello everyone, I would like to know if the configuration I want to do is
> viable:
> 1 Load Balancer HAProxy configured in TCP mode.
> 2 Squid servers 4.7.2 with negotiate kerberos authentication and LDAP
> group authorizations.
> The idea is that the web clients of my lan point to the IP/Name of the
> Load Balancer and that this distributes the load between the proxy
> servers.
> Attached is a link to a configuration diagram.
> https://cloudcraft.co/view/00ccd7cb-861c-4e70-a38e-980fdd6cfad3?key=iEa-Gyp8R0ZSh-fxDNi58A
> Thank you very much in advance for your comments.
> Best regards
>
> Gabriel
>
>
> _______________________________________________
> squid-users mailing list

> squid-users@.squid-cache

> http://lists.squid-cache.org/listinfo/squid-users





--
Sent from: http://squid-web-proxy-cache.1019090.n4.nabble.com/Squid-Users-f1019091.html
_______________________________________________
squid-users mailing list
[hidden email]
http://lists.squid-cache.org/listinfo/squid-users
Reply | Threaded
Open this post in threaded view
|

Re: HAProxy + Squid

Amos Jeffries
Administrator
In reply to this post by Rafael Akchurin
On 9/08/19 1:44 am, neok wrote:
> Hi, I finally did the configuration differently. It's working very well for
> me.
>

What you are doing is polluting every HTTP message with two new headers.

The way Rafael suggested is more efficient since the PROXY protocol
details are only delivered at the start of each TCP connection, and HTTP
messages do not need to be reformatted at the LB as they pass.

Note that Squid will be extending that XFF header itself anyway. But
with your way the LB IP address will be broadcast to the origin(s) in
the XFF header along with the client address. With PROXY protocol Squid
adds only the client address there.

Amos
_______________________________________________
squid-users mailing list
[hidden email]
http://lists.squid-cache.org/listinfo/squid-users
Reply | Threaded
Open this post in threaded view
|

Re: HAProxy + Squid

neok
Thank you, Amos. Taking into account your and Rafael's recommendations, I configured HAProxy and Squid to use the PROXY protocol instead of reformatting the messages.
At the moment I disabled authentication, due to internal requirements.
I had a hard time dealing with the HAProxy health checks, but I was able to fix it.
However, by configuring Squid in this way, I had a last problem that I didn't expect:
Squid reports the client's IP to my internet gateway instead of their own IP.
It's true, I want to see my clients' IPs in Squid's log; but I want Squid's IP to reach my gateway and not my clients'. This way I can make my clients browse internet only through my proxies.

I'm really not sure if continuing with this configuration I'm doing will be possible to achieve it.
I appreciate in advance any indication you can give me.


haproxy.cfg
global
    log /dev/log    local0
    log /dev/log    local1 notice
    chroot /var/lib/haproxy
    stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
    stats timeout 30s
    user haproxy
    group haproxy
    daemon
    maxconn 4000
    ca-base /etc/ssl/certs
    crt-base /etc/ssl/private
    ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
    ssl-default-bind-options no-sslv3

defaults
    log global
    mode tcp
    option tcplog
    option  dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000

frontend squid_in
    bind *:3128
    default_backend squid_pool

backend squid_pool
    balance source
    mode tcp
server px1 x.x.x.1:3128 check port 8181 send-proxy inter 2000 rise 2 fall 3
server px2 x.x.x.2:3128 check port 8181 send-proxy inter 2000 rise 2 fall 3


squid.conf
acl localnet src 192.168.12.1-192.168.13.254 # my clients IP's
acl localnet src 192.168.11.80 # haproxy IP

acl SSL_ports port 443
acl Safe_ports port 80      # http
acl Safe_ports port 21      # ftp
acl Safe_ports port 443     # https
acl Safe_ports port 70      # gopher
acl Safe_ports port 210     # wais
#acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280     # http-mgmt
acl Safe_ports port 488     # gss-http
acl Safe_ports port 591     # filemaker
acl Safe_ports port 777     # multiling http
acl Safe_ports port 8181 # haproxy health checks port
acl CONNECT method CONNECT

# list of allowed domains
acl LS_whitedomains dstdomain "/etc/squid/acl/whitedomains.txt"

# list of bloqued domains
acl LS_blackdomains dstdomain "/etc/squid/acl/blackdomains.txt"
acl LS_malicius dstdomain "/etc/squid/acl/malicius.txt"
acl LS_porn dstdomain "/etc/squid/acl/porn.txt"

# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager

# We strongly recommend the following be uncommented to protect innocent web applications running on the proxy server who think the only one who can access services on "localhost" is a local user
#http_access deny to_localhost
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
# implementation of access list policies
http_access deny LS_blackdomains
http_access allow LS_whitedomains
http_access deny LS_malicius
http_access deny LS_porn

# limit downloads to 10 Mb/s to the localnet network
delay_pools 1
delay_class 1 2
delay_parameters 1 1310720/1966080 917504/1310720
delay_access 1 allow localnet

# implementation of core access policies
proxy_protocol_access allow localnet
http_access allow localnet
http_access allow localhost

# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
http_port 3128 require-proxy-header

# port used only for haproxy health checks
http_port 8181

# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid

# Add any of your own refresh_pattern entries above these.
refresh_pattern ^ftp:       1440    20% 10080
refresh_pattern ^gopher:    1440    0%  1440
refresh_pattern -i (/cgi-bin/|\?) 0 0%  0
refresh_pattern .       0   20% 4320

# squid customization settings
quick_abort_min 0 KB
quick_abort_max 0 KB
read_timeout 5 minutes
request_timeout 3 minutes
shutdown_lifetime 0 seconds
ipcache_size 2048
fqdncache_size 4096
cache_mgr [hidden email]
visible_hostname px1
httpd_suppress_version_string on
forwarded_for off


Best regards
Gabriel

El vie., 9 de ago. de 2019 a la(s) 03:45, Amos Jeffries ([hidden email]) escribió:
On 9/08/19 1:44 am, neok wrote:
> Hi, I finally did the configuration differently. It's working very well for
> me.
>

What you are doing is polluting every HTTP message with two new headers.

The way Rafael suggested is more efficient since the PROXY protocol
details are only delivered at the start of each TCP connection, and HTTP
messages do not need to be reformatted at the LB as they pass.

Note that Squid will be extending that XFF header itself anyway. But
with your way the LB IP address will be broadcast to the origin(s) in
the XFF header along with the client address. With PROXY protocol Squid
adds only the client address there.

Amos
_______________________________________________
squid-users mailing list
[hidden email]
http://lists.squid-cache.org/listinfo/squid-users

_______________________________________________
squid-users mailing list
[hidden email]
http://lists.squid-cache.org/listinfo/squid-users
Reply | Threaded
Open this post in threaded view
|

Re: HAProxy + Squid

Amos Jeffries
Administrator
On 16/08/19 8:46 am, Service MV wrote:

> Thank you, Amos. Taking into account your and Rafael's recommendations,
> I configured HAProxy and Squid to use the PROXY protocol instead of
> reformatting the messages.
> At the moment I disabled authentication, due to internal requirements.
> I had a hard time dealing with the HAProxy health checks, but I was able
> to fix it.
> However, by configuring Squid in this way, I had a last problem that I
> didn't expect:
> Squid reports the client's IP to my internet gateway instead of their
> own IP.

Your Squid should be using its own machines default IP to connect at the
TCP level, and you have "forwarded_for off" already to prevent it adding
the X-Forwarded-For header.

Maybe HAProxy is adding it to the headers still. But I do not see the
config option that is supposed to need in your haproxy.cnf

Maybe the server is getting the info some other way directly from the
client?


>
> squid.conf
> acl localnet src 192.168.12.1-192.168.13.254# my clients IP's
> acl localnet src 192.168.11.80# haproxy IP
>
...

> # implementation of core access policies
> proxy_protocol_access allow localnet

Careful. Since localnet includes your client IPs this means clients can
connect directly to Squid and send forged PROXY details.

You should have another src ACL that matches only the HAProxy IP. Use
that here.

...
> forwarded_for off
>


Either "transparent" or "delete" would seem to suite your needs better here.


Amos
_______________________________________________
squid-users mailing list
[hidden email]
http://lists.squid-cache.org/listinfo/squid-users