cloudflared
$ cloudflared 官方出品 高风险cloudflared 用于将本地服务接入 Cloudflare Tunnel(tunnel)、查询隧道状态(tunnel list --output json),以及为非浏览器客户端获取 Cloudflare Access 令牌(access token)。快速隧道(--url)会作为长期前台守护进程运行。
brew install cloudflared 管理 Cloudflare Tunnel 路由与获取 Access 令牌(cloudflared access token)必须使用该本地客户端,暂无 MCP 替代品。
Agent 友好度体检单
本地探针实测证据抓取的 --help 摘要
NAME:
cloudflared - Cloudflare's command-line tool and agent
USAGE:
cloudflared [global options] [command] [command options]
VERSION:
2025.6.1 (built 2025-06-17T09:42:18Z)
DESCRIPTION:
cloudflared connects your machine or user identity to Cloudflare's global network.
You can use it to authenticate a session to reach an API behind Access, route web traffic to this machine,
and configure access control.
See https://developers.cloudflare.com/cloudflare-one/connections/connect-apps for more in-depth documentation.
COMMANDS:
update Update the agent if a new version exists
version Print the version
proxy-dns Run a DNS over HTTPS proxy server.
tail Stream logs from a remote cloudflared
service Manages the cloudflared launch agent
help, h Shows a list of commands or help for one command
Access:
access, forward access <subcommand>
Tunnel:
tunnel Use Cloudflare Tunnel to expose private services to the Internet or to Cloudflare connected private users.
GLOBAL OPTIONS:
--output value Output format for the logs (default, json) (default: "default") [$TUNNEL_MANAGEMENT_OUTPUT, $TUNNEL_LOG_OUTPUT]
--credentials-file value, --cred-file value Filepath at which to read/write the tunnel credentials [$TUNNEL_CRED_FILE]
--region value Cloudflare Edge region to connect to. Omit or set to empty to connect to the global region. [$TUNNEL_REGION]
--edge-ip-version value Cloudflare Edge IP address version to connect with. {4, 6, auto} (default: "4") [$TUNNEL_EDGE_IP_VERSION]
--edge-bind-address value Bind to IP address for outgoing connections to Cloudflare Edge. [$TUNNEL_EDGE_BIND_ADDRESS]
--label value Use this option to give a meaningful label to a specific connector. When a tunnel starts up, a connector id unique to the tunnel is generated. This is a uuid. To make it easier to identify a connector, we will use the hostname of the machine the tunnel is running on along with the connector ID. This option exists if one wants to have more control over what their individual connectors are called.
--post-quantum, --pq When given creates an experimental post-quantum secure tunnel (default: false) [$TUNNEL_POST_QUANTUM]
--management-diagnostics Enables the in-depth diagnostic routes to be made availab FCRS-1.0 六维评分拆解
在 tunnel list/info 上支持 --output json、提供 --no-autoupdate 与可脚本化的 access token,但 tunnel run 为长期阻塞守护进程。
- Supports
--output jsonon management commands andaccess token
通过公网 trycloudflare.com 暴露本地服务会绕过本地防火墙;在 ~/.cloudflared/ 下保存 cert.pem 与隧道凭据。
- Publicly exposes localhost ports; stores
~/.cloudflared/cert.pem
静态 Go 单二进制,支持 brew、apt/rpm、Docker 与 GitHub Releases 安装。
- Single static Go binary across macOS, Linux, Windows
非常适合本地 Webhook 联调、预览分享以及在脚本中穿透 Cloudflare Access 鉴权。
- Zero-cost quick tunnels and Cloudflare Access CLI token helpers
Cloudflare 官方开源项目(cloudflare/cloudflared),Apache-2.0 协议。
- Official
cloudflare/cloudflaredrepository
developers.cloudflare.com 文档与 --help 说明极其完善。
- Official docs at developers.cloudflare.com
安全边界、鉴权与放权指南
在 ~/.cloudflared/ 目录保存源证书(cert.pem)与隧道凭据 JSON;Access 令牌按应用域名缓存在本地。
免费开源(Apache-2.0 协议)Go 二进制;Cloudflare Zero Trust 免费版即可使用基础隧道。
# cloudflared Agent Rules - Never run `cloudflared tunnel --url` unattended without user approval—it exposes localhost services to the public internet. - Pass `--no-autoupdate` in CI/agent runs and terminate background tunnel processes explicitly when finished.
Agent 高频安全命令配方
只读查询(安全推荐)
cloudflared tunnel list --output json
向 Cloudflare API 查询活跃隧道并输出结构化 JSON(--output json)。
cloudflared access token -app=https://internal.example.com
打印 Access JWT 令牌,方便 Shell 脚本注入 cf-access-token 请求头。
受控写入与预演
cloudflared tunnel --url http://localhost:3000 --no-autoupdate
将本地 3000 端口映射到临时 trycloudflare.com 公网地址,直至手动终止。
核心优势
- + 管理子命令原生支持
--output json输出。 - + 单文件静态 Go 二进制,快速
--url隧道无需登录账号即可启动。
注意事项与踩坑点
- ! 启动快速隧道会直接将
localhost服务暴露到公网。 - ! 隧道运行命令会作为前台守护进程持续阻塞。