controlplane

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 23 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 controlplane builds Connect clients for the console's node channel (NodeService and ProbeService): CA-pinned clients for enrollment and an mTLS channel with hot-swappable credentials for everything else.

Index

Constants

View Source
const (
	CheckUnreachable      = "unreachable"
	CheckWebSocketRefused = "websocket_refused"
	CheckTLSUntrusted     = "tls_untrusted"
	CheckRejected         = "rejected"
	CheckWrongIdentity    = "wrong_identity"
	CheckInvalidAddress   = "invalid_address"
)

Codes of a failed check (ChannelStatus.error_code).

View Source
const (
	DefaultFailoverAfter = 3 * time.Minute
	DefaultRetryPrimary  = 5 * time.Minute
	DefaultCheckTimeout  = 20 * time.Second
)

Follow timing defaults (Follower).

View Source
const FollowFeature = "channel-follow-v1"

FollowFeature is the capability of following the console's node channel address (ChannelStatus, CheckChannel, `set-server`).

View Source
const MaxMessageBytes = 128 << 20

MaxMessageBytes bounds a single response message (config snapshots).

View Source
const WebSocketPath = "/node-channel"

WebSocketPath is where a wss:// or ws:// server URL is served: the console's WebSocket entry on its web port.

View Source
const WebSocketProtocol = "edgeweir-node-channel"

WebSocketProtocol is the WebSocket subprotocol of that entry.

Variables

View Source
var DefaultFollowBackoff = []time.Duration{time.Minute, 5 * time.Minute, 15 * time.Minute, time.Hour}

DefaultFollowBackoff is the wait before the console's address is checked again after a failed check (the last step repeats).

Functions

func CheckCode added in v1.2.0

func CheckCode(err error) string

CheckCode returns the code of a failed check (CheckUnreachable for an error that does not tell more).

func IsAuthError

func IsAuthError(err error) bool

IsAuthError reports whether err means the console rejected the node's credentials (deleted node, revoked or expired certificate, used token).

func NewPinnedClient

func NewPinnedClient(serverURL, serverName, pin string) (client nodev1connect.NodeServiceClient, closeFn func(), err error)

NewPinnedClient returns a NodeService client for Enroll that trusts only the CA matching pin. close releases idle connections.

func NewPinnedProbeClient

func NewPinnedProbeClient(serverURL, serverName, pin string) (client nodev1connect.ProbeServiceClient, closeFn func(), err error)

NewPinnedProbeClient returns a ProbeService client for EnrollProbe that trusts only the CA matching pin. close releases idle connections.

func NewTransport

func NewTransport(u *url.URL, cfg *tls.Config) *http.Transport

NewTransport returns the HTTP transport used for the node channel at u. HTTP/2 is negotiated via ALPN; pings detect dead connections under long-lived WatchConfig streams. For a wss:// or ws:// URL each connection is a WebSocket to the console's entry with cfg's TLS inside it.

func ParseServerURL

func ParseServerURL(raw string) (*url.URL, error)

ParseServerURL validates the console node-channel base URL: https:// for the node channel port, wss:// (ws:// for a plain-HTTP console) for its WebSocket entry on the console's web port. Either way the channel's TLS is terminated by the console: through the entry it runs inside the WebSocket.

Types

type Address added in v1.2.0

type Address struct {
	URL        string
	ServerName string
}

Address is a node channel URL and the TLS server name the console's certificate is verified against (empty: the URL's host). Whatever the address, the certificate must come from the CA pinned at enrollment.

func CurrentAddress added in v1.2.0

func CurrentAddress(id identity.Identity) Address

CurrentAddress and FallbackAddress are the addresses of an identity file.

func FallbackAddress added in v1.2.0

func FallbackAddress(id identity.Identity) Address

func ParseAddress added in v1.2.0

func ParseAddress(rawURL, serverName string) (Address, error)

