Documentation
¶
Overview ¶
Package enrollment implements one-time enrollment tokens used to bootstrap client identities against a bridgectl server.
Index ¶
Constants ¶
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 (*Store) Get ¶
Get retrieves a copy of a token by its full value string. Returns nil if not found.
func (*Store) Validate ¶
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 ¶
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.