Table of Contents
HAProxy
HAProxy provides a way of connecting a (TCP) service that is behind a firewall, or private IP addressing scheme to be publicly available using a public address.
While incoming NAT may be able to achieve the same result (if your firewall provides that function), a proxy has some additional benefits that may be helpful:
- it can connect to multiple targets for any incoming connection, enabling you to spread the workload to multiple backends. Or even move the backend around only requiring to reconfigure the proxy to point to the new backend address.
- do some level of filtering based on the number of, or frequency of, connections from a particular source, so that the backend can be protected from (some level of) front end abuse.
- Depending on the proxy, you might get a nice stats GUI giving you an idea of how your frontend and backend is performing. (HAProxy provides a useful web status gui.)
(NOTE: HAProxy only proxies TCP packets - there are other solutions that can proxy UDP as well - they may or may not support the HAProxy Proto protocol, so you’ll need to verify that they do if you use it.)
If you are using Synchronet, with a NAT device in front of it, that hides the true “source” IP address, then the HAProxy configuration may help you. One example is if using Synchronet with docker, particularly docker swarm (and possibly Kubernetes as well) - where the running application sees connections from the docker proxy, often 172.17* or 10.*.
NOTE: The assumption is, that if you still use NAT, to connect your incoming connections to HAProxy, that that NAT device is still passing the true source IP address to HAProxy - this feature won’t help you anymore if it isnt.
When the true source IP address is lost, and replaced with the NAT devices source (like what occurs in a docker swarm or kubernetes), any Synchronet configuration you have that relates to the source IP address (IP.CAN, LoginAttempt* configurations, etc), are effectively useless. Even the greeting “You've connectded from ....” will show the incorrect hostname and IP address.
When HAProxy Proto is enabled, a connection from the proxy begins with a header in which the proxy tells Synchronet the true source of the connecting client, before passing on the client's own data. In v3.22 and later, the proxies are listed in TrustedProxies: a connection from any other address is an ordinary direct connection, so callers can still connect directly. With TrustedProxies blank, and in earlier versions, Synchronet accepts connections only via the proxy, and believes the header from any client that sends one.
This is achieved via HAProxy Protocol - documented here: http://www.haproxy.org/download/1.8/doc/proxy-protocol.txt
Synchronet supports both v1 and v2 of that protocol, and if using v2 you can also use the Proxy’s “health check” to check that Synchronet is up and accepting connections and if not, redirect the connections to a different backend or even mail you that Synchronet is down.
Step 1: Configuring Synchronet to use the HAProxy Proto
To configure Synchronet to work with HAProxy, you need to do the following:
- Add HAPROXY_PROTO to your options configuration for [BBS] (PROXY Protocol under SCFG->Servers->Terminal Server->Reverse Proxy in v3.22 and later).
- (v3.22 and later) Set
TrustedProxiesto the proxy's IP address (or addresses or CIDR ranges, separated by commas): Trusted Proxies in the same SCFG menu. Only connections from those addresses are expected to begin with the PROXY protocol header; any other client connects directly, as without the proxy. Left blank, every connection must come via the proxy, and a client that can reach the BBS ports directly can send its own header and claim any IP address, so set it whenever the BBS ports can be reached other than through the proxy.
EG:
[BBS] Terminal Server ... Options = XTRN_MINIMIZED | ALLOW_RLOGIN | ALLOW_SSH | HAPROXY_PROTO TrustedProxies = 192.168.1.10
The Web Server supports the same option and setting, in its [Web] section and its own SCFG Reverse Proxy menu (see Web Server).
Step 2: Configuring HAProxy
Configure HAProxy, so that the `backend` server is configured with “send-proxy” or “send-proxy-v2” protocol enabled. (The later being v2 of the protocol.)
(If using v2 of the protocol, you can add “check inter Xs” (where X is a number) to the backend configuration, the proxy will validate the connection every X seconds. If it fails then the proxy can redirect traffic to another backend, or email you.)
Here is an example:
# telnet frontend fe-telnet bind :::23 bind :23 default_backend be-telnet maxconn 9 backend be-telnet balance roundrobin stick-table type ip size 20k expire 30m stick on src server sbbs bbs.lan:23 check inter 60s send-proxy-v2
(You can repeat this for your rlogin, and ssh connections as well.)
This configuration enables the proxy to receive connections on port 23 (using IPv4 or IPv6) and limit it to 9 incoming connections. The proxy will then proxy the connects to the backend host “bbs.lan” also on port 23, using v2 of the HAProxy Proto protocol.
Every 60s the proxy will send a health check connections to the BBS to make sure it is still up. If you configured “email-alerts”, then HAProxy will send you an email if a check fails.
Start HAProxy, and then connect to HAProxy’s IP address to connect to your BBS.
Import Notes
- You need to be running a build of Synchronet that was built after 22nd Nov, 2020.
- When HAPROXY_PROTO is used with
TrustedProxiesblank (or in versions before v3.22), Synchronet no longer accepts direct connections to your SSH, Telnet or Rlogin ports. You'll need to connect to Synchronet via the proxy. To connect directly too, list the proxy inTrustedProxies(v3.22 and later), or remove the HAPROXY_PROTO option from your *BBS* stanza. - HAPRoxy can only proxy TCP connections, so if you want to use any of the UDP prots, you'll need to continue to use your NAT setup for those ports (or find a proxy that can handle NAT as well).
Other Useful items
- If you add an email-alert configuration, HAProxy can email you if Synchronet stops responding (if you enable the health check).
- If you dont want to use the health check, just remove the *check inter Xs* from the server configuration