Skip to main content

Serverless adblocking via Cloudflare Zero Trust Gateway

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cloudflare_gateway_adblocking-0.1.4.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file cloudflare_gateway_adblocking-0.1.4.tar.gz.

File metadata

File hashes

Hashes for cloudflare_gateway_adblocking-0.1.4.tar.gz
Algorithm Hash digest
SHA256 3569d902bff63677b00b70faa169c4978d8fed7fd833d5d1c567f74c7d57c1dc
MD5 653a82119d4e69bf5301c6402d8f8065
BLAKE2b-256 adabafb97fea3e654ff3af79b6ba85c6a3281c508503f9b413e2281d9e4cd1b2

See more details on using hashes here.

File details

Details for the file cloudflare_gateway_adblocking-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for cloudflare_gateway_adblocking-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 cfef4c83fa0ec26a12f1860c020b1ffc108119177a63449df90b8cd9b8b1469c
MD5 697689bad31d1992f50c96534adf9cf5
BLAKE2b-256 a544e209c2311c3748abe78a3b946fd93c12e7aa4b2ca5d464526e9f390c5ff6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page