Documentation
¶
Overview ¶
Package enroll obtains the nkey broker credential sqi-worker authenticates with: loading an existing seed from disk when one is present, and otherwise enrolling with sqi-server over REST when a join token is configured.
Enrollment runs over REST rather than NATS: the broker refuses unauthenticated connections, so it cannot be the channel a worker gets its first credential over. The enrollment URL is nats.server_url; it is not derived from mDNS discovery.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoCredential = errors.New("worker: no credential and no join token")
ErrNoCredential is returned when no credential file exists and no join token is configured to obtain one. It is not fatal on a farm that does not require worker authentication; see EnsureCredential for how callers treat it.
Functions ¶
func EnsureCredential ¶
func EnsureCredential(ctx context.Context, cfg Config, logger *slog.Logger) (seed []byte, publicKey string, err error)
EnsureCredential returns this worker's nkey seed and public key: loading an existing credential file if one is present, and otherwise enrolling with sqi-server over REST using a configured join token.
An existing seed is loaded first, so an enrolled worker never re-enrolls because a join token is still configured; only when no seed exists does enrollment happen. When neither a seed nor a token is available, EnsureCredential returns ErrNoCredential, and the caller decides whether that is fatal (a farm that requires authentication) or fine (an auth-off farm, where the caller proceeds with no credential and the broker decides whether to accept the connection).
A credential is written to disk only after the server confirms enrollment, so a failed enrollment leaves no seed for a later boot to reuse.
Types ¶
type Config ¶
type Config struct {
// WorkerID is this worker's stable, server-correlated identity.
WorkerID string
// CredentialFile is the path to this worker's nkey seed file.
CredentialFile string
// JoinToken is a worker enrollment token, used once to obtain a
// credential.
JoinToken string
// JoinTokenFile is a path to a file containing a join token, and takes
// precedence over JoinToken when both are set.
JoinTokenFile string
// ServerURL is the sqi-server HTTP base URL used for enrollment.
ServerURL string
// HTTPClient performs the enrollment request. When nil, one is built from
// TLSCAFile and InsecureSkipVerify below.
HTTPClient *http.Client
// TLSCAFile is the CA that verifies the server's certificate at
// ServerURL. Empty means the system roots; set means that CA only, so a
// farm CA pins the acceptable issuer rather than widening it.
TLSCAFile string
// InsecureSkipVerify disables verification of the server's certificate.
// Development only.
InsecureSkipVerify bool
}
Config holds everything EnsureCredential needs to load or obtain a credential. It is passed by value and kept separate from the worker configuration struct, so a seed never travels through, or is logged by, general-purpose configuration plumbing.