warp

package
v0.2.0-dev.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 38 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package warp is the panel side of the WARP egress: one Cloudflare WARP account per node, either registered by the panel at the owner's click (an anonymous device registration, the same call the 1.1.1.1 app makes, with the Cloudflare terms accepted on the owner's behalf) or imported from wgcf files, stored encrypted, turned into the node's WarpSpec, and shown (without secrets) in the admin WarpService.

The panel talks to Cloudflare only when the owner clicks: register, refresh, delete, or (off by default) the auto_reregister setting. Nothing here runs by itself. Secrets (private key, access token, device id, license) never reach a log line, an audit row or a response.

Index

Constants

View Source
const (
	// APIURL is the Cloudflare client API. Tests point the Client elsewhere.
	APIURL = "https://api.cloudflareclient.com"
	// TOSURL is the terms the UI links next to the register button and that the owner accepts for the account.
	TOSURL = "https://www.cloudflare.com/application/terms/"

	// SettingKey is the setting that holds the owner's Params overrides (JSON).
	SettingKey = "warp.api"
)
View Source
const (
	// CapReach is the Hello capability of an agent that answers WarpReach. The panel sends nothing to an agent without it.
	CapReach = "warp-reach/1"
	// SettingReach holds the owner's list as a JSON array of host names; absent = DefaultReachDomains, "[]" = the check is off.
	SettingReach = "warp.reach_domains"
)
View Source
const CapWarp = "warp/1"

CapWarp is the Hello capability of an agent that can run WARP. The panel registers or imports an account only for a node that listed it (agent.proto, AWG AND WARP).

Variables

View Source
var DefaultReachDomains = []string{"notion.com", "discord.com", "chatgpt.com", "claude.ai"}

DefaultReachDomains is the built-in list: sites that people reach through a VPN every day, behind Cloudflare or a region check, and whose answer to a plain page request is an ordinary page when they are not refusing WARP. notion.com is the one owners reported (a block page at some colos); discord.com, chatgpt.com and claude.ai refuse by region and by address reputation. A site that always challenges scripted clients reads "error" (a challenge is not a refusal) and never alerts.

Functions

func Summary

func Summary(a *store.WarpAccountRow, online bool, now time.Time) *adminv1.WarpSummary

Summary is the WARP badge of a node card (Node.warp); nil a gives the "not configured" badge.

func ViewState

func ViewState(a *store.WarpAccountRow, online bool, now time.Time) adminv1.WarpState

ViewState is the state the node badge shows (for the fleet module's Node.warp): a is nil when the node has no account, online is whether the node has an agent stream now.

Types

type APIError

type APIError struct {
	Status  int
	Code    int
	Message string
}

APIError is a non-2xx answer. Message is Cloudflare's own error text (it carries no secret of ours), cut short.

func (*APIError) Error

func (e *APIError) Error() string

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is the Cloudflare client API (the one the 1.1.1.1 app and wgcf talk to), limited to what the panel needs: register a device, read it back, delete it. Every call is made on the owner's click (see the package comment). It never logs a body, a header or a token.

func NewClient

func NewClient(p Params) (*Client, error)

NewClient returns a client for APIURL whose TLS ClientHello imitates the Android app, per p.TLSSpecID.

func NewClientFor

func NewClientFor(base string, hc *http.Client) *Client

NewClientFor is a client for another base URL and transport (tests run a fake API).

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, p Params, id, token string) error

Delete removes our own device. An answer of 404 (already gone) is success.

func (*Client) Get

func (c *Client) Get(ctx context.Context, p Params, id, token string) (Registration, error)

Get reads a registered device back (its endpoint, addresses and client id may have changed).

func (*Client) Register

func (c *Client) Register(ctx context.Context, p Params, pub string, tos time.Time) (Registration, error)

Register creates an anonymous device for the WireGuard public key pub (base64) and returns the account. tos is the moment the owner accepted the terms. An answer of 429 is an *APIError with Status 429.

type Config

type Config struct {
	// StepUp is auth.Service.RequireStepUp: register, import and delete call it first. Required.
	StepUp func(context.Context) error
	// Actor returns the admin id for audit rows. Default: the signed-in admin.
	Actor func(context.Context) string
	// NewClient builds the Cloudflare client for the current Params. Default NewClient (uTLS); tests inject a fake API.
	NewClient func(Params) (*Client, error)
	// Resolver resolves the endpoint name of an imported profile, once. Default: the system resolver, IPv4 only.
	Resolver func(ctx context.Context, host string) ([]netip.Addr, error)
	// Backoff is the wait before each retry after HTTP 429; when the last retry is refused too, the owner is told to
	// import a wgcf profile. Default 3 s, 9 s.
	Backoff []time.Duration
	// Pause is the gap kept between two registrations (they are sequential, and Cloudflare rate-limits bursts).
	// Default: a random 2-5 s.
	Pause func() time.Duration
	// Sleep waits d or until ctx ends (tests replace it). Now is the clock.
	Sleep func(ctx context.Context, d time.Duration) error
	Now   func() time.Time
	Log   *slog.Logger
	// RestartPolls is how many times (restartPoll apart) RestartWarp looks whether the node applied the pause before
	// it resumes anyway. Default 80 (20 s).
	RestartPolls int
}

Config configures Service.

type Fleet

