enrollment

package
v0.0.0-...-63dd1cf Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package enrollment provides the controller-side enrollment system for accepting or rejecting agent enrollment requests via NATS.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type KVStore

type KVStore = jetstream.KeyValue

KVStore wraps the jetstream.KeyValue interface for testability.

type KeyRotationMessage

type KeyRotationMessage struct {
	NewPublicKey []byte `json:"new_public_key"`
}

KeyRotationMessage is published to agents when the controller rotates its keypair.

type NATSSubscriber

type NATSSubscriber interface {
	Subscribe(
		subj string,
		cb nats.MsgHandler,
	) (*nats.Subscription, error)
	PublishCore(
		subj string,
		data []byte,
	) error
}

NATSSubscriber defines the NATS operations needed by the enrollment watcher for subscribing to enrollment requests and publishing responses. Satisfied by the nats-client's *Client type (Subscribe + PublishCore).

type PKIProvider

type PKIProvider interface {
	PublicKey() ed25519.PublicKey
}

PKIProvider defines the PKI operations needed by the enrollment watcher to provide the controller's public key in acceptance responses.

type PendingAgent

type PendingAgent struct {
	MachineID   string    `json:"machine_id"`
	Hostname    string    `json:"hostname"`
	PublicKey   []byte    `json:"public_key"`
	Fingerprint string    `json:"fingerprint"`
	RequestedAt time.Time `json:"requested_at"`
}

PendingAgent represents an agent awaiting enrollment acceptance.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher monitors NATS for agent enrollment requests and manages pending agents in a JetStream KV bucket.

func NewWatcher

func NewWatcher(
	logger *slog.Logger,
	nc NATSSubscriber,
	enrollmentKV KVStore,
	pkiProvider PKIProvider,
	autoAccept bool,
	namespace string,
) *Watcher

NewWatcher creates a new enrollment Watcher.

func (*Watcher) AcceptAgent

func (w *Watcher) AcceptAgent(
	ctx context.Context,
	machineID string,
) error

AcceptAgent accepts a pending agent by machine ID. It publishes an acceptance response containing the controller's public key to the agent's response subject and deletes the pending entry from KV.

func (*Watcher) AcceptByFingerprint

func (w *Watcher) AcceptByFingerprint(
	ctx context.Context,
	fingerprint string,
) error

AcceptByFingerprint scans the pending KV for an agent matching the given fingerprint and accepts it. Returns an error if no matching agent is found.

func (*Watcher) AcceptByHostname

func (w *Watcher) AcceptByHostname(
	ctx context.Context,
	hostname string,
) error

AcceptByHostname scans the pending KV for an agent matching the given hostname and accepts it. Returns an error if no matching agent is found.

func (*Watcher) ListPending

func (w *Watcher) ListPending(
	ctx context.Context,
) ([]PendingAgent, error)

ListPending returns all pending agents from the enrollment KV bucket.

func (*Watcher) RejectAgent

func (w *Watcher) RejectAgent(
	ctx context.Context,
	machineID string,
	reason string,
) error

RejectAgent rejects a pending agent by machine ID. It publishes a rejection response to the agent's response subject and deletes the pending entry from KV.

func (*Watcher) RejectByHostname

func (w *Watcher) RejectByHostname(
	ctx context.Context,
	hostname string,
	reason string,
) error

RejectByHostname scans the pending KV for an agent matching the given hostname and rejects it. Returns an error if no matching agent is found.

func (*Watcher) RotateControllerKey

func (w *Watcher) RotateControllerKey() error

RotateControllerKey publishes the controller's current public key to all agents via the pki.rotate subject. Agents receiving this message move their current controller key to previous and store the new key, enabling a grace period where both keys are accepted.

func (*Watcher) Start

func (w *Watcher) Start(
	ctx context.Context,
) error

Start subscribes to the enrollment request subject and blocks until the context is cancelled. Returns nil on clean shutdown.

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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