Skip to main content

IjimaAuth

Struct IjimaAuth 

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

Ijima’s auth core: an AccessController (capability → partition resolver) plus a capability issuer and a grant verifier sharing one Ed25519 key, and an in-memory revocation set (the grant kill-switch — see docs/adr/token-revocation.md).

A daemon constructs one of these at startup, hydrates the revocation set from the store (hydrate_revocations), and serves; an admin CLI uses the issuer to mint grant tokens via IjimaAuth::issue_grant_bearer.

Implementations§

Source§

impl IjimaAuth

Source

pub fn from_embedded_policy() -> Result<Self>

Loads the embedded policy/policy.toml and generates a fresh Ed25519 issuer key pair.

Use only for tests/ephemeral runs — every call produces a new key, so issued tokens will not verify against a different instance. For a persistent daemon/CLI, use from_embedded_policy_with_seed with a seed from key_store.

§Errors

Returns IjimaError::InvalidInput if the policy TOML is invalid.

Source

pub fn from_embedded_policy_with_seed(seed: [u8; 32]) -> Result<Self>

Loads the embedded policy and constructs the issuer from a known 32-byte Ed25519 seed. The same seed must be shared by every process that issues or verifies tokens for this Ijima instance.

§Errors

Returns IjimaError::InvalidInput if the policy TOML is invalid.

Source

pub fn generate_seed() -> [u8; 32]

Generates a fresh random 32-byte issuer seed (for first-time setup).

Delegates to KeyStore::generate_seed.

Source

pub fn issuer_public_key_hex(&self) -> String

The issuer’s Ed25519 public key as lowercase hex, for distribution to verifiers and operator visibility.

Source

pub fn grassmannian(&self) -> (usize, usize)

Returns the Grassmannian the controller operates on.

Source

pub fn issue_grant_bearer( &self, principal: impl Into<PrincipalId>, capabilities: &[&str], ) -> Result<String>

Issues a multi-capability grant token (base64 wire format) granting every capability in capabilities to principal.

Each capability’s partition is resolved from the embedded policy; an unknown capability is rejected. Singleton grants are issued with issue_bearer.

§Errors

Returns IjimaError::InvalidInput if a capability is unknown to the policy, the grant is empty, or Schubert’s issuer rejects the inputs.

Source

pub fn issue_grant_bearer_with_expiry( &self, principal: impl Into<PrincipalId>, capabilities: &[&str], expires_at_unix: u64, ) -> Result<String>

Issues a grant that dies at expires_at_unix (Unix seconds, Schubert 0.5 ADR-0001: the boundary is inclusive — the grant is dead the instant now >= expires_at). Expiry is covered by the signature and enforced by GrantVerifier::verify standalone; expired bearers fail verify_bearer with an expired detail.

§Errors

Returns IjimaError::InvalidInput on unknown capabilities or issuer rejection — same contract as issue_grant_bearer.

Source

pub fn issue_grant_bearer_under_policy( &self, principal: impl Into<PrincipalId>, capabilities: &[&str], policy: &GrantPolicy, expires_at: Option<u64>, ) -> Result<String>

Policy-constrained issuance (Schubert 0.5 #20.3): signs only what policy entitles this principal to carry. Fails closed — an unknown principal or a capability outside the entitlement denies with schubert::SchubertError::GrantDeniedByPolicy detail (no smuggling a stronger geometry under an allowed id). expires_at passes through to the issuer (None = never, pre-0.5 behavior).

This is the seam ijima token issue builds on; the unconstrained issue_grant_bearer remains for test tooling and trusted offline flows.

§Errors

Returns IjimaError::InvalidInput when the policy denies the request, or for unknown capabilities.

Source

pub fn grant_verifier(&self) -> &GrantVerifier

The grant verifier (exposes verify_at for clock-injected checks).

Source

pub fn resolve_issuance_policy(explicit: Option<&Path>) -> Result<String>

Resolves the issuance policy for ijima token issue (Schubert 0.5 #20.3): an explicit --policy path wins (unreadable = hard error — an explicit pointer must be honored); then $IJIMA_POLICY (same hard-error rule); then $IJIMA_DIR/policy.toml if present; otherwise the embedded default (which seeds no principals — a fresh install mints nothing until the operator provisions a policy file).

§Errors

Returns IjimaError::InvalidInput when an explicit/env policy path cannot be read or the fallback resolution fails.

Source

pub fn issuance_policy_from_source(toml_str: &str) -> Result<PolicyConfig>

Builds the schubert::policy::PolicyConfig that constrains issuance from a resolved policy source. Two shapes are accepted:

  • Full policy (contains [capabilities]): parsed and validated as a complete policy. Must match the embedded partition map the daemon verifies with — a diverging geometry is an operator error, surfaced as a hard parse error.
  • Principals-only overlay (the operator-friendly default): [principals.<name>] grants = [...] sections merged onto the embedded policy. Partitions always derive from the embedded policy, so an overlay can only assign existing capabilities — never redefine the geometry (the #20.3 anti-smuggling invariant). The overlay’s principal map is authoritative: removing a principal removes their issuance entitlement (already-issued grants keep verifying — they are proof-carrying — until expiry or revocation).
§Errors

Returns IjimaError::InvalidInput when neither shape parses, an overlay carries non-principal sections, or the merged config fails validation.

Source

pub fn issue_bearer( &self, principal: impl Into<PrincipalId>, capability: impl AsRef<str>, ) -> Result<String>

Convenience: issues a single-capability grant. Equivalent to issue_grant_bearer with one entry.

§Errors

Returns IjimaError::InvalidInput if the capability is unknown or Schubert’s issuer rejects the inputs.

Source

pub fn hydrate_revocations(&self, revocations: &[TokenRevocation])

Hydrates the in-memory revocation set from store-backed records (daemon boot). Replaces any prior set.

Source

pub fn revoke(&self, hash: &str)

Adds a revocation to the in-memory set (after the store write — the admin route persists first, then calls this). Idempotent.

Source

pub fn is_revoked(&self, bearer: &str) -> bool

True if the bearer’s hash is revoked.

Source

pub fn verify_bearer(&self, bearer: &str) -> Result<AuthenticatedPrincipal>

Decodes + cryptographically verifies a bearer grant token, returning the authenticated principal and the verified grant. A revoked bearer is rejected here — exactly as dead as a bad signature.

§Errors

Returns IjimaError::InvalidInput on a malformed, bad-signature, or revoked token.

Source

pub fn require( &self, bearer: &str, required: &str, ) -> Result<AuthenticatedPrincipal>

Convenience guard for handlers: verifies the token (authn) and authorizes via geometric containment — succeeds when the grant implies required (see AuthenticatedPrincipal::may).

§Errors

Returns an error if the token is invalid or does not imply required.

Trait Implementations§

Source§

impl Debug for IjimaAuth

Source§

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

Formats the value using the given formatter. 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<U> As for U

Source§

fn as_<T>(self) -> T
where T: CastFrom<U>, U: Sized,

Casts self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more
Source§

impl<T> AsyncFriendly for T
where T: Send + Sync + 'static,

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<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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 = 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
Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool

Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool