Skip to main content

Cloudflare Gateway Adblocking

PyPI
Serverless adblocking via Cloudflare Zero Trust Gateway

What is this?

This is a serverless adblocking solution that uses Cloudflare's Zero Trust Gateway to block ads by parsing a hosts file and creating a firewall rule to block the domains. It can be used as an alternative to Pi-Hole or other adblocking solutions.
This project was heavily inspired by this blog post

Prerequisites

  • Python > 3.10
  • A Cloudflare account with Zero Trust enabled
  • A Cloudflare API tolken with the following permissions:
    • Zero Trust: Edit
    • Account Firewall Access Rules: Edit
    • Access: Apps and Policies: Edit
  • A device with the WARP client installed and configured to use a Zero Trust account

Installation

From PyPi

pip install cloudflare-gateway-adblocking

Usage

Setting Cloudflare credentials

Environment variables

The following environment variables can be used to set the Cloudflare credentials:

  • CLOUDFLARE_ACCOUNT_ID
  • CLOUDFLARE_TOKEN
    These can either be set in the environment or in a .env file in the current working directory.

Command line flags

The following command line flags can be used to set the Cloudflare credentials:

  • Cloudflare Account ID: --account-id / -a
  • Cloudflare Token: --token / -t

Passing blocklists

Blocklists can be passed to the program via the command line flag --blocklist / -b. This flag can either point to a hosts file or a directory containing hosts files. If this flag is not passed, the program will look for a file or directory named blocklists in the current working directory.

Passing whitelists

Whitelists can be passed to the program via the command line flag --whitelist / -w. This flag can either point to a hosts file or a directory containing hosts files. If this flag is not passed, then if a file or directory named whitelists exists in the current working directory, it will be used. Domains in this whitelist will be excluded from the blocklists.

Uploading blocklists and creating a firewall policy

To upload the blocklists to Cloudflare and create a firewall policy, use the upload subcommand.
For example:
cloudflare-gateway-adblocking upload

Deleting blocklists and firewall policy

To delete the blocklists from Cloudflare and delete the firewall policy, use the delete subcommand.
For example:
cloudflare-gateway-adblocking delete

Help

For help, use the --help flag.

Contributing

  • Sponsoring via GitHub
  • Contributing code via a pull request
  • Reporting encoutered issues

Release files for cloudflare-gateway-adblocking 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cloudflare-gateway-adblocking 0.1.4
File Size Uploaded
cloudflare_gateway_adblocking-0.1.4.tar.gz 7.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cloudflare-gateway-adblocking 0.1.4
File Interpreter ABI Platform
cloudflare_gateway_adblocking-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 17.0 kB

Release files / cloudflare_gateway_adblocking-0.1.4.tar.gz

Download URL cloudflare_gateway_adblocking-0.1.4.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3569d902bff63677b00b70faa169c4978d8fed7fd833d5d1c567f74c7d57c1dc
BLAKE2b-256 checksum
How to use checksums
adabafb97fea3e654ff3af79b6ba85c6a3281c508503f9b413e2281d9e4cd1b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Release files / cloudflare_gateway_adblocking-0.1.4-py3-none-any.whl

Download URL cloudflare_gateway_adblocking-0.1.4-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cfef4c83fa0ec26a12f1860c020b1ffc108119177a63449df90b8cd9b8b1469c
BLAKE2b-256 checksum
How to use checksums
a544e209c2311c3748abe78a3b946fd93c12e7aa4b2ca5d464526e9f390c5ff6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page