inventory

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0, Apache-2.0 Imports: 12 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 the mapped ID within the configured provider/tenant.
	// The caller must validate the OIDC token before extracting this ID.
	// Compare IDs byte-for-byte, never falling back to userName or email.
	// The resolved ID is immutable and non-reassignable; UserName is mutable.
	LookupUser(ctx context.Context, id 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
	// principal domain 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
	Domain        principal.Domain
}

ResolvedHost carries both the authorization resource consumed by Writ and issuance metadata that must remain outside the pure policy model. For a shared named domain, Policy.Name is the domain rather than the requested hostname because the resulting credential is portable across every member.

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:`) uses the same DNS-label-aware hostname patterns as Writ host selectors. Account-name entries adopt the requested name; destination-bound named domains expose that domain as the Writ resource so policy cannot claim per-member isolation. Patterns are 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 missing id, duplicate id/userName, or duplicate exact host name across the set is a load error. All IDs belong to the policy server's single configured provider/tenant. 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, id 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