Interface IGrantStore
- Namespace
- MailFathom.Application.Access.Grants
- Assembly
- MailFathom.Application.dll
Where the three records a user's grant is computed from are kept: roles, groups, and role assignments.
public interface IGrantStore
Remarks
A role is a name and a list of permissions, a group is a set of users, and an assignment gives one role to one user or group at one scope. They are records in PostgreSQL rather than configuration, so a change to any of them is the same on every replica from the moment it commits.
A role's list is stored as it was written: a name as the name, and a pattern as the pattern. Every read that computes a grant resolves a stored pattern against the set this build publishes at that moment, through GrantedBy(string?), so two builds serving one database during a rolling upgrade each grant what their own build publishes in a pattern's reach, and nothing is rewritten when the newer one starts.
Every invariant a write can break is decided by the database at the moment of the write rather than by a read a moment earlier: a role name and a group name are unique across the deployment, an assignment names a role, a principal, and a scope that exist, and the same role is never given to the same principal at the same scope twice. Each refusal is answered as an outcome rather than raised. Removing a user or an organization takes every membership and assignment naming it with it in the statement that removes it, while removing a role or a group that is still assigned is refused, because it would revoke a grant from everybody holding it as a side effect.
Three writes guard something that is the deployment's rather than a row's: a deployment where nobody holds AdminRolesWrite over it is one nobody can administer without the database. Revoking an assignment, ending a membership, and replacing a role's list are each refused as LastRoot when they would take the last root away, decided inside the write with every role giving the name locked, so two writes each removing one of two roots cannot both pass. A role listing a pattern that reaches the name gives it exactly as one listing the name does. Nothing else is refused over it, so it is not an invariant a caller may rely on: removing the last user who holds the root, or moving them out of the organization whose group gives it to them, takes it away.
Nothing here decides who may write what. The escalation rules — nobody grants more than they hold, or wider than they hold it — belong to the use cases that call this store.
Methods
- AddGroupMemberAsync(Guid, UserId, DateTimeOffset, CancellationToken)
Makes a user a member of a group.
- AssignAsync(Guid, Guid, AssignmentPrincipal, AssignmentScope, DateTimeOffset, CancellationToken)
Gives a role to a user or a group at a scope.
- DeleteGroupAsync(Guid, CancellationToken)
Removes a group nothing is assigned to, and its memberships with it.
- DeleteRoleAsync(Guid, CancellationToken)
Removes a role nobody is assigned.
- HoldsWideningRoleAsync(AssignmentPrincipal, CancellationToken)
Reads whether any role a principal's assignments give lists a pattern, so what the principal holds widens on upgrade.
- ReadAssignmentAsync(Guid, CancellationToken)
Reads one assignment.
- ReadAssignmentsAsync(AdministrativeListingQuery, GrantListingReach, CancellationToken)
Reads one page of the role assignments a reach covers, in identifier order.
- ReadGrantOfAsync(UserId, CancellationToken)
Reads what one user holds through every assignment naming them and every assignment naming a group they are a member of.
- ReadGrantOfGroupAsync(Guid, CancellationToken)
Reads what joining a group gives: every permission its assignments' roles list, paired with each assignment's scope.
- ReadGrantSourcesOfAsync(UserId, GrantListingReach, int, CancellationToken)
Reads why one user holds what they hold: one row per permission, entry of a role's list granting it, and assignment.
- ReadGroupAsync(Guid, CancellationToken)
Reads one group.
- ReadGroupMembersAsync(Guid, AdministrativeListingQuery, CancellationToken)
Reads one page of the members of one group, in user identifier order.
- ReadGroupsAsync(AdministrativeListingQuery, GrantListingReach, CancellationToken)
Reads one page of the groups a reach covers, in identifier order.
- ReadRoleAsync(Guid, CancellationToken)
Reads one role.
- ReadRolesAsync(AdministrativeListingQuery, CancellationToken)
Reads one page of the roles this deployment holds, in identifier order.
- ReadRolesHeldByAsync(UserId, CancellationToken)
Reads which roles one user holds, at which scopes, through the same assignments ReadGrantOfAsync(UserId, CancellationToken) reads.
- ReadUserPlacementAsync(UserId, CancellationToken)
Reads which organization one user belongs to.
- RemoveGroupMemberAsync(Guid, UserId, CancellationToken)
Ends a user's membership of a group.
- RenameGroupAsync(Guid, string, CancellationToken)
Replaces the name an operator reads a group by.
- RenameRoleAsync(Guid, string, CancellationToken)
Replaces the name an operator reads a role by.
- ReplaceRolePermissionsAsync(Guid, RolePermissions, CancellationToken)
Replaces the whole list of permissions a role grants.
- RevokeAsync(Guid, CancellationToken)
Revokes one assignment.