Skip to main content

CedarEngine

Struct CedarEngine 

Source
pub struct CedarEngine { /* private fields */ }
Expand description

A Cedar policy set, compiled once.

Compiled at construction rather than per request: parsing on every effect would put a parser in the hot path and, worse, would make a malformed policy a runtime failure at an arbitrary moment instead of a startup one.

Implementations§

Source§

impl CedarEngine

Source

pub fn new(source: &str) -> Result<Self, CedarError>

Compile a policy set from Cedar source.

§Errors

If the source does not parse. Failing here — at startup, loudly — is the point: a policy set that cannot be compiled must never become a plane that denies everything for reasons nobody can see.

Source

pub fn from_bundle( source: &str, schema_json: Option<&str>, entities_json: Option<&str>, ) -> Result<Self, CedarError>

Compile a complete Cedar policy bundle.

A declared schema is used to validate the policies at startup, parse static entities, parse each request context, and construct the request. Static entities are the facts intentionally frozen into this bundle; per-call facts remain in PolicyRequest::context.

§Errors

If rules/schema/entities do not parse, or the policies do not validate strictly against the schema. Every failure is a startup refusal.

Trait Implementations§

Source§

impl Debug for CedarEngine

Source§

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

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

impl PolicyEngine for CedarEngine

Source§

fn preflight(&self, requests: &[PolicyRequest<'_>]) -> Vec<String>

Evaluate each probe and report the rules that could not be evaluated.

The trap this catches is Cedar’s totality: every rule is evaluated against every request, so a when clause reading an attribute the request does not carry errors rather than failing to match, and an unevaluable rule refuses the call because it may be the forbid that would have stopped it. One such rule denies every effect of every run, from a policy set that parsed and validated cleanly — which is exactly how a deployment found itself with a plane that refused everything.

Each probe is asked on its own resource and again on every resource a rule’s scope names that no probe names itself. A probe’s placeholder resource reaches only the rules scoped to any resource, so a forbid on resource == Resource::"payment.transfer" whose condition is unguarded would otherwise never be evaluated here — and would refuse every transfer. Its arguments are the probe’s, which carry none, so a rule reading one guards it with context.args has ….

Only unevaluable sets are reported. A set that merely denies the probes is a working default-deny plane, and reporting it would make this check the reason nobody writes one.

Source§

fn authorize(&self, request: &PolicyRequest<'_>) -> PolicyDecision

Source§

fn bundle(&self) -> PolicyBundleIdentity

Identifies every static input that can affect evaluation. Read more
Source§

fn digest(&self) -> Digest

Compact digest of bundle.

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> MaybeSend for T
where T: Send,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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