Autoupdate IP Allowlist for Cloudflare

Today we’ve got a little something for those of you who use QUIC.cloud and Cloudflare together: a script that will help you automate the allowlisting of QUIC.cloud IP addresses in your Cloudflare account.

In order for QUIC.cloud services to run uninterrupted, every domain that uses the services must allow QUIC.cloud IPs access to its server. You do this by adding the IP addresses to any firewalls you may have in place. This can be at the application level, server level, or CDN level. (You can take a look at our documentation if you want to learn more about these various firewall levels.)

Today, we want to introduce our free Auto-Update Script for Cloudflare, and show you how to use it.

About the script

The purpose of this script is to automate allowlisting and deletion of QUIC.cloud IPs from the Cloudflare WAF. It can be run manually or can be executed regularly in a cron job.
The main features include:

  • Dynamic IP Management: Fetches active node IP addresses from QUIC.cloud, and adds them to Cloudflare’s allowlist.
  • Credential Validation: Ensures API credentials are correct before proceeding.
  • Pagination Support: Handles large lists of IP addresses efficiently.
  • Progress Tracking: Displays real-time progress with a visual bar.
  • Error Handling: Provides clear feedback for failed operations.

The script uses the following libraries and tools:

  • jq: JSON parsing for API responses.
  • curl: HTTP requests for Cloudflare API and QUIC.cloud.
  • bash: Core scripting language.

The script completes three phases:

  1. Validation Phase:
    1. Verifies jq is installed.
    2. Verifies Cloudflare credentials via API.
  2. IP Retrieval:
    1. Fetches IPs from QUIC.cloud dynamically.
  3. Allowlisting/Deletion:
    1. Compares retrieved IPs with existing Cloudflare allowlist.
    2. Adds or deletes IPs as needed.

A progress bar is shown while the script is running, and a detailed summary is displayed when the script finishes.

Set up and use the script

To use the script, you will need to download it, and grant execute permissions:

wget https://raw.githubusercontent.com/QuicCloud/scripts/refs/heads/main/cf/cloudflare-auto-update.sh
chmod +x cloudflare-auto-update.sh

Edit the script and update your Cloudflare credentials by replacing the your_cloudflare placeholders:

# Define your Cloudflare credentials
CF_EMAIL="your_cloudflare_email"
CF_API_KEY="your_cloudflare_api_key"
CF_ZONE_ID="your_cloudflare_zone_id"

Once the credentials are added to the script, you can run it manually to allowlist the IPs, or to delete them, like so:

./cloudflare-auto-update.sh
./cloudflare-auto-update.sh delete

Or, use crontab to automate script execution, like so:

0 0 * * * cloudflare-auto-update.sh

Conclusion

We hope Cloudflare users will find this script helpful! Be sure to visit our GitHub repository for more handy scripts!

[Editor’s note: Thank you to Ashok for providing the technical details for this blog post.]

Leave a Comment