macOSWindowsLinux

开源替代 ngrok

Cloudflare Tunnel client

cloudflarereverse-proxycloudflare-tunnelzero-trust-network-access
Star 增长趋势
Star
16.2k
Forks
1.5k
周增长
+70
Issues
504
5k10k15k
2018年2月2020年12月2023年11月2026年10月
制品库Go Modules
README

Cloudflare Tunnel client

Contains the command-line client for Cloudflare Tunnel, a tunneling daemon that proxies traffic from the Cloudflare network to your origins. This daemon sits between Cloudflare network and your origin (e.g. a webserver). Cloudflare attracts client requests and sends them to you via this daemon, without requiring you to poke holes on your firewall --- your origin can remain as closed as possible. Extensive documentation can be found in the Cloudflare Tunnel section of the Cloudflare Docs. All usages related with proxying to your origins are available under cloudflared tunnel help.

You can also use cloudflared to access Tunnel origins (that are protected with cloudflared tunnel) for TCP traffic at Layer 4 (i.e., not HTTP/websocket), which is relevant for use cases such as SSH, RDP, etc. Such usages are available under cloudflared access help.

You can instead use WARP client to access private origins behind Tunnels for Layer 4 traffic without requiring cloudflared access commands on the client side.

Before you get started

Before you use Cloudflare Tunnel, you'll need to complete a few steps in the Cloudflare dashboard: you need to add a website to your Cloudflare account. Note that today it is possible to use Tunnel without a website (e.g. for private routing), but for legacy reasons this requirement is still necessary:

  1. Add a website to Cloudflare
  2. Change your domain nameservers to Cloudflare

Installing cloudflared

Downloads are available as standalone binaries, a Docker image, and Debian, RPM, and Homebrew packages. You can also find releases here on the cloudflared GitHub repository.

User documentation for Cloudflare Tunnel can be found at https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/

Creating Tunnels and routing traffic

Once installed, you can authenticate cloudflared into your Cloudflare account and begin creating Tunnels to serve traffic to your origins.

TryCloudflare

Want to test Cloudflare Tunnel before adding a website to Cloudflare? You can do so with TryCloudflare using the documentation available here.

Breaking Changes

Removal of CLI flags, environment variables, configuration keys, or commands is a breaking change. Such removals must be announced in the Cloudflare Tunnel changelog before the release that removes them.

Deprecated versions

Cloudflare currently supports versions of cloudflared that are within one year of the most recent release. Breaking changes unrelated to feature availability may be introduced that will impact versions released more than one year ago. You can read more about upgrading cloudflared in our developer documentation.

For example, as of January 2023 Cloudflare will support cloudflared version 2023.1.1 to cloudflared 2022.1.1.

Development

Requirements

Updating Go

The go directive in go.mod must specify the full major.minor.patch version (for example, go 1.27.3). Do not omit the patch version, including .0 releases. This is the exact Go version used to build and test cloudflared: the Makefile exports GOTOOLCHAIN=go<version> from it, so make downloads that toolchain whenever the installed Go is older or newer. Tools that make runs with go run pkg@version also use this toolchain. A toolchain directive in go.mod is ignored; do not add one. To use the installed Go instead, run make <target> GOTOOLCHAIN=local.

When upgrading Go, update the go directive and all corresponding version references in .gitlab-ci.yml, .ci/image/Dockerfile, .github/workflows/check.yaml, and the Dockerfiles. Update the Linux CI builder image and digest in .ci/linux.gitlab-ci.yml to match; its golangVersion selects the major/minor image family. On macOS and Windows a mismatch only costs a toolchain download. Builds that use GOTOOLCHAIN=local fail if their Go is older than go.mod and use their own Go if it is newer.

Build

To build cloudflared locally run make cloudflared

Test

To locally run the tests run make test

Linting

To format the code and keep a good code quality use make fmt and make lint

Mocks

After changes on interfaces you might need to regenerate the mocks, so run make mocks

Git Hooks

To avoid CI errors, you can install pre-push hooks that run linting and tests before each push:

make install-hooks

This will configure git to use the hooks in .githooks/ that run make fmt-check lint test before each push.