Documentation
¶
Overview ¶
Package tunnel runs a Cloudflare Tunnel in front of roji, so selected routes can be reached from outside the machine.
cloudflared is driven as a child process rather than linked as a library: importing it pulls in a QUIC stack and several megabytes of binary for a feature most runs never turn on. roji already shells out to `docker compose` for the same reason.
Index ¶
Constants ¶
const Binary = "cloudflared"
Binary is the cloudflared executable, looked up on PATH.
Variables ¶
This section is empty.
Functions ¶
func LookPath ¶
LookPath returns the cloudflared executable, or an error naming what to install when it is not on PATH.
func RenderConfig ¶
RenderConfig returns the cloudflared configuration for cfg.
One catch-all ingress rule, never a rule per route: roji resolves hostnames itself, and cloudflared has no way to reload its configuration short of a restart. A rule per route would mean restarting the tunnel — and dropping every connection through it — each time a container starts or stops.
The wildcard covers one level, which is all Cloudflare's Universal SSL certificate does. The trailing rule answers anything the wildcard misses, and cloudflared refuses to start without it.
func WriteConfig ¶
WriteConfig writes the generated cloudflared configuration for cfg.
Types ¶
type Config ¶
type Config struct {
// Domain is the Cloudflare zone, e.g. "example.com".
Domain string
// Name is the named tunnel, created beforehand with `cloudflared tunnel create`.
Name string
// Port is the loopback port cloudflared forwards to.
Port int
// ConfigPath is where the generated cloudflared configuration is written.
ConfigPath string
}
Config describes the tunnel to run.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner supervises one cloudflared process.
A crashed tunnel is reported and left down. Restarting it is the job of whatever supervises roji itself: roji is not a process manager, and a tunnel that keeps failing to authenticate would otherwise retry forever in silence.
func (*Runner) Start ¶
Start writes the configuration and launches cloudflared.
It returns once the process has been spawned, not once the tunnel is established: cloudflared reports its own progress, and roji has no way to wait for a connection to Cloudflare's edge that would not also hang startup when the network is down.
The process is deliberately not tied to a context. Stop owns its lifetime, and a context would end it with SIGKILL at exactly the moment shutdown wants to signal it instead — see Stop.
func (*Runner) Stop ¶
func (r *Runner) Stop()
Stop shuts cloudflared down, waiting for it to close its connections.
Signalling first rather than killing outright lets cloudflared tell Cloudflare's edge it is going away, so requests in flight are not cut off and the next start does not race an old registration. A process that ignores the signal is killed once stopTimeout passes.