Using Cloudflare Zero Trust to Expose Services
Cloudflare Zero Trust (formerly Cloudflare Access) provides enterprise-grade secure access control, suitable for users who need higher security and performance.
- ✅ Enterprise-grade security: Multi-layer identity authentication
- ✅ Global CDN: Low-latency access
- ✅ Fine-grained control: Rule-based access control
- ✅ Audit logs: Detailed access records
- ✅ DDoS protection: Automatic attack protection
In addition to using Tailscale, you can also choose to use Cloudflare Tunnel to securely expose your TeslaMateAPI service. Cloudflare Tunnel provides a secure way without the need to open firewall ports or configure complex network settings.
Setup Guide
Prerequisites
- Register a Cloudflare account
- Add your domain to Cloudflare and change nameservers
- Have TeslaMateAPI running on
localhost:8080
Step 1: Create a Tunnel
- Log in to Zero Trust Dashboard
- Navigate to Networks > Tunnels
- Click Create a tunnel
- Choose Cloudflared for the connector type and select Next
- Enter a descriptive name for your tunnel (e.g.,
teslamate-api-tunnel
) - Click Save tunnel
Step 2: Install and Run Cloudflared
- Select your operating system from the environment options
- Copy the installation command provided
- Run the command in your terminal to install and connect cloudflared
- Wait for the connector to appear in the Zero Trust dashboard
- Click Next when the connector is active
Step 3: Configure Public Hostname
- In the Public Hostnames tab, click Add a public hostname
- Configure the hostname:
- Subdomain: Enter your desired subdomain (e.g.,
teslamate-api
) - Domain: Select your domain from the dropdown
- Service: Enter
http://localhost:8080
⚠️ Important: Use HTTP, not HTTPS
- Subdomain: Enter your desired subdomain (e.g.,
- Under Additional application settings, configure any needed parameters
- Click Save hostname
Make sure to use http://localhost:8080
(not https://
) as the service URL, since TeslaMateAPI typically runs without SSL internally.
Step 4: Test and Configure Mytesla
- Your API is now accessible at
https://your-subdomain.your-domain.com
- Test the connection:
curl https://your-subdomain.your-domain.com/api/ping
# Should return: {"message": "pong"} - In Mytesla.cc, go to Settings → TeslaMate
- Enter your API URL:
https://your-subdomain.your-domain.com
- Add your API token if configured
- Test the connection
- You can also manually verify by visiting
https://your-subdomain.your-domain.com/api/ping
in your browser - it should return{"message": "pong"}
The /api/ping
endpoint is specifically for verifying that the TeslaMateAPI service is accessible and working correctly. A successful response of {"message": "pong"}
indicates the service is functioning properly.
Reference Documentation
For detailed operation guide, please refer to Cloudflare official documentation: