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 ¶
- func ClaimCodePath(dataDir string) string
- func ClearClaimCode(dataDir string) error
- func ClientTLSConfig(id *Identity, creds *Credentials, insecureSkipVerify bool) (*tls.Config, error)
- func Enrolled(dataDir string) bool
- func ReadClaimCode(dataDir string) (string, error)
- func SaveClaimCode(dataDir, code string) error
- func SaveCredentials(dataDir string, c *Credentials) error
- type Credentials
- type Identity
- type LoginFlow
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClaimCodePath ¶
ClaimCodePath is the handoff location for a pending claim code.
func ClearClaimCode ¶
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 ReadClaimCode ¶
ReadClaimCode returns a pending claim code, or os.ErrNotExist when the node has nothing to enroll with.
func SaveClaimCode ¶
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, prof *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, prof *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 ¶
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) Fingerprint ¶
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
}
LoginFlow implements the `tera login` browser handoff: a PKCE-style loopback callback that receives the claim code from the signup page.
- generate code_verifier + S256 challenge
- open <login_url>?redirect_uri=http://127.0.0.1:<port>/callback&code_challenge=...
- the web page (after auth) redirects to the loopback with ?claim_code=...&state=...
- daemon uses the claim code in the Enroll RPC.