enroll

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: 14 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 enroll implements `edgeweir-node enroll`: it exchanges a single-use token and a locally generated CSR for a node certificate issued by the console's internal CA. `edgeweir-node probe` enrolls a probe the same way (Probe).

Trust bootstrap follows kubeadm's discovery model: the install command carries the SHA-256 of the internal CA certificate, the TLS handshake is verified against that pin before the token is sent, and the CA returned in the response must hash to the same pin.

Index

Constants

View Source
const (
	StatusEnrolled          = "enrolled"           // exit 0
	StatusAlreadyEnrolled   = "already_enrolled"   // exit 0 with --if-not-enrolled, else 10
	StatusError             = "error"              // exit 1
	StatusUsage             = "usage"              // exit 2
	StatusEnrolledElsewhere = "enrolled_elsewhere" // exit 11
	StatusTokenRejected     = "token_rejected"     // exit 12
	StatusUnreachable       = "unreachable"        // exit 13
	StatusCAMismatch        = "ca_mismatch"        // exit 14
	StatusStateDir          = "state_dir"          // exit 15
	StatusBusy              = "busy"               // exit 16
	StatusConsoleError      = "console_error"      // exit 17
)

Statuses of the result line, each with its exit status.

View Source
const (
	ExitOK                = 0
	ExitError             = 1
	ExitUsage             = 2
	ExitAlreadyEnrolled   = 10
	ExitEnrolledElsewhere = 11
	ExitTokenRejected     = 12
	ExitUnreachable       = 13
	ExitCAMismatch        = 14
	ExitStateDir          = 15
	ExitBusy              = 16
	ExitConsoleError      = 17
)

Exit statuses of `edgeweir-node enroll`.

View Source
const ResultPrefix = "EDGEWEIR_RESULT "

ResultPrefix starts the result line; the rest of the line is JSON.

View Source
const ResultVersion = 1

ResultVersion is the version of the result line's fields.

Variables

View Source
var ErrAgentRunning = errors.New("edgeweir-node run is using this state directory; stop it first " +
	"(e.g. systemctl stop edgeweir-node), enroll --force, then start it again")

ErrAgentRunning is returned by a forced enrollment while an agent runs with the state directory: the agent keeps the identity it loaded, and a certificate renewal could write the old node's certificate next to the new key.

View Source
var ErrAlreadyEnrolled = errors.New("node is already enrolled (use --force to replace the identity)")

ErrAlreadyEnrolled is returned when an identity exists and Force is off.

View Source
var ErrBadResponse = errors.New("invalid enroll response")

ErrBadResponse marks an answer of the console that the node cannot use (missing fields, a certificate that does not fit the key).

View Source
var ErrBusy = errors.New("another enrollment is running with this state directory; " +
	"wait for it, then run this command again")

ErrBusy is returned while another enrollment runs with the state directory.

View Source
var ErrEnrolledElsewhere = errors.New("node is enrolled with another console (its identity pins another CA)")

ErrEnrolledElsewhere is returned by Existing when the identity pins another console CA than the one asked for.

View Source
var ErrInvalidOptions = errors.New("invalid enrollment options")

ErrInvalidOptions marks an invalid server URL, CA pin or missing token.

View Source
var ErrProbeAlreadyEnrolled = errors.New("probe is already enrolled")

ErrProbeAlreadyEnrolled is returned when a probe identity exists.

View Source
var ErrStateDir = errors.New("state directory unusable")

ErrStateDir marks a state directory that cannot hold the identity.

View Source
var ErrTokenRejected = errors.New("console rejected the enrollment token (expired or already used)")

ErrTokenRejected marks a token the console refused (unknown, expired or used).

Functions

func Existing added in v1.7.0

func Existing(stateDir, caSHA256 string) (*identity.Identity, error)

Existing returns the identity of an enrolled node in stateDir when it pins the CA caSHA256 (the same console), with ErrEnrolledElsewhere when it pins another one, and identity.ErrNotEnrolled when there is none. Nothing is sent and no token is needed (`enroll --if-not-enrolled`).

func Probe

func Probe(ctx context.Context, opts ProbeOptions) (*identity.Identity, error)

Probe enrolls a probe with ProbeService.EnrollProbe: the same trust bootstrap as a node (CA pin checked before the token is sent, the key never leaves this host) and the probe layout of the identity store.

func Run

func Run(ctx context.Context, opts Options) (*identity.Identity, error)

Run performs the enrollment and persists the identity.

Types

type Options

type Options struct {
	// ServerURL is the console node-channel base URL, e.g. https://console:8443.
	ServerURL string
	// Token is the single-use enrollment token.
	Token string
	// CASHA256 is the pinned internal CA fingerprint (hex SHA-256 of DER).
	CASHA256 string
	// ServerName overrides the TLS server name (defaults to the URL host).
	ServerName string
	// StateDir is where the identity is written.
	StateDir string
	// Force replaces an existing identity.
	Force bool
	// Info describes this node; collected automatically when nil.
	Info *nodev1.NodeInfo
	// Timeout bounds the Enroll RPC (default 30s).
	Timeout time.Duration
	Logger  *slog.Logger
}

Options configures an enrollment.

type ProbeOptions

type ProbeOptions struct {
	ServerURL  string
	Token      string
	CASHA256   string
	ServerName string
	// StateDir receives the probe layout of the identity (probe.key,
	// probe.crt, ca.crt, probe.json).
	StateDir string
	Info     *nodev1.ProbeInfo
	Timeout  time.Duration
	Logger   *slog.Logger
}

ProbeOptions configures the enrollment of a probe (`edgeweir-node probe`).

type Result added in v1.7.0

type Result struct {
	V      int    `json:"v"`
	Step   string `json:"step"`
	Status string `json:"status"`
	Exit   int    `json:"exit"`
	// Retry tells whether running the same command again (same token) may
	// succeed: the failure was in the network or a concurrent enrollment.
	Retry     bool   `json:"retry"`
	NodeID    string `json:"node_id,omitempty"`
	NodeName  string `json:"node_name,omitempty"`
	ClusterID string `json:"cluster_id,omitempty"`
	// CASHA256 is the CA an existing identity pins (enrolled_elsewhere).
	CASHA256 string `json:"ca_sha256,omitempty"`
	// NotAfter is when the node certificate expires (enrolled).
	NotAfter string `json:"not_after,omitempty"`
	// Message is English detail for logs; callers go by Status.
	Message string `json:"message,omitempty"`
}

Result is the result line of one `edgeweir-node enroll`.

func Outcome added in v1.7.0

func Outcome(err error) Result

Outcome classifies an error of Run or Existing for the result line and the exit status.

func Succeeded added in v1.7.0

func Succeeded(id *identity.Identity, notAfter time.Time) Result

Succeeded is the result of a completed enrollment.

func (Result) WithIdentity added in v1.7.0

func (r Result) WithIdentity(id *identity.Identity) Result

WithIdentity fills the identity fields of r from id.

func (Result) Write added in v1.7.0

func (r Result) Write(w io.Writer) error

Write writes r as one line.

Jump to

Keyboard shortcuts

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