ADR-015 — Cross-tenant user administration by permission (no host scope) + operational/system permission poles
Date: 2026-08-19
Status: Accepted
Extends: ADR-010 (1 user → N tenants), ADR-013 (PermissionAction + IsConsole/IsSystem).
Relates to: the SA-only tenant-administration model (todos/001), the role-assignment authority guard (todos/002).
Origin: three defects reported by a derived product (ABBC Hub) against code copied verbatim from this template.
Context
Three findings arrived together, and only the third is cosmetic:
- Membership assignment failed silently.
PUT /v1/users/{id}withtenantIds: [2, 1, 3]answered200 OKand stored[2].CreateAsync/ReconcileMembershipsAsyncintersected the request with the caller's authority (allowedTenantIds, i.e. the caller's own memberships) and dropped the remainder without an error. - Nobody could grant a second tenant. Authority came exclusively from the caller's own memberships, and reach (
IsMemberAsync) exclusively from a membership in the active tenant. An institution admin was refused (correctly — it must not hand out a tenant it does not belong to); a central operator could not even open the user, because it holds no membership in the target's tenant. The only window where a user could gain a tenant was creation, and it closed on the first membership. - The platform administrator held the business permissions, so it appeared in screens that are, by definition, acts of a tenant.
(1) is a plain bug — fixed by refusing instead of truncating. (2) and (3) are model questions, and the product had answered them locally by inventing a host scope: int? tenantId with null meaning "no tenant / Master", a TenantScope type, an IHostStaffAuthority, and a listing that in host scope showed only accounts with no membership at all (its staff).
Decision
1. Refuse out-of-authority additions; keep removals confined — asymmetrically
IUserManagement.CreateAsync/UpdateAsync refuse a requested tenant outside allowedTenantIds with User.TenantNotAssignable (403, naming the ids), before any write, next to the existing pre-transaction authority checks. Removals stay filtered by authority: a membership the user already holds outside the caller's authority is preserved when absent from the payload and accepted when echoed back.
Both halves are required. Without the refusal, a grant vanishes silently. Without the removal filter, an admin of tenant A saving a user who also belongs to B would delete the B membership, because A's form cannot show B — one silent data loss traded for another. The shape mirrors PlanRolesForTenantAsync, which had already settled the same question for group assignment.
2. Reach is a permission, not a second kind of identity — no host scope
Cross-tenant user administration is expressed as Users.ManageAllTenants, a [SystemPermission] [ConsolePermission]. Its holder reaches every user regardless of membership and may assign every tenant. Every IUserManagement operation takes an explicit crossTenant flag alongside the active tenant; the pair is the caller's reach. Reach is resolved by the caller from its effective permissions (CallerReach), never inferred inside the implementation, so each widening is visible at the call site.
The host scope was rejected for this template:
- There is no tenant-less identity here. The system administrator is the default tenant's
Admin, seeded with aTenantUsermembership; login itself fails withAuth.NoTenantfor a user with no membership (ADR-010). Anullscope would require inventing "staff account without a tenant" and teachingActiveTenantSelectorand the session endpoints about it — a change to authentication, to fix a question about authorization. - The privilege axis already exists.
[SystemPermission]+IsSystemrole + the provisioning strip is exactly the machinery that keepsTenants.*SA-only (ADR-013,todos/001). Reusing it costs one constant; a parallelTenantScope/IHostStaffAuthorityaxis would mean two ways to say "privileged". - It keeps the model honest about primacy. A nullable scope forces the question "which tenant does the row show?", answerable only by inventing a primary membership (flag + migration + a rule for which one wins).
TenantUseris a join without rank, and thetenantIdin the user detail is the asker's active scope, not an attribute of the user. So a row shows the whole membership list (UserSummaryResponse.Tenants) — the only truthful answer available.
Consequently a user row carries its tenants, and the SPA shows that column only to a caller with cross-tenant reach (redundant otherwise). The tenant picker is fed by GET /v1/users/assignable-tenants, which applies the same reach as the write endpoints — an option the API would refuse is worse than no option.
3. Two poles in the catalogue: [OperationalPermission] vs [SystemPermission]
A third marker joins the two from ADR-013. [OperationalPermission] marks an act performed on behalf of a tenant (business features — Orders.*); [SystemPermission] marks an act of platform administration (Tenants.*, Users.ManageAllTenants). They are opposite poles, and provisioning reads them:
| Group | Grant |
|---|---|
System administrator — the default tenant's Admin | PermissionCatalog.AllExceptOperational() |
A runtime tenant's own Admin | PermissionCatalog.AllExceptSystem() |
Operator / Viewer (canonical example groups) | the operational set they need |
The exclusion for runtime tenants was previously a string prefix (p.StartsWith("Tenants.")); it is now metadata-driven, so a newly declared privileged permission is withheld the moment it is annotated — Users.ManageAllTenants would otherwise have leaked to every tenant's Admin on the day it was added.
The visible consequence: the default tenant's Admin no longer holds Orders.*, and therefore can neither operate the example feature nor grant those permissions to other groups (the safe merge in SetGroupPermissions preserves what a caller cannot grant). The default tenant's business is run by its own groups — Operator (create/read/approve) and Viewer (read). A deployment that wants one principal doing both must say so explicitly, by giving a group both sets.
4. Provisioning a system group revokes, it does not only add
RoleProvisioner.EnsureRoleAsync reconciles the grant of an IsSystem role: permissions outside the desired set are revoked. Editable groups stay additive — revoking there would silently undo an administrator's configuration — and a system group is safe to reconcile because it is read-only at runtime, so the provisioner owns its grant entirely.
Reconciliation alone is not enough: ProvisionSystemRolesAsync runs only at tenant creation, so an existing tenant would never see a narrowed canon. IdentitySeeder therefore re-provisions the system group of every non-default tenant on startup. Grants are persisted, not derived — without this pass, tightening the rules changes nothing in any environment that already ran the wider version, while the test suite goes green.
Consequences
IUserManagementis a breaking contract change:QueryUsersInTenant→QueryUsers(tenantId, crossTenant, …),GetByIdAsync/SetActiveAsync/ResetPasswordAsync/UpdateAsynctakecrossTenant, andIsReachableAsync/GetAssignableTenantIdsAsyncare new. The avatar slices moved from an ad-hoc membership check toIsReachableAsync.- A caller that today receives
200for a partially-assignabletenantIdswill receive403. PermissionActiongainsIsOperational(migrationAddPermissionActionIsOperational), reconciled byPermissionActionSeederlike the other flags;GET /v1/permissionsexposes it.- Environments upgrade without manual steps: startup re-provisioning revokes what the narrowed canon no longer grants.
Users.ManageAllTenantsreaches a group only throughRoleProvisioner(system permission + read-only system group), so it cannot be self-granted — the anti-escalation is structural, as in ADR-013.
Alternatives considered
- Host scope as the product built it (
int?,TenantScope,IHostStaffAuthority) — rejected above; it would also have shipped with the product's own rule that host listing shows only membership-less accounts, which is the very restriction that made the user unreachable. - Treating cross-tenant authority as unbounded instead of materializing the tenant ids — rejected: an id matching no tenant would then create a membership pointing nowhere.
GetAssignableTenantIdsAsynclists the real tenants, so a typo is still refused. - Skipping
[OperationalPermission]and leaving the system administrator with the full catalogue — the smaller change, but it leaves "the platform operator operates for tenants" true by default, which is the defect the product reported. - Revoking on every group, not only system groups — rejected: it would fight administrators, silently reverting deliberate configuration on the next startup.