Skip to content

net/cloudflared: new plugin for Cloudflare Tunnel integration#5406

Open
AlanMartines wants to merge 1 commit intoopnsense:masterfrom
AlanMartines:master
Open

net/cloudflared: new plugin for Cloudflare Tunnel integration#5406
AlanMartines wants to merge 1 commit intoopnsense:masterfrom
AlanMartines:master

Conversation

@AlanMartines
Copy link
Copy Markdown

Important notices

Model used: Claude Sonnet 4.6 (Anthropic)
Extent of AI involvement: Code generation and review assistance throughout development.


Describe the problem

OPNsense has no native interface for managing Cloudflare Tunnel (cloudflared).
Users must configure it manually via CLI, with no integration into the
OPNsense service management or web UI.


Describe the proposed solution

Adds a new plugin net/cloudflared that integrates Cloudflare Tunnel into
OPNsense as a first-class service:

  • Native MVC UI under Services: Cloudflare Tunnel
  • Token-based setup (Method 1 — managed tunnels via Cloudflare Zero Trust)
  • Integrated binary installer/updater (kjake FreeBSD fork, auto-detects
    FreeBSD version and CPU architecture via GitHub API)
  • Apply button automatically reloads templates, applies sysctl QUIC tunables
    and restarts the service
  • Real-time tunnel health status badge in the UI (via local metrics endpoint)
  • Registered in System: Diagnostics: Services
  • Post-quantum encryption support (--post-quantum)
  • Tested on OPNsense 26.1.6-amd64 / FreeBSD 14.3-RELEASE-p10

Related issue

N/A

@sopex
Copy link
Copy Markdown
Member

sopex commented Apr 17, 2026

Closes: #5070

@Monviech
Copy link
Copy Markdown
Member

Installing a binary via a script is a no-go. The cloudflared tunnel must exist in freebsd ports and a plugin here only a slim configuration wrapper around it.

@AlanMartines
Copy link
Copy Markdown
Author

The plugin was created precisely because there is currently no equivalent implementation or configuration available in the FreeBSD ports for cloudflared with this level of integration. The goal is not to replace an official port, but to fill this gap by providing a practical way to configure and operate the tunnel within the environment, even if in an encapsulated manner.

If an official port with proper support becomes available, the approach can be revisited so that the plugin acts only as a minimal configuration wrapper around that implementation.

@Monviech
Copy link
Copy Markdown
Member

I understand your position, but it does not change the initial requirement if an existing freebsd port I'm afraid.

insanityinside added a commit to insanityinside/opnsense-plugins that referenced this pull request May 8, 2026
Reworks the original plugin by Alan Martines to address the architectural
feedback on PR opnsense#5406: the custom binary installer is replaced with
PLUGIN_DEPENDS= cloudflared, delegating binary management entirely to pkg
via the FreeBSD ports tree. The plugin is now a pure configuration wrapper.

Binary and service:
- Remove install_binary.sh and bundled rc.d script; use FreeBSD port
- Pass tunnel token via TUNNEL_TOKEN env var (cloudflared_env in rc.subr)
  so it does not appear in ps aux; /etc/rc.conf.d/cloudflared chmod 600
- Add config.yml template; move options out of rc.conf.d command args
- Hardcode no-autoupdate: true (pkg manages the binary; self-update
  is inappropriate)

New features:
- Transport protocol selector: Auto (QUIC with HTTP/2 fallback, default),
  QUIC-only (UDP 7844), HTTP/2-only (TCP 443)
- Automatic outbound firewall rule for TCP/UDP 7844 via cloudflared_firewall()
  hook; UDP active for Auto and QUIC-only modes, TCP for Auto and HTTP/2-only
- quic-disable-pmtu-discovery option: workaround for intermittent QUIC
  stream errors on networks where ICMP is filtered
- Log viewer tab with client-side pagination (25/50/100/200 lines/page,
  Older/Newer navigation) and Follow mode for live tailing
- Crash recovery: monitor.sh syshook and cron job restart cloudflared if
  it exits unexpectedly; sentinel file suppresses watchdog after intentional
  stop
- newwanip/newwanip6 hook to restart on WAN IP change if daemon exits

Reliability fixes:
- Improve tunnel health detection: cross-check Prometheus metrics against
  log output to catch stale ha_connections; report accurate down state

Other:
- Security notice in UI: tunnel traffic bypasses OPNsense firewall rules
- Translations for 20 languages in addition to the original pt_BR
  (machine generated)
- BSD license headers on all scripts
- README.md entry

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants