Documentation
¶
Overview ¶
Package access is who may do what: the seeded roles and groups, the checks a resolver makes against a caller's effective permissions, and the one rescue path that bypasses them.
The model is groups, roles, permissions and users. Roles and domains attach only to groups; a user in a group holds the group's roles over the group's domains, additively across groups. Nothing attaches to a user directly.
Index ¶
- Variables
- func AddUserToGroups(tx db.Transaction, userId string, groupNames ...string) error
- func AppPasswordStillValid(tx db.Transaction, appPasswordId string) (bool, error)
- func AuthenticateAppPassword(tx db.Transaction, username, password string) (*models.Mailbox, error)
- func AuthenticateAppPasswordCounting(tx db.Transaction, username, password string) (*models.Mailbox, *models.MailboxAppPassword, int, error)
- func AuthenticateAppPasswordWithID(tx db.Transaction, username, password string) (*models.Mailbox, *models.MailboxAppPassword, error)
- func AuthenticateSyncCredential(transaction db.Transaction, username, password string) (*models.SyncCredential, error)
- func CanReadMail(tx db.Transaction, user *models.User, permissions *models.EffectivePermissions, ...) (bool, error)
- func EnsureMailbox(tx db.Transaction, user *models.User) (bool, error)
- func EnsureMailboxes(tx db.Transaction) (int, error)
- func EnsureSeeded(tx db.Transaction) (bool, error)
- func MailboxMaySend(tx db.Transaction, mailbox *models.Mailbox, from string) (bool, error)
- func MailboxMayWrite(tx db.Transaction, mailbox *models.Mailbox) (bool, error)
- func ReconcileIDPGroups(tx db.Transaction, user *models.User, claimed []string) error
- func Rescue(tx db.Transaction, username string) error
- func SignInWithIdentity(tx db.Transaction, provider string, claims *IdentityClaims, ...) (*models.User, bool, error)
- type IdentityClaims
- type Principal
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoAccount is a sign-in by somebody with no account here, at a // provider that does not make one. ErrNoAccount = errors.New("access: no account for this identity") // ErrAccountDisabled is a sign-in to an account that has been turned off. ErrAccountDisabled = errors.New("access: the account is disabled") )
var ErrInvalidAppPassword = errors.New("access: invalid address or app password")
ErrInvalidAppPassword is every way an app-password sign-in can be wrong.
Functions ¶
func AddUserToGroups ¶
func AddUserToGroups(tx db.Transaction, userId string, groupNames ...string) error
AddUserToGroups puts a user into the groups named, creating none: a group somebody deleted stays deleted.
func AppPasswordStillValid ¶
func AppPasswordStillValid(tx db.Transaction, appPasswordId string) (bool, error)
AppPasswordStillValid says whether a session signed in with an app password may go on: the password exists, the mailbox exists, and its owner is enabled and may still read mail.
func AuthenticateAppPassword ¶
AuthenticateAppPassword is how a mail program signs in: one of the mailbox's addresses as the login name and an app password of that mailbox. Nothing else opens a mailbox this way — not the account password, not a passkey — and the app password is what picks the mailbox, so a person with two mailboxes sets up two accounts in their program.
Returns the mailbox, or ErrInvalidAppPassword for every way of being wrong, so that a guess learns nothing about which part was.
func AuthenticateAppPasswordCounting ¶
func AuthenticateAppPasswordCounting(tx db.Transaction, username, password string) (*models.Mailbox, *models.MailboxAppPassword, int, error)
AuthenticateAppPasswordCounting is the same, and says how many password hashes it spent.
A refusal tries every app password the mailbox has that was made before tags existed, and a hash costs about a sixth of a second on purpose. Counted as one attempt, a mailbox with twenty such devices therefore sold twenty times as much of this server's time per token as an empty one -- three seconds of a core for one packet, from anybody, on every port that takes an app password. A caller with a rate limiter charges it this many.
func AuthenticateAppPasswordWithID ¶
func AuthenticateAppPasswordWithID(tx db.Transaction, username, password string) (*models.Mailbox, *models.MailboxAppPassword, error)
AuthenticateAppPasswordWithID is AuthenticateAppPassword returning the app password that matched too, for a session that wants to check later that it still exists.
func AuthenticateSyncCredential ¶ added in v0.139.0
func AuthenticateSyncCredential(transaction db.Transaction, username, password string) (*models.SyncCredential, error)
AuthenticateSyncCredential verifies a scoped sync password, never an account password.
func CanReadMail ¶
func CanReadMail(tx db.Transaction, user *models.User, permissions *models.EffectivePermissions, mail *models.Mail) (bool, error)
CanReadMail says whether a person may see a message: as the operator of its domain, holding mail:audit over it, or as the owner of a mailbox holding it, with mail:read.
func EnsureMailbox ¶
EnsureMailbox gives a user their mailbox when they have none: "Personal", with the folders every mail program expects. Reports whether it made one.
func EnsureMailboxes ¶
func EnsureMailboxes(tx db.Transaction) (int, error)
EnsureMailboxes gives every user who has none a mailbox: what a server that predates mailboxes runs on the first start with them.
func EnsureSeeded ¶
func EnsureSeeded(tx db.Transaction) (bool, error)
EnsureSeeded creates the three roles and the two groups a fresh server starts with, when they are missing, and reports whether it made anything.
Only when missing by name: a role somebody renamed or deleted is theirs to have renamed or deleted, and this must not put it back. The exception is a server with no groups at all, which is a server that has never had access control — every existing user goes into Administrators then, so that the day this lands nobody can do less than they could the day before.
func MailboxMaySend ¶
MailboxMaySend says whether a mailbox's owner may send, and whether the address is one of the mailbox's own.
func MailboxMayWrite ¶
MailboxMayWrite says whether a mailbox's owner may change its mail: flag, move, delete, file, and add to it. A mail program signed in with an app password holds no more than the owner does in the dashboard.
func ReconcileIDPGroups ¶
ReconcileIDPGroups puts the user in every group whose idpGroup the provider claimed and takes them out of every group whose idpGroup it did not. Groups with no idpGroup are never touched: those are managed here.
func Rescue ¶
func Rescue(tx db.Transaction, username string) error
Rescue puts a user into a group that holds every permission, recreating the Administrator role and the Administrators group if they were deleted. The way back for an administrator who edited themselves out; run on the host, against the database, with no permission check, and recorded as such.
func SignInWithIdentity ¶
func SignInWithIdentity(tx db.Transaction, provider string, claims *IdentityClaims, createUsers, shouldProvisionMailbox bool) (*models.User, bool, error)
SignInWithIdentity is what a single sign-on comes to once the provider has said who this is: the account bound to (provider, subject), or a new one when the provider may make accounts, with the groups that name an identity-provider group reconciled against what was claimed. Returns the user and whether they were just created.
Types ¶
type IdentityClaims ¶
type IdentityClaims struct {
Subject string
Email string
Name string
Username string
Groups []string
}
IdentityClaims is what an identity provider said about the person signing in, in this package's terms rather than the protocol's.
type Principal ¶ added in v0.48.0
type Principal struct {
// IsServiceEnabled checks live deployment policy; nil preserves standalone callers.
IsServiceEnabled func(models.Service) bool
// User is the account, or nil for the console, the command line run on
// the server itself with the local token, which is not an account.
User *models.User
// Permissions is what the caller may do, resolved once from the
// database for this request and never cached across requests.
Permissions *models.EffectivePermissions
// Console says the caller is the host itself, which may do everything.
Console bool
// Impersonator is the operator signed in as User, when the request is
// an impersonation: User is whose account it is, Impersonator who is
// really there.
Impersonator *models.User
// CredentialKind is what the request signed in with. It is how an
// operation that must be a person's own tap tells one from a program
// that holds the person's command line token. Empty for a request that
// did not come in over HTTP with a credential, such as the agent's own
// operations, which are therefore never taken as a tap.
CredentialKind models.CredentialKind
}
Principal is who a request is made by, established once per request: the account, and what it may do, resolved from its groups. Nil for a request nobody is signed in to.
func (*Principal) IsImpersonation ¶ added in v0.107.0
IsImpersonation says whether an operator is signed in as the account rather than its owner.
func (*Principal) IsPersonsTap ¶ added in v0.170.0
IsPersonsTap says whether the request is the person's own tap on a screen: signed in by the dashboard's session or by the phone app's token, and not an operator signed in as the person.
func (*Principal) RequireService ¶ added in v0.139.0
RequireService checks service policy independently of permissions.