Documentation
¶
Overview ¶
Package provision contains the panel's SSH provisioning primitives.
Index ¶
- Constants
- Variables
- func CanonicalPublicServerKey(input string) (string, *adminv1.NodeServerKey, error)
- func DoHLookup(client *http.Client) func(ctx context.Context, host string) ([]netip.Addr, error)
- func ForwardMarker(build string) http.Handler
- type BinarySource
- type Client
- func (c *Client) Dial(ctx context.Context, target Target, password, confirmedFingerprint string) (*Connection, error)
- func (c *Client) DialAs(ctx context.Context, target Target, ...) (*Connection, error)
- func (c *Client) DialKey(ctx context.Context, target Target, username string, signer ssh.Signer, ...) (*Connection, error)
- func (c *Client) Fingerprint(ctx context.Context, target Target) (fingerprint, algorithm string, err error)
- type Config
- type Connection
- type NodeManager
- type NodeSpec
- type Service
- func (s *Service) AddNodeServerKey(ctx context.Context, req *connect.Request[adminv1.AddNodeServerKeyRequest]) (*connect.Response[adminv1.AddNodeServerKeyResponse], error)
- func (s *Service) AttachNodeServerAccess(ctx context.Context, ...) (*connect.Response[adminv1.AttachNodeServerAccessResponse], error)
- func (s *Service) CancelNodeProvision(ctx context.Context, jobID string) (string, error)
- func (s *Service) CheckSSH(ctx context.Context, req *connect.Request[adminv1.CheckSSHRequest]) (*connect.Response[adminv1.CheckSSHResponse], error)
- func (s *Service) Drain(ctx context.Context) (more, busy bool, err error)
- func (s *Service) ForgetNodeServerAccess(ctx context.Context, ...) (*connect.Response[adminv1.ForgetNodeServerAccessResponse], error)
- func (s *Service) GetNodeProvision(ctx context.Context, req *connect.Request[adminv1.GetNodeProvisionRequest]) (*connect.Response[adminv1.GetNodeProvisionResponse], error)
- func (s *Service) GetPanelSSHKey(ctx context.Context, _ *connect.Request[adminv1.GetPanelSSHKeyRequest]) (*connect.Response[adminv1.GetPanelSSHKeyResponse], error)
- func (s *Service) GetSSHFingerprint(ctx context.Context, req *connect.Request[adminv1.GetSSHFingerprintRequest]) (*connect.Response[adminv1.GetSSHFingerprintResponse], error)
- func (s *Service) Handler(opts ...connect.HandlerOption) (string, http.Handler)
- func (s *Service) ListNodeProvisionEvents(ctx context.Context, ...) (*connect.Response[adminv1.ListNodeProvisionEventsResponse], error)
- func (s *Service) ListNodeProvisions(ctx context.Context, _ *connect.Request[adminv1.ListNodeProvisionsRequest]) (*connect.Response[adminv1.ListNodeProvisionsResponse], error)
- func (s *Service) ListNodeServerAccess(ctx context.Context, _ *connect.Request[adminv1.ListNodeServerAccessRequest]) (*connect.Response[adminv1.ListNodeServerAccessResponse], error)
- func (s *Service) ListNodeServerKeys(ctx context.Context, req *connect.Request[adminv1.ListNodeServerKeysRequest]) (*connect.Response[adminv1.ListNodeServerKeysResponse], error)
- func (s *Service) PageHandler() http.Handler
- func (s *Service) RemoveNodeServerKey(ctx context.Context, req *connect.Request[adminv1.RemoveNodeServerKeyRequest]) (*connect.Response[adminv1.RemoveNodeServerKeyResponse], error)
- func (s *Service) RetryNodeProvision(ctx context.Context, req *connect.Request[adminv1.RetryNodeProvisionRequest]) (*connect.Response[adminv1.RetryNodeProvisionResponse], error)
- func (s *Service) RevealNodeServerPassword(ctx context.Context, ...) (*connect.Response[adminv1.RevealNodeServerPasswordResponse], error)
- func (s *Service) RotateNodeServerPassword(ctx context.Context, ...) (*connect.Response[adminv1.RotateNodeServerPasswordResponse], error)
- func (s *Service) Run(ctx context.Context) error
- func (s *Service) StartNodeProvision(ctx context.Context, req *connect.Request[adminv1.StartNodeProvisionRequest]) (*connect.Response[adminv1.StartNodeProvisionResponse], error)
- type Target
Constants ¶
const AdminPagePath = "/nodes/install"
AdminPagePath is the exact path used by the authenticated panel wizard. The HTTP server also serves its slash-suffixed form without redirecting.
const DefaultSSHPort = 22
DefaultSSHPort is used when the owner leaves the SSH port blank.
const ForwardHeader = "X-Mistgate-Forward"
ForwardHeader marks a request that the panel answers with 204 instead of serving: the edge Worker cannot hold an SSH socket, so it sends the original request to the Provisioner Worker. The value is "provision;v=<build>"; the Worker strips the header and tells the Provisioner which build asked, so that two Workers of different builds do not run one request between them.
Variables ¶
var ( // ErrHostKey reports that the server key changed after the owner confirmed it. ErrHostKey = errors.New("provision: SSH host key does not match the confirmed fingerprint") // ErrAuthRejected reports that the server refused the offered SSH credential. ErrAuthRejected = errors.New("provision: SSH server rejected the login or password") // ErrNoPasswordAuth reports that the server offers neither password nor keyboard-interactive login (key-only // sshd): the password was never sent, so no password can fix it. ErrNoPasswordAuth = errors.New("provision: SSH server offers no password login") // ErrPlatformRefused reports that the network the panel connects from refused the connection or could not reach the // target. The edge edition's sockets cannot tell a refusing platform (Cloudflare addresses, private ranges) from a // closed port, so the word is "refused or unreachable"; the owner can still install the node by hand. ErrPlatformRefused = errors.New("provision: the connection to the SSH target was refused or the target is unreachable from the panel network") )
var ( // ErrUnsafeTarget covers malformed hosts and any address that is not public unicast. ErrUnsafeTarget = errors.New("provision: SSH target must resolve only to public unicast addresses") // ErrNoAddress means DNS returned no addresses for the target. ErrNoAddress = errors.New("provision: SSH target has no usable address") )
Functions ¶
func CanonicalPublicServerKey ¶ added in v0.1.74
func CanonicalPublicServerKey(input string) (string, *adminv1.NodeServerKey, error)
CanonicalPublicServerKey validates and canonicalizes a single public key for planning tools.
func DoHLookup ¶ added in v0.1.35
DoHLookup resolves host through Cloudflare's DNS-over-HTTPS JSON API, for a runtime with no system resolver (the edge edition). It asks for A and AAAA records and returns every address of both; CNAME records in an answer are skipped (the resolver has followed them). A name that does not exist, or has no address, is ErrNoAddress. A failure of either query is an error rather than a partial answer: the caller checks that every address is public, and an AAAA record that failed to arrive could be the one that is not. A nil client uses http.DefaultClient.
func ForwardMarker ¶ added in v0.1.36
ForwardMarker answers every request with that marker. It stands where the ProvisioningService and the install page would be served, inside the admin's sign-in check: a visitor who is not signed in never gets it.
Types ¶
type BinarySource ¶
type BinarySource interface {
OpenNodeBinary(ctx context.Context, goos, goarch string) (io.ReadCloser, int64, string, error)
}
BinarySource returns a node binary from the currently trusted release, its size and the sha256 (hex) in the signed manifest. The reader is a local file on the VPS edition and a network stream on the edge, hence the context. The caller verifies the bytes it transfers against the digest.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client performs password-free host-key discovery and pinned SSH connections. The production constructor uses the system resolver and a standard TCP dialer.
func NewClient ¶
func NewClient() *Client
NewClient builds a production SSH client with bounded timeouts.
func NewClientWith ¶ added in v0.1.35
func NewClientWith(dial func(ctx context.Context, network, address string) (net.Conn, error), lookup func(ctx context.Context, host string) ([]netip.Addr, error)) *Client
NewClientWith builds a client over the caller's connection source and name lookup, for a runtime that has neither a system resolver nor a TCP dialer (the edge edition's sockets and DNS-over-HTTPS). Every address it is asked about still goes through the same public-unicast check as with NewClient.
func (*Client) Dial ¶
func (c *Client) Dial(ctx context.Context, target Target, password, confirmedFingerprint string) (*Connection, error)
Dial authenticates as root only after the host presents the fingerprint the owner confirmed in the UI. A changed or unexpected key never receives the password.
func (*Client) DialAs ¶
func (c *Client) DialAs(ctx context.Context, target Target, username, password, confirmedFingerprint string) (*Connection, error)
DialAs authenticates with the supplied account after the server presents the confirmed host key. Non-root accounts are accepted only when the remote preflight proves passwordless sudo works.
func (*Client) DialKey ¶ added in v0.1.74
func (c *Client) DialKey(ctx context.Context, target Target, username string, signer ssh.Signer, confirmedFingerprint string) (*Connection, error)
DialKey authenticates with a panel SSH key only after the server presents the confirmed fingerprint.
func (*Client) Fingerprint ¶
func (c *Client) Fingerprint(ctx context.Context, target Target) (fingerprint, algorithm string, err error)
Fingerprint reads one reachable server key without authenticating and returns its SHA-256 fingerprint and key type. The SSH handshake is stopped as soon as the key is received, before an auth request.
type Config ¶
type Config struct {
StepUp func(context.Context) error
Nodes NodeManager
Binaries BinarySource
PanelAddr string
AgentSNI string
// LinkURL (wss://host/<secret-prefix>/) makes the node enrol over the panel's public link instead of the mTLS
// endpoint (--link-url, no --panel or --sni), and its host:port is what the node's reachability probe dials. Set by
// the edge edition only; PanelAddr is then unused. With neither, installs say panel_address_not_configured.
LinkURL string
// Kick, when set, is called instead of waking the in-process worker loop whenever a job is queued: a host without
// a loop (the edge alarm) wakes its own runner. It runs inside the request that queued the job, so it must not block.
Kick func()
Log *slog.Logger
Now func() time.Time
SSH *Client
WaitOnline time.Duration
RetryDelay time.Duration
}
Config contains the services needed for durable SSH provisioning.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection is an authenticated SSH client whose lifetime follows the context passed to Dial. Close it when the provisioning phase ends.
func (*Connection) Close ¶
func (c *Connection) Close() error
Close ends the SSH connection and stops its cancellation hook.
func (*Connection) NewSession ¶
func (c *Connection) NewSession() (*ssh.Session, error)
NewSession opens one SSH session on the verified connection.
func (*Connection) PrivilegedCommand ¶
func (c *Connection) PrivilegedCommand(command string) string
PrivilegedCommand runs a command with root privileges without prompting for a second password.
type NodeManager ¶
type NodeManager interface {
CreateProvisionEnrollment(context.Context, NodeSpec, string, time.Time, time.Time) (token, caFingerprint string, err error)
ProvisionNodeState(context.Context, string) (state string, connected bool, err error)
}
NodeManager joins a durable installation job to the fleet CA and agent stream.
type NodeSpec ¶
type NodeSpec struct {
ID, Name, Address, CountryCode, Location, Provider string
}
NodeSpec is the node metadata reserved by one provisioning job.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service exposes the owner-only provisioning API and runs durable jobs.
func NewService ¶
NewService builds the provisioning API and its background worker.
func (*Service) AddNodeServerKey ¶ added in v0.1.74
func (*Service) AttachNodeServerAccess ¶ added in v0.1.74
func (*Service) CancelNodeProvision ¶
CancelNodeProvision stops a queued install immediately or asks the active SSH worker to stop. An active cancellation is reported as uncertain because remote commands may already have changed the host.
func (*Service) CheckSSH ¶
func (s *Service) CheckSSH(ctx context.Context, req *connect.Request[adminv1.CheckSSHRequest]) (*connect.Response[adminv1.CheckSSHResponse], error)
CheckSSH authenticates only after the submitted fingerprint exactly matches the host key.
func (*Service) Drain ¶ added in v0.1.35
Drain is the pass of a host that cannot keep a loop running between events (the edge edition's alarm): it claims and runs at most one queued job, then says whether another is waiting. busy: a pass is already running in this process, nothing was done. The first pass of a Service also recovers jobs a dead process left running, as Run does at start.
func (*Service) ForgetNodeServerAccess ¶ added in v0.1.15
func (s *Service) ForgetNodeServerAccess(ctx context.Context, req *connect.Request[adminv1.ForgetNodeServerAccessRequest]) (*connect.Response[adminv1.ForgetNodeServerAccessResponse], error)
ForgetNodeServerAccess deletes the saved access of a retired node, sealed password included. Retiring keeps it on purpose (the password may be one only the panel knows), so forgetting is the owner's own step-up protected decision.
func (*Service) GetNodeProvision ¶
func (s *Service) GetNodeProvision(ctx context.Context, req *connect.Request[adminv1.GetNodeProvisionRequest]) (*connect.Response[adminv1.GetNodeProvisionResponse], error)
GetNodeProvision returns public job status; its encrypted secret is omitted.
func (*Service) GetPanelSSHKey ¶ added in v0.1.74
func (s *Service) GetPanelSSHKey(ctx context.Context, _ *connect.Request[adminv1.GetPanelSSHKeyRequest]) (*connect.Response[adminv1.GetPanelSSHKeyResponse], error)
GetPanelSSHKey lazily creates the panel's single ed25519 SSH identity and returns only its public half.
func (*Service) GetSSHFingerprint ¶
func (s *Service) GetSSHFingerprint(ctx context.Context, req *connect.Request[adminv1.GetSSHFingerprintRequest]) (*connect.Response[adminv1.GetSSHFingerprintResponse], error)
GetSSHFingerprint reads the remote SSH host key without sending authentication.
func (*Service) ListNodeProvisionEvents ¶
func (s *Service) ListNodeProvisionEvents(ctx context.Context, req *connect.Request[adminv1.ListNodeProvisionEventsRequest]) (*connect.Response[adminv1.ListNodeProvisionEventsResponse], error)
ListNodeProvisionEvents returns only stable event codes, never remote output.
func (*Service) ListNodeProvisions ¶
func (s *Service) ListNodeProvisions(ctx context.Context, _ *connect.Request[adminv1.ListNodeProvisionsRequest]) (*connect.Response[adminv1.ListNodeProvisionsResponse], error)
ListNodeProvisions returns the most recently updated provisioning jobs.
func (*Service) ListNodeServerAccess ¶
func (s *Service) ListNodeServerAccess(ctx context.Context, _ *connect.Request[adminv1.ListNodeServerAccessRequest]) (*connect.Response[adminv1.ListNodeServerAccessResponse], error)
ListNodeServerAccess returns connection metadata only; encrypted credentials stay inside the panel.
func (*Service) ListNodeServerKeys ¶ added in v0.1.74
func (s *Service) ListNodeServerKeys(ctx context.Context, req *connect.Request[adminv1.ListNodeServerKeysRequest]) (*connect.Response[adminv1.ListNodeServerKeysResponse], error)
ListNodeServerKeys reads and parses the login user's authorized_keys without privilege escalation.
func (*Service) PageHandler ¶
PageHandler serves the Go-rendered SSH installation wizard. The HTTP server wraps it in the same owner-only session and cross-origin protections as the admin API.
func (*Service) RemoveNodeServerKey ¶ added in v0.1.74
func (*Service) RetryNodeProvision ¶
func (s *Service) RetryNodeProvision(ctx context.Context, req *connect.Request[adminv1.RetryNodeProvisionRequest]) (*connect.Response[adminv1.RetryNodeProvisionResponse], error)
RetryNodeProvision requeues a failed or cancelled job with freshly supplied SSH login credentials. A cancelled job may have changed the host already; the worker's resume path (preflight identity check, enroll --resume-key) picks up from there. A job whose node was retired cannot come back.
func (*Service) RevealNodeServerPassword ¶ added in v0.1.1
func (s *Service) RevealNodeServerPassword(ctx context.Context, req *connect.Request[adminv1.RevealNodeServerPasswordRequest]) (*connect.Response[adminv1.RevealNodeServerPasswordResponse], error)
RevealNodeServerPassword is an owner-only, step-up protected panel operation. It is intentionally not registered as an MCP tool: the admin can retrieve the encrypted-at-rest credential in the panel, while an agent can only request a generated password rotation and receives its status.
func (*Service) RotateNodeServerPassword ¶
func (s *Service) RotateNodeServerPassword(ctx context.Context, req *connect.Request[adminv1.RotateNodeServerPasswordRequest]) (*connect.Response[adminv1.RotateNodeServerPasswordResponse], error)
RotateNodeServerPassword changes the OS login password over the pinned SSH connection and verifies it with a fresh authentication before the panel promotes the encrypted credential. With generate the panel makes the password itself (the MCP rotation): it is never returned, the owner can reveal it after step-up.
func (*Service) StartNodeProvision ¶
func (s *Service) StartNodeProvision(ctx context.Context, req *connect.Request[adminv1.StartNodeProvisionRequest]) (*connect.Response[adminv1.StartNodeProvisionResponse], error)
StartNodeProvision stores the selected SSH login sealed to this job and queues installation. The MCP apply sends plan_id instead and the login choice comes from that plan's approval (ownerLogin).
type Target ¶
type Target struct {
// contains filtered or unexported fields
}
Target is a normalized SSH host and port. Construct it with NewTarget so DNS search suffixes, zones and malformed host names cannot alter where we dial.
func (Target) Address ¶
Address returns the target in host:port form, with IPv6 brackets when needed.