Skip to content

dautovri/cloudflare-topology

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Cloudflare Zero Trust Network Topology Mapper

Cloudflare Zero Trust Python 3.12+ License

Generate interactive network topology visualizations for your Cloudflare Zero Trust infrastructure. See your tunnels, access applications, policies, identity providers, and private networks as a beautiful, interactive graph.

Inspired by tailscale-network-topology-mapper


πŸ“Έ Screenshot

Cloudflare Zero Trust Topology Visualization


✨ Features

Resource Visualization
πŸ”΅ Tunnels Cloudflare Tunnels with connector status, ingress rules, origin IPs
🟒 Access Applications Self-hosted apps, SaaS apps with domains and session duration
🟑 Access Policies Allow/deny/bypass rules with include/exclude/require logic
🟠 Access Groups Reusable identity groups with member criteria
🟣 Virtual Networks Private network segmentation for tunnel routing
πŸ”΄ WARP Devices Enrolled devices with user info and last seen status
🌐 Identity Providers Okta, Azure AD, Google, GitHub, and other IdPs
πŸ›‘οΈ Gateway Rules DNS and HTTP firewall policies (optional)

Interactive Visualization

  • Search: Find nodes by name, domain, or type
  • Filter: Toggle visibility by resource type
  • Zoom & Pan: Navigate large topologies
  • Drag: Rearrange nodes manually
  • Tooltips: Hover for detailed configuration info
  • Dark Theme: Easy on the eyes, matches Cloudflare dashboard

πŸš€ Quick Start

Prerequisites

  • Python 3.12+
  • Cloudflare API Token with Zero Trust read permissions

1. Clone & Install

git clone https://github.com/yourusername/cloudflare-topology.git
cd cloudflare-topology
pip install -r requirements.txt

2. Configure Credentials

export CLOUDFLARE_API_TOKEN="your-api-token"
export CLOUDFLARE_ACCOUNT_ID="your-account-id"
πŸ“ Where to find your Account ID

Your Account ID is visible in:

  • The URL when logged into Cloudflare: dash.cloudflare.com/<ACCOUNT_ID>/...
  • Any zone's Overview page β†’ right sidebar under "Account ID"
  • Workers & Pages β†’ right sidebar

3. Generate Topology

# Basic usage - opens in browser
python main.py

# Skip tunnel configs for faster generation
python main.py --no-tunnel-configs

# Include Gateway firewall rules
python main.py --include-gateway

# Debug mode with verbose output
python main.py --debug

🐳 Docker Deployment

Run as a web service with automatic regeneration:

# Build
make build

# Run (requires env vars)
export CLOUDFLARE_API_TOKEN="your-token"
export CLOUDFLARE_ACCOUNT_ID="your-account-id"
make run

# View at http://localhost:8080

Or with docker directly:

docker build -t cloudflare-topology .

docker run -d \
  --name cloudflare-topology \
  -p 8080:8080 \
  -e CLOUDFLARE_API_TOKEN="your-token" \
  -e CLOUDFLARE_ACCOUNT_ID="your-account-id" \
  cloudflare-topology

Docker Endpoints

Endpoint Method Description
/ GET View topology visualization
/health GET Health check
/regenerate POST Trigger topology refresh

πŸ”‘ API Token Permissions

Create a token at Cloudflare Dashboard β†’ API Tokens:

Required Permissions

Permission Scope Used For
Zero Trust: Read Account Tunnels, virtual networks, routes
Access: Apps and Policies: Read Account Applications, policies, groups

Optional Permissions

Permission Scope Used For
Devices: Read Account WARP device enrollment
Gateway: Read Account DNS/HTTP firewall rules
πŸ›‘οΈ Recommended: Use a Custom Token

Create a token with only the permissions you need. Avoid using Global API Keys.

  1. Go to API Tokens
  2. Click "Create Token"
  3. Use "Create Custom Token"
  4. Add the permissions listed above
  5. Set appropriate TTL and IP restrictions for security

🎨 Node Types & Colors

Type Color Shape Description
Cloudflare Orange Star Central hub node
Tunnel Blue #3b82f6 Hexagon Cloudflare Tunnel connectors
Application Green #22c55e Circle Access-protected applications
Policy Yellow #eab308 Triangle Access policy rules
Group Orange #f97316 Circle Access groups
Identity Provider Cyan #06b6d4 Star Okta, Azure AD, etc.
Virtual Network Purple #a855f7 Square Private network segments
Route Lime #84cc16 Circle Private network routes
Device Red #ef4444 Diamond WARP-enrolled devices
Gateway Rule Pink #ec4899 Triangle Firewall policies

βš™οΈ CLI Options

python main.py [OPTIONS]

Options:
  --debug              Enable verbose debug logging
  --output, -o FILE    Output HTML file (default: network_topology.html)
  --no-browser         Don't auto-open browser after generation
  --no-devices         Skip fetching WARP devices (faster)
  --no-tunnel-configs  Skip fetching detailed tunnel configurations
  --include-gateway    Include Gateway firewall rules

Environment Variables

Variable Required Description
CLOUDFLARE_API_TOKEN βœ… API token with Zero Trust read permissions
CLOUDFLARE_ACCOUNT_ID βœ… Your Cloudflare account ID
DEBUG ❌ Set to true for debug logging

πŸ“ Project Structure

cloudflare-topology/
β”œβ”€β”€ main.py                 # CLI entry point
β”œβ”€β”€ config.py               # Configuration, colors, API endpoints
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ Dockerfile              # Container image
β”œβ”€β”€ Makefile                # Build/run commands
β”‚
β”œβ”€β”€ models/
β”‚   └── cloudflare_data.py  # Data models for all resources
β”‚
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ cloudflare_api.py   # Cloudflare API client with pagination
β”‚   β”œβ”€β”€ network_graph.py    # Graph builder (nodes & edges)
β”‚   └── renderer.py         # HTML/CSS/JS visualization
β”‚
β”œβ”€β”€ server/
β”‚   └── server.py           # Flask server for Docker
β”‚
└── tests/
    β”œβ”€β”€ test_config.py
    β”œβ”€β”€ test_models.py
    └── test_network_graph.py

πŸ§ͺ Development

# Install dev dependencies
pip install -r requirements.txt

# Run tests
make test
# or
python -m pytest tests/ -v

# Lint
make lint

🀝 Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests
  5. Submit a pull request

πŸ“œ License

Apache 2.0 - see LICENSE for details.


πŸ™ Acknowledgments


Made with ☁️ for the Cloudflare community

About

Interactive network topology visualizer for Cloudflare Zero Trust infrastructure

Topics

Resources

License

Stars

Watchers

Forks

Contributors