Table of Contents

Who a use case is running for

A use case can be reached by more than one thing. Today an MCP tool, an administrative route, a background worker, and the attachment download link all end at application-layer code, and each of them arrives by a different path with different checks in front of it. This page describes what that code is told about whoever reached it, and why the check that acts on it lives there rather than only in the middleware a request happened to pass through.

The vocabulary of named permissions itself — what a permission is, which ones exist, and how a credential comes to hold one — is what a credential may do, and ADR 0012 is the record behind it. What follows is only how that grant reaches the code that acts on it.

Two checks, and why neither replaces the other

The transport refuses cheaply. A check at the endpoint turns a request away without reaching a use case at all, and it is the only place a decision can be reflected in what a caller is offered rather than only in what it is told. The MCP surface uses both halves of that: admission is decided there, and the grant is weighed there too, which is what lets a tools/list carry only the tools this caller may call.

The use case is the authority. An entrypoint added later — a rule action, a worker, a command, a second protocol — reaches the same code without passing that middleware, so a check that lived only there is one the new entrypoint forgets. Asking inside the use case makes the answer a property of the operation rather than of the route somebody happened to arrive by, which is what leaves a new entrypoint safe by default instead of safe by the author remembering.

The two are not redundant, because they are answering for different sets of callers. A use case never relies on the transport having already asked, and the transport never relies on the use case being the only way in.

What the application layer is told

AuthorizedPrincipal is the whole of it: the identity the work was admitted under, the permissions that identity holds, and — where the work is somebody's mail rather than the deployment's — the user it is acting for. Nothing from System.Security.Claims, ASP.NET Core, or the MCP SDK crosses that line, and no use case learns which credential admitted a caller — that is a question the transport already answered. Boundaries.UnitTests holds a rule keeping claims types out of Application and Domain, because those are the one family of types the project references cannot refuse on their own.

The identity is not one shape. Where an operator wrote the credential it is that entry's own name; where a token brought it, it is the issuer and subject the deployment authorized — a host name and that authorization server's identifier for a person; and where the surface configures no credential at all it is the fixed word anonymous, because there is nothing to tell one caller apart from another. So a boundary that names the caller to its own readers reads the identity and decides for itself what it may show, and a refusal never carries it.

There are three kinds of principal, and none of them is a weaker version of another:

Kind What it is What it holds
Caller Somebody who presented a credential a configured entry admits, or — where the surface configures no entry at all — somebody who presented nothing On a mail surface, what the user's roles grant kept to what the credential names, each permission at the scopes it was granted at; on the administrative surface, what the user's roles grant, kept to what its credential names and, on an entry that reads them, to a token's own scopes — or, where the surface configures no entry, what the default administrator's roles grant — with its mail names held only as the ceiling a credential written there is bounded by, since that caller acts for no user
Process identity MailFathom itself, running work no caller requested Nothing, by construction
Signed capability A ticket this deployment signed for one object Nothing; the ticket is the authorization

The process identity is a kind of its own rather than a caller holding everything, and that is the point of modelling it. A principal that could be admitted by holding a permission would be reachable by whoever an operator granted that permission to — so a use case that may run without a caller admits it by name, and never by a permission check.

An administrative permission is asked about over what as well as what. RequirePermission asks for a name held over the whole deployment, and every administrative operation admitted at the deployment scope alone asks it — recording an organization, deleting one, and changing its short name among them. The reads published under mailfathom.admin.audit.read and the operations that administer a user, their record, their credentials, or an organization's display name, and that administer or operate on a mail account, its mailbox, or a user's contact book, ask over what they name: RequirePermissionOverAsync or PermitsOverAsync with the user or the mail account, and PermitsOverScopeAsync with an organization or with a scope another grant is held at. AccessAuthorization places a user or an account through IAdministrativeTargets — the organization it belongs to, and the one user it is wholly the concern of — read from the records per question so a move between organizations reaches the next check on every replica. A listing asks ScopesOf and answers within them rather than refusing — the store cuts the page over what those scopes cover rather than filtering it after it was cut — and the synchronization status, which reports every configured account, asks CoveredMailAccountsAsync and leaves out the ones no scope of the caller covers. An act only the deployment scope admits behind an operation that otherwise names a target asks RequirePermissionOverTheDeployment, whose refusal a boundary may answer as held only below the deployment because it was decided before anything the request names was read. A name held over the deployment answers without placing anything, and a read across several mail accounts asks CoveredMailAccountsAsync, which places them in one read. A read addressed by an identifier of its own, such as one queued message, learns its account only by reading the record: it asks RequirePermissionAtAnyScope before reading, then PermitsOverAsync over the account it found, and answers a record outside the caller's scope as one it did not find. A boundary that has to answer a target outside the caller's scope exactly as one that does not exist asks PermitsOverAsync first and takes the not-found path itself, which is how a refusal stops disclosing that the target exists elsewhere; PermitsAtAnyScope is the cheap question the transport asks of such a route, since it cannot place the target. A use case that already read the record it acts on places it itself and asks PermitsOver, which reads nothing.

