enroll

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 23 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

This section is empty.

Variables

This section is empty.

Functions

func ClaimCodePath

func ClaimCodePath(dataDir string) string

ClaimCodePath is the handoff location for a pending claim code.

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, 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 system roots (production presents a public certificate for tunnel.teraflock.ai) with the mesh CA appended for self-hosted and test coordinators that serve a mesh-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 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 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 string, cap *typesv1.CapabilityProfile, dataDir string) (*Credentials, error)

Enroll performs the Enroll RPC with a claim code and persists the result.

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, cap *typesv1.CapabilityProfile, dataDir string) (*Credentials, error)

RotateIfNeeded re-enrolls when the client cert is within 7 days 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 = xdg-open/open.
	OpenBrowser func(url string) error
}

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 uses the claim code in the Enroll RPC.

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
}

Result of a completed login flow.

Jump to

Keyboard shortcuts

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