cloudflared Documentation

Go cloudflare-tunnel & reverse-proxy repository by @cloudflare. AI agent rules & system prompts with 16k stars.

16,459 stars Go Go 1 file ยท ~2,391 tokens #cloudflare#cloudflare-tunnel#reverse-proxy#zero-trust-network-access
RAW Doc

Docker & Self-Hosted Deployment Verified OCI

Deploy cloudflared on any server, homelab, or cloud container platform.

1-Click Terminal Command
bash (docker run)
docker run -d --name cloudflared --restart always cloudflare/cloudflared:latest

Technical Documentation: cloudflare/cloudflared

โ„น๏ธ Provenance: Multi-Tier Ingestion ยท CodeWiki Reference

Overview (`README.md`)

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.4). 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:

bash
make install-hooks

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


Overview (`component-tests/README.md`)

Requirements

  1. Python 3.10 or later with packages in the given requirements.txt

    • E.g. with venv:
    • python3 -m venv ./.venv
    • source ./.venv/bin/activate
    • python3 -m pip install -r requirements.txt
  2. Create a config yaml file, for example:

text
cloudflared_binary: "cloudflared"
tunnel: "3d539f97-cd3a-4d8e-c33b-65e9099c7a8d"
credentials_file: "/Users/tunnel/.cloudflared/3d539f97-cd3a-4d8e-c33b-65e9099c7a8d.json"
origincert: "/Users/tunnel/.cloudflared/cert.pem"
ingress:
- hostname: named-tunnel-component-tests.example.com
  service: hello_world
- service: http_status:404
  1. Route hostname to the tunnel. For the example config above, we can do that via
text
cloudflared tunnel route dns 3d539f97-cd3a-4d8e-c33b-65e9099c7a8d named-tunnel-component-tests.example.com
  1. Turn on linter
    If you are using Visual Studio, follow https://code.visualstudio.com/docs/python/linting to turn on linter.

  2. Turn on formatter
    If you are using Visual Studio, follow https://code.visualstudio.com/docs/python/editing#_formatting
    to turn on formatter and https://marketplace.visualstudio.com/items?itemName=cbrevik.toggle-format-on-save
    to turn on format on save.

  3. If you have cloudflared running as a service on your machine, you can either stop the service or ignore the service tests
    via --ignore test_service.py

How to run

Specify path to config file via env var COMPONENT_TESTS_CONFIG. This is required.

All tests

Run pytest inside this(component-tests) folder

Specific files

Run pytest <file 1 name>.py <file 2 name>.py

Specific tests

Run pytest file.py -k <test 1 name> -k <test 2 name>

Live Logging

Running with -o log_cli=true outputs logging to CLI as the tests are. By default the log level is WARN.
--log-cli-level control logging level.
For example, to log at info level, run pytest -o log_cli=true --log-cli-level=INFO.
See https://docs.pytest.org/en/latest/logging.html#live-logs for more documentation on logging.


--- METRICS ---