pub struct Gate { /* private fields */ }Expand description
The one rule in front of every call: the method’s grant, held through a
role on the target’s scope, within the session’s ceiling. Default deny.
Cheap to clone (one Arc); cheap to ask (memory only), so a stream may
ask per event.
Implementations§
Source§impl Gate
impl Gate
Sourcepub fn new(
memberships: Arc<dyn Memberships>,
roles: Arc<dyn Roles>,
resolve: Arc<dyn Resolve>,
) -> Gate
pub fn new( memberships: Arc<dyn Memberships>, roles: Arc<dyn Roles>, resolve: Arc<dyn Resolve>, ) -> Gate
A gate over a service’s memberships, roles and resolver.
Sourcepub fn with_generation(self, generation: GrantsGeneration) -> Gate
pub fn with_generation(self, generation: GrantsGeneration) -> Gate
BIDIR-8: this gate, counting its moves in generation — the
service’s one (GrantsGeneration), shared by every gate it builds.
Without it a gate counts alone, from 0.
Sourcepub fn generation(&self) -> &GrantsGeneration
pub fn generation(&self) -> &GrantsGeneration
BIDIR-8: the grants generation this gate’s answers are decided at.
Sourcepub fn moved(&self, why: GrantsMove) -> u64
pub fn moved(&self, why: GrantsMove) -> u64
BIDIR-8: a write that could change this gate’s answers happened (the service wrote it — the gate keeps no memberships of its own): the generation moves once. Answers the generation now.
Sourcepub fn with_liveness(self, liveness: Arc<dyn Liveness>) -> Gate
pub fn with_liveness(self, liveness: Arc<dyn Liveness>) -> Gate
AUTH-11: this gate, asking liveness whether a caller’s sign-in
still stands before every check. Without it the gate still refuses
a caller past its expires_at stamp (AuthContext::expired).
Sourcepub fn alive(&self, caller: &AuthContext) -> Result<(), String>
pub fn alive(&self, caller: &AuthContext) -> Result<(), String>
AUTH-11: whether caller’s sign-in still stands: not past its
expires_at, and live by the service’s Liveness. An anonymous
context has no sign-in to end: Ok.
Sourcepub fn lists(&self, role: &RoleName, grant: &Grant) -> bool
pub fn lists(&self, role: &RoleName, grant: &Grant) -> bool
Whether role lists grant (ADMIN lists every grant).
Sourcepub fn roles_listing(&self, grant: &Grant) -> Vec<RoleName>
pub fn roles_listing(&self, grant: &Grant) -> Vec<RoleName>
The roles that list grant, ADMIN last.
Sourcepub fn held_on(&self, caller: &AuthContext, grant: &Grant) -> Vec<ScopeRef>
pub fn held_on(&self, caller: &AuthContext, grant: &Grant) -> Vec<ScopeRef>
Where the caller holds grant, within its ceiling: [*] when
everywhere, [] when nowhere (and for an anonymous caller). What a
method without a target answers from. ONE-6: data scopes only — an
address scope is never among them.
Sourcepub fn fingerprint(&self, caller: &AuthContext) -> Option<Fingerprint>
pub fn fingerprint(&self, caller: &AuthContext) -> Option<Fingerprint>
PERF-15: what this gate’s answers about caller read, besides the
grants generation — its principal’s memberships and its session’s
ceiling (Fingerprint); None when it is anonymous. The
memberships are read now, from memory.
Sourcepub fn held_on_by(&self, who: &Fingerprint, grant: &Grant) -> Vec<ScopeRef>
pub fn held_on_by(&self, who: &Fingerprint, grant: &Grant) -> Vec<ScopeRef>
PERF-15: Gate::held_on for whoever has who — read from the
fingerprint instead of the memberships, by the same rule, so a view
built from it is exactly the one built from any caller it was taken
of.
Sourcepub fn check(
&self,
caller: Option<&AuthContext>,
grant: &Grant,
target: Option<&str>,
) -> Result<Reach, Refusal>
pub fn check( &self, caller: Option<&AuthContext>, grant: &Grant, target: Option<&str>, ) -> Result<Reach, Refusal>
Allowed when the grant is listed by a role held on a scope in the
target’s chain — or anywhere, for a call with no target — and every
ceiling layer allows it the same way. The Reach is live (it asks
this gate again on Reach::allows / Reach::current).
AUTH-11: first, the caller’s sign-in must still stand
(Gate::alive) — a signed-out session holds nothing, so a socket
that signed out cannot go on to call auth.grant.
ONE-6: decided on data scopes and * alone. An address scope never
counts here — not for a target, and not as “held anywhere” for a
read with no target: it opens a door (Gate::check_everywhere_at)
and holds no data. A caller holding a grant only on addresses is
refused here, as one holding it nowhere is.
Sourcepub fn check_everywhere(
&self,
caller: Option<&AuthContext>,
grant: &Grant,
) -> Result<Reach, Refusal>
pub fn check_everywhere( &self, caller: Option<&AuthContext>, grant: &Grant, ) -> Result<Reach, Refusal>
KEEL-31: the check for a method that acts on the whole service (it
names no target because its target is everything: a key rotated, a
process spawned, a peer connected). Allowed only where the grant is
held on * — by a role held on * that lists it, and every ceiling
layer allowing it on * — never because it is held on some scope. A
scoped admin, or a session minted admin@X, is refused, naming *.
The reach is [*] and stays live by this same rule.
Sourcepub fn check_everywhere_at(
&self,
caller: Option<&AuthContext>,
call: &DispatchedCall,
) -> Result<Reach, Refusal>
pub fn check_everywhere_at( &self, caller: Option<&AuthContext>, call: &DispatchedCall, ) -> Result<Reach, Refusal>
ONE-6: the door — Gate::check_everywhere of the dispatched
call, for its own grant: may this caller make this call at this
address. Admitted where a role listing the grant is held on a scope
that opens the call’s door — * (self), the activation’s address
(/dyn for dyn.connect), the method’s own (/dyn.connect), or a
subtree above it (/dyn.*) — and every ceiling layer has an entry
allowing the grant on such a scope. A data scope never opens a door
(KEEL-31), nor an address that does not cover the call (/ui,
/dyn.peer.shop.*). A refusal names the activation’s address.
The reach says what was admitted apart from what data is held:
Reach::holds_activation is true; Reach::held_on is the
caller’s data scopes for the grant, as Gate::check reads them —
[*] for a holder of *, [] for one who holds only addresses — so
Reach::is_everywhere is true only for a real *. It stays live
by this same rule, at the same door.
Sourcepub fn reach_of_public(
&self,
caller: Option<&AuthContext>,
grant: &Grant,
) -> Reach
pub fn reach_of_public( &self, caller: Option<&AuthContext>, grant: &Grant, ) -> Reach
The reach of a public method: what Gate::check would allow
without a target, or an empty (still live) reach when the caller holds
the grant nowhere or is anonymous. A public method is never refused.