How do i acomplish that "limit connections to origin to allow only cloudflare ips" ? Do i need to add the ip's to firewall wan zone's subnet list, or lan zone's subnet list, or both, or other place ?
i mean, how to allow global connection to my openwrt device only from cloudflare ip's (cloudflare.com/ips-v4)
i created an "online trigger" following this tutorial [OpenWrt Wiki] Hotplug extras
and then create a shell script to fetch the cloudflare ip with below code :
#!/bin/sh
logger -t "Custom Script - CFFW" "Updating cloudflare IPs"
if curl -X GET https://www.cloudflare.com/ips-v4 >/tmp/cloudflareips;then
logger -t "Custom Script - CFFW" "Obtained cloudflare ip list"
for cfip in $(cat /tmp/cloudflareips);do
for firewall_zone in $(uci -X show firewall | grep "=zone$" | awk -F"=" '{print $1}');do
zone_name=$(uci get ${firewall_zone}.name) &&
case ${zone_name} in
wan)
#
logger -t "Custom Script - CFFW" "Add ${cfip} to ${zone_name} firewall zone"
uci -q del_list ${firewall_zone}.subnet="${cfip}" &&
uci add_list ${firewall_zone}.subnet="${cfip}" &&
uci commit ${firewall_zone}.subnet
;;
esac
done
done
logger -t "Custom Script - CFFW" "Reload firewall"
/etc/init.d/firewall reload
else
logger -t "Custom Script - CFFW" "Failed to obtain cloudflare ip list"
fi
exit 0
It's not really clear what that means. So using what I can determine from your script, I'll give an example for allowing the IPs on the WAN zone.
Interesting script...not sure what "trigger", etc - but nonetheless I would do something like this and add it to a cron job (if you want to write the fail loop and logger events, I'll leave you to work on that). Also in my example, I'll be using wget, since curl is not installed by default and the UCI method of just editing the respective config files (instead of scripting uci commands):