user

package
v0.11.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: Apache-2.0 Imports: 12 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func SeedFromIdentity(ctx context.Context, s *Store, id *identity.Store, log *slog.Logger) error

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

func VerifyPassword(hash, cleartext string) bool

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 NewStore

func NewStore(db storage.DB) *Store

NewStore constructs a Store over db: the pool, or a transaction.

func (*Store) BumpTokenVersion added in v0.10.0

func (s *Store) BumpTokenVersion(ctx context.Context, id string) error

BumpTokenVersion invalidates every token the user holds.

func (*Store) ByOIDCSubject

func (s *Store) ByOIDCSubject(ctx context.Context, subject string) (*User, error)

ByOIDCSubject returns the user holding the external identity subject ("issuer|sub") among its sign-in identities, or (nil, nil).

func (*Store) ByUsername

func (s *Store) ByUsername(ctx context.Context, username string) (*User, error)

ByUsername returns the user with the given username, or (nil, nil).

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id string) error

Delete removes a user by id.

func (*Store) Directory added in v0.10.8

func (s *Store) Directory() directory.UserStore

Directory is the auth module's store under this one, for writes that run through the directory.

func (*Store) Get

func (s *Store) Get(ctx context.Context, id string) (*User, error)

Get returns the user with the given id, or (nil, nil) if not found.

func (*Store) List

func (s *Store) List(ctx context.Context) ([]*User, error)

List returns every user, oldest first.

func (*Store) MissingIDs added in v0.10.0

func (s *Store) MissingIDs(ctx context.Context, ids []string) ([]string, error)

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.

func (*Store) Upsert

func (s *Store) Upsert(ctx context.Context, u *User) error

Upsert writes u. Caller is responsible for stamping ID.

func (*Store) Usernames added in v0.11.1

func (s *Store) Usernames(ctx context.Context, ids []string) (map[string]string, error)

Usernames maps each of ids that has a users row to its username, in one query. Ids without a row are absent.

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

func FromDirectory(d *directory.User) *User

FromDirectory is a directory account as a User; nil stays nil.

func (*User) HasRole

func (u *User) HasRole(role string) bool

HasRole reports whether the user carries role.

func (*User) ToDirectory added in v0.10.8

func (u *User) ToDirectory() *directory.User

ToDirectory is u as the directory stores it.

Jump to

Keyboard shortcuts

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