identity

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: AGPL-3.0 Imports: 14 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 identity persists the node's enrollment result in the state directory:

node.key       ECDSA P-256 private key, PKCS#8 PEM, mode 0600
node.crt       node client certificate issued by the internal CA
ca.crt         internal CA certificate (verified against the pin)
identity.json  node id, cluster id, name and console address
run.lock       held (flock) by `edgeweir-node run` while it runs
identity.lock  held (flock) while the console address is changed
enroll.lock    held (flock) by `edgeweir-node enroll` while it enrolls
enroll.key     the key of an enrollment not completed yet, mode 0600
decommissioned written when the console decommissioned the node; the
               agent does not start while it exists, an enrollment
               removes it

enroll.key is written before the token and CSR are sent and reused by every retry until an enrollment is saved (then it is node.key): an attempt whose answer was lost (the SSH session or the connection died after the console issued the certificate) is retried with the same public key, which lets the console answer with the node it already created instead of a second one.

identity.json is written last and is the "enrolled" marker; the other files are always complete when it exists. Every file is replaced atomically (temp file, fsync, rename, fsync dir).

A probe (`edgeweir-node probe`) keeps its identity in its own state directory with the same rules: probe.key (0600), probe.crt, ca.crt and probe.json (probe id, name, region and console address).

Index

Constants

View Source
const (
	KeyFile      = "node.key"
	CertFile     = "node.crt"
	CAFile       = "ca.crt"
	IdentityFile = "identity.json"
	// ConfigDir holds the last-known-good configuration (see configstore).
	ConfigDir = "config"
	// RunLockFile is locked by a running agent (LockRun).
	RunLockFile = "run.lock"
	// IdentityLockFile is locked while the console address in the identity
	// file is changed (UpdateServer).
	IdentityLockFile = "identity.lock"
	// EnrollLockFile is locked by a running enrollment (LockEnroll).
	EnrollLockFile = "enroll.lock"
	// PendingKeyFile is the key of an enrollment not completed yet.
	PendingKeyFile = "enroll.key"
	// DecommissionedFile marks a node the console decommissioned.
	DecommissionedFile = "decommissioned"

	// The probe layout (Store.Probe).
	ProbeKeyFile      = "probe.key"
	ProbeCertFile     = "probe.crt"
	ProbeIdentityFile = "probe.json"
)

File names inside the state directory.

View Source
const (
	ServerSourceConsole = "console"
	ServerSourceCommand = "command"
)

How Identity.ServerURL was set; empty means the enrollment.

Variables

View Source
var ErrEnrolling = errors.New("another enrollment is running with this state directory")

ErrEnrolling is returned by LockEnroll when another enrollment runs with the state directory.

View Source
var ErrIdentityReplaced = errors.New("the identity was replaced meanwhile (enrolled again)")

ErrIdentityReplaced is returned by UpdateServer when the identity file names another enrollment than the one expected.

View Source
var ErrNotEnrolled = errors.New("node is not enrolled")

ErrNotEnrolled is returned by Load when identity.json does not exist.

View Source
var ErrProbeNotEnrolled = errors.New("probe is not enrolled")

ErrProbeNotEnrolled is returned by Load when probe.json does not exist.

View Source
var ErrRunning = errors.New("an edgeweir-node agent is running with this state directory")

ErrRunning is returned by LockRun when an agent already runs with the state directory.

Functions

func SameIdentity added in v1.2.0

func SameIdentity(a, b Identity) bool

SameIdentity reports whether a and b name the same enrollment (the console address aside).

func SameServer added in v1.2.0

func SameServer(a, b Identity) bool

SameServer reports whether a and b carry the same console addresses.

Types

type Identity