The user is a second axis, and it is not a permission. A permission says which operations a caller may perform; the user says whose mail those operations run against, and no grant an operator writes can make one caller act for another. So a principal carries a user or carries none, and the two questions are asked separately: RequirePermission answers the first and RequireUser the second. A caller admitted on a surface that serves one user's mail acts for that user; the deployment administrator and this process's own identity act for nobody, and a caller-scoped read reached by either is refused rather than answered with an empty set — an empty answer there would publish the read to them in the shape of an answer. Which surfaces carry a user is settled where a request becomes a principal, one section below.

Work that runs for nobody still has to know whose mail it touches. Synchronization and embedding are performed under this process's own identity, which carries no user by construction — so a bound stated per user cannot be read off the principal, and asking RequireUser there would refuse the work rather than answer it. IMailOwnership is what answers instead: it resolves the user of a stored message from the mail graph, where ownership lives on the row itself, and it is the only way to reach that fact without a caller. It has nothing to resolve a user from an account with, and deliberately so — an account identifier names one mailbox within its user rather than across the deployment, so a question that names the identifier alone has no single answer, and whoever holds the account already holds the pair. Reading it is not an authorization decision and grants nothing — a worker was already admitted by name — and it is deliberately not a way for a caller to act for somebody else, because nothing published to a caller consults it.

The contact book is two books, and which of them a principal reaches follows from the user it acts for. A caller reads their own book beside the collected book of each mail account assigned to them, so ContactBookOwnership resolves the caller's user with RequireUser and composes the scope from the assignment relation — a principal acting for nobody reaches no book rather than falling back to whoever the deployment serves. The two principals that legitimately maintain a book without being a caller are outside that reading rather than exceptions to it: an administrative route names the user, or the mail account, it acts for, and MailFathom's own synchronization writes the collected book of the account it is synchronizing and reads no user at all. Contacts § Two books, and a read of both is where what that decides is described.

The signed capability is what GET /mcp/attachments/{capability} runs under. That route authenticates nobody by design: the URL carries a ticket verified against the deployment's key ring, and what it names is one attachment of one email rather than a surface. So the capability is the authorization, already bounded to a single object and a lifetime, and the entrypoint behind that route admits that kind and asks for no permission beside it. It is a principal kind rather than an exception, so the next capability-authorized route does not have to argue for its own.

The use case those two share serves the client surface's own attachment route as well, and the second entrypoint admits a caller granted mailfathom.mail.read and no capability at all — a reader who authenticated needs nothing minted for them. The two are disjoint in both directions rather than one being a relaxation of the other: a caller however broadly granted cannot redeem a link's entrypoint, and a redeemed capability cannot reach the client's. Everything either of them establishes afterwards is the same, which is why they are two authorizations over one resolution rather than two use cases.

How it gets there

The host composes one IAuthorizedPrincipalSource per scope, which for a served request is that request:

  • A request an authentication scheme validated becomes a caller, named by what this deployment authorized — the identifier of the user credential the presented value resolved to on a mail-serving surface, and on the administrative surface the user and that credential together, as user <user id> credential <credential id>, which is what every administrative act, log scope, and audit record names. What the credential names travels as claims the scheme wrote when it was judged, so nothing per request re-reads a configuration section or the credential's row. Those claims are a narrowing rather than the grant: a step after authorization reads the user's own grant through UserGrantResolver, which each replica remembers per user until a change to what users are granted makes it forget, and the caller holds that grant kept to the names the claims carry — on a mail-serving surface the credential's own names on the user-facing half, and on the administrative surface both halves, kept to what its credential names and, where its entry reads them, to a token's scopes, whose user-facing names that principal holds for comparison and never performs. A request that step never reached holds nothing.
  • A scope with no request behind it is the process's own identity. Work reached outside a request in this process is work no caller asked for.
  • A route that verified a capability states that principal onto its own scope before it reaches the use case. The download route is the one that does.

