Skip to main content

AuthzEngine

Struct AuthzEngine 

Source
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

Source

pub fn new() -> Self

Create an engine with no policies and the built-in schema.

Source

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.

Source

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.

Source

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.

Source

pub fn remove_policy(&self, id: &str) -> bool

Remove a policy by id. Returns whether it was there.

Source

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.

Source

pub fn policy_count(&self) -> usize

Number of active policies.

Source

pub fn policy_ids(&self) -> Vec<String>

The ids of the active policies.

Source

pub fn authorize_namespace( &self, principal: &ChronixPrincipal, action: ChronixAction, namespace: &ChronixNamespace, ) -> Decision

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.

Source

pub fn authorize_system( &self, principal: &ChronixPrincipal, action: ChronixAction, ) -> Decision

May principal perform the administrative action?

Trait Implementations§

Source§

impl Debug for AuthzEngine

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AuthzEngine

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more