provision

package
v0.2.0-dev.5 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: 39 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 provision contains the panel's SSH provisioning primitives.

Index

Constants

View Source
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.

View Source
const DefaultSSHPort = 22

DefaultSSHPort is used when the owner leaves the SSH port blank.

View Source
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

View Source
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")
)
View Source
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

func DoHLookup(client *http.Client) func(ctx context.Context, host string) ([]netip.Addr, error)

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

func ForwardMarker(build string) http.Handler

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
	// Sharing is who the node is handed out to; the zero value lets the panel decide when the node is made.
	Sharing store.NodeShareChoice
}

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

func NewService(st *store.Store, vlt *vault.Vault, cfg Config) (*Service, error)

NewService builds the provisioning API and its background worker.

func (*Service) AddNodeServerKey added in v0.1.74

func (*Service) CancelNodeProvision

func (s *Service) CancelNodeProvision(ctx context.Context, jobID string) (string, error)

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

CheckSSH authenticates only after the submitted fingerprint exactly matches the host key.

func (*Service) Drain added in v0.1.35

func (s *Service) Drain(ctx context.Context) (more, busy bool, err error)

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

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

GetNodeProvision returns public job status; its encrypted secret is omitted.

func (*Service) GetPanelSSHKey added in v0.1.74

GetPanelSSHKey lazily creates the panel's single ed25519 SSH identity and returns only its public half.

func (*Service) GetSSHFingerprint

GetSSHFingerprint reads the remote SSH host key without sending authentication.

func (*Service) Handler

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

Handler mounts the owner-only ProvisioningService Connect handler.

func (*Service) ListNodeProvisionEvents

ListNodeProvisionEvents returns only stable event codes, never remote output.

func (*Service) ListNodeProvisions

ListNodeProvisions returns the most recently updated provisioning jobs.

func (*Service) ListNodeServerAccess

ListNodeServerAccess returns connection metadata only; encrypted credentials stay inside the panel.

func (*Service) ListNodeServerKeys added in v0.1.74

ListNodeServerKeys reads and parses the login user's authorized_keys without privilege escalation.

func (*Service) PageHandler

func (s *Service) PageHandler() http.Handler

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) RetryNodeProvision

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

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

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) Run

func (s *Service) Run(ctx context.Context) error

Run recovers interrupted jobs and executes queued installations serially.

func (*Service) StartNodeProvision

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 NewTarget

func NewTarget(host string, port uint32) (Target, error)

NewTarget validates and normalizes an SSH hostname or IP address and port.

func (Target) Address

func (t Target) Address() string

Address returns the target in host:port form, with IPv6 brackets when needed.

func (Target) Host

func (t Target) Host() string

Host returns the normalized SSH hostname or IP address.

func (Target) Port

func (t Target) Port() uint16

Port returns the normalized SSH port.

Jump to

Keyboard shortcuts

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