A request that authenticated nothing depends on what the surface it reached configures. Where that surface configures no Authentication entry at all, the caller is served anyway — there is no credential to narrow it with, which is the posture ADR 0012 settled and the startup record already states, so reporting no principal there would have a use case refuse every call on a deployment whose own record says it serves somebody. On the MCP or client surface that caller acts for the user the deployment serves and holds what that user's roles grant on the user-facing half; on the administrative surface it acts for no user, is named user <the default administrator> credential none, and holds what the default administrator's roles grant — and where the default administrator was removed, it is no principal at all, so such an endpoint serves nobody. Where the surface does configure a credential, such a request is none of the three.

The download route is withheld from that grant on either posture. The MCP surface serves it beside the protocol route, so the paragraph above would otherwise admit it out of the transport wherever the deployment configures no MCP credential — a second and weaker way into an attachment than the signature the route exists to check, and one holding on one posture only. The adapter therefore answers no principal for a path that route serves before it asks either surface, and the route's own statement, made once the ticket verifies, is the only thing that authorizes it.

Two of the three surfaces serve one user's mail, and the adapter is where that is decided. A caller admitted on the MCP surface or on the client surface is admitted to act for the user this deployment serves; a caller admitted on the administrative surface is not, because an administrator is admitted to a deployment rather than to somebody's mailbox. The split holds on either posture — a caller the surface authenticated and a caller admitted by the surface configuring no credential are both admitted the same way — because it follows from the path the request arrived on rather than from what it presented.

Which user that is comes from the credential wherever a credential was presented, and from a startup gate otherwise. Every credential a mail-serving surface accepts resolves one user record, whichever of the four methods it is, so a request admitted on one carries that user as a claim and the adapter acts for it — which is what lets one deployment serve more than one person's mail over one address, and what makes a credential resolving no user refusable exactly as an unknown credential is. The same read carries the two endpoint switches on that user's row, so a user an administrator kept off the surface the request arrived on is refused at authentication with that same answer, whatever the method and however long ago a session or token was minted, and never reaches a policy to be told 403 instead.

The gate reads, while the host starts, whether the deployment holds nobody, one user, or several — never anybody's record, which a replica reads the first time something acts for that user, together with the mail accounts assigned to them, and keeps while somebody keeps asking. No configuration source names a user or declares a mailbox. A caller that names no user needs at most one user to act for, so the gate refuses to come up on more while McpEndpoint or ClientEndpoint admits such a caller — which is a surface requiring no authentication and nothing else. Every credential these two surfaces admit is a record naming the user it belongs to, whichever of the four methods presents it, so what an entry states is a method rather than a person and reading the entry would answer nothing; what admits several users is requiring a credential on both surfaces — or the surfaces being off.

The administrative surface is deliberately outside that reading. An administrator acts for the deployment rather than for a person, and every route there that is about one user names the user it is about, so a deployment of several leaves nothing unanswered. That is also what makes recording a second user reachable at all: the surface an operator would use to correct the other two cannot be the surface the refusal closes. No administrative route resolves the sole user any more — the contact book was the last of them, and each of its routes now names the user, or the mail account, whose book it reaches. Which mail accounts a caller owns was never one of them either: it is resolved from the user each served account carries, so every mailbox read answers a caller with their own half of a deployment serving several. The health endpoints record what each refusal means to an operator.

The claim decides whose mail a request reaches on the two mail-serving surfaces alone. On the administrative surface it decides whose grant the caller holds and whom an act is attributed to, and the principal still acts for no user: an administrator signed in with a credential of their own is not thereby acting on their own mailbox, and a user-scoped use case refuses them however broad their grant. Every administrative route about one user names that user instead. Admission there asks one more thing of the user than a mail-serving surface does — that their roles grant at least one administrative permission at some scope — and a credential whose user holds none is refused at authentication with the answer an unknown credential gets.

