Skip to main content

CapabilityEngine

Struct CapabilityEngine 

Source
pub struct CapabilityEngine<P: PolicyBackend> { /* private fields */ }
Expand description

The Hessra Capability Engine.

Evaluates policy, orchestrates token minting/verification, and manages information flow control via context tokens.

The engine is generic over a PolicyBackend implementation, allowing different policy models (CList, RBAC, ABAC, etc.) to be plugged in.

Implementations§

Source§

impl<P: PolicyBackend> CapabilityEngine<P>

Source

pub fn new(policy: P, keypair: KeyPair) -> Self

Create a new engine with a policy backend and signing keypair.

Source

pub fn with_generated_keys(policy: P) -> Self

Create a new engine that generates its own keypair.

Useful for local/development use where the engine manages its own keys.

Source

pub fn public_key(&self) -> PublicKey

Get the engine’s public key (for token verification).

Source

pub fn policy(&self) -> &P

Get a reference to the policy backend.

Source

pub fn evaluate( &self, subject: &ObjectId, target: &ObjectId, operation: &Operation, context: Option<&ContextToken>, ) -> PolicyDecision

Evaluate whether a capability request would be granted, without minting.

Checks both the capability space (does the subject hold this capability?) and exposure restrictions (would context exposure block this?).

Source

pub fn mint_capability( &self, subject: &ObjectId, target: &ObjectId, operation: &Operation, context: Option<&ContextToken>, ) -> Result<MintResult, EngineError>

Mint a capability token for a subject to access a target with an operation.

The engine:

  1. Evaluates the policy (capability space + exposure restrictions)
  2. If granted, mints a capability token via hessra-cap-token
  3. If the target has data classifications, auto-applies exposure to the context

Returns a MintResult containing the token and optionally an updated context.

Source

pub fn verify_capability( &self, token: &str, target: &ObjectId, operation: &Operation, ) -> Result<(), EngineError>

Verify a capability token for a target and operation.

This is capability-first verification: no subject is required. The token IS the proof of authorization.

Source

pub fn mint_capability_with_options( &self, subject: &ObjectId, target: &ObjectId, operation: &Operation, context: Option<&ContextToken>, options: MintOptions, ) -> Result<MintResult, EngineError>

Mint a capability token with additional restrictions.

Like mint_capability, but supports namespace restriction and custom time config. This is useful when the caller needs to propagate namespace restrictions or control token lifetime.

Source

pub fn issue_capability( &self, subject: &ObjectId, target: &ObjectId, operation: &Operation, options: MintOptions, ) -> Result<String, EngineError>

Issue a capability token directly, without policy evaluation.

Use this when the caller has already performed authorization checks through its own mechanisms (e.g., enterprise RBAC, custom domain logic). For the fully-managed path that includes policy evaluation, use mint_capability or mint_capability_with_options instead.

Source

pub fn attenuate_with_designations( &self, token: &str, designations: &[Designation], ) -> Result<String, EngineError>

Attenuate a capability token with designations.

Adds designation checks to narrow the token’s scope to specific object instances. The verifier must provide matching designation facts.

Source

pub fn mint_designated_capability( &self, subject: &ObjectId, target: &ObjectId, operation: &Operation, designations: &[Designation], context: Option<&ContextToken>, ) -> Result<MintResult, EngineError>

Convenience: mint a capability and immediately attenuate with designations.

Source

pub fn verify_designated_capability( &self, token: &str, target: &ObjectId, operation: &Operation, designations: &[Designation], ) -> Result<(), EngineError>

Verify a capability token that includes designation checks.

Source

pub fn mint_identity( &self, subject: &ObjectId, config: IdentityConfig, ) -> Result<String, EngineError>

Mint an identity token for a subject.

Source

pub fn authenticate(&self, token: &str) -> Result<ObjectId, EngineError>

Verify an identity token and return the authenticated object ID.

This verifies the token as a bearer token (no specific identity required).

Source

pub fn verify_identity( &self, token: &str, expected_identity: &ObjectId, ) -> Result<(), EngineError>

Verify an identity token for a specific identity.

Source

pub fn mint_context( &self, subject: &ObjectId, session_config: SessionConfig, ) -> Result<ContextToken, EngineError>

Mint a fresh context token for a subject (new session, no exposure).

Source

pub fn add_exposure( &self, context: &ContextToken, data_source: &ObjectId, ) -> Result<ContextToken, EngineError>

Add exposure to a context token from a specific data source.

Looks up the data source’s classification in the policy and adds the corresponding exposure labels to the context token.

Source

pub fn add_exposure_label( &self, context: &ContextToken, label: ExposureLabel, source: &ObjectId, ) -> Result<ContextToken, EngineError>

Add a specific exposure label directly to a context token.

Source

pub fn fork_context( &self, parent: &ContextToken, child_subject: &ObjectId, session_config: SessionConfig, ) -> Result<ContextToken, EngineError>

Fork a context token for a sub-agent, inheriting the parent’s exposure.

Source

pub fn extract_exposure( &self, context: &ContextToken, ) -> Result<Vec<ExposureLabel>, EngineError>

Extract exposure labels from a context token by re-parsing the Biscuit.

Source

pub fn list_grants(&self, subject: &ObjectId) -> Vec<CapabilityGrant>

List all capability grants for a subject.

Source

pub fn can_delegate(&self, subject: &ObjectId) -> bool

Check if a subject can delegate capabilities.

Auto Trait Implementations§

§

impl<P> Freeze for CapabilityEngine<P>
where P: Freeze,

§

impl<P> RefUnwindSafe for CapabilityEngine<P>
where P: RefUnwindSafe,

§

impl<P> Send for CapabilityEngine<P>

§

impl<P> Sync for CapabilityEngine<P>

§

impl<P> Unpin for CapabilityEngine<P>
where P: Unpin,

§

impl<P> UnsafeUnpin for CapabilityEngine<P>
where P: UnsafeUnpin,

§

impl<P> UnwindSafe for CapabilityEngine<P>
where P: UnwindSafe,

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> 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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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