Documentation
¶
Overview ¶
Package inventory owns managed host facts, enrollment, patterns, and storage.
Index ¶
- Constants
- Variables
- func CheckVersion(current Host, expectedVersion string) error
- func DecodeYAML(data []byte, dst any) error
- func NewID() string
- func SameHostFacts(a, b Host) bool
- type AuditEvent
- type EnrollmentToken
- type Host
- func Creation(id string, host Host, now time.Time) (Host, error)
- func Enroll(ctx context.Context, store Store, id string, host Host, token string, ...) (*Host, error)
- func ParseHost(data []byte) (Host, error)
- func Replacement(current, proposed Host, expectedVersion string, now time.Time) (Host, error)
- func Review(current, proposed Host, expectedVersion string, now time.Time) (Host, string, error)
- type Hosts
- type PrincipalMode
- type Store
- type WriteConditions
Constants ¶
const ( StatusPending = "pending" StatusActive = "active" StatusDenied = "denied" )
Host enrollment statuses. Status remains a string in storage and API records.
const DefaultPageLimit = 100
const MaxPageLimit = 1000
Variables ¶
var ( ErrStorage = errors.New("managed inventory storage unavailable") ErrConflict = errors.New("inventory conflict") ErrNotFound = errors.New("inventory record not found") ErrToken = errors.New("invalid, expired, revoked, or used enrollment token") ErrVersion = errors.New("record changed; reload before retrying") )
Functions ¶
func CheckVersion ¶ added in v0.43.0
CheckVersion compares opaque versions. Empty means no requested version check; the backend determines the consistency of checking and applying a mutation.
func DecodeYAML ¶
func NewID ¶ added in v0.43.0
func NewID() string
NewID creates an inventory resource ID or single-use enrollment credential.
func SameHostFacts ¶ added in v0.43.0
SameHostFacts compares enrollment facts without lifecycle metadata.
Types ¶
type AuditEvent ¶
type AuditEvent struct {
At time.Time `yaml:"at"`
Actor string `yaml:"actor"`
Action string `yaml:"action"`
Resource string `yaml:"resource"`
}
AuditEvent is supplied by the caller alongside a mutation. Storage preserves every field, including the supplied timestamp.
func NewAuditEvent ¶ added in v0.43.0
func NewAuditEvent(actor, action, resource string) AuditEvent
NewAuditEvent describes an operation using the actor authenticated by the caller. The caller selects the resource ID before constructing the event.
type EnrollmentToken ¶
type EnrollmentToken struct {
ID string `yaml:"id"`
ExpiresAt time.Time `yaml:"expires-at"`
UsedBy string `yaml:"used-by,omitempty"`
Revoked bool `yaml:"revoked"`
}
EnrollmentToken's ID is also its secret and the resulting host ID. Unused tokens retain an empty UsedBy value.
type Host ¶
type Host struct {
ID string `yaml:"-"`
Version string `yaml:"-"`
CreatedAt time.Time `yaml:"-"`
UpdatedAt time.Time `yaml:"-"`
Status string `yaml:"-"`
Names []string `yaml:"names"`
Labels map[string]string `yaml:"labels"`
Accounts []string `yaml:"accounts"`
PrincipalMode PrincipalMode `yaml:"principal-mode"`
Realm principal.Realm `yaml:"realm,omitempty"`
}
Host contains inventory names, authorization facts, and enrollment metadata. Names may be exact hostnames or wildcard expressions. Lookup prefers exact names; wildcard matches supply facts for the requested hostname. Version is an opaque storage token, empty when the store does not support versioning.
func Creation ¶ added in v0.43.0
Creation prepares storage metadata without deciding the host's status.
func Enroll ¶ added in v0.43.0
func Enroll(ctx context.Context, store Store, id string, host Host, token string, event AuditEvent) (*Host, error)
Enroll validates a PUT enrollment before one storage operation. A preapproval token is the host ID; the control-plane pending-enrollment bearer never enters this layer. An identical retry does not update the existing host.
func Replacement ¶ added in v0.43.0
Replacement checks resource metadata and prepares a complete host write. Review policy belongs to Review, not this storage operation.
func Review ¶ added in v0.43.0
Review validates an administrator edit or review at the Epithet boundary. A review cannot also edit the facts being approved. Storage accepts complete replacements, without imposing the administrator review workflow.
func (Host) MarshalYAML ¶ added in v0.43.0
func (*Host) UnmarshalYAML ¶ added in v0.43.0
UnmarshalYAML reads only editable fields; lifecycle metadata is not an input.
type Hosts ¶
Hosts resolves machines independently of the user directory. LookupHost returns host facts. A missing host returns nil; lookup failures return an error. Read consistency and visibility are backend-specific. Managed lookups prefer exact names over patterns and return ErrConflict for multiple matching active patterns.
type PrincipalMode ¶
type PrincipalMode string
PrincipalMode selects how an allowed account@host tuple is represented in an issued SSH certificate.
const ( // AccountNamePrincipals places the literal requested account name in the // certificate. It is compatible with ordinary OpenSSH CA configuration but // is not destination-bound. AccountNamePrincipals PrincipalMode = "account-name" // EpithetPrincipalV1 derives a destination-bound v1 principal from the // principal realm and requested account name. EpithetPrincipalV1 PrincipalMode = principal.SchemeV1 )
func (PrincipalMode) Effective ¶
func (m PrincipalMode) Effective() PrincipalMode
Effective returns the concrete mode represented by m.
func (PrincipalMode) Validate ¶
func (m PrincipalMode) Validate() error
Validate rejects unknown non-empty principal modes. Empty is the zero-value spelling of AccountNamePrincipals for compatibility with custom inventory implementations constructed in Go.
type Store ¶
type Store interface {
// SupportsVersioning is stable for the store's lifetime. When true, returned
// hosts have nonempty versions that change on mutation. HTTP exposes them as
// ETags. When false, versions and mutation preconditions are empty.
SupportsVersioning() bool
// UpsertHost creates or replaces host.ID, subject to the supplied conditions.
// Storage owns versions and timestamps; an update retains CreatedAt. The
// supplied audit event accompanies the write; an unchanged retry appends none.
// A nonempty expected version cannot match a missing host.
UpsertHost(ctx context.Context, host Host, conditions WriteConditions, event AuditEvent) (*Host, error)
// Removal retains audit history and appends the supplied event. A missing ID
// returns ErrNotFound; a failed version precondition returns ErrVersion.
RemoveHost(ctx context.Context, id string, expectedVersion string, event AuditEvent) error
// GetHost returns ErrNotFound for an absent ID.
GetHost(ctx context.Context, id string) (*Host, error)
// ListHosts returns hosts ordered by ID, strictly after the cursor.
// Empty after starts a read; nonempty after is a full resource ID. Zero limit
// defaults to 100; negative limits and limits above 1,000 are invalid. Pending
// filters host records before applying the limit. A short page ends that read.
// Each page is independent; later calls may observe changes.
ListHosts(ctx context.Context, after string, limit int, pending bool) ([]Host, error)
// CreateToken stores a single-use credential without creating a host.
// Its supplied ID becomes the host ID on enrollment. Lifetime must be
// positive and at most 24 hours.
CreateToken(ctx context.Context, id string, lifetime time.Duration, event AuditEvent) (EnrollmentToken, error)
// RevokeToken prevents unused credentials from authorizing enrollment.
RevokeToken(ctx context.Context, id string, event AuditEvent) error
// Audit returns events and a backend-owned continuation cursor. Empty input
// starts a read; empty next completes it. Callers forward cursors unchanged.
// Ordering, visibility and cursor lifetime belong to the backend. Timestamps
// need not be unique or monotonic. Zero limit defaults to 100; maximum 1,000.
Audit(ctx context.Context, cursor string, limit int) (events []AuditEvent, next string, err error)
}
Store is the inventory management contract, independent of Hosts fact lookup. Epithet owns enrollment and review policy; implementations persist host and token operations. Enrollment and any token consumption form one storage call. Consistency is backend-specific.
Only active records contribute lookup facts or reserve authorization names. Active exact names and identical patterns are unique. Overlapping patterns are permitted; ambiguity is detected by Hosts.LookupHost. Admission or edits violating name/pattern uniqueness return ErrConflict. Realms may be shared across records without constraints on their labels or account sets.
Returned records and collections are independent snapshots, including results of mutations. Implementations must not retain or modify caller-owned maps or slices. Nil accounts mean unrestricted; an empty non-nil slice means no accounts. Storage failures return errors matching ErrStorage, never missing records. Validation errors have no sentinel unless a method specifies one below. Contexts bound reads and mutations. The caller owns the store's lifetime; HTTP handlers never close it. Callers construct audit events before storage, supplying the authenticated actor, action, resource and operation timestamp. Storage preserves all event fields. Callers also assign IDs before creation using NewID. Mutation timestamps use event.At. Storage never generates IDs or completes audit events. Version is an opaque, backend-owned token, compared only for equality. Stores without versioning return empty Host.Version and receive empty expectedVersion. Empty expectedVersion means no requested version check; enforcement and consistency are backend properties.
type WriteConditions ¶ added in v0.43.0
type WriteConditions struct {
ExpectedVersion string
// CreateOnly forbids replacing an existing host. Identical facts return the
// stored host unchanged, including its status, metadata, and audit history.
// Different facts return ErrConflict. Enrollment uses this for safe retries.
CreateOnly bool
// ConsumeToken requires the single-use token whose secret is host.ID and
// consumes it with creation. It never authorizes replacement. An identical
// retry of a host created with that token returns the stored host unchanged;
// invalid credentials or different facts return ErrToken.
ConsumeToken bool
}
WriteConditions constrain an upsert without exposing backend transactions. The zero value allows creation or replacement without a version precondition. Epithet checks enrollment and administrator-review policy before storage.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package sqlitestore implements managed inventory using embedded SQLite.
|
Package sqlitestore implements managed inventory using embedded SQLite. |
|
Package storetest provides the inventory backend contract suite.
|
Package storetest provides the inventory backend contract suite. |