The client surface reaches the same adapter and is no third case. It is the third surface a request can arrive on, and its grant is resolved exactly as the MCP surface's is — the user's roles, kept to what the credential names, or to the whole of the user-facing half where it configures none. Its session route reports that grant rather than requiring anything of it, and its mail-reading routes reach the use cases that already ask, under the permissions they already name: GET /api/client/accounts is published under mailfathom.mail.read and calls the same account reader an agent's list_accounts reaches.

What a refusal is, and what each boundary does with it

A use case refuses by raising PrincipalNotAuthorizedException, which carries error code 14001 and, where the requirement was a grant rather than a kind, the permission that would have sufficed. It is an application failure rather than a status code or a protocol result, because the same refusal is meant to reach two boundaries that answer it differently — and a use case that raised either shape directly would have decided both.

A use case that acts on one user's mail and is reached by a principal acting for no user is refused the same way and with the same code, because from the use case's side it is the same fact: what reached it cannot say whose mail it is about. A deployment that cannot resolve its own user never reaches a use case at all, and answers 14002 DeploymentUserUnresolved in the two places that reading is taken. Several users behind a surface that admits a caller naming none is a refusal to start, so nothing serves. Several users otherwise is a start that succeeds, and the code is then answered per request, as 409 on the handful of acts above that resolve the sole user and name none themselves. 14003 DefaultAdministratorUnusable is the third code of the family and is answered at startup alone: a MAILFATHOM_ADMIN_PASSWORD the password policy refuses, or a default administrator whose username another user's password credential already holds, stops the start naming which — the default administrator is the page.

A use case reached under no principal at all is refused the same way. That is the case an entrypoint produces by omission — it never said what admitted the work — and refusing it is what "fails rather than defaulting to permitted" means in the one place the decision is taken.

The MCP surface answers it by saying nothing. The use cases behind its tools each require a permission — mailfathom.mail.read for the four that read the local mailbox copy, mailfathom.assistant.use beside it for the one that answers from it, mailfathom.mail.flags.write for the one that changes a mailbox, mailfathom.mail.drafts.write for the three that write a draft, and the two contact names for the book — and the endpoint asks the same question ahead of them, from the grant the caller was admitted under. mailfathom.mail.send is asked for a third time by the outbox a send is written down in, which is the case that shows which of the checks is the authority: an entrypoint reaching that use case from anywhere else meets the same refusal without passing the endpoint at all. A tool the grant does not permit is absent from tools/list, and a call naming one is answered as a call naming a tool that does not exist: the same error, the same code, and nothing about the caller, the credential, or the permission. So this refusal never reaches a client in a form it could read; the MCP tools page states which tool requires which permission.

The two HTTP surfaces answer it by naming the permission and nothing else. Every route on either publishes the one permission it requires as endpoint metadata, decided beside the route rather than in a list a new route could be added without joining, and a group filter reads that metadata ahead of the handler: a caller the grant does not admit is refused 403 in the endpoint's ordinary problem shape, stating the permission that would have sufficed and carrying it as a permission member so mfctl can say what to grant. A route publishing no decision is refused to everyone, and so is one published under the other half's permission, which makes either omission a visible failure rather than an open route. The use case behind the route asks the same question again and raises this refusal on its own, and the filter answers that exception in the same shape — so the transport is a cheap first reading rather than the authority. GET /session is the one route on each surface that requires no permission, because reporting what the credential is and what it may do is what a caller holding nothing needs in order to learn that it holds nothing. The administrative one also names the user and the roles that user holds at each scope, read from the user's own records rather than off the principal, which acts for no user there by design. Which half a route may draw on is the group's decision rather than the route's, so the same filter serves both surfaces and each names its own. The administrative endpoint page and the client endpoint page carry the two mappings.

Every surface records its refusals, and no surface's answer is the record. A refusal is counted by mailfathom.authorization.refusals — by surface, by the tool or route that was refused, and by the permission that would have sufficed — with a warning beside it naming who the work was admitted as, which the boundary reads from AccessAuthorization rather than from the refusal, since the failure itself is barred from carrying an identity. A tool withheld from a listing is not a refusal and is not recorded: nothing was refused, and every narrowed caller would produce one on every listing. Telemetry holds what each channel carries.

The other requirement in force is the download route's, which admits a signed capability and nothing else.

The transport's own reading of the grant goes through the same AccessAuthorization the use cases ask, which reports a verdict instead of raising where a boundary has to compose an answer rather than perform an operation. One definition of what holding a permission means is what keeps a listing from offering a tool the use case behind it would then refuse.