type Fleet interface {
	// Live reads the durable liveness projection for the fleet in one statement.
	Live(ctx context.Context) ([]store.NodeLiveRow, error)
	// NodeLive reads one node's durable liveness projection.
	NodeLive(ctx context.Context, nodeID string) (store.NodeLiveRow, error)
	// StateChanged asks for a recompute of the desired state of the nodes. Deleting an account must reach the node as
	// a FULL state, because a delta cannot say "remove" (agent.proto, DesiredState.warp).
	StateChanged()
	// OnlineByInbound counts the open sessions of every inbound of the connected nodes.
	OnlineByInbound(ctx context.Context) map[string]int
	// WarpPauseApplied: the node confirmed a desired state that pauses its WARP (RestartWarp waits for it).
	WarpPauseApplied(ctx context.Context, nodeID string) bool
}

Fleet is what the module needs from the fleet module (*fleet.Fleet implements it).

type Params

type Params struct {
	APIVersion      string `json:"api_version"`       // the path segment of the URL, "v0a5641"
	UserAgent       string `json:"user_agent"`        // what the Android app sends
	CFClientVersion string `json:"cf_client_version"` // CF-Client-Version header
	TLSSpecID       string `json:"tls_spec_id"`       // which uTLS ClientHello to imitate, see tlsSpecs
	AutoReregister  bool   `json:"auto_reregister"`   // off by default; see AutoReregister in service.go
}

Params are the constants the registration request is built from. They changed twice in 2026, so they are data: the built-in values plus an owner override in the setting warp.api. An empty string field falls back to the built-in value.

func Defaults

func Defaults() Params

Defaults are the built-in values: wgcf v2.3.0 (2026-09-18), the release that fixed the HTTP 429 on /reg.

func (Params) Customised

func (p Params) Customised() bool

Customised is true when a request constant differs from the built-in value (auto_reregister is a separate switch).

func (Params) Validate

func (p Params) Validate() error

Validate refuses what cannot be a header value or a path segment, and an unknown ClientHello id.

type Registration

type Registration struct {
	ID, Token, License, AccountType string // secrets except AccountType
	ClientID                        string // base64; its first three bytes are the "reserved" bytes
	PeerPublicKey                   string
	EndpointV4, EndpointV6          string
	Ports                           []uint16
	AddressV4, AddressV6            string // with prefix: "172.16.0.2/32", "2606:4700:110:1::2/128"
}

Registration is what the panel keeps from a registration answer. Endpoints are IP literals without a port.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the WARP module.

func New

func New(st *store.Store, v *vault.Vault, fl Fleet, cfg Config) (*Service, error)

New builds the module. fl may be nil.

func (*Service) AutoReregister

func (s *Service) AutoReregister(ctx context.Context, nodeID string) (bool, error)

AutoReregister is for the fleet module, when a node reports that its WARP needs attention: with the owner's auto_reregister switch on (off by default; turning it on accepts the terms for future accounts too), an account that came from a registration and is marked revoked is replaced by a new registration, at most once an hour per node. The old account stays until the new one is stored. It reports whether a new account was made.

func (*Service) CheckReach

func (s *Service) CheckReach(ctx context.Context)

CheckReach asks every node that can answer to check the owner's sites. A node that is offline, whose agent is old, whose WARP is not up or has been paused is skipped (its last result stays, and ages out of reachFresh).

func (*Service) Conditions

func (s *Service) Conditions(ctx context.Context) []panelhealth.ExtCond

Conditions is the health condition source (health.Service.AddConditionSource): WARP_REACH for a site of the current list that the node's runs said "blocked" twice and that has not answered "ok" since, while the result is fresh and the account is not paused. It reads the stored results only, so it costs a read of the accounts and no request to any node.

func (*Service) Handler

func (s *Service) Handler(opts ...connect.HandlerOption) (string, http.Handler)

Handler is the admin WarpService (see fleet.NodeHandler for how it is mounted behind the session).

func (*Service) NeedsAttention

func (s *Service) NeedsAttention(ctx context.Context, nodeID, reason string) error

NeedsAttention records (or clears, with "") why the owner has to decide; the node event warp_needs_attention {reason} ends here. A node without an account is ignored.

func (*Service) ReachHandler

func (s *Service) ReachHandler(opts ...connect.HandlerOption) (string, http.Handler)

ReachHandler is the WarpReachService (proto/mistgate/warpreach/v1): the owner's list of sites. A package of its own, kept out of the Cloudflare Workers (the app mounts a refusing stub there). Mount it like Handler.

func (*Service) RefreshByNode

func (s *Service) RefreshByNode(ctx context.Context, nodeID string) error

RefreshByNode is for the fleet module: a node whose WARP cannot heal itself asked the panel to read the account again (agent.proto warp ladder, read-only at Cloudflare). It creates nothing.

func (*Service) RunReach

func (s *Service) RunReach(ctx context.Context)

RunReach is the loop of the VPS edition: the first check a minute after the panel starts, then one every reachEvery. The Cloudflare edition runs no loops (see internal/panel/app/background_js.go), so the check does not run there yet.

func (*Service) Spec

func (s *Service) Spec(ctx context.Context, nodeID string) (*plugin.WarpSpec, error)

Spec is the node's WarpSpec for the desired state: nil when the node has no account. An account that is paused (enabled = false) is returned with Enabled false, which tears the tunnel down on the node and makes every inbound with egress "warp" fail closed. The caller must send it only to a stream that listed CapWarp.

func (*Service) StoreHealth

func (s *Service) StoreHealth(ctx context.Context, nodeID string, h *agentv1.WarpHealth) error

StoreHealth keeps the last WarpHealth a node reported (StatsBatch.warp), for GetWarp and the node badge. A node without an account is ignored.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL