enroll

package
v0.9.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 22 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 manages node identity (Ed25519 keypair that never leaves the device), CSR generation, the Enroll RPC, credential storage, and the `tera login` PKCE-style browser handoff (SPEC §4.1, §6).

Index

Constants

View Source
const RotationWindow = 7 * 24 * time.Hour

RotationWindow is how long before expiry the daemon starts renewing the client certificate (RotateIfNeeded).

Variables

This section is empty.

Functions

func ClaimCodePath

func ClaimCodePath(dataDir string) string

ClaimCodePath is the handoff location for a pending claim code.

func ClaimVerifierPath added in v0.6.1

func ClaimVerifierPath(dataDir string) string

ClaimVerifierPath is the handoff location for the code's PKCE verifier.

func ClearClaimCode

func ClearClaimCode(dataDir string) error

ClearClaimCode removes a consumed claim code. Claim codes are one-shot at the coordinator, so keeping a spent one around would only produce confusing retry failures on every restart.

func ClientTLSConfig

func ClientTLSConfig(id *Identity, creds *Credentials, pinnedCA []byte, insecureSkipVerify bool) (*tls.Config, error)

ClientTLSConfig builds the mTLS client config for the coordinator tunnel from the node identity and enrollment credentials. The client certificate is the one the mesh CA issued at enrollment; the server is verified against RootPool with the enrolled mesh CA and the operator's pinned CA (tunnel.ca_cert, may be nil) appended for self-hosted and test coordinators that serve a private-CA-issued cert.

func Enrolled

func Enrolled(dataDir string) bool

Enrolled reports whether credentials exist.

func ReadClaimCode

func ReadClaimCode(dataDir string) (string, error)

ReadClaimCode returns a pending claim code, or os.ErrNotExist when the node has nothing to enroll with.

func ReadClaimVerifier added in v0.6.1

func ReadClaimVerifier(dataDir string) (string, error)

ReadClaimVerifier returns the verifier stored beside the claim code, or "" when there is none (codes from the claim page's --claim-code path carry no PKCE binding).

func RemoveCredentials added in v0.6.9

func RemoveCredentials(dataDir string) error

RemoveCredentials deletes the persisted enrollment artifacts so the node can be claimed again (e.g. under a different account). The device identity (node.key) is left in place — only the coordinator-issued cert and node ID tied to the previous enrollment are removed.

func RootPool added in v0.6.1

func RootPool(extra ...[]byte) (*x509.CertPool, error)

RootPool is the server-verification pool for every coordinator dial: the system roots (production presents a public certificate for tunnel.teraflock.ai) plus each non-empty extra PEM — the mesh CA the node enrolled with, and tunnel.ca_cert when the operator pinned one for a self-hosted coordinator. A non-empty PEM that holds no certificate is an error rather than a silently narrower pool.

func SaveClaimCode

func SaveClaimCode(dataDir, code string) error

SaveClaimCode persists a claim code for the daemon to consume on its next start (0600 — a claim code grants enrollment to the operator's account).

func SaveClaimVerifier added in v0.6.1

func SaveClaimVerifier(dataDir, verifier string) error

SaveClaimVerifier persists the PKCE verifier beside a pending claim code (0600 — with the code it is the whole credential). An empty verifier removes any stale one so a `--claim-code` login after an abandoned browser flow does not send the wrong proof.

func SaveCredentials

func SaveCredentials(dataDir string, c *Credentials) error

SaveCredentials persists creds with 0600.

Types

type Credentials

type Credentials struct {
	NodeID            string
	ClientCertPEM     []byte
	CACertPEM         []byte
	CoordinatorPubKey ed25519.PublicKey
	CertExpiresAt     time.Time
}

Credentials are the enrollment artifacts persisted to the data dir.

func Enroll

func Enroll(ctx context.Context, client tunnelv1.TunnelServiceClient, id *Identity, claimCode, verifier string, prof *typesv1.CapabilityProfile, dataDir string) (*Credentials, error)

Enroll performs the Enroll RPC with a claim code and persists the result. verifier is the PKCE code_verifier from the browser flow ("" for codes obtained any other way); the coordinator checks it against the challenge bound to the code (control-plane#6).

func LoadCredentials

func LoadCredentials(dataDir string) (*Credentials, error)

LoadCredentials reads persisted enrollment artifacts; os.ErrNotExist if the node has never enrolled.

func RotateIfNeeded

func RotateIfNeeded(ctx context.Context, client tunnelv1.TunnelServiceClient, id *Identity, creds *Credentials, prof *typesv1.CapabilityProfile, dataDir string) (*Credentials, error)

RotateIfNeeded re-enrolls when the client cert is within RotationWindow of expiry. Cert rotation happens over the tunnel every 30 days (SPEC §6). TODO(rotation): the real coordinator will accept rotation without a claim code, authenticated by the existing mTLS session; the fake accepts the sentinel code below.

type Identity

type Identity struct {
	Priv ed25519.PrivateKey
	Pub  ed25519.PublicKey
}

Identity is the node's Ed25519 keypair. NodeID = key fingerprint.

func LoadOrGenerateIdentity

func LoadOrGenerateIdentity(dataDir string) (*Identity, error)

LoadOrGenerateIdentity returns the persisted identity, creating one with 0600 permissions on first run.

TODO(keychain): move private key storage to OS keychain / DPAPI / secret service; file with 0600 is the documented Phase 0 baseline.

func (*Identity) CSR

func (id *Identity) CSR() ([]byte, error)

CSR generates a PEM-encoded certificate signing request for the identity.

func (*Identity) Fingerprint

func (id *Identity) Fingerprint() string

Fingerprint is the node identity string (sha256 of the raw public key).

type LoginFlow

type LoginFlow struct {
	// LoginURL is the browser page (config enroll.login_url).
	LoginURL string
	// OpenBrowser launches the URL; overridable in tests. Nil = browser.Open.
	OpenBrowser func(url string) error
	// OnURL, if set, is called with the login URL as soon as it's built —
	// before the browser is opened and before Run blocks on the callback —
	// so a caller on a headless/remote box can print it immediately instead
	// of only learning it after the whole flow finishes or times out.
	OnURL func(url string)
}

LoginFlow implements the `tera login` browser handoff: a PKCE-style loopback callback that receives the claim code from the signup page.

  1. generate code_verifier + S256 challenge
  2. open <login_url>?redirect_uri=http://127.0.0.1:<port>/callback&code_challenge=...
  3. the web page (after auth) redirects to the loopback with ?claim_code=...&state=...
  4. daemon sends the claim code and the verifier in the Enroll RPC; the coordinator refuses the code unless SHA256(verifier) matches the challenge the claim page stored with it (control-plane#6).

func (*LoginFlow) Run

func (f *LoginFlow) Run(ctx context.Context) (*Result, string, error)

Run executes the flow, blocking until the callback arrives or ctx ends. It returns the URL it opened (for "visit this URL" fallback output).

type Result

type Result struct {
	ClaimCode string
	// Verifier is the PKCE code_verifier whose S256 hash the claim page
	// received; it must reach the coordinator with the claim code.
	Verifier string
}

Result of a completed login flow.

Jump to

Keyboard shortcuts

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