Skip to main content

A tool to manage Caddy reverse proxy configurations with Cloudflare DNS.

Project description

CADProxy

CADProxy is a tool designed to manage Caddy reverse proxy configurations with Cloudflare DNS. This tool simplifies the process of configuring reverse proxy setups and managing DNS records, utilizing AWS S3 for storing configuration profiles.

Features

  • Automatic DNS Record Management: Automatically adds DNS records to Cloudflare.
  • Caddy Configuration Management: Updates Caddy configuration with new reverse proxy entries.
  • AWS S3 Integration: Stores and retrieves Caddy configuration profiles from S3.
  • Profile Management: Easily create and manage different configuration profiles for different domains.

Requirements

  • Python 3.11 or higher
  • Caddy server
  • Cloudflare API token and zone ID
  • AWS S3 access key and secret key
  • dig command-line tool for DNS resolution checks

Installation

You can install CADProxy using pip:

pip install cadprox

Configuration

Environment Variables

Create a .env file in the root directory of your project with the following content:

S3_ACCESS_KEY=<your_s3_access_key>
S3_SECRET_KEY=<your_s3_secret_key>
S3_REGION=<your_s3_region>
S3_BUCKET=<your_s3_bucket_name>
S3_CADDY_FILENAME=Caddyfile  # Default filename, can be changed per profile

Initial Setup

  1. Create a Profile:

    Run the following command to create a new profile:

    cadprox create <main_domain>
    

    You will be prompted to enter the following details:

    • Cloudflare API token
    • Cloudflare Zone ID
    • S3 Caddy filename (optional, defaults to Caddyfile)
    • Main domain

    Example:

    cadprox create aiagency.dev
    

Usage

  1. Add a New Subdomain:

    To add a new subdomain and configure the reverse proxy, run:

    cadprox add <subdomain> -p <port>
    

    Example:

    cadprox add subdomain.aiagency.dev -p 8080
    

    This command performs the following actions:

    • Adds a DNS record for the subdomain in Cloudflare.
    • Waits until the DNS record is resolvable.
    • Downloads the current Caddyfile from the specified S3 bucket.
    • Updates the Caddyfile with the new reverse proxy entry.
    • Uploads the updated Caddyfile back to S3.
    • Reloads the Caddy server with the new configuration.

Detailed Workflow

  1. Create Profile:

    • Prompts user for Cloudflare and S3 details.
    • Stores these details in a caddy_profiles.json file in the specified S3 bucket.
  2. Add Subdomain:

    • Validates input and environment variables.
    • Retrieves external IP of the server.
    • Adds DNS record to Cloudflare.
    • Waits for DNS propagation.
    • Downloads the Caddyfile from S3.
    • Updates the Caddyfile with new reverse proxy settings.
    • Uploads the updated Caddyfile to S3.
    • Reloads the Caddy server.

Logging and Error Handling

CADProxy uses Python's logging module for logging information, errors, and debugging messages. Logs are displayed in the console for easy tracking of actions and errors.

Example Output

CLOUDFLARE_API_TOKEN: <hidden>
CLOUDFLARE_ZONE_ID: <hidden>
S3_CADDY_FILENAME: Caddyfile
MAIN_DOMAIN: aiagency.dev
INFO: Downloaded Caddyfile from S3 bucket caddy-configs
INFO: Successfully added DNS record: subdomain.aiagency.dev -> 192.0.2.1
INFO: subdomain.aiagency.dev is now resolvable
INFO: Updated Caddyfile with new entry for subdomain.aiagency.dev
INFO: Uploaded Caddyfile to S3 bucket caddy-configs
INFO: Caddy server reloaded successfully

Docker

First you need to create a caddy network:

docker network create caddy_network

Then run caddy docker

mkdir -p ~/cadprox_config && touch ~/cadprox_config/Caddyfile_docker && docker run -d \
    --name caddy \
    --network caddy_network \
    -p 8555:443 \
    -v ~/cadprox_config/Caddyfile_docker:/etc/caddy/Caddyfile \
    -v caddy_data:/data \
    -v caddy_config:/config \
    caddy:latest
mkdir -p ~/cadprox_config && touch ~/cadprox_config/Caddyfile_docker &&  docker run -d \
    --name caddy \
    --network caddy_network \
    -p 8555:443 \
    -v ~/cadprox_config/Caddyfile_docker:/etc/caddy/Caddyfile \
    -v caddy_data:/data \
    -v caddy_config:/config \
    caddy:latest

docker exec caddy caddy fmt --overwrite /etc/caddy/Caddyfile docker exec caddy caddy reload --config /etc/caddy/Caddyfile

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

Contact

For any issues, questions, or suggestions, please open an issue on the GitHub repository. More info Thriveroute.com.

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

cadprox-4.6.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cadprox-4.6-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file cadprox-4.6.tar.gz.

File metadata

  • Download URL: cadprox-4.6.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for cadprox-4.6.tar.gz
Algorithm Hash digest
SHA256 cf22638d0a163d30edd5fcbb86075a0dfe143676baba324b78902a25bded9fea
MD5 74e694c9be93f5c1d98b47fea9f270b2
BLAKE2b-256 e01f9a539dfa4e779ef75a6b70bb9dd109e6fea52577734c1448a1f95d745f4a

See more details on using hashes here.

File details

Details for the file cadprox-4.6-py3-none-any.whl.

File metadata

  • Download URL: cadprox-4.6-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.11.9

File hashes

Hashes for cadprox-4.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9295930208845427beeb33496ede1f40023f10dbc003c4b766086960c113217f
MD5 9c36fbe1b3a97b37e2c767c0e3011df3
BLAKE2b-256 85b9ae0b4132c083066b6bb657ead8af408c5c0f5ff4cd09c36af9b21f6cacb5

See more details on using hashes here.

Supported by

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