type Identity struct {
	NodeID    string `json:"node_id,omitempty"`
	ClusterID string `json:"cluster_id,omitempty"`
	NodeName  string `json:"node_name,omitempty"`
	ProbeID   string `json:"probe_id,omitempty"`
	ProbeName string `json:"probe_name,omitempty"`
	// RegionID is the region a probe measures from.
	RegionID   string    `json:"region_id,omitempty"`
	ServerURL  string    `json:"server_url"`
	ServerName string    `json:"server_name"`
	CASHA256   string    `json:"ca_sha256"`
	EnrolledAt time.Time `json:"enrolled_at"`
	// The console address used before the last change of ServerURL (the
	// agent tries it while ServerURL fails), how ServerURL was set
	// (ServerSource*) and when. Empty until the address first changes.
	FallbackServerURL  string    `json:"fallback_server_url,omitempty"`
	FallbackServerName string    `json:"fallback_server_name,omitempty"`
	ServerSource       string    `json:"server_source,omitempty"`
	ServerChangedAt    time.Time `json:"server_changed_at,omitzero"`
}

Identity is the non-secret enrollment metadata: the node fields for a node, the probe fields for a probe.

type Loaded

type Loaded struct {
	Identity
	Key         crypto.Signer
	Certificate *x509.Certificate
	TLS         tls.Certificate
	CA          *x509.Certificate
	CAPool      *x509.CertPool
}

Loaded is a fully parsed identity ready to build TLS configurations.

type Store

type Store struct {
	Dir string
	// Probe selects the probe layout (probe.key, probe.crt, probe.json).
	Probe bool
}

Store reads and writes identity files in a state directory.

func (Store) CertFile

func (s Store) CertFile() string

func (Store) Enrolled

func (s Store) Enrolled() bool

Enrolled reports whether identity.json (probe.json) exists.

func (Store) EnsureDir

func (s Store) EnsureDir() error

EnsureDir creates the state directory with mode 0700 if missing.

func (Store) IdentityFile

func (s Store) IdentityFile() string

func (Store) KeyFile

func (s Store) KeyFile() string

KeyFile, CertFile and IdentityFile are the names of the store's layout.

func (Store) Load

func (s Store) Load() (*Loaded, error)

Load reads and validates the identity. A certificate swap interrupted by a crash (see SwapCertificate) is completed transparently.

func (Store) LockEnroll added in v1.7.0

func (s Store) LockEnroll() (release func(), err error)

LockEnroll takes the enrollment lock of the state directory (EnrollLockFile, flock): two enrollments of one host at the same time (a retried batch install while the first attempt still runs) would both use a token and leave the console with two nodes. It fails with ErrEnrolling when another process holds it.

func (Store) LockRun

func (s Store) LockRun() (release func(), err error)

LockRun takes the run lock of the state directory (RunLockFile, flock): `edgeweir-node run` holds it while it uses the identity, `enroll --force` while it replaces one, so that an identity is never replaced under a running agent. It fails with ErrRunning when another process holds it.

func (Store) Path

func (s Store) Path(name string) string

Path returns the absolute path of a file in the state directory.

func (Store) PendingKey added in v1.7.0

func (s Store) PendingKey() (key crypto.Signer, reused bool, err error)

PendingKey returns the key of an enrollment not completed yet (PendingKeyFile), or creates and stores a new one. reused tells which. An unreadable pending key is replaced.

func (Store) ReadIdentity

func (s Store) ReadIdentity() (*Identity, error)

ReadIdentity reads only identity.json (probe.json) without keys or certificates.

func (Store) Remove

func (s Store) Remove() error

Remove deletes the identity and the cached configuration (used by `enroll --force`). The identity marker is removed first.

func (Store) Save

func (s Store) Save(id Identity, keyPEM, certPEM, caPEM []byte) error

Save writes key, certificate, CA and identity (in that order, identity last) atomically.

func (Store) SwapCertificate

func (s Store) SwapCertificate(keyPEM, certPEM []byte) error

SwapCertificate installs a renewed key pair. Both files are staged as *.new first, then renamed key-first; Load repairs an interrupted swap.

func (Store) UpdateServer added in v1.2.0

func (s Store) UpdateServer(expect Identity, update func(*Identity)) (*Identity, error)

UpdateServer changes the console addresses of the identity file under the identity lock: update gets the identity as stored, and the file is replaced atomically with what it leaves. The other fields (and the keys) stay as they are; expect is the enrollment the caller loaded.

func (Store) WaitForEnrollment

func (s Store) WaitForEnrollment(ctx context.Context, interval time.Duration, log *slog.Logger) error

WaitForEnrollment blocks until identity.json appears or ctx is done.

Jump to

Keyboard shortcuts

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