ParseAddress validates an address the console gives out or an operator types (set-server): https://, wss:// or ws:// with a host and an optional port, nothing else (no userinfo, path, query or fragment), and a server name that is a DNS name or an IP. It returns the address with the URL in its canonical form (scheme://host[:port], default port left out).

func (Address) Empty added in v1.2.0

func (a Address) Empty() bool

Empty reports whether a has no URL.

func (Address) Equal added in v1.2.0

func (a Address) Equal(b Address) bool

Equal reports whether a and b reach the same URL (default ports and the case of the host aside) and verify the same name.

func (Address) Host added in v1.2.0

func (a Address) Host() string

Host returns the URL's host name or IP ("" for an unparsable URL).

func (Address) Name added in v1.2.0

func (a Address) Name() string

Name returns the server name, or the URL's host when it is empty.

func (Address) Proto added in v1.2.0

func (a Address) Proto() *nodev1.ChannelAddress

Proto returns a as a ChannelAddress (nil when empty).

func (Address) String added in v1.2.0

func (a Address) String() string

type Channel

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

Channel is the authenticated (mTLS) node channel. Credentials can be reloaded after certificate renewal without restarting the agent, and the console address changed (Use, Reload).

func NewChannel

func NewChannel(store identity.Store) (*Channel, error)

NewChannel loads the identity from store and builds the mTLS client.

func (*Channel) Changed

func (c *Channel) Changed() <-chan struct{}

Changed returns a channel that is closed on the next Reload.

func (*Channel) Client

Client returns the current NodeService client.

func (*Channel) Close

func (c *Channel) Close()

Close releases idle connections.

func (*Channel) Identity

func (c *Channel) Identity() *identity.Loaded

Identity returns the currently loaded identity.

func (*Channel) InUse added in v1.2.0

func (c *Channel) InUse() (Address, bool)

InUse returns the address new connections go to, and whether it is the fallback Use switched to.

func (*Channel) ProbeClient

func (c *Channel) ProbeClient() nodev1connect.ProbeServiceClient

ProbeClient returns the current ProbeService client (same connection and certificate as Client).

func (*Channel) Reload

func (c *Channel) Reload() error

Reload re-reads the identity from disk and replaces the transport, so that new connections present the current certificate and go to the identity's console address (leaving the fallback Use switched to). Streams opened on the old transport keep running until they end; watchers should restart when Changed fires.

func (*Channel) Use added in v1.2.0

func (c *Channel) Use(addr Address) error

