Documentation
¶
Overview ¶
Package users holds the Users of the Organization (C-03): reading a user, the profile a user edits — display name, time zone and language — the start-up step that creates the bootstrap Admin, the administration of users by Admins with the rule that the Organization keeps an active Admin, the single-use password setup links and the emergency password reset of the CLI.
Index ¶
- Constants
- Variables
- func EnsureBootstrapAdmin(ctx context.Context, s Store, w *audit.Writer, log *logging.Logger, ...) error
- type Admin
- func (a *Admin) CompleteSetup(ctx context.Context, token, password string, addr netip.Addr) error
- func (a *Admin) ConvertToLocal(ctx context.Context, r Requester, id string) (User, SetupLink, error)
- func (a *Admin) Create(ctx context.Context, r Requester, n NewUser) (User, SetupLink, error)
- func (a *Admin) CreateSetupLink(ctx context.Context, r Requester, id string) (SetupLink, error)
- func (a *Admin) Delete(ctx context.Context, r Requester, id string, version *int64) error
- func (a *Admin) Disable(ctx context.Context, r Requester, id string) (User, error)
- func (a *Admin) Enable(ctx context.Context, r Requester, id string) (User, error)
- func (a *Admin) Get(ctx context.Context, id string) (User, error)
- func (a *Admin) List(ctx context.Context, f ListFilter) (Page, error)
- func (a *Admin) ResetPassword(ctx context.Context, actor, login, password string) (string, error)
- func (a *Admin) SetLinkRemover(r LinkRemover)
- func (a *Admin) SetOwnerReleaser(r OwnerReleaser)
- func (a *Admin) Update(ctx context.Context, r Requester, id string, version *int64, c Changes) (User, error)
- type AdminQueries
- type AdminStore
- type Bootstrap
- type Changes
- type Cursor
- type Directory
- type DirectoryEntry
- type DirectoryPage
- type DirectoryQueries
- type FieldError
- type LinkRemover
- type ListFilter
- type NewUser
- type OwnerReleaser
- type Page
- type Profile
- type PruneQueries
- type Pruner
- type Queries
- type Requester
- type Service
- type SetupLink
- type Store
- type User
Constants ¶
const ( StatusActive = "active" StatusDisabled = "disabled" StatusDeleted = "deleted" )
The statuses of a user.
const ( ReleaseDisabled = "owner_disabled" ReleaseDeleted = "owner_deleted" )
The reasons of the release of an Owner, as OwnerReleaser takes them (C-03.FR-13).
const ( BootstrapEmailVar = "MUSTER_BOOTSTRAP_ADMIN_EMAIL" BootstrapPasswordVar = "MUSTER_BOOTSTRAP_ADMIN_PASSWORD" BootstrapPasswordFileVar = "MUSTER_BOOTSTRAP_ADMIN_PASSWORD_FILE" )
The bootstrap variables (C-02.FR-1).
const ( // PasswordSetupLinkTTL is auth.password_setup_link_ttl (P-05): a link sets a password once, within 24 hours. PasswordSetupLinkTTL = 24 * time.Hour // PasswordSetupPruneAfter is auth.password_setup_prune_after: a link is deleted this long after it expired, used // and superseded links included, so that a late click still answers link_used or link_expired instead of an // unknown token for a week. PasswordSetupPruneAfter = 7 * 24 * time.Hour // SetupPath is the page of the SPA that completes a link; the token follows in the URL fragment. SetupPath = "password-setup" )
const ActionConvertedToLocal = "user.converted_to_local"
ActionConvertedToLocal is the Audit log action of an OIDC account an Admin converted back to local.
const DeletedPrefix = "deleted-user-"
DeletedPrefix starts the name and the login of a deleted user, deleted-user-<public_id>; no login may start with it.
const SourceLocal = "local"
SourceLocal is a user an Admin created.
Variables ¶
var ( // ErrNameTaken is a login that another user has, compared lowercased. ErrNameTaken = errors.New("another user has this login") // ErrLastAdmin is a change that would leave the Organization without an active Admin (C-03.FR-31). ErrLastAdmin = errors.New("the last active Admin cannot be disabled, deleted or given a lower Role") // ErrVersionMismatch is an If-Match that names another version of the user. ErrVersionMismatch = errors.New("the user changed since it was read") // ErrRoleLocked is a Role change of an account that signs in through OIDC while OIDC and oidc.sync_role are both // on: the identity provider decides its Role (C-03.FR-29). ErrRoleLocked = errors.New("the identity provider decides the Role of this account") // ErrNotLinked is a conversion to local of an account that does not sign in through OIDC. ErrNotLinked = errors.New("the account does not sign in through OIDC") )
var ( // ErrLinkNotFound is a token that names no password setup link. ErrLinkNotFound = errors.New("no such password setup link") // ErrLinkExpired is a link past auth.password_setup_link_ttl. ErrLinkExpired = errors.New("the password setup link expired") // ErrLinkUsed is a link that set a password already or that a newer link replaced. ErrLinkUsed = errors.New("the password setup link was used or replaced") )
var ErrNotFound = errors.New("no such user")
ErrNotFound is a user that does not exist in the Organization.
var Languages = []string{"en", "ru"}
The languages of the UI.
Functions ¶
func EnsureBootstrapAdmin ¶
func EnsureBootstrapAdmin(ctx context.Context, s Store, w *audit.Writer, log *logging.Logger, orgID int64, b Bootstrap, now time.Time) error
EnsureBootstrapAdmin is the start-up step of C-03.FR-22. When the Organization has no Admin and Email is set, it creates a local Admin whose login and email are Email, whose name is the part of Email before @ and whose password is Password, which must be at least auth.password_min_length long, and records user.created by the actor bootstrap. When an Admin exists the variables are ignored with bootstrap_admin_ignored; with neither an Admin nor the variables it logs bootstrap_admin_missing. now is the business time.
Types ¶
type Admin ¶
type Admin struct {
// contains filtered or unexported fields
}
Admin administers the users of the Organization (C-03.FR-3, FR-13, FR-31): every change is recorded in the Audit log with a before/after diff, in the transaction of the change.
func NewAdmin ¶
func NewAdmin(orgID int64, s AdminStore, w *audit.Writer, business clock.Clock, publicURL *url.URL) *Admin
NewAdmin returns the Admin of the Organization orgID; clock is the business clock and publicURL is MUSTER_PUBLIC_URL, the base of the password setup links.
func (*Admin) CompleteSetup ¶
CompleteSetup sets a password from the token of a setup link (C-03.FR-26): an unknown token is ErrLinkNotFound, a used or superseded link ErrLinkUsed and an expired one ErrLinkExpired, checked in that order on the business clock; a password shorter than auth.password_min_length is a FieldError. None of them changes anything. The link is used once, the user's sessions end, and the Audit log records user.password_set by the system, since the person holding the link is not signed in. The password is hashed before the transaction, which locks the user and then the link, in the order of every other change of a user and its links, and checks the link again.
func (*Admin) ConvertToLocal ¶
func (a *Admin) ConvertToLocal(ctx context.Context, r Requester, id string) (User, SetupLink, error)
ConvertToLocal converts the account id, which signs in through OIDC, back to local (C-03.FR-29): the identity and the offline token are removed with its re-check, the sessions end (converted_to_local), and the returned password setup link sets its first password, as at creation. The TOTP enrolment stays. An account without an identity is ErrNotLinked.
func (*Admin) Create ¶
Create creates a local user without a password and issues its first password setup link (C-03.FR-3). A login that another user has in any case is ErrNameTaken.
func (*Admin) CreateSetupLink ¶
CreateSetupLink issues a new password setup link for the user id; it supersedes the user's older links. An account that signs in through OIDC has no password to set (auth.ErrNotLocal).
func (*Admin) Delete ¶
Delete deletes the user id (C-03.FR-13): the row stays with the status deleted, the name and the login become deleted-user-<public_id>, the email and the password are erased, the sessions end, the Personal access tokens are revoked with the reason owner_deleted (C-04.FR-1), open password setup links are superseded, their acknowledged Alert Groups are released and their Account links removed (C-03.FR-13). The Audit log keeps the user's earlier entries, which show the new name. A non-nil version must be the user's; deleting the last active Admin is ErrLastAdmin.
func (*Admin) Disable ¶
Disable disables the user id and ends their sessions; until Enable they cannot sign in. Their acknowledged Alert Groups are released in the same transaction (C-03.FR-13). Disabling the last active Admin is ErrLastAdmin. A disabled user is returned unchanged.
func (*Admin) Enable ¶
Enable enables the user id again; no acknowledgement comes back. An active user is returned unchanged.
func (*Admin) List ¶
List returns a page of at most f.Limit users in the order of their name, deleted users included.
func (*Admin) ResetPassword ¶
ResetPassword is `muster admin reset-password` (C-03.FR-11): it sets password on the account whose login is login, compared lowercased — an account that signs in through OIDC included, whose identity and offline token it removes in the same update, with its re-check, so that the account never holds both — ends its sessions, supersedes its password setup links and records user.password_reset by the CLI actor named actor, with whether an identity was removed. It returns the public_id of the account. A deleted or unknown account is ErrNotFound.
func (*Admin) SetLinkRemover ¶
func (a *Admin) SetLinkRemover(r LinkRemover)
SetLinkRemover sets what removes the Account links of the users that Delete deletes; the runtime sets it on the Admin the API uses. One without removes nothing.
func (*Admin) SetOwnerReleaser ¶
func (a *Admin) SetOwnerReleaser(r OwnerReleaser)
SetOwnerReleaser sets what releases the acknowledgements of the users that Disable and Delete disable or delete; the runtime sets it on the Admin the API uses. Only an Admin that never disables or deletes — the one of muster admin reset-password — goes without; one without releases nothing.
func (*Admin) Update ¶
func (a *Admin) Update(ctx context.Context, r Requester, id string, version *int64, c Changes) (User, error)
Update changes the name, the email and the Role of the user id at version, the version its If-Match names, or at any version when version is nil. A Role change ends the user's sessions; giving the last active Admin a lower Role is ErrLastAdmin, and changing the Role of an account that signs in through OIDC while OIDC and oidc.sync_role are both on is ErrRoleLocked. Nothing changes, and nothing is recorded, when the values are the ones the user has.
type AdminQueries ¶
type AdminQueries interface {
GetUser(ctx context.Context, arg dbgen.GetUserParams) (dbgen.GetUserRow, error)
GetUserByPublicID(ctx context.Context, arg dbgen.GetUserByPublicIDParams) (dbgen.GetUserByPublicIDRow, error)
GetUserByLogin(ctx context.Context, arg dbgen.GetUserByLoginParams) (dbgen.GetUserByLoginRow, error)
ListUsers(ctx context.Context, arg dbgen.ListUsersParams) ([]dbgen.ListUsersRow, error)
LockActiveAdmins(ctx context.Context, orgID int64) ([]int64, error)
LockUser(ctx context.Context, arg dbgen.LockUserParams) (int64, error)
CreateUser(ctx context.Context, arg dbgen.CreateUserParams) (int64, error)
UpdateUser(ctx context.Context, arg dbgen.UpdateUserParams) (int64, error)
SetUserStatus(ctx context.Context, arg dbgen.SetUserStatusParams) (int64, error)
PseudonymizeUser(ctx context.Context, arg dbgen.PseudonymizeUserParams) (int64, error)
SetUserPassword(ctx context.Context, arg dbgen.SetUserPasswordParams) (int64, error)
EndSessionsOfUser(ctx context.Context, arg dbgen.EndSessionsOfUserParams) (int64, error)
RevokeTokensOfUser(ctx context.Context, arg dbgen.RevokeTokensOfUserParams) (int64, error)
RoleSyncOn(ctx context.Context, orgID int64) (bool, error)
ConvertToLocal(ctx context.Context, arg dbgen.ConvertToLocalParams) (int64, error)
ResetUserPassword(ctx context.Context, arg dbgen.ResetUserPasswordParams) (int64, error)
DeleteOIDCCheck(ctx context.Context, arg dbgen.DeleteOIDCCheckParams) error
InsertPasswordSetup(ctx context.Context, arg dbgen.InsertPasswordSetupParams) error
SupersedePasswordSetups(ctx context.Context, arg dbgen.SupersedePasswordSetupsParams) (int64, error)
GetPasswordSetup(ctx context.Context, arg dbgen.GetPasswordSetupParams) (dbgen.GetPasswordSetupRow, error)
MarkPasswordSetupUsed(ctx context.Context, arg dbgen.MarkPasswordSetupUsedParams) (int64, error)
ListUserDirectory(ctx context.Context, arg dbgen.ListUserDirectoryParams) ([]dbgen.ListUserDirectoryRow, error)
// Tx is the connection the queries run on: inside InTx, its transaction, which the OwnerReleaser joins.
Tx() dbgen.DBTX
audit.Store
}
AdminQueries are the queries of user administration, with the insert of the Audit log.
type AdminStore ¶
type AdminStore interface {
AdminQueries
InTx(ctx context.Context, f func(AdminQueries) error) error
}
AdminStore runs the queries of user administration alone or in one transaction.
func NewAdminStore ¶
func NewAdminStore(pool *pgxpool.Pool) AdminStore
NewAdminStore is the AdminStore over the main pool.
type Bootstrap ¶
Bootstrap is the bootstrap Admin the environment asks for; an empty Email asks for none.
type Changes ¶
Changes are what an Admin edits on a user; EmailSet false keeps the email, and a nil Email with EmailSet clears it.
type Directory ¶
type Directory struct {
// contains filtered or unexported fields
}
Directory is the user directory of the Organization (C-10.FR-13): every user, deleted ones included, with only what the Owner filter, Mention settings and other pickers show, for everyone who reads Alert Groups — unlike List of Admin, which shows the email, the Role and the sign-in details to Admins.
func NewDirectory ¶
func NewDirectory(orgID int64, q DirectoryQueries) *Directory
NewDirectory returns the user directory of the Organization orgID.
type DirectoryEntry ¶
DirectoryEntry is a user in the directory (UserRef): Deactivated when the user was deleted, whose name and login are then the pseudonym deleted-user-<public_id>.
type DirectoryPage ¶
type DirectoryPage struct {
Entries []DirectoryEntry
Next *Cursor
}
DirectoryPage is a page of the directory; Next is nil on the last page.
type DirectoryQueries ¶
type DirectoryQueries interface {
ListUserDirectory(ctx context.Context, arg dbgen.ListUserDirectoryParams) ([]dbgen.ListUserDirectoryRow, error)
}
DirectoryQueries are the queries of the user directory.
type FieldError ¶
FieldError is a profile field that is not valid, at a JSON pointer of the request body, with a stable code of the validation-failed problem.
func (*FieldError) Error ¶
func (e *FieldError) Error() string
type LinkRemover ¶
type LinkRemover interface {
RemoveUserLinks(ctx context.Context, tx dbgen.DBTX, userID int64, actor audit.Actor, t audit.Transport,
addr netip.Addr) (func(context.Context), error)
}
LinkRemover removes the Account links of a deleted user (C-03.FR-13, C-18.FR-8): Admin calls it inside the transaction tx of the delete, after the release of their acknowledgements and before the Audit log entry, with the actor, the Transport and the client address of the delete; it deletes the links, each recorded as account_link.unlink with the reason user_deleted, and voids the pending link requests. An error rolls the delete back. It returns what to run once tx committed, or nil. The Account links implement it (ADR-0016: the interface is declared by its consumer).
type ListFilter ¶
ListFilter selects users; empty fields do not filter. Q matches the name, the login and the email.
type OwnerReleaser ¶
type OwnerReleaser interface {
ReleaseOwner(ctx context.Context, tx dbgen.DBTX, userID int64, reason string) (func(context.Context), error)
}
OwnerReleaser releases the acknowledgements of a disabled or deleted user (C-03.FR-13): each acknowledged Alert Group the user owns becomes firing without an Owner. Admin calls it inside the transaction tx of the disable or the delete, after the status change and before the Audit log entry, with the reason ReleaseDisabled or ReleaseDeleted; an error rolls the change back. It returns what to run once tx committed, or nil. The Alert Group lifecycle implements it (ADR-0016: the interface is declared by its consumer, so users never imports groups).
type Profile ¶
Profile is what a user edits about themselves; a nil time zone or language follows the browser.
type PruneQueries ¶
type PruneQueries interface {
PrunePasswordSetups(ctx context.Context, arg dbgen.PrunePasswordSetupsParams) (int64, error)
}
PruneQueries are the deletes of short-lived pruning; *dbgen.Queries implements them.
type Pruner ¶
type Pruner struct {
// contains filtered or unexported fields
}
Pruner deletes the password setup links that expired PasswordSetupPruneAfter ago, for the short_lived_pruning Leader task.
type Queries ¶
type Queries interface {
GetUser(ctx context.Context, arg dbgen.GetUserParams) (dbgen.GetUserRow, error)
UpdateProfile(ctx context.Context, arg dbgen.UpdateProfileParams) (int64, error)
CountAdmins(ctx context.Context, orgID int64) (int64, error)
CreateUser(ctx context.Context, arg dbgen.CreateUserParams) (int64, error)
audit.Store
}
Queries are the queries of the package, with the insert of the Audit log.
type Requester ¶
Requester is who asks for an administrative change and how: the actor and the Transport of the Audit log entry, and the client address.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service reads users and changes profiles in the Organization.
func NewService ¶
NewService returns the Service of the Organization orgID; clock is the business clock.
type SetupLink ¶
SetupLink is a single-use password setup link: MUSTER_PUBLIC_URL/password-setup#token=<token>.
type User ¶
type User struct {
ID int64
PublicID string
Login string
Name string
Email string
Role string
Source string
Status string
HasPassword bool
HasOIDCIdentity bool
OfflineAccess bool
// RoleLocked says that the identity provider decides the Role: the account signs in through OIDC while OIDC and
// oidc.sync_role are both on.
RoleLocked bool
TOTPEnabled bool
TimeZone *string
Language *string
LastSignInAt *time.Time
CreatedAt time.Time
Version int64
}
User is a user as the API shows it.
func (User) SignInMethod ¶
SignInMethod is how the user signs in now: oidc with an identity, local otherwise.