Documentation
¶
Overview ¶
Package identity holds the rules of managing the people of one auth: creating a person, disabling one and ending their sessions, seating one in a role. An application does not call it directly. The code generator writes, for every auth an application declares, the resources over the auth's own tables and the methods that change them; each method's body is one call into this package, so the rules are compiled and tested once and are the same for every auth of every application.
Every rule runs inside the caller's transaction (resource.ReadWriteTransaction): a generated handler's, or one an application opened to create a person beside its own rows and commit them together. Nothing here commits, and nothing reads a row a sibling call buffered in the same transaction, which Spanner applies only at the commit: a rule takes what it needs from its caller.
The sign-in paths do not come through here. The session library reads and writes the same tables in its own storage, on its own transactions, and is unchanged by this package; what couples the two is the schema, the few rules both hold (each marked "shared rule" where this package holds its half), and the word to the permission engine once a membership is committed.
Index ¶
- func RolesFollowRename(manager access.UserManager) session.UserRenamedHook
- func Scope(domain *string, everyDomain bool) (accesstypes.PolicyScope, error)
- type EmailChange
- type HeldImpersonation
- type Invitation
- type MailLink
- type Manager
- func (m *Manager) AssignRole(ctx context.Context, txn resource.ReadWriteTransaction, ...) error
- func (m *Manager) CreateUser(ctx context.Context, txn resource.ReadWriteTransaction, account *NewAccount) (impulse.UUID, error)
- func (m *Manager) DeleteUser(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error
- func (m *Manager) DirectorySeated(auth string) session.DirectorySeatedHook[*spanner.ReadWriteTransaction]
- func (m *Manager) DisableUser(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error
- func (m *Manager) EnableUser(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error
- func (m *Manager) EndImpersonation(ctx context.Context, txn resource.ReadWriteTransaction, sessionID impulse.UUID) error
- func (m *Manager) EndSession(ctx context.Context, txn resource.ReadWriteTransaction, sessionID impulse.UUID) error
- func (m *Manager) EndUserSessions(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error
- func (m *Manager) InvitationAccepted(auth string) session.InvitationAcceptedHook[*spanner.ReadWriteTransaction]
- func (m *Manager) Invite(ctx context.Context, txn resource.ReadWriteTransaction, inv *Invitation, ...) (impulse.UUID, error)
- func (m *Manager) RemoveRole(ctx context.Context, txn resource.ReadWriteTransaction, ...) error
- func (m *Manager) RenameUser(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, ...) error
- func (m *Manager) RequirePasswordChange(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error
- func (m *Manager) RevokeToken(ctx context.Context, txn resource.ReadWriteTransaction, tokenID impulse.UUID) error
- func (m *Manager) RevokeTrustedDevices(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error
- func (m *Manager) SetEmail(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, ...) error
- func (m *Manager) SetTemporaryPassword(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, ...) error
- func (m *Manager) Tenant(ctx context.Context) (*Tenant, error)
- func (m *Manager) TenantRoles(ctx context.Context, domain accesstypes.Domain) ([]access.RoleInfo, error)
- func (m *Manager) UnlinkIdentity(ctx context.Context, txn resource.ReadWriteTransaction, ...) error
- func (m *Manager) UnlockSignIn(ctx context.Context, txn resource.ReadWriteTransaction, name string) error
- func (m *Manager) WithdrawInvitation(ctx context.Context, txn resource.ReadWriteTransaction, ...) error
- type NewAccount
- type NewUser
- type Option
- type SessionAPI
- type Store
- type Tenant
- func (t *Tenant) AssignRole(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, ...) error
- func (t *Tenant) CreateUser(ctx context.Context, txn resource.ReadWriteTransaction, account *NewAccount) (impulse.UUID, error)
- func (t *Tenant) Domain() accesstypes.Domain
- func (t *Tenant) Invite(ctx context.Context, txn resource.ReadWriteTransaction, inv *Invitation, ...) (impulse.UUID, error)
- func (t *Tenant) RemoveRole(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, ...) error
- type Token
- type UserChange
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RolesFollowRename ¶
func RolesFollowRename(manager access.UserManager) session.UserRenamedHook
RolesFollowRename answers the session library's hook for a rename the library makes itself (session.Auth.SetUserRenamed): where the sign-in name is the person's email address, a verified new address renames the user, and the roles held under the old name move to the new one, as RenameUser moves them for a rename an administrator makes. The permission store names a person by username, so a person renamed keeps their roles only if the memberships follow the name.
The session library calls the hook once the transaction that renamed the user has committed and hands it no transaction, so the memberships move through the engine: in each place roles are held, they are given under the new name and then taken from the old. The two writes are not one transaction. A failure midway is logged with what moved, and the hook is safe to run again: giving a role already held changes nothing.
func Scope ¶
func Scope(domain *string, everyDomain bool) (accesstypes.PolicyScope, error)
Scope answers the scope a membership is asked for in: one domain when domain names one, every domain when everyDomain is set, the global scope otherwise. Naming a domain and every domain together is refused, and so is an empty domain: a request says which it means.
Types ¶
type EmailChange ¶
type EmailChange struct {
Address *string
}
EmailChange is the address a change writes on a user row: Address, nil for none.
type HeldImpersonation ¶
type HeldImpersonation struct {
// SessionID is the session the record belongs to.
SessionID impulse.UUID
// ActsAsRole marks a record whose session acts as a role: such a session carries
// the actor's own username, where one that views as a user carries that user's.
ActsAsRole bool
}
HeldImpersonation is one standing impersonation record a person holds as its actor.
type Invitation ¶
type Invitation struct {
// Email is the address the invitation is mailed to.
Email string
// Domain is the tenant the roles are held in, nil for an invitation into the
// application: a role of the global scope is then held there, and a role of the
// domain kind in every tenant.
Domain *string
// Roles are the roles the acceptance gives: at least one.
Roles []accesstypes.Role
}
Invitation is an invitation to send: an address, and the roles whoever accepts it is given.
type MailLink ¶
type MailLink struct {
// Invitation says the link is an invitation (the others are an address's
// verification and a sign-up).
Invitation bool
// Consumed says the link was followed or withdrawn, and ExpiresAt is when it stops
// being accepted.
Consumed bool
ExpiresAt time.Time
}
MailLink is a link the auth mailed, as the rules read it.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager applies the rules to one auth: over the store of its tables, with the permission engine that reads its memberships.
func New ¶
func New(store Store, controller access.Controller, sessions SessionAPI, opts ...Option) (*Manager, error)
New returns the manager of one auth. controller is the permission engine the auth's memberships are read by: the rule a membership's role is held to is its own (access.UserManager.Membership), and it is told once a membership is committed. sessions is the API of the session library's Auth that signs the auth's people in.
func (*Manager) AssignRole ¶
func (m *Manager) AssignRole(ctx context.Context, txn resource.ReadWriteTransaction, scope accesstypes.PolicyScope, username string, role accesstypes.Role) error
AssignRole buffers the membership that says the person holds the role in the scope, in the caller's transaction, and has the permission engine told once the transaction has committed, so the person's next request is served with the role. The person is named by username, the engine's name for them, and is not looked up: a user created earlier in the same transaction is not readable until the commit, and the caller holds the username. A membership the person holds already is left as it is.
"Holds already" is what the database has committed: a read in a transaction does not see what the transaction itself buffered, so a second call for one membership in one transaction buffers the row again and the commit is refused. One transaction gives a membership once. The session library keeps to this for the two hooks of a sign-in (a default role the accepted invitation names too is left to the invitation).
The rule is the permission engine's (access.UserManager.Membership): the role exists in the scope under exactly this spelling, and the username is not empty. A role of the release's role file is known to the engine; a custom role is read from the auth's roles table in the caller's transaction, so a role deleted beside the membership fails one of the two.
func (*Manager) CreateUser ¶
func (m *Manager) CreateUser(ctx context.Context, txn resource.ReadWriteTransaction, account *NewAccount) (impulse.UUID, error)
CreateUser buffers a new user and the memberships that give them their roles, in the caller's transaction. Without a password the person signs in through a directory, or follows an invitation and chooses their own; with one (NewAccount.Password) it is a temporary password, which the person changes before anything else is served. It answers the id the row is created under, so the caller may write its own rows beside it before anything is committed. A username or an address another user holds is refused by the table's unique indexes when the transaction commits.
A person is created holding a role: an account that holds no role anywhere is not kept (RemoveRole deletes one with its last role), so none is created without one. Every role is held in the one scope and is held to the rule a role assigned later is (AssignRole): it exists there under exactly this spelling.
Shared rule: an address is written bare, the part a message is sent to, as the session library writes one (its address function); a value that is no address is refused.
func (*Manager) DeleteUser ¶
func (m *Manager) DeleteUser(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error
DeleteUser buffers the removal of a user, in the caller's transaction: every session they hold is ended, their identity links and every membership they hold go, then the row, and the permission engine is told once the transaction has committed. Nobody deletes themselves: the request's caller is refused their own account.
Shared rule: the session library's DeleteSessionUser; the memberships are the user management's, which removes every one the person holds with the account.
func (*Manager) DirectorySeated ¶
func (m *Manager) DirectorySeated(auth string) session.DirectorySeatedHook[*spanner.ReadWriteTransaction]
DirectorySeated answers the session library's hook for a directory's default role (session.Auth.SetDirectoryAdmission): each default role the tenants' directory rows name is buffered as a membership of the person in its tenant, in the transaction that creates the person. A role that cannot be given fails the transaction, so no account is left holding nothing.
auth names the Auth in the log line a given role leaves.
func (*Manager) DisableUser ¶
func (m *Manager) DisableUser(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error
DisableUser buffers the disabling of a user and the end of every session they hold (EndUserSessions), in the caller's transaction: once it commits, the person's next request is refused, and so is their next sign-in. The sign-in paths cache neither fact. Nobody disables themselves: the request's caller is refused their own account.
Shared rule: disabling a user ends their sessions, which the session library's DeactivateSessionUser does in two commits of its own.
func (*Manager) EnableUser ¶
func (m *Manager) EnableUser(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error
EnableUser buffers the enabling of a disabled user, who may sign in again once it commits. The sessions that ended when the user was disabled stay ended.
func (*Manager) EndImpersonation ¶
func (m *Manager) EndImpersonation(ctx context.Context, txn resource.ReadWriteTransaction, sessionID impulse.UUID) error
EndImpersonation buffers the end of one impersonated session: the session and its record, as EndSession ends them. A session that was established as nobody else has no record and is refused, so the call cannot end a person's own session by mistake; a record that has ended already is left as it is.
Shared rule: the session library's DestroyImpersonatedSession, which acts only where a record stands.
func (*Manager) EndSession ¶
func (m *Manager) EndSession(ctx context.Context, txn resource.ReadWriteTransaction, sessionID impulse.UUID) error
EndSession buffers the end of one session and of its impersonation record, if it has one that still stands, in the caller's transaction: once it commits, the next request that carries the session is refused. A session that has ended already is left as it is, and a session that does not exist is refused.
Shared rule: the session library ends a session and its record together (DestroySession, DestroyImpersonatedSession). A session established from this one, as someone else, is not ended with it, as it is not there.
func (*Manager) EndUserSessions ¶
func (m *Manager) EndUserSessions(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error
EndUserSessions buffers the end of every session a user holds, in the caller's transaction: the sessions that are the user's own, and the sessions the user established as someone or something else, which are found by the user's name in their records since such a session belongs to whoever it acts as. Every record of those sessions that still stands ends with them. A user that does not exist holds none.
Shared rule: the session library's DestroyUserSessions. One thing it does is left to the library: a record still standing beside a session of the user that had ended before (the state a browser that never came back leaves) is ended there the next time that browser returns, and stands for nothing until then, since its session is refused.
func (*Manager) InvitationAccepted ¶
func (m *Manager) InvitationAccepted(auth string) session.InvitationAcceptedHook[*spanner.ReadWriteTransaction]
InvitationAccepted answers the session library's hook for an accepted invitation (session.Auth.SetInvitationAccepted): the roles the invitation carries are buffered as memberships of the person in the transaction that consumes the invitation. An invitation into a tenant gives its roles in that tenant; one into the application gives each role where that role is held, the global scope for a role of the global kind and every tenant for one of the domain kind, as Invite checked when it wrote the invitation. A role that can no longer be given (the role file changed since) fails the transaction: the invitation stands, and a person the sign-in would have created is not created.
auth names the Auth in the log line a given role leaves.
func (*Manager) Invite ¶
func (m *Manager) Invite(ctx context.Context, txn resource.ReadWriteTransaction, inv *Invitation, sent func(sent bool)) (impulse.UUID, error)
Invite buffers an invitation in the caller's transaction and has its link mailed once the transaction has committed. It answers the invitation's id. The session library prepares the invitation (the address check, the token, the time the link stands for) and keeps the token, the message and the sender; the row is written here, beside whatever else the transaction writes, so an invitation and the application's own rows are committed together or not at all.
A message cannot be taken back, so it is not sent until the rows are committed: the send is a step after the commit (resource.AfterCommit). sent is told how it went, after the commit and before the transaction's ExecuteFunc returns: true once the message is with the sender, false when it could not be sent, in which case the session library has withdrawn the invitation, so no link stands that nobody holds, and the caller invites again. A transaction that does not commit sends nothing and never calls sent. sent may be nil.
An invitation gives a role, at least one: a person an invitation admits holding no role is deleted by the rule on an account nothing admits. Every role must exist where the acceptance seats it: in the tenant for an invitation into one, and in the global scope or in every tenant for an invitation into the application. The request's caller is recorded as its sender where they are a user of the auth.
Shared rule: the session library's Invite, which stores the row and mails the link in its own storage and answers a failed send as an error.
func (*Manager) RemoveRole ¶
func (m *Manager) RemoveRole(ctx context.Context, txn resource.ReadWriteTransaction, scope accesstypes.PolicyScope, username string, role accesstypes.Role) error
RemoveRole buffers the removal of the person's membership of the role in the scope, and has the permission engine told once the transaction has committed. A membership the person does not hold is no error, and the role need not exist any more: a membership of a role since deleted is removed like any other.
Two rules of the user management are held here. A person who removes a role from themselves is held to the rule on the last administrator (refuseLastAdministrator). And a person left with no role anywhere is deleted with their identity links and sessions in the same transaction (deleteWithLastRole), whoever removed the role.
What the person holds is read as committed: a second removal for the same person in one transaction does not see the first, as no read sees a buffered write, so the account is deleted only when one call removes the last role. Remove one role of a person per transaction.
func (*Manager) RenameUser ¶
func (m *Manager) RenameUser(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, username string) error
RenameUser buffers a new username for a user, in the caller's transaction, and with it everything that names the person by username: their live sessions, the standing impersonation records they hold as actor (and the sessions of those that act as a role, which carry the actor's own name), and every membership, since the permission store names a person by username and a person renamed keeps their roles only if the rows follow the name. A name another user holds is a Conflict; the same name in another case is the person's own.
Shared rule: the session library's ChangeSessionUserUsername, which renames the user, the live sessions and the standing records in one transaction of its own; the memberships follow through the hook the application sets for it (RolesFollowRename).
func (*Manager) RequirePasswordChange ¶
func (m *Manager) RequirePasswordChange(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error
RequirePasswordChange buffers the requirement that a user change their password: once it commits, every request of theirs is refused, on the sessions they hold and on new ones, until they have changed it. The way out is theirs alone and takes the password they hold, so the requirement is refused for a user who holds none: nothing they could do would lift it.
Shared rule: the session library refuses the flag on a user without a password where it creates one (CreateSessionUser), and reads it on every request.
func (*Manager) RevokeToken ¶
func (m *Manager) RevokeToken(ctx context.Context, txn resource.ReadWriteTransaction, tokenID impulse.UUID) error
RevokeToken buffers the revocation of one bearer token, in the caller's transaction: once it commits, the next request that carries the token is refused, since the session library reads the row on every request. A token is revoked by a mark and its row stays. A token that belongs to a device authorization takes its family with it, every token of the authorization that is not revoked yet, the expired ones among them, so no successor of it stays in use. A token that is revoked or expired already is refused as one that does not exist: there is nothing live to revoke.
Shared rule: the session library's RevokeToken, here for any person's token, where the library's own route revokes the caller's.
func (*Manager) RevokeTrustedDevices ¶
func (m *Manager) RevokeTrustedDevices(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error
RevokeTrustedDevices buffers an administrator's reset of a user's second factor, in the caller's transaction: every browser the person asked to be remembered is forgotten, so their next sign-in from any of them asks for the factor. The sessions that stand are not touched (EndUserSessions ends them).
Shared rule: the session library's ResetFactors.
func (*Manager) SetEmail ¶
func (m *Manager) SetEmail(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, email *string) error
SetEmail buffers an address on a user, entered by hand, or takes the address off (nil): an operator's entry, for a person whose address changed or who was created without one. The address is held unverified, whatever the one before it was, and is trusted for nothing until the person verifies it themselves; it reserves the address all the same, so one another user holds is refused by the table's unique index when the transaction commits.
It is for an auth whose usernames are not the addresses: where they are, the address is the username, and it changes when the person verifies a new one.
Shared rule: the session library's SetSessionUserEmail, which writes the address bare and clears the time it was verified.
func (*Manager) SetTemporaryPassword ¶
func (m *Manager) SetTemporaryPassword(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, password string) error
SetTemporaryPassword buffers a password an operator chose for a user, in the caller's transaction: the person must change it before anything else is served, every session they hold is ended, and the count of failed sign-ins kept under their name is cleared, so a person locked out signs in with the new password at once. The hash is the session library's, made by the password method's hasher.
Shared rule: the session library's ResetSessionUserPassword, which does the same in commits of its own.
func (*Manager) Tenant ¶
Tenant answers the rules for the tenant a method runs for: the one its request was checked in. A tenant's method acts for a request, so one run outside any request, in a transaction of the application's own, has no tenant and is an error: there the application runs the whole application's method and names the tenant itself.
func (*Manager) TenantRoles ¶
func (m *Manager) TenantRoles(ctx context.Context, domain accesstypes.Domain) ([]access.RoleInfo, error)
TenantRoles lists the roles that exist in one tenant, by name: the tenant roles of the release's role file, and the custom roles held in the tenant and in every tenant (access.UserManager.Roles). They are the roles a membership of the tenant may name, so the list is what a role is picked from. Which of them a person may give is the role file's to say, in a condition on the grant of the method that gives one.
func (*Manager) UnlinkIdentity ¶
func (m *Manager) UnlinkIdentity(ctx context.Context, txn resource.ReadWriteTransaction, identityID impulse.UUID) error
UnlinkIdentity buffers the removal of one identity, the link between a user and the identity a directory verified for them, in the caller's transaction: once it commits, a sign-in through that identity no longer reaches the user. The sessions established through it stand. A user who holds no password keeps at least one identity, since with none they could not sign in at all; a user who holds a password may lose every one.
The count that rule reads is the committed one: a second unlink of the same user's identities in one transaction does not see the first, as no read sees a buffered write. Unlink one identity of a user per transaction.
Shared rule: the session library's UnlinkIdentity, with its refusal (sessionstorage.ErrLastSignInMethod).
func (*Manager) UnlockSignIn ¶
func (m *Manager) UnlockSignIn(ctx context.Context, txn resource.ReadWriteTransaction, name string) error
UnlockSignIn buffers the removal of the count of failed sign-ins kept under a name, in the caller's transaction, and with it the lock the count earned: once it commits, the name may sign in again. The name is what was typed into the username field, whether or not a user holds it, and is keyed as the session library keys it (session.SignInAttemptName); a name with no count is no error.
Each instance of the application trusts what it remembers of a name for a few seconds, a lock included, so the lock is gone from every instance within that time of the commit, never at once. The locks the session library holds against a client's address and cookie are in each instance's memory alone and are not cleared: they throttle a client that kept trying, whatever name it tried.
func (*Manager) WithdrawInvitation ¶
func (m *Manager) WithdrawInvitation(ctx context.Context, txn resource.ReadWriteTransaction, invitationID impulse.UUID) error
WithdrawInvitation buffers the withdrawal of an invitation that stands, in the caller's transaction: its link is then dead. It holds to invitations alone: the mail links table also keeps the links that verify an address and that start a sign-up, and one of those under the id is not found, as an invitation that does not exist is. An invitation that was accepted, withdrawn or has expired no longer stands and is not found either.
Shared rule: the session library's RevokeInvitation, which consumes the live link of the id whatever its kind.
type NewAccount ¶
type NewAccount struct {
Username string
// Email is the person's address, entered unverified; nil for none, and always nil
// where the auth's usernames are the addresses.
Email *string
// Scope is where the roles are held, and Roles the roles: at least one.
Scope accesstypes.PolicyScope
Roles []accesstypes.Role
// Password is a temporary password an operator chose, which the person changes
// before anything else is served; nil for a person who signs in another way or
// chooses their own from an invitation. PasswordRequired marks an auth where the
// password is the only way in, so a person created without one could never sign
// in. Both are for an auth with a password method alone.
Password *string
PasswordRequired bool
}
NewAccount is a person to create: who they are, and the roles they hold from the start.
type NewUser ¶
type NewUser struct {
Username string
// Email is the address the person is reached at, nil for none. It is written
// unverified.
Email *string
}
NewUser is a user row as InsertUser writes it.
type Option ¶
type Option func(*Manager)
Option configures a manager.
func WithAdministratorRoles ¶
func WithAdministratorRoles(global, domain []accesstypes.Role) Option
WithAdministratorRoles names the roles whose holders administer: global, the ones held in the global scope, and domain, the ones held in a tenant. The rule on a person removing a role from themselves reads them (RemoveRole): nobody gives up an administrator role nobody else would hold. Without them a person removes no role from themselves at all.
type SessionAPI ¶
type SessionAPI interface {
// HashPassword hashes a password as the users table holds one; an empty password
// is refused.
HashPassword(password string) (string, error)
// PrepareInvitation checks and makes an invitation without storing or mailing it:
// the row to store, and the step that mails its link once the row is committed.
// The token, the message and the sender stay in the session library.
PrepareInvitation(ctx context.Context, req *session.InvitationRequest) (session.PreparedInvitation, error)
}
SessionAPI is what the rules take from the session library's Auth, the one that signs the auth's people in: the API of the application's own Auth satisfies it (session.Auth.API). The password method's hasher is the Auth's, so a password written here is one the sign-in can check.
type Store ¶
type Store interface {
// InsertUser buffers a new user and answers the id the row is created under.
InsertUser(ctx context.Context, txn resource.ReadWriteTransaction, user *NewUser) (impulse.UUID, error)
// UpdateUser buffers a change to a user: every field of change that is set.
UpdateUser(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID, change *UserChange) error
// SetPassword buffers a user's password hash, as the session library's hasher
// rendered it, and whether the person must change the password before anything
// else is served. An auth with no password method has no such write.
SetPassword(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID, hash string, changeRequired bool) error
// ClearAttempts buffers the removal of the count of failed sign-ins kept under a
// name (session.SignInAttemptName); a name with no count is no error.
ClearAttempts(ctx context.Context, txn resource.ReadWriteTransaction, name string) error
// UserHasPassword reads whether a user holds a password; found is false where no
// user holds the id. The hash itself is read by nothing.
UserHasPassword(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) (has, found bool, err error)
// IdentityUser reads the user an identity links to; found is false where no
// identity holds the id. An auth that keeps no identities finds none.
IdentityUser(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) (userID impulse.UUID, found bool, err error)
// Identities lists the identities linked to a user.
Identities(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) ([]impulse.UUID, error)
// DeleteIdentity buffers the removal of an identity.
DeleteIdentity(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) error
// Token reads a bearer token; found is false where no token holds the id. An auth
// that issues no tokens finds none.
Token(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) (token *Token, found bool, err error)
// FamilyTokens lists the tokens of a family that are not revoked.
FamilyTokens(ctx context.Context, txn resource.ReadWriteTransaction, family impulse.UUID) ([]impulse.UUID, error)
// RevokeToken buffers the revocation of one token, with the reason.
RevokeToken(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID, reason string) error
// Username reads a user's username; found is false where no user holds the id.
Username(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) (username string, found bool, err error)
// UserID reads the id of the user who holds a username, compared as the auth
// compares names at a sign-in; found is false where none does.
UserID(ctx context.Context, txn resource.ReadWriteTransaction, username string) (id impulse.UUID, found bool, err error)
// DeleteUser buffers the removal of a user row.
DeleteUser(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) error
// LiveSessions lists the sessions of the user that have not ended.
LiveSessions(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) ([]impulse.UUID, error)
// SessionExpired reads whether a session has ended; found is false where no
// session holds the id.
SessionExpired(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) (expired, found bool, err error)
// EndSession buffers the end of one session.
EndSession(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) error
// RenameSession buffers a new username on one session.
RenameSession(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID, username string) error
// Impersonation reads the impersonation record of a session: found is false where
// the session has none, and live says a record that is found has not ended. An
// auth that keeps no such records finds none.
Impersonation(ctx context.Context, txn resource.ReadWriteTransaction, sessionID impulse.UUID) (live, found bool, err error)
// ImpersonationsHeldBy lists the sessions whose record has not ended and names the
// username as its actor, a person of this auth (the record's realm is empty). An
// auth that keeps no such records answers none.
ImpersonationsHeldBy(ctx context.Context, txn resource.ReadWriteTransaction, username string) ([]HeldImpersonation, error)
// RenameImpersonationActor buffers a new actor's name on a session's record.
RenameImpersonationActor(ctx context.Context, txn resource.ReadWriteTransaction, sessionID impulse.UUID, username string) error
// EndImpersonation buffers the end of a session's impersonation record, with the
// reason it ended.
EndImpersonation(ctx context.Context, txn resource.ReadWriteTransaction, sessionID impulse.UUID, reason string) error
// HasRole reports whether the roles table holds the row of a custom role, read in
// the transaction.
HasRole(ctx context.Context, txn resource.ReadWriteTransaction, key *access.RoleKey) (bool, error)
// HasMembership reports whether the membership row is committed.
HasMembership(ctx context.Context, txn resource.ReadWriteTransaction, key *access.MembershipKey) (bool, error)
// Memberships lists every membership the username holds, wherever it is held.
Memberships(ctx context.Context, txn resource.ReadWriteTransaction, username string) ([]access.MembershipKey, error)
// RoleHolders lists who holds the role where the key says it is held.
RoleHolders(ctx context.Context, txn resource.ReadWriteTransaction, key *access.RoleKey) ([]accesstypes.User, error)
// InsertMembership buffers a membership row.
InsertMembership(ctx context.Context, txn resource.ReadWriteTransaction, key *access.MembershipKey) error
// DeleteMembership buffers the removal of a membership row.
DeleteMembership(ctx context.Context, txn resource.ReadWriteTransaction, key *access.MembershipKey) error
// InsertInvitation buffers the mail links row of a prepared invitation, as the
// session library says one is written (session.InvitationRow).
InsertInvitation(ctx context.Context, txn resource.ReadWriteTransaction, row *session.InvitationRow) error
// MailLink reads one link the auth mailed; found is false where no link holds the
// id.
MailLink(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) (link *MailLink, found bool, err error)
// ConsumeMailLink buffers the consumption of one link: it is then dead.
ConsumeMailLink(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) error
// TrustedDevices lists the browsers the user asked to be remembered after the
// second factor that are not revoked. An auth that keeps none answers none.
TrustedDevices(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) ([]impulse.UUID, error)
// RevokeTrustedDevice buffers the revocation of one remembered browser.
RevokeTrustedDevice(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) error
}
Store is what the rules need of one auth's tables: single reads and single buffered writes, which the generated package of the auth implements over its own typed queries and patches. An implementation holds no rule: it maps the values it is given onto the auth's columns and answers what it read.
type Tenant ¶
type Tenant struct {
// contains filtered or unexported fields
}
Tenant is the rules as the methods of one tenant apply them.
func (*Tenant) AssignRole ¶
func (t *Tenant) AssignRole(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, role accesstypes.Role) error
AssignRole buffers the membership that gives a person a role in the tenant (see Manager.AssignRole, whose rule on the role it is held to). The person is named by the id of their account.
func (*Tenant) CreateUser ¶
func (t *Tenant) CreateUser(ctx context.Context, txn resource.ReadWriteTransaction, account *NewAccount) (impulse.UUID, error)
CreateUser buffers a new user who holds the roles in the tenant (see Manager.CreateUser). The roles are held in the tenant whatever scope the account names.
func (*Tenant) Invite ¶
func (t *Tenant) Invite(ctx context.Context, txn resource.ReadWriteTransaction, inv *Invitation, sent func(sent bool)) (impulse.UUID, error)
Invite buffers an invitation into the tenant and has its link mailed once the transaction has committed (see Manager.Invite). The roles are held in the tenant whatever tenant the invitation names.
func (*Tenant) RemoveRole ¶
func (t *Tenant) RemoveRole(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, role accesstypes.Role) error
RemoveRole buffers the removal of a role a person holds in the tenant, under the rules of Manager.RemoveRole: the last administrator of the tenant keeps the role, and a person left with no role anywhere is deleted. The person's id and the role are the key of the row in the tenant's list of the roles held there.
The role goes where the tenant holds a membership of its own for it. A role the person holds in every tenant alone is a row of the tenant's list too, and is not the tenant's to take: it is refused as a Conflict, and goes for the whole application or not at all. A role the person holds neither way is no error.
type Token ¶
type Token struct {
// Family is the device authorization the token belongs to, nil for a token that
// stands alone.
Family *impulse.UUID
// ExpiresAt is when the token stops being accepted, and Revoked whether it was
// revoked before that.
ExpiresAt time.Time
Revoked bool
}
Token is a bearer token as the rules read it.
type UserChange ¶
type UserChange struct {
Username *string
Disabled *bool
PasswordChangeRequired *bool
// Email, where set, replaces the address the row holds. An address written here was
// entered by hand, so the row is left unverified: the time the address it held was
// verified goes with it.
Email *EmailChange
}
UserChange is a change to a user row: a nil field is left as it is.