enrollment

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 8 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 enrollment implements one-time enrollment tokens used to bootstrap client identities against a bridgectl server.

Index

Constants

View Source
const (
	// TokenPrefix is prepended to every enrollment token for visual identification.
	TokenPrefix = "brg_enroll_"
	// DefaultTokenExpiry is the default lifetime of an enrollment token.
	DefaultTokenExpiry = 15 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store persists enrollment tokens to a JSON file in the state directory. It is safe for concurrent use.

func NewStore

func NewStore(stateDir string) (*Store, error)

NewStore opens or creates a token store at the given path.

func (*Store) Get

func (s *Store) Get(value string) *Token

Get retrieves a copy of a token by its full value string. Returns nil if not found.

func (*Store) List

func (s *Store) List() []*Token

List returns copies of all tokens (including expired and used ones).

func (*Store) MarkUsed

func (s *Store) MarkUsed(value string) error

MarkUsed atomically marks a token as used and persists the change.

func (*Store) Put

func (s *Store) Put(token *Token) error

Put adds or updates a token in the store and persists to disk.

func (*Store) Validate

func (s *Store) Validate(value string) (*Token, error)

Validate looks up a token and checks it is valid (not used, not expired). Returns an error with a specific reason on failure.

func (*Store) ValidateAndConsume

func (s *Store) ValidateAndConsume(value string) (*Token, error)

ValidateAndConsume atomically validates a token and marks it as used, preventing concurrent enrollment with the same token. The token is persisted as used immediately, so even if the enrollment fails afterward, the token cannot be reused.

type Token

type Token struct {
	// Value is the full token string including prefix (e.g. "brg_enroll_abc123...").
	Value string `json:"value"`
	// Identity is the intended certificate CN for the enrolling client.
	Identity string `json:"identity"`
	// ExpiresAt is when this token becomes invalid.
	ExpiresAt time.Time `json:"expires_at"`
	// Used indicates the token has been consumed by a successful enrollment.
	Used bool `json:"used"`
	// CreatedAt is when the token was generated.
	CreatedAt time.Time `json:"created_at"`
	// CreatedBy is the identity that generated this token (e.g. admin CN).
	CreatedBy string `json:"created_by,omitempty"`
	// ServerURL is the bridgectl server URL encoded in the token metadata.
	ServerURL string `json:"server_url,omitempty"`
	// CAFingerprint is the SHA-256 fingerprint of the CA root for trust bootstrap.
	CAFingerprint string `json:"ca_fingerprint,omitempty"`
}

Token represents a one-time enrollment credential.

func Generate

func Generate(identity string, expiry time.Duration, serverURL, caFingerprint string) (*Token, error)

Generate creates a new enrollment token for the given identity.

func (*Token) IsExpired

func (t *Token) IsExpired() bool

IsExpired reports whether the token has passed its expiry time.

func (*Token) IsValid

func (t *Token) IsValid() bool

IsValid reports whether the token can still be used for enrollment.

func (*Token) MarkUsed

func (t *Token) MarkUsed() error

MarkUsed marks the token as consumed. It returns an error if the token is already used or expired.

func (*Token) Redacted

func (t *Token) Redacted() string

Redacted returns the token value with the random portion masked for safe logging. Only the first 8 hex characters are visible. Safe to call on zero-value tokens or tokens with short values.

Jump to

Keyboard shortcuts

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