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 ¶
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.
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`.
const ResultPrefix = "EDGEWEIR_RESULT "
ResultPrefix starts the result line; the rest of the line is JSON.
const ResultVersion = 1
ResultVersion is the version of the result line's fields.
Variables ¶
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.
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.
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).
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.
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.
var ErrInvalidOptions = errors.New("invalid enrollment options")
ErrInvalidOptions marks an invalid server URL, CA pin or missing token.
var ErrProbeAlreadyEnrolled = errors.New("probe is already enrolled")
ErrProbeAlreadyEnrolled is returned when a probe identity exists.
var ErrStateDir = errors.New("state directory unusable")
ErrStateDir marks a state directory that cannot hold the identity.
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
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`).
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
Outcome classifies an error of Run or Existing for the result line and the exit status.
func (Result) WithIdentity ¶ added in v1.7.0
WithIdentity fills the identity fields of r from id.