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
- Variables
- func Summary(a *store.WarpAccountRow, online bool, now time.Time) *adminv1.WarpSummary
- func ViewState(a *store.WarpAccountRow, online bool, now time.Time) adminv1.WarpState
- type APIError
- type Client
- func (c *Client) Delete(ctx context.Context, p Params, id, token string) error
- func (c *Client) Get(ctx context.Context, p Params, id, token string) (Registration, error)
- func (c *Client) Register(ctx context.Context, p Params, pub string, tos time.Time) (Registration, error)
- func (c *Client) SetLicense(ctx context.Context, p Params, id, token, key string) error
- type Config
- type Fleet
- type Params
- type Registration
- type Service
- func (s *Service) AutoReregister(ctx context.Context, nodeID string) (bool, error)
- func (s *Service) CheckReach(ctx context.Context)
- func (s *Service) Conditions(ctx context.Context) []panelhealth.ExtCond
- func (s *Service) Handler(opts ...connect.HandlerOption) (string, http.Handler)
- func (s *Service) NeedsAttention(ctx context.Context, nodeID, reason string) error
- func (s *Service) ReachHandler(opts ...connect.HandlerOption) (string, http.Handler)
- func (s *Service) RefreshByNode(ctx context.Context, nodeID string) error
- func (s *Service) RunReach(ctx context.Context)
- func (s *Service) Spec(ctx context.Context, nodeID string) (*plugin.WarpSpec, error)
- func (s *Service) StoreHealth(ctx context.Context, nodeID string, h *agentv1.WarpHealth) error
Constants ¶
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" )
const (
// SettingReach holds the owner's list as a JSON array of host names; absent = DefaultReachDomains, "[]" = the check is off.
SettingReach = "warp.reach_domains"
)
Variables ¶
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.
Types ¶
type APIError ¶
APIError is a non-2xx answer. Message is Cloudflare's own error text (it carries no secret of ours), cut short.
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, bind a WARP+ license key to it, 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 ¶
NewClient returns a client for APIURL whose TLS ClientHello imitates the Android app, per p.TLSSpecID.
func NewClientFor ¶
NewClientFor is a client for another base URL and transport (tests run a fake API).
func (*Client) Get ¶
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.
func (*Client) SetLicense ¶
SetLicense binds a WARP+ license key to our device: PUT /reg/{id}/account with {"license": key}, the request the 1.1.1.1 app makes when a key is typed in and that wgcf's "update --license-key" makes. The answer (the account) is not read: callers Get the device afterwards. The key is the only secret of the call: a copy of it in Cloudflare's error text is cut out before the error leaves, so no log line can carry it.
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 ¶
Customised is true when a request constant differs from the built-in value (auto_reregister is a separate switch).
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 (*Service) AutoReregister ¶
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 ¶
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 ¶
Handler is the admin WarpService (see fleet.NodeHandler for how it is mounted behind the session).
func (*Service) NeedsAttention ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 agentcap.Warp.
func (*Service) StoreHealth ¶
StoreHealth keeps the last WarpHealth a node reported (StatsBatch.warp), for GetWarp and the node badge. A node without an account is ignored.