Use connects to addr (the identity's fallback address) with the loaded credentials until the next Reload, without changing the identity file.

type CheckError added in v1.2.0

type CheckError struct {
	Code string
	Err  error
}

CheckError is a failed check with its code.

func (*CheckError) Error added in v1.2.0

func (e *CheckError) Error() string

func (*CheckError) Unwrap added in v1.2.0

func (e *CheckError) Unwrap() error

type CheckResult added in v1.2.0

type CheckResult struct {
	// The address the console gives out; empty when it did not say (a
	// console without CheckChannel).
	Advertised Address
	// The console answered, but has no CheckChannel: an RPC without side
	// effects stood in for it.
	Legacy bool
	// How far the node's clock is ahead of the console's (negative:
	// behind), from a second CheckChannel on the open connection
	// (CheckWithClock): the console's time against the middle of its round
	// trip (RTT). Unset for a console that does not tell its time.
	ClockOffset time.Duration
	ClockRTT    time.Duration
	ClockKnown  bool
}

CheckResult is the console's answer at the checked address.

func Check added in v1.2.0

func Check(ctx context.Context, id *identity.Loaded, cert func() *tls.Certificate, addr Address) (CheckResult, error)

Check makes one authenticated call at addr with id's credentials: the connection trusts only the CA pinned at enrollment and presents the client certificate cert returns; the console must answer for id's node (CheckChannel) or probe (CheckProbeChannel). A console without these RPCs is checked with GetCertificates (no ids) or GetProbeTargets. Errors are CheckErrors.

func CheckWithClock added in v1.5.0

func CheckWithClock(ctx context.Context, id *identity.Loaded, cert func() *tls.Certificate, addr Address) (CheckResult, error)

CheckWithClock is Check for a node that also measures its clock against the console's with a second call (CheckResult.ClockOffset).

type Follower added in v1.2.0

type Follower struct {
	Channel *Channel
	Store   identity.Store
	Log     *slog.Logger
	// BeforeCheck runs before a check connects to an address (the node
	// agent adds its host to the nftables allow list); Hosts includes it
	// meanwhile.
	BeforeCheck func(ctx context.Context)
	// Switched runs after the address in use changed (or a check failed),
	// so the status is reported at once.
	Switched func()

	FailoverAfter time.Duration
	RetryPrimary  time.Duration
	Backoff       []time.Duration
	CheckTimeout  time.Duration
	Now           func() time.Time
	// contains filtered or unexported fields
}

Follower moves a Channel to the address the console gives out:

  • the console's address (SetDesired, from every heartbeat) is checked with Check before anything changes; a passing check persists it in the identity file atomically, keeps the address in use as the fallback and reloads the channel. A failing one is reported (Status) and retried after DefaultFollowBackoff; a new address is checked at once. Only the latest address counts.
  • while no call succeeded on the persisted address for FailoverAfter, the fallback is checked and, when it passes, used until the persisted address passes a check again (every RetryPrimary). The fallback is never persisted: after a restart the agent connects to the persisted address first.

func (*Follower) Hosts added in v1.2.0

func (f *Follower) Hosts() []string

Hosts returns the hosts the agent may connect to as the console: the persisted and fallback addresses, the one in use and the one being checked.

func (*Follower) NoteFailure added in v1.2.0

func (f *Follower) NoteFailure(err error)

func (*Follower) NoteOK added in v1.2.0

func (f *Follower) NoteOK()

NoteOK records a successful call on the address in use; NoteFailure a failed one.

func (*Follower) Run added in v1.2.0

func (f *Follower) Run(ctx context.Context)

Run checks and switches addresses until ctx is done.

func (*Follower) SetDesired added in v1.2.0

func (f *Follower) SetDesired(a *nodev1.ChannelAddress)

SetDesired takes the address the console gives out (nil: the console does not say, e.g. an older console: the address in use stays). An address the agent refuses is reported as invalid_address and never connected to.

func (*Follower) Status added in v1.2.0

func (f *Follower) Status() *nodev1.ChannelStatus

Status is the ChannelStatus of heartbeats.

func (*Follower) Step added in v1.2.0

func (f *Follower) Step(ctx context.Context)

Step does what is due now: switch to the console's address, fall back, or return from the fallback. At most one check per step.

type SetServerResult added in v1.2.0

type SetServerResult struct {
	// The address before and after; Unchanged when addr was already the
	// identity's address (checked all the same).
	Previous  Address
	Current   Address
	Unchanged bool
	CheckResult
}

SetServerResult is what SetServer did.

func SetServer added in v1.2.0

func SetServer(ctx context.Context, store identity.Store, addr Address) (SetServerResult, error)

SetServer checks addr with the identity in store (Check: the pinned CA and the identity's client certificate) and, when the check passes, makes it the identity's console address, keeping the previous one as the fallback. The identity, keys and certificate stay; nothing changes when the check fails. A running agent picks the address up on its own.

type WebSocketRefusedError added in v1.2.0

type WebSocketRefusedError struct {
	Endpoint string
	// HTTP status of the answer; 0 when the handshake succeeded with another
	// subprotocol.
	Status int
	Err    error
}

WebSocketRefusedError: the server at a wss:// or ws:// URL answered, but not as the console's node channel entry (e.g. 404 while the entry is closed, or another service).

func (*WebSocketRefusedError) Error added in v1.2.0

func (e *WebSocketRefusedError) Error() string

func (*WebSocketRefusedError) Unwrap added in v1.2.0

func (e *WebSocketRefusedError) Unwrap() error

Jump to

Keyboard shortcuts

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