Expand description
Spike: request-scoped identity and authorization for the network surfaces.
The shipped auth module authenticates a connection: its
Authenticator returns a bare bool, so a
request either passes the bearer-token gate or it does not, and no identity
survives into the handler. That is enough for a single trusted operator, but
it cannot express three things this spike explores:
- Optional, layered enforcement. A surface may run wide open, require only authentication, or require authentication and per-operation authorization — chosen at deploy time without recompiling.
- External identity providers on a shared, public system. A transactor
or peer server exposed to many tenants must accept tokens minted by
someone else (an OIDC issuer, an mTLS CA) and turn them into a local
Principal, not compare them to a single static secret. - Many users, different views, one server. Because identity is bound to
the request (not the connection), one hosted peer can answer two
callers concurrently and give each a different authorization decision and
a different
ViewFilterover the same database.
The model is deliberately transport-adjacent: Guard bundles a chosen
(IdentityProvider, Authorizer) pair, and IdentityInterceptor is
the only tonic-facing piece. A deployment that wants none of this constructs
Guard::disabled and behaves exactly as today.
Authn is synchronous and authz is asynchronous, on purpose:
authenticating a request is local verification (a token compare, a signature
check against cached keys, an mTLS subject) and it runs inside the
synchronous tonic Interceptor; authorizing one may consult an external
policy oracle (OpenFGA / Auth0 FGA answer a per-decision network Check), and
it runs handler-side where awaiting is free. A provider that genuinely needs
I/O (OIDC token introspection) caches results and refreshes out of band, so
IdentityProvider::authenticate stays a cheap synchronous lookup.
See docs/design/auth.md for how this maps onto the RPC surface and the
migration away from the bool authenticator.
Structs§
- Access
- A specific access: an
Actionon an optional target database. - Allow
All - Permits every access. Used when a surface requires authentication but not
authorization (or none at all, paired with
AllowAnonymous). - Allow
Anonymous - Accepts everyone as
Principal::anonymous. Used when a surface does not require authentication. - Attribute
Allowlist - A
ViewFilterthat hides every attribute outside an allowlist. - Composite
Provider - Tries a list of providers in order, so one shared system can accept several
issuers at once (static tokens for internal tools, OIDC for humans, mTLS for
services). The first provider to accept wins; the first to reject stops the
chain. If every provider abstains, the composite abstains too — whether that
becomes anonymous access or a rejection is the
Guard’s policy. - Credentials
- Raw credentials extracted from a request, before authentication.
- External
Tokens - Adapts a
TokenVerifierinto anIdentityProvider. - Grant
- A grant held by a role: which actions, over which databases, with what view.
- Guard
- A chosen (
IdentityProvider,Authorizer) pair — the policy a surface enforces. OneGuardserves every request on a surface; identity is derived per request, so a single guard handles many concurrent callers. - Identity
Interceptor - tonic interceptor that authenticates each request and stashes the resulting
Principalin the request extensions. Because it runs per request, two callers on the same connection get their own identities — the basis for multi-tenant serving. Handlers then callprincipalandGuard::authorizeonce they know the concreteAccess. - Policy
Authorizer - A role-based authorizer: a principal’s roles select
Grants, and the union of matching grants decides the access. Deny-by-default — an access no grant covers is refused. - Principal
- An authenticated (or anonymous) caller, carried in request extensions.
- Static
Tokens - Maps a fixed set of bearer tokens to fixed principals.
Enums§
- Action
- The operation a request wants to perform, for authorization.
- Action
Class - A coarse class of action, so grants need not list every
Action. - Auth
Error - Failure of authentication or authorization.
- Decision
- The outcome of an authorization check.
Traits§
- Authorizer
- Decides whether a
Principalmay perform anAccess. - Identity
Provider - Turns credentials into a
Principal, or declines. - Token
Verifier - Verifies an opaque bearer token minted by an external issuer.
- View
Filter - Restricts what a principal may see within a database it is allowed to read.
Functions§
- principal
- Reads the
PrincipalanIdentityInterceptorattached to a request, defaulting to anonymous when no interceptor ran (e.g. embedded transport).