tiippex/cloudflare-access-policy-ip-updater

By tiippex

Updated about 1 year ago

Updates Cloudflare ZeroTrust AccessPolicies by adding the current public IP and optionally other IPs

Image
Networking
0

1.2K

tiippex/cloudflare-access-policy-ip-updater repository overview

Cloudflare Zero Trust Access Policy IP Updater

This Docker container fetches the public IP address of the host it is running on and updates a Cloudflare Zero Trust Access Policies by adding the current public IP to the Policy. It also accepts a comma-separated list of additional IPs to whitelist, and can resolve DNS records to IP addresses. The updates are made at a configurable interval.

Features:

  • Fetches the current public IP address from https://ip.tiippex.de.
  • Adds the current public IP to Cloudflare Zero Trust's Access Polices.
  • Accepts a list of IP addresses or DNS records to whitelist alongside the public IP.
  • Runs at a user-defined interval (in minutes), or runs once and exits if no interval is specified.
  • Optional IP lookup and DNS resolution for more flexibility.

API Key Permissions:

  • When creating the API token in Cloudflare, set the following permission for the token:
    • Account > Access: Apps and Policies > Edit.

Environment Variables:

Environment VariableDescriptionRequiredDefault
CLOUDFLARE_API_KEYYour Cloudflare API key.YesNone
CLOUDFLARE_ACCOUNT_IDThe Account ID from your Cloudflare dashboard.YesNone
CLOUDFLARE_POLICY_IDThe Access Policy ID from your Zero Trust dashboard.YesNone
IP_RANGEA comma-separated list of IPs to whitelistNoNone
IP_LOOKUP_ENABLEDSet to true (default) or false to control whether the public IP lookup is performed.Notrue
IP_FROM_DNSA comma-separated list of DNS records to resolve to IPs and whitelist.NoNone
UPDATE_INTERVAL_MINUTESTime in minutes between updates. If not set, the script will run once and then stop.NoNone

Running the Docker Container:

To run the Docker container with necessary environment variables:

docker run -e TZ=Europe/Berlin \
           -e CLOUDFLARE_API_KEY=your_api_key \
           -e CLOUDFLARE_ACCOUNT_ID=your_account_id \
           -e CLOUDFLARE_POLICY_ID=your_policy_id \
           -e IP_RANGE="127.0.0.1,10.0.0.0/24" \
           -e IP_LOOKUP_ENABLED=true \
           -e IP_FROM_DNS="example.com,github.com" \
           -e UPDATE_INTERVAL_MINUTES=15 \
           tiippex/cloudflare-access-policy-ip-updater:latest

Docker Compose Example:

Below is an example docker-compose.yml file that you can use to set up the container using Docker Compose:

version: "3"
services:
  cloudflare-access-policy-updater:
    image: tiippex/cloudflare-access-policy-ip-updater:latest
    environment:
      - TZ=Europe/Berlin
      - CLOUDFLARE_API_KEY=your_api_key
      - CLOUDFLARE_ACCOUNT_ID=your_account_id
      - CLOUDFLARE_POLICY_ID=your_policy_id
      - IP_RANGE=127.0.0.1,10.0.0.0/24
      - IP_LOOKUP_ENABLED=true
      - IP_FROM_DNS=example.com,github.com
      - UPDATE_INTERVAL_MINUTES=15
    restart: always

Tag summary

Content type

Image

Digest

sha256:f88ca9fad

Size

47.8 MB

Last updated

about 1 year ago

docker pull tiippex/cloudflare-access-policy-ip-updater:474e377d278b331f4dabd7b56fe1f29bfc3f6c3f