pub struct AuthzEngine { /* private fields */ }Expand description
The Cedar-based authorization engine.
Thread-safe — share it as Arc<AuthzEngine>.
§Default-deny
A request no policy permits is denied. An engine with no policies at all
therefore denies everything, which is why chronixd treats “no policy
directory configured” as “no policy engine” rather than as an empty one.
§Cross-tenant isolation is not a policy
It is a property of the credential: a key or token carries the namespaces
it may act in, and the gate refuses a header naming any other before
Cedar is consulted. There used to be a built-in forbid policy for this
which nothing loaded and which compared a principal.namespace attribute
nothing set — an isolation guarantee that existed only as a string
constant. Policies narrow what a credential may do; they are not what
keeps tenants apart.
Implementations§
Source§impl AuthzEngine
impl AuthzEngine
Sourcepub fn check_policies(policy_src: &str) -> Result<usize>
pub fn check_policies(policy_src: &str) -> Result<usize>
Parse and validate policy_src without installing it.
§Errors
AuthzError::PolicyParse if it is not Cedar,
AuthzError::PolicyValidation if it does not fit the schema.
Sourcepub fn load_policies(&self, policy_src: &str) -> Result<usize>
pub fn load_policies(&self, policy_src: &str) -> Result<usize>
Replace the active policy set.
§Errors
As check_policies; the active set is left
untouched when either fails.
Sourcepub fn add_policy(&self, id: &str, policy_src: &str) -> Result<()>
pub fn add_policy(&self, id: &str, policy_src: &str) -> Result<()>
Add one policy, keeping the rest.
Clone-and-swap: the candidate is built and validated without a lock held, and the write lock is taken only for the swap, so a rejected policy leaves the active set exactly as it was.
§Errors
As check_policies, or
AuthzError::Internal if id is already taken.
Sourcepub fn remove_policy(&self, id: &str) -> bool
pub fn remove_policy(&self, id: &str) -> bool
Remove a policy by id. Returns whether it was there.
Sourcepub fn load_policies_from_dir(&self, dir: &Path) -> Result<usize>
pub fn load_policies_from_dir(&self, dir: &Path) -> Result<usize>
Load every .cedar file in dir as one policy set.
§Errors
The directory cannot be read, or the combined text does not parse or validate.
Sourcepub fn policy_count(&self) -> usize
pub fn policy_count(&self) -> usize
Number of active policies.
Sourcepub fn policy_ids(&self) -> Vec<String>
pub fn policy_ids(&self) -> Vec<String>
The ids of the active policies.
May principal perform action in namespace?
action must be a data action; an administrative one cannot reach a
namespace resource under the schema, so asking would be a decision
nobody can write a policy for. Debug builds assert it.
May principal perform the administrative action?
Trait Implementations§
Source§impl Debug for AuthzEngine
impl Debug for AuthzEngine
Auto Trait Implementations§
impl !Freeze for AuthzEngine
impl !RefUnwindSafe for AuthzEngine
impl !UnwindSafe for AuthzEngine
impl Send for AuthzEngine
impl Sync for AuthzEngine
impl Unpin for AuthzEngine
impl UnsafeUnpin for AuthzEngine
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more