Cloudflare Gateway Adblocking
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_IDCLOUDFLARE_TOKEN
These can either be set in the environment or in a.envfile 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
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cloudflare_gateway_adblocking-0.1.4.tar.gz | 7.6 kB | Without provenance | Details for cloudflare_gateway_adblocking-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cloudflare_gateway_adblocking-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for cloudflare_gateway_adblocking-0.1.4-py3-none-any.whl |
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
|
Security for cloudflare-gateway-adblocking 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.