Hi, I was searching if there is any lua geoip plugin for HAproxy and found this your project. I see you have implemented it by doing lookups to location service or (untested) lua mmdb library. For the the first option, this is possible do it other and I think more easy way, since there you need to do that caching for performance reasons.
Using geoip database or ipinfo it is posible to generate geoip.txt with all ip ranges and countries - I am doing it here (big file) http://iwik.org/ipcountry/geoip.txt
Just yesterday have switched source of data and details are here on my blog https://blog.erben.sk/2024/09/14/new-country-ip-ranges-generator/ including link to source.
And you can use it for ACL like this
# GeoIP ACL - allow only from SK and CZ
acl acl_geoloc_sk_cz src,map_ip(/etc/haproxy/geoip.txt) -m reg -i (SK|CZ)
acl acl_internal src 10.0.0.0/8 192.168.0.0/16
http-request deny if !acl_geoloc_sk_cz !acl_internal
Or in frontend part, set variable
http-response set-header geoip-countrycode %[src,map_ip(/etc/haproxy/geoip.txt)]
Or just in custom logformat (end of this huge line)
log-format vhost:%[capture.req.hdr(0)]|client:%ci|time:%Ts|method:%HM|protocol:%HV|uri:"%[capture.req.uri]"|status:%ST|outbytes:%B|inbytes:%U|referer:"%[capture.req.hdr(4)]"|ua:"%[capture.req.hdr(5)]"|cr
eate:%Tt|sslprot:%sslv|sslciph:%sslc|ssl_sni:%[ssl_fc_sni]|ssl_fc_has_early:%[ssl_fc_has_early]|backend_name:%b|frontend_name:%f|country:%[src,map_ip(/etc/haproxy/geoip.txt)]
Anyway, when I find some time, I will try doing some test with that lua mmdb library.
Hi, I was searching if there is any lua geoip plugin for HAproxy and found this your project. I see you have implemented it by doing lookups to location service or (untested) lua mmdb library. For the the first option, this is possible do it other and I think more easy way, since there you need to do that caching for performance reasons.
Using geoip database or ipinfo it is posible to generate geoip.txt with all ip ranges and countries - I am doing it here (big file) http://iwik.org/ipcountry/geoip.txt
Just yesterday have switched source of data and details are here on my blog https://blog.erben.sk/2024/09/14/new-country-ip-ranges-generator/ including link to source.
And you can use it for ACL like this
Or in frontend part, set variable
http-response set-header geoip-countrycode %[src,map_ip(/etc/haproxy/geoip.txt)]Or just in custom logformat (end of this huge line)
Anyway, when I find some time, I will try doing some test with that lua mmdb library.