Documentation
¶
Overview ¶
Package user owns the DB-backed user account: the row behind a login session. Users are not a catalog kind — no metadata envelope, no snapshot, no NOTIFY; they are identity, not routing config.
Two credential shapes coexist on one row: a local bcrypt password hash (password login) and/or an external identity subject ("issuer|sub", OIDC login). Either may be absent. Authorization is out of scope — roles are carried verbatim for app/authz to interpret.
Index ¶
- Constants
- func SeedFromIdentity(ctx context.Context, s *Store, id *identity.Store, log *slog.Logger) error
- func VerifyPassword(hash, cleartext string) bool
- type Store
- func (s *Store) BumpTokenVersion(ctx context.Context, id string) error
- func (s *Store) ByOIDCSubject(ctx context.Context, subject string) (*User, error)
- func (s *Store) ByUsername(ctx context.Context, username string) (*User, error)
- func (s *Store) Delete(ctx context.Context, id string) error
- func (s *Store) Directory() directory.UserStore
- func (s *Store) Get(ctx context.Context, id string) (*User, error)
- func (s *Store) List(ctx context.Context) ([]*User, error)
- func (s *Store) MissingIDs(ctx context.Context, ids []string) ([]string, error)
- func (s *Store) TokenVersionsAndDisabled(ctx context.Context) (map[string]int, map[string]struct{}, error)
- func (s *Store) Upsert(ctx context.Context, u *User) error
- type User
Constants ¶
const RoleAdmin = "admin"
RoleAdmin is the only role with defined meaning today: full access, including rows owned by other users.
Variables ¶
This section is empty.
Functions ¶
func SeedFromIdentity ¶
SeedFromIdentity copies YAML identity users (config/users/) into the users table, seed-if-absent by username — same pattern as the settings seed. The YAML files remain the bootstrap/break-glass path; the table is what login reads. Plain-text YAML passwords are bcrypt-hashed on ingest so cleartext never lands in Postgres; already-hashed values are stored verbatim.
func VerifyPassword ¶
VerifyPassword checks cleartext against the stored hash. A plain stored value is accepted without a warning: the YAML seed hashes plain passwords on ingest, so one here should not occur and is kept for defense in depth. Empty hash never matches: an OIDC-only user has no password login.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the User data-access type.
func (*Store) BumpTokenVersion ¶ added in v0.10.0
BumpTokenVersion invalidates every token the user holds.
func (*Store) ByOIDCSubject ¶
ByOIDCSubject returns the user holding the external identity subject ("issuer|sub") among its sign-in identities, or (nil, nil).
func (*Store) ByUsername ¶
ByUsername returns the user with the given username, or (nil, nil).
func (*Store) Directory ¶ added in v0.10.8
Directory is the auth module's store under this one, for writes that run through the directory.
func (*Store) MissingIDs ¶ added in v0.10.0
MissingIDs returns the subset of ids with no users row, in one query. Callers validating a membership list would otherwise issue a Get per member.
func (*Store) TokenVersionsAndDisabled ¶ added in v0.11.0
func (s *Store) TokenVersionsAndDisabled(ctx context.Context) (map[string]int, map[string]struct{}, error)
TokenVersionsAndDisabled returns every enabled user's current token version and the set of disabled user ids from one read. They are the snapshot's whole view of users — small enough to rebuild on every NOTIFY. A disabled account is absent from the versions, which is what makes its live tokens stop verifying.
type User ¶
type User struct {
ID string `json:"id"`
Username string `json:"username"`
Email string `json:"email,omitempty"`
PasswordHash string `json:"-"`
OIDCSubject string `json:"oidcSubject,omitempty"`
Roles []string `json:"roles,omitempty"`
Disabled bool `json:"disabled,omitempty"`
// TokenVersion is the generation every inference token this user holds
// must carry. Bumping it invalidates all of them at once.
TokenVersion int `json:"tokenVersion,omitempty"`
// ResourceVersion is the stored row's version; a write carrying it applies only while the row still has it.
ResourceVersion string `json:"-"`
CreatedAt time.Time `json:"createdAt,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
}
User is one account row.
func FromDirectory ¶ added in v0.10.8
FromDirectory is a directory account as a User; nil stays nil.
func (*User) ToDirectory ¶ added in v0.10.8
ToDirectory is u as the directory stores it.