Haproxy is an awesome load balancer for TCP and HTTP connections. In this short post we will see how to secure bind by source IP address
Configuration of HaProxy to allow and reject connections by IP Address:
For doing this we will use ACL to check source IP and based on it we will decide how to proceed.
In my use case I want to publish RabbitMQ management interface to few public users. It will be served through different from 80/443 port. So my config looks like:
listen port_5672 bind :15672 mode tcp acl network_allowed src 18.104.22.168 22.214.171.124.2 tcp-request connection reject if !network_allowed server rmq_rmq1_1 127.0.0.1:25672 checkNote: RabbitMQ management interface is running on port 25672
So as you can see I’m adding new listener on port 15672 which backend will be 127.0.0.1:25672. Interesting part here is ACL conditions
acl network_allowed src 126.96.36.199 188.8.131.52.2 tcp-request connection reject if !network_allowedIt’s a pretty straightforward and self-explanatory. Of course this can be used in frontend section as well.
frontend www bind *:80 mode tcp acl network_allowed src 184.108.40.206 220.127.116.11 tcp-request connection reject if !network_allowed use_backend backend_server_original