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
- Variables
- func CheckCode(err error) string
- func IsAuthError(err error) bool
- func NewPinnedClient(serverURL, serverName, pin string) (client nodev1connect.NodeServiceClient, closeFn func(), err error)
- func NewPinnedProbeClient(serverURL, serverName, pin string) (client nodev1connect.ProbeServiceClient, closeFn func(), err error)
- func NewTransport(u *url.URL, cfg *tls.Config) *http.Transport
- func ParseServerURL(raw string) (*url.URL, error)
- type Address
- type Channel
- func (c *Channel) Changed() <-chan struct{}
- func (c *Channel) Client() nodev1connect.NodeServiceClient
- func (c *Channel) Close()
- func (c *Channel) Identity() *identity.Loaded
- func (c *Channel) InUse() (Address, bool)
- func (c *Channel) ProbeClient() nodev1connect.ProbeServiceClient
- func (c *Channel) Reload() error
- func (c *Channel) Use(addr Address) error
- type CheckError
- type CheckResult
- type Follower
- func (f *Follower) Hosts() []string
- func (f *Follower) NoteFailure(err error)
- func (f *Follower) NoteOK()
- func (f *Follower) Run(ctx context.Context)
- func (f *Follower) SetDesired(a *nodev1.ChannelAddress)
- func (f *Follower) Status() *nodev1.ChannelStatus
- func (f *Follower) Step(ctx context.Context)
- type SetServerResult
- type WebSocketRefusedError
Constants ¶
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).
const ( DefaultFailoverAfter = 3 * time.Minute DefaultRetryPrimary = 5 * time.Minute DefaultCheckTimeout = 20 * time.Second )
Follow timing defaults (Follower).
const FollowFeature = "channel-follow-v1"
FollowFeature is the capability of following the console's node channel address (ChannelStatus, CheckChannel, `set-server`).
const MaxMessageBytes = 128 << 20
MaxMessageBytes bounds a single response message (config snapshots).
const WebSocketPath = "/node-channel"
WebSocketPath is where a wss:// or ws:// server URL is served: the console's WebSocket entry on its web port.
const WebSocketProtocol = "edgeweir-node-channel"
WebSocketProtocol is the WebSocket subprotocol of that entry.
Variables ¶
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
CheckCode returns the code of a failed check (CheckUnreachable for an error that does not tell more).
func IsAuthError ¶
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 ¶
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 ¶
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
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
CurrentAddress and FallbackAddress are the addresses of an identity file.
func FallbackAddress ¶ added in v1.2.0
func ParseAddress ¶ added in v1.2.0
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) Equal ¶ added in v1.2.0
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
Host returns the URL's host name or IP ("" for an unparsable URL).
func (Address) Name ¶ added in v1.2.0
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).
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 ¶
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 ¶
func (c *Channel) Client() nodev1connect.NodeServiceClient
Client returns the current NodeService client.
func (*Channel) InUse ¶ added in v1.2.0
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 ¶
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.
type CheckError ¶ added in v1.2.0
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
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 (*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) 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.
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
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