-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
12cef8c
commit afe3953
Showing
8 changed files
with
169 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# Basic TCP Example with GeoIP | ||
|
||
## Config | ||
|
||
```yaml | ||
# you may want to add a prefix to the logs, so you can easily filter them in your log-processing system | ||
# see also: https://www.haproxy.com/blog/haproxy-log-customization | ||
logformat_tcp: "TCP: %ci:%cp [%t] %ft %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq" | ||
# logformat_http: "HTTP: %ci:%cp [%tr] %ft %b/%s %TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r" | ||
|
||
haproxy: | ||
frontends: | ||
fe_mail_smtp: | ||
mode: 'tcp' | ||
bind: ['[::]:25 v4v6'] | ||
|
||
routes: | ||
be_mail_smtp: | ||
|
||
lines: | ||
- "log-format \"{{ logformat_tcp }}\"" | ||
|
||
fe_mail_imap: | ||
mode: 'tcp' | ||
bind: ['[::]:993 v4v6'] | ||
|
||
geoip: | ||
enable: true | ||
|
||
routes: | ||
be_mail_imap: | ||
filter_country: ['SI'] | ||
|
||
lines: | ||
- "log-format \"{{ logformat_tcp }}\"" | ||
|
||
default_backend: 'be_fallback_tcp' | ||
|
||
backends: | ||
be_mail_smtp: | ||
mode: 'tcp' | ||
servers: 'mail-gateway 192.168.0.10:25' | ||
|
||
be_mail_imap: | ||
mode: 'tcp' | ||
servers: 'mail-server 192.168.0.11:993' | ||
|
||
be_fallback_tcp: | ||
mode: 'tcp' | ||
lines: 'tcp-request content reject' | ||
``` | ||
---- | ||
## Result | ||
For services and `haproxy.cfg` see [Example GeoIP](https://github.com/ansibleguy/infra_haproxy/blob/latest/ExampleGeoIP.md) | ||
|
||
```bash | ||
# logs | ||
root@test-ag-haproxy-tcp:/# journalctl -u haproxy -n 200 | grep TCP | ||
> May 05 15:55:57 lb01 haproxy[99127]: TCP: ::ffff:193.222.96.0:57424 [05/May/2024:15:55:57.548] fe_mail_smtp be_mail_smtp/mail-gateway 1/25/274 297 -- 3/1/0/0/0 0/0 | ||
root@test-ag-haproxy-tcp:/# cat /etc/haproxy/conf.d/frontend.cfg | ||
> # Ansible managed: Do NOT edit this file manually! | ||
> # ansibleguy.infra_haproxy | ||
> | ||
> frontend fe_mail_smtp | ||
> mode tcp | ||
> bind [::]:25 v4v6 | ||
> | ||
> log-format "TCP: %ci:%cp [%t] %ft %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq" | ||
> | ||
> # BACKEND be_mail_smtp | ||
> acl be_mail_smtp_filter_ip always_true | ||
> acl be_mail_smtp_filter_not_ip always_false | ||
> | ||
> use_backend be_mail_smtp if be_mail_smtp_filter_ip !be_mail_smtp_filter_not_ip | ||
> | ||
> frontend fe_mail_imap | ||
> mode tcp | ||
> bind [::]:993 v4v6 | ||
> | ||
> # GEOIP | ||
> acl private_nets src 192.168.0.0/16 172.16.0.0/12 10.0.0.0/8 127.0.0.0/8 ::1 | ||
> http-request set-var(txn.geoip_country) str(00) if private_nets | ||
> | ||
> ## GEOIP COUNTRY | ||
> acl geoip_country_in_map src,ipmask(24,48),map_ip(/etc/haproxy/map/geoip_country.map) -m found | ||
> http-request set-var(txn.geoip_country) src,ipmask(24,48),map(/etc/haproxy/map/geoip_country.map) if !private_nets geoip_country_in_map | ||
> http-request lua.lookup_geoip_country if !{ var(txn.geoip_country) -m found } | ||
> http-request set-map(/etc/haproxy/map/geoip_country.map) %[src,ipmask(24,48)] %[var(txn.geoip_country)] if !private_nets !geoip_country_in_map | ||
> http-request capture var(txn.geoip_country) len 2 | ||
> | ||
> ## GEOIP ASN | ||
> acl geoip_asn_in_map src,ipmask(24,48),map_ip(/etc/haproxy/map/geoip_asn.map) -m found | ||
> http-request set-var(txn.geoip_asn) src,ipmask(24,48),map(/etc/haproxy/map/geoip_asn.map) if !private_nets geoip_asn_in_map | ||
> http-request lua.lookup_geoip_asn if !{ var(txn.geoip_asn) -m found } | ||
> http-request set-map(/etc/haproxy/map/geoip_asn.map) %[src,ipmask(24,48)] %[var(txn.geoip_asn)] if !private_nets !geoip_asn_in_map | ||
> http-request capture var(txn.geoip_asn) len 10 | ||
> | ||
> log-format "TCP: %ci:%cp [%t] %ft %b/%s %Tw/%Tc/%Tt %B %ts %ac/%fc/%bc/%sc/%rc %sq/%bq" | ||
> | ||
> # BACKEND be_mail_imap | ||
> acl be_mail_imap_filter_ip always_true | ||
> acl be_mail_imap_filter_not_ip always_false | ||
> acl be_mail_imap_filter_country var(txn.geoip_country) -m str -i SI | ||
> acl be_mail_imap_filter_not_country always_false | ||
> acl be_mail_imap_filter_asn always_true | ||
> acl be_mail_imap_filter_not_asn always_false | ||
> | ||
> use_backend be_mail_imap if be_mail_imap_filter_ip !be_mail_imap_filter_not_ip be_mail_imap_filter_asn !be_mail_imap_filter_not_asn be_mail_imap_filter_country !be_mail_imap_filter_not_country | ||
> | ||
> default_backend be_fallback_tcp | ||
root@test-ag-haproxy-tcp:/# cat /etc/haproxy/conf.d/backend.cfg | ||
> # Ansible managed: Do NOT edit this file manually! | ||
> # ansibleguy.infra_haproxy | ||
> | ||
> backend be_mail_smtp | ||
> mode tcp | ||
> balance leastconn | ||
> | ||
> server mail-gateway 192.168.0.10:25 check | ||
> | ||
> backend be_mail_imap | ||
> mode tcp | ||
> balance leastconn | ||
> | ||
> server mail-server 192.168.0.11:993 check | ||
> | ||
> backend be_fallback_tcp | ||
> mode tcp | ||
> balance leastconn | ||
> | ||
> tcp-request content reject | ||
> | ||
> backend be_haproxy_geoip | ||
> server haproxy_geoip 127.0.0.1:8406 check | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Basic Example with WAF | ||
# Basic WAF Example | ||
|
||
There are still some basic WAF features to be implemented. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters