Skip to main content

Overview

IronClaw’s tunnel system wraps external tunnel binaries (cloudflared, ngrok, tailscale, etc.) behind a common trait. The gateway starts a tunnel after binding its local port and stops it on shutdown.

Supported Providers

Configuration

Environment Variables

Provider Setup

None (Local Only)

No tunnel. Agent is only accessible on localhost.
Use Cases:
  • Local development
  • Single-user setups
  • Behind existing reverse proxy

Cloudflare Zero Trust

Secure, authenticated tunnel via Cloudflare’s network.

Setup

  1. Create Cloudflare account at cloudflare.com
  2. Install cloudflared:
  3. Create tunnel in Zero Trust dashboard:
    • Navigate to Networks > Tunnels
    • Click “Create a tunnel”
    • Choose “Cloudflared”
    • Copy the tunnel token
  4. Configure IronClaw:
  5. Start IronClaw:
    The tunnel URL will be displayed in logs:
Features:
  • Zero Trust authentication
  • Automatic HTTPS
  • DDoS protection
  • Access control policies
  • No firewall configuration needed
Configuration:

Tailscale

Private mesh VPN with optional public access.

Setup (Tailnet-Only)

  1. Install Tailscale:
  2. Authenticate:
  3. Configure IronClaw:
  4. Start IronClaw:
    Access via: https://<machine-name>.<tailnet-name>.ts.net

Setup (Public Funnel)

  1. Enable Funnel (requires Tailscale account):
  2. Start IronClaw:
    Public URL: https://<machine-name>.<tailnet-name>.ts.net
Features:
  • Private mesh network
  • Automatic HTTPS (via Let’s Encrypt)
  • ACLs for access control
  • Optional public access (Funnel)
  • Magic DNS
Configuration:

ngrok

Instant public URLs for testing and demos.

Setup

  1. Create account at ngrok.com
  2. Install ngrok:
  3. Get auth token from dashboard
  4. Configure IronClaw:
  5. Start IronClaw:
    URL: https://random-string.ngrok.app

Custom Domain (Paid)

Features:
  • Instant public URLs
  • Web inspection UI
  • Replay requests
  • Custom domains (paid)
  • Edge routing
Configuration:

Custom Tunnel

Use any tunnel binary with placeholders.

Example: bore.pub

Example: localtunnel

Example: Custom cloudflared

Placeholders:
  • {host} - Local bind address (e.g., 127.0.0.1)
  • {port} - Local bind port (e.g., 3000)
Configuration:

Tunnel Lifecycle

Startup

Shutdown

Health Checks

URL Extraction

Cloudflare

Parses cloudflared output:
Extraction: Look for https://.*cfargotunnel.com

Tailscale

Queries tailscale status --json:
URL: https://<DNSName> (strips trailing dot)

ngrok

Parses ngrok output:
Extraction: Look for https://.*ngrok.app

Custom

Matches url_pattern in stdout:
First line containing pattern is used as URL.

Programmatic API

Creating Tunnels

Tunnel Trait

Security Considerations

Tunnel Authentication

  • Cloudflare: Zero Trust policies (IP restrictions, auth providers)
  • Tailscale: ACLs, MagicDNS, device authorization
  • ngrok: Basic auth, OAuth, SAML (paid plans)
  • Custom: Depends on provider

Gateway Authentication

In addition to tunnel auth, IronClaw gateway has:
  • API key authentication (GATEWAY_API_KEY)
  • Rate limiting
  • Request validation
  • CORS configuration
Production:
Development:
Team Access:

Troubleshooting

Tunnel Process Dies

Solutions:
  1. Check binary is installed: which cloudflared
  2. Check logs for tunnel errors
  3. Verify credentials are valid
  4. Ensure port is not already in use

URL Not Extracted

Solutions:
  1. Check tunnel binary output format hasn’t changed
  2. For custom tunnels, verify url_pattern matches
  3. Increase startup timeout
  4. Check logs for tunnel startup errors

Connection Refused

Causes:
  1. Tunnel not fully started (takes 10-30s)
  2. Gateway not listening on correct port
  3. Firewall blocking outbound tunnel connection
Solutions:
  1. Wait 30 seconds and retry
  2. Check gateway is running: lsof -i :3000
  3. Verify GATEWAY_PORT matches tunnel forwarding

Cloudflare 502 Bad Gateway

Causes:
  1. Gateway crashed after tunnel started
  2. Port mismatch between gateway and tunnel
  3. Network connectivity issues
Solutions:
  1. Restart IronClaw
  2. Verify GATEWAY_PORT configuration
  3. Check gateway health: curl localhost:3000/health

Performance

Latency

Throughput

  • Cloudflare: Unlimited bandwidth
  • Tailscale: Full network speed (P2P)
  • ngrok: Rate limited on free plan

Recommendations

  • Low latency: Tailscale (P2P) or None (local)
  • High throughput: Cloudflare or Tailscale
  • Quick setup: ngrok
  • Production: Cloudflare (Zero Trust) or Tailscale (team)

Source Code

Key files:
  • src/tunnel/mod.rs - Tunnel trait and factory
  • src/tunnel/cloudflare.rs - Cloudflare implementation
  • src/tunnel/tailscale.rs - Tailscale implementation
  • src/tunnel/ngrok.rs - ngrok implementation
  • src/tunnel/custom.rs - Custom tunnel implementation
  • src/tunnel/none.rs - No-tunnel implementation