Documentation
¶
Index ¶
- Constants
- Variables
- type AuditRecord
- type AuditStore
- type DirectoryUser
- type Group
- type GroupStore
- type MFAChallenge
- type SQLStore
- func (s *SQLStore) ApplyInstaller(ctx context.Context, b applysetup.Common, check bool) (applysetup.Report, error)
- func (s *SQLStore) Audit() AuditStore
- func (s *SQLStore) Close() error
- func (s *SQLStore) Drive() *drive.Store
- func (s *SQLStore) Driver() string
- func (s *SQLStore) Groups() GroupStore
- func (s *SQLStore) InstallerAdministrator(ctx context.Context, id string) (bool, error)
- func (s *SQLStore) Ping(ctx context.Context) error
- func (s *SQLStore) ResetAfterRestore(ctx context.Context) error
- func (s *SQLStore) Sessions() SessionStore
- func (s *SQLStore) Settings() SettingsStore
- func (s *SQLStore) Users() UserStore
- type Session
- type SessionStore
- type Setting
- type SettingsStore
- type Store
- type User
- type UserStore
Constants ¶
const InstallerConfigKey = "installer.config"
Variables ¶
var ( ErrNotFound = errors.New("record not found") ErrAlreadyExists = errors.New("record already exists") ErrSessionExpired = errors.New("session expired") // ErrSSOSessionEnded means the identity provider already ended the login being signed in. ErrSSOSessionEnded = errors.New("SSO session already ended") // ErrStale reports a directory event no newer than the last one applied to the account. ErrStale = errors.New("directory event is not newer than the applied state") ErrInvalidUsername = errors.New("directory username must be 1-128 letters, digits or ._@+-") )
Functions ¶
This section is empty.
Types ¶
type AuditRecord ¶
type AuditRecord struct {
ID int64 `json:"id"`
UserID string `json:"user_id"`
Action string `json:"action"` // e.g. "auth.login", "scim.user_created"
Resource string `json:"resource"`
Details string `json:"details,omitempty"`
IPAddress string `json:"ip_address"`
CreatedAt time.Time `json:"created_at"`
}
AuditRecord logs security and operational events with tamper-evident structure.
type AuditStore ¶
type AuditStore interface {
LogAudit(ctx context.Context, r *AuditRecord) error
ListAuditRecords(ctx context.Context, offset, limit int) ([]*AuditRecord, int, error)
}
AuditStore logs security events.
type DirectoryUser ¶
type DirectoryUser struct {
ID string
Provider string
Subject string
Username string
Email string
DisplayName string
Active bool
EventTime int64
}
DirectoryUser is what a directory may assert about an account. It has no role: new accounts are "user" and application administration is an operator grant (SetDirectoryRole). ID empty creates a Provider ("scim" or "kysignon") account; otherwise it updates that directory account. A nonzero EventTime (unix seconds) applies only when strictly newer than the account's last applied event, else ErrStale.
type Group ¶
type Group struct {
ID string `json:"id"`
DisplayName string `json:"display_name"`
ExternalID string `json:"external_id,omitempty"`
Members []string `json:"members,omitempty"` // User IDs
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Group represents a SCIM/RBAC user group.
type GroupStore ¶
type GroupStore interface {
CreateGroup(ctx context.Context, g *Group) error
ReplaceGroup(ctx context.Context, g *Group, create bool) error
GetGroupByExternalID(ctx context.Context, id string) (*Group, error)
GetGroupByID(ctx context.Context, id string) (*Group, error)
GetGroupByName(ctx context.Context, name string) (*Group, error)
UpdateGroup(ctx context.Context, g *Group) error
DeleteGroup(ctx context.Context, id string) error
ListGroups(ctx context.Context, offset, limit int) ([]*Group, int, error)
AddGroupMember(ctx context.Context, groupID, userID string) error
RemoveGroupMember(ctx context.Context, groupID, userID string) error
GetUserGroups(ctx context.Context, userID string) ([]*Group, error)
}
GroupStore defines repository operations for SCIM and RBAC groups.
type SQLStore ¶
type SQLStore struct {
// contains filtered or unexported fields
}
SQLStore implements Store on top of database/sql.
func (*SQLStore) ApplyInstaller ¶
func (s *SQLStore) ApplyInstaller(ctx context.Context, b applysetup.Common, check bool) (applysetup.Report, error)
ApplyInstaller commits accounts, ownership and audits together. It never adopts another account, changes credentials or takes ownership of pre-existing settings.
func (*SQLStore) Audit ¶
func (s *SQLStore) Audit() AuditStore
func (*SQLStore) Groups ¶
func (s *SQLStore) Groups() GroupStore
func (*SQLStore) InstallerAdministrator ¶
InstallerAdministrator marks only newly created, explicitly dedicated accounts. Existing accounts and their content are retained for an explicit migration.
func (*SQLStore) ResetAfterRestore ¶ added in v0.4.3
ResetAfterRestore ends restored access grants and turns scheduled deposits off in one transaction. Passwords, MFA secrets, directory membership and content remain as backed up; operators reconcile those separately.
func (*SQLStore) Sessions ¶
func (s *SQLStore) Sessions() SessionStore
func (*SQLStore) Settings ¶
func (s *SQLStore) Settings() SettingsStore
type Session ¶
type Session struct {
TokenHash string `json:"token_hash"`
UserID string `json:"user_id"`
UserAgent string `json:"user_agent"`
IPAddress string `json:"ip_address"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
// SSOSID is the identity provider's sid for an SSO login; empty for local sign-in.
SSOSID string `json:"-"`
// StepUpAt is when the user last re-proved who they are in this session; zero if never.
StepUpAt time.Time `json:"-"`
}
Session represents an active authenticated user session.
type SessionStore ¶
type SessionStore interface {
// CreateSession refuses when the password or the MFA state changed since the caller checked them.
CreateSession(ctx context.Context, s *Session, expectedPasswordHash string, mfaEnabled bool) error
GetSession(ctx context.Context, tokenHash string) (*Session, error)
// StepUp records at as the session's latest step-up; ErrNotFound when the session is gone.
StepUp(ctx context.Context, tokenHash string, at time.Time) error
DeleteSession(ctx context.Context, tokenHash string) error
DeleteUserSessions(ctx context.Context, userID string) error
// EndSSOSubject ends the provider subject's sessions whose credentials were verified
// before cutoff and fences that subject's earlier logins until fenceUntil.
EndSSOSubject(ctx context.Context, provider, subject string, cutoff, fenceUntil time.Time) error
// EndSSOSession ends every session of an SSO login and fences its sid until fenceUntil.
EndSSOSession(ctx context.Context, sid string, fenceUntil time.Time) error
EndSession(ctx context.Context, tokenHash string) error
CleanExpiredSessions(ctx context.Context) error
CleanExpiredMFAChallenges(ctx context.Context) error
CreateMFAChallenge(ctx context.Context, challenge *MFAChallenge, expectedPasswordHash string) error
ConsumeMFAChallenge(ctx context.Context, tokenHash string) (userID, passwordHash string, err error)
}
SessionStore defines repository operations for active login sessions.
type Setting ¶
type Setting struct {
Key string `json:"key"`
Value string `json:"value"`
UpdatedAt time.Time `json:"updated_at"`
}
Setting represents a durable server-wide key-value configuration entry.
type SettingsStore ¶
type SettingsStore interface {
GetSetting(ctx context.Context, key string) (string, error)
SetSetting(ctx context.Context, key, val string) error
DeleteSetting(ctx context.Context, key string) error
GetAllSettings(ctx context.Context) (map[string]string, error)
}
SettingsStore handles persistent key-value configuration.
type Store ¶
type Store interface {
Drive() *drive.Store
Users() UserStore
Sessions() SessionStore
Groups() GroupStore
Audit() AuditStore
Settings() SettingsStore
ApplyInstaller(context.Context, applysetup.Common, bool) (applysetup.Report, error)
InstallerAdministrator(context.Context, string) (bool, error)
Driver() string
Ping(ctx context.Context) error
Close() error
// ResetAfterRestore invalidates restored bearer grants without changing accounts or content.
ResetAfterRestore(context.Context) error
}
Store defines the unified storage contract implemented across SQLite, PostgreSQL, and MySQL.
type User ¶
type User struct {
ID string `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
DisplayName string `json:"display_name"`
PasswordHash string `json:"-"` // Never serialized to JSON
Role string `json:"role"` // "admin", "user", "manager"
Status string `json:"status"` // "active", "suspended", "inactive"
SSOProvider string `json:"sso_provider"` // "local", "kysignon", "oidc", "saml", "scim"
SSOSubject string `json:"sso_subject,omitempty"`
TOTPSecretEnc string `json:"-"` // AES-256-GCM encrypted
TOTPEnabled bool `json:"totp_enabled"`
TOTPLastCounter int64 `json:"-"` // last RFC 6238 counter accepted; refuses replay inside the skew window
RecoveryCodesHash string `json:"-"` // JSON array of sha256 hashes
MustChangePassword bool `json:"must_change_password"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
LastLoginAt *time.Time `json:"last_login_at,omitempty"`
}
User represents an identity within the system.
type UserStore ¶
type UserStore interface {
CreateUser(ctx context.Context, u *User) error
GetUserByID(ctx context.Context, id string) (*User, error)
GetUserByUsername(ctx context.Context, username string) (*User, error)
GetUserByEmail(ctx context.Context, email string) (*User, error)
GetUserBySSO(ctx context.Context, provider, subject string) (*User, error)
UpdateUser(ctx context.Context, u *User) error
// ApplyDirectoryUser is the one directory (SCIM, KySignOn) write path; see DirectoryUser.
ApplyDirectoryUser(ctx context.Context, d *DirectoryUser) (*User, error)
// DeleteDirectoryUser deletes a directory account; eventTime orders it like ApplyDirectoryUser.
DeleteDirectoryUser(ctx context.Context, id string, eventTime int64) error
ResetAdminPassword(ctx context.Context, userID, newHash string) error
RenameLocalAdmin(ctx context.Context, oldName, newName string) error
SetDirectoryRole(ctx context.Context, subject, role string) error
CompletePasswordChange(ctx context.Context, userID, oldHash, newHash, ip string) error
DeleteUser(ctx context.Context, id string) error
// OpenInNewTab is the user's choice to open files in a new browser tab (default true).
// It lives outside User so profile and directory updates never overwrite it.
OpenInNewTab(ctx context.Context, userID string) (bool, error)
SetOpenInNewTab(ctx context.Context, userID string, v bool) error
ListUsers(ctx context.Context, offset, limit int, search string) ([]*User, int, error)
// ListDirectoryUsers pages SCIM-provisioned accounts only.
ListDirectoryUsers(ctx context.Context, offset, limit int) ([]*User, int, error)
CountUsers(ctx context.Context) (int, error)
}
UserStore defines repository operations for accounts.