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
- func ClaimCodePath(dataDir string) string
- func ClaimVerifierPath(dataDir string) string
- func ClearClaimCode(dataDir string) error
- func ClientTLSConfig(id *Identity, creds *Credentials, pinnedCA []byte, insecureSkipVerify bool) (*tls.Config, error)
- func Enrolled(dataDir string) bool
- func ReadClaimCode(dataDir string) (string, error)
- func ReadClaimVerifier(dataDir string) (string, error)
- func RemoveCredentials(dataDir string) error
- func RootPool(extra ...[]byte) (*x509.CertPool, error)
- func SaveClaimCode(dataDir, code string) error
- func SaveClaimVerifier(dataDir, verifier string) error
- func SaveCredentials(dataDir string, c *Credentials) error
- type Credentials
- type Identity
- type LoginFlow
- type Result
Constants ¶
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 ¶
ClaimCodePath is the handoff location for a pending claim code.
func ClaimVerifierPath ¶ added in v0.6.1
ClaimVerifierPath is the handoff location for the code's PKCE verifier.
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, 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 ReadClaimCode ¶
ReadClaimCode returns a pending claim code, or os.ErrNotExist when the node has nothing to enroll with.
func ReadClaimVerifier ¶ added in v0.6.1
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
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
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 ¶
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
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 ¶
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
// 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.
- 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 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).