inventory

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: Apache-2.0, Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package inventory resolves the entities a writ policy matches against: users (SCIM-shaped, RFC 7643) and hosts (name + labels + optional account list). The interface is the pluggability seam — today's implementation is a static file, later ones may be databases or live SCIM stores, and implementations are free to synthesize hosts (e.g. pattern-derived labels for short-lived VMs).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Inventory

type Inventory interface {
	// LookupUser resolves an OIDC-bound identity to a user by comparing
	// it byte-for-byte against the configured SCIM identity attribute
	// (default userName).
	LookupUser(ctx context.Context, identity string) (*eval.User, error)

	// LookupHost resolves a requested host name. Callers must pass the
	// name through il.HostName first; implementations may synthesize a
	// host for names they can derive attributes for.
	LookupHost(ctx context.Context, name string) (*ResolvedHost, error)
}

Inventory looks up users and hosts at evaluation time.

A (nil, nil) return means "no such entity" — a structural non-match that the evaluator turns into a 403, not an error. A non-nil error means the lookup itself failed and the evaluation must fail closed (500).

type PrincipalMode added in v0.23.0

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
	// host ID and requested account name.
	EpithetPrincipalV1 PrincipalMode = principal.SchemeV1
)

func (PrincipalMode) Effective added in v0.23.0

func (m PrincipalMode) Effective() PrincipalMode

Effective returns the concrete mode represented by m.

func (PrincipalMode) Validate added in v0.23.0

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 ResolvedHost added in v0.23.0

type ResolvedHost struct {
	Policy        eval.Host
	PrincipalMode PrincipalMode
	HostID        hostid.ID
}

ResolvedHost carries both the host attributes consumed by Writ and, as the inventory grows, issuance metadata that must remain outside the pure policy model. Keeping those layers separate prevents certificate-construction details from becoming policy-language semantics.

type Static

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

Static is a file-backed inventory: SCIM-shaped users and hosts loaded once at startup. Reload is a process restart, like the policy itself.

Host entries come in two forms. An exact entry (`name:`) is one registered host. A pattern entry (`pattern:`, writ glob — `*`/`?` only) synthesizes a host for any requested name it matches, adopting the requested name and carrying the entry's labels: the escape hatch for fleets of short-lived hosts (VM pools, CI runners) that follow a naming pattern but cannot be enumerated in a file.

func NewStatic

func NewStatic(paths []string, options ...StaticOption) (*Static, error)

NewStatic loads an inventory from one or more YAML files. Files concatenate; a duplicate userName or exact host name across the set is a load error. Decoding is strict — an unknown field is an error, not a silently ignored typo.

func (*Static) LookupHost

func (s *Static) LookupHost(_ context.Context, name string) (*ResolvedHost, error)

LookupHost implements Inventory: exact entries first, then pattern entries in file order, first match wins.

func (*Static) LookupUser

func (s *Static) LookupUser(_ context.Context, identity string) (*eval.User, error)

LookupUser implements Inventory.

type StaticOption added in v0.23.0

type StaticOption func(*staticOptions) error

StaticOption configures static inventory loading.

func WithDefaultPrincipalMode added in v0.23.0

func WithDefaultPrincipalMode(mode PrincipalMode) StaticOption

WithDefaultPrincipalMode sets the mode inherited by host entries that omit principal-mode. The default is AccountNamePrincipals.

Jump to

Keyboard shortcuts

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