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
impl CedarEngine
Sourcepub fn new(source: &str) -> Result<Self, CedarError>
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.
Sourcepub fn from_bundle(
source: &str,
schema_json: Option<&str>,
entities_json: Option<&str>,
) -> Result<Self, CedarError>
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
impl Debug for CedarEngine
Source§impl PolicyEngine for CedarEngine
impl PolicyEngine for CedarEngine
Source§fn preflight(&self, requests: &[PolicyRequest<'_>]) -> Vec<String>
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 bundle(&self) -> PolicyBundleIdentity
fn bundle(&self) -> PolicyBundleIdentity
Auto Trait Implementations§
impl !Freeze for CedarEngine
impl RefUnwindSafe for CedarEngine
impl Send for CedarEngine
impl Sync for CedarEngine
impl Unpin for CedarEngine
impl UnsafeUnpin for CedarEngine
impl UnwindSafe for CedarEngine
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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