pub struct EnvelopeContext {
pub request_id: u64,
pub cnf: [u8; 32],
/* private fields */
}Expand description
Context extracted from a verified SignedEnvelope.
Passed to service handlers after signature verification. Handlers use this for:
- Authorization checks via
subject() - Correlation via
request_id
§Example
fn handle_request(&self, ctx: &EnvelopeContext, payload: &[u8]) -> Result<(Vec<u8>, Option<Continuation>)> {
// Check authorization
let sub = ctx.subject().to_string();
if !policy_manager.check(&sub, "Model", "infer") {
return Err(anyhow!("unauthorized: {}", sub));
}
// Process request...
}Fields§
§request_id: u64Unique request ID for correlation and logging
cnf: [u8; 32]Ed25519 public key of the envelope signer (RFC 7800 confirmation key). Cryptographically verified by Ed25519 signature check.
Implementations§
Source§impl EnvelopeContext
impl EnvelopeContext
Sourcepub fn from_mediated_evidence(
evidence: &[u8],
mediator_service: &str,
operation: &str,
) -> Result<Self>
pub fn from_mediated_evidence( evidence: &[u8], mediator_service: &str, operation: &str, ) -> Result<Self>
Verify the original holder’s hybrid transcript without granting local transport provenance. Credential verification is still mandatory.
Sourcepub fn original_holder_evidence(&self) -> Option<&[u8]>
pub fn original_holder_evidence(&self) -> Option<&[u8]>
Bounded original signed request for a read-only mediated Policy query. Possession of these bytes is not an identity grant; the receiver must independently verify holder, credential, target, method and freshness.
Sourcepub fn admit_mediated_query(
&self,
mediator: &str,
resource: &str,
operation: &str,
) -> Result<()>
pub fn admit_mediated_query( &self, mediator: &str, resource: &str, operation: &str, ) -> Result<()>
Record a verified holder’s derived authorization query, independently of the request’s original dispatch admission. No default local store: startup must install the topology-qualified replay backend.
Sourcepub fn from_verified_as_system(envelope: &SignedEnvelope) -> Self
pub fn from_verified_as_system(envelope: &SignedEnvelope) -> Self
Create context for a FixedSigner (inproc/IPC) caller.
Sets key_derived_subject = Subject::new("system"), so subject() always
returns "system" for this context regardless of any caller-asserted
authorization field. Used in process_request for inproc callers.
Sourcepub fn from_callback_service(request_id: u64, service_name: &str) -> Self
pub fn from_callback_service(request_id: u64, service_name: &str) -> Self
Create a service-identity context for internal callbacks that bypass the envelope pipeline.
Used by services that make inproc self-calls without a real SignedEnvelope
(e.g., InferenceService callback mode). Sets key_derived_subject = "service:{name}"
so that subject() returns a proper service identity for authorization.
cnf is zeroed because there is no real envelope; the service subject
is asserted directly and is trusted because this constructor is only reachable
from internal code paths that never cross a network boundary.
Sourcepub fn ensure_browser_method(
&self,
actual_method_discriminator: u16,
) -> Result<()>
pub fn ensure_browser_method( &self, actual_method_discriminator: u16, ) -> Result<()>
Compare the sealed client method commitment with the discriminator independently decoded by generated service dispatch. Legacy carriers have no commitment; browser dispatch always installs one.
Sourcepub fn subject(&self) -> Subject
pub fn subject(&self) -> Subject
Get the cryptographically-verified authorization subject.
Resolution order:
- Key-derived subject (from verified Ed25519 signer key via
KeyRegistry). For FixedSigner/inproc callers this is alwaysSubject::new("system"). - JWT upgrade: if the envelope carries a verified JWT token, use its subject.
Federated JWTs (
issnon-empty) produceSubject::federated(iss, sub). Subject::anonymous()— no verified identity.
The caller-asserted envelope authorization is not preserved in the context — only verified state is available to handlers.
Sourcepub fn domain(&self) -> Result<String>
pub fn domain(&self) -> Result<String>
Derive the Casbin request domain from the verified tenant binding.
For network callers this comes only from a JWT after verify_claims()
verifies its signature and issuer. Trusted in-process constructors bind
their callers to the local tenant. The subject name is deliberately not
a fallback: multiple subjects may share a tenant, and identities without
a tenant binding must fail closed.
Sourcepub fn verified_tenant(&self) -> Option<&str>
pub fn verified_tenant(&self) -> Option<&str>
Return the authority-verified tenant binding, if the request has one.
Callers must still use Self::domain before treating this value as a
Casbin domain: that accessor rejects empty and wildcard tenant claims.
This optional view lets cross-tenant authorities distinguish a missing
tenant (where an authenticated service principal may use the global
policy domain) from a present-but-invalid tenant (which must fail
closed).
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Check if the identity is authenticated (not anonymous).
Sourcepub fn authenticated_signer_key(&self) -> Option<VerifyingKey>
pub fn authenticated_signer_key(&self) -> Option<VerifyingKey>
Return the verified Ed25519 signer key for this authenticated request.
This is the authentication-bound key material for the subject returned
by Self::subject. For JWT callers, verify_claims() requires the
JWT confirmation key to match cnf before the context reaches a
handler. For key-resolved callers, the subject is resolved from this
same verified key. Callback contexts have no envelope signer and are
deliberately refused.
Sourcepub fn authenticated_pairwise_did(&self) -> Option<Did>
pub fn authenticated_pairwise_did(&self) -> Option<Did>
Return this request’s self-certifying pairwise DID.
This is deliberately distinct from Self::subject. The latter is a
Casbin-facing authorization label (for example "alice" or
"https://issuer:alice"); it is not a decentralized identifier and
must never be relabelled as one. The pairwise DID is derived only from
the Ed25519 key whose possession the verified envelope established.
Callback contexts and anonymous requests have no such identity.
Sourcepub fn authenticated_pq_signer_key(&self) -> Option<MlDsaVerifyingKey>
pub fn authenticated_pq_signer_key(&self) -> Option<MlDsaVerifyingKey>
Return the trusted PQ key anchored to this request’s verified signer.
A missing binding is represented as None because Classical transport
authentication is a valid, lower-assurance state; the returned key is
never taken from request data.
Sourcepub fn claims(&self) -> Option<&Claims>
pub fn claims(&self) -> Option<&Claims>
Get user claims (if present, after verify_claims has run).
Sourcepub fn verified_key_material(&self) -> VerifiedKeyMaterial
pub fn verified_key_material(&self) -> VerifiedKeyMaterial
Derive the verified key material (S8/#574, S1/#548). This is the accessor that threads crypto-derived assurance from the envelope’s verified signature into MAC context assembly.
Returns the [VerifiedKeyMaterial] assurance axis for THIS verified
envelope, derived (never trusted) from what the signature layer actually
verified:
PqHybrid— the envelope’scnfEd25519 signer key is cryptographically verified (it isself.cnf, set duringSelf::from_verifiedfrom the signature check) AND a bound ML-DSA-65 anchor for that identity is present in the globalPqTrustStore(register_pq_trustbinding) under the enforced Hybrid policy. This is the kid-anchored binding the rest of the TCB uses — the PQ key is resolved from the trust store keyed by the EdDSA identity, never self-asserted. A session-overlay binding also reachesPqHybrid, but only when it has been confirmed out of band; a first-contact binding is capped atClassicalbycrate::session_pq_overlay::PqProvenance::key_material.Classical— thecnfEd25519 signer key is verified but NO bound ML-DSA-65 anchor is present (the federation edge, or a pre-PQ identity), or the only binding is a first-contact one, which makes the signature checkable without making the signer more trusted.Unverified— thecnfkey is zeroed (a callback-service context with no real envelope; assurance floors to the S1Unverifiedfloor so it dominates nothing above it).
Re-derive per verified envelope; never cache across identities. Each envelope has its own signer; caching would conflate assurances.
This is the load-bearing S8 input: without it every subject floors to
Unverified and dominates nothing (S6 would deny everything). The MAC
PDP combines this with the clearance off Claims via
crate::auth::mac::SubjectContextClaims::security_context.
Sourcepub fn security_context(&self) -> Option<SecurityContext>
pub fn security_context(&self) -> Option<SecurityContext>
Derive the full MAC [SecurityContext] for this verified envelope: the
two-input S1 derivation (clearance from Claims + assurance from
Self::verified_key_material). This is the convenience entry-point the
MAC PDP / S6 grant path call; it composes the authority-asserted
clearance with the crypto-derived assurance, clamping the assurance axis
DOWN to what the verified key supports.
Returns None (→ S1 deny) when the subject carries no clearance
(unlabeled subject) — there is no default clearance. The resulting
context is a SIBLING to Subject: identity and clearance are
independent dimensions of the same verified principal.
Re-derive per verified envelope; never cache across identities.
Sourcepub fn is_federate_tui_class(&self) -> bool
pub fn is_federate_tui_class(&self) -> bool
Get the effective verified JWT token from the envelope.
For an authorized relay this is the delegated bearer, allowing a
downstream service to preserve the original user’s verified identity
across another local service boundary.
Whether the verified credential is of the Federate TUI client class
(set by verify_claims; never caller-supplied).
Sourcepub fn is_delegated_bearer(&self) -> bool
pub fn is_delegated_bearer(&self) -> bool
Whether this request’s identity came from a delegated bearer token (an authenticated service mediator presented the holder’s token).
pub fn has_delegated_resource_audience(&self) -> bool
pub fn jwt_token(&self) -> Option<&str>
Sourcepub fn verified_direct_jwt(&self) -> Option<(&Claims, &str)>
pub fn verified_direct_jwt(&self) -> Option<(&Claims, &str)>
A direct network credential only after the full verifier returned successfully. Never substitutes a relayed bearer, legacy claims, local callback identity, or a partially checked JWT. The returned claims remain evidence, not a dispatch permit.
Sourcepub fn deferred_federate_credential(&self) -> Option<(&Claims, &str)>
pub fn deferred_federate_credential(&self) -> Option<(&Claims, &str)>
Signature-verified reserved credential awaiting dynamic holder proof,
current session and Policy request-use admission. This is evidence only;
subject(), domain() and claims() remain unpublished meanwhile.
Sourcepub fn request_proof_cwt(&self) -> Option<&[u8]>
pub fn request_proof_cwt(&self) -> Option<&[u8]>
Original verified-envelope proof bytes, still untrusted until the appropriate signer-suite verifier authenticates them.
Sourcepub fn admitted_federate_operation(
&self,
resource: &str,
operation: &str,
) -> bool
pub fn admitted_federate_operation( &self, resource: &str, operation: &str, ) -> bool
Exact request-local Policy-use coordinate, never a reusable permit. A serving handler must compare every generated authorization call with this tuple and perform its ordinary fresh Policy check as well.
pub fn is_federate_admitted(&self) -> bool
Sourcepub fn has_user_context(&self) -> bool
pub fn has_user_context(&self) -> bool
Check if request has user context
Sourcepub fn internal_work(&self) -> Option<&InternalWorkContext>
pub fn internal_work(&self) -> Option<&InternalWorkContext>
The verified internal execution work order, when this request crossed a
pinned single-service execution boundary (Model → its Inference
subprocessor). None for every direct caller; a service MUST treat its
presence as “the controller already authorized this exact operation” —
never as bearer delegation.
Sourcepub fn ephemeral_pubkey(&self) -> Option<[u8; 32]>
pub fn ephemeral_pubkey(&self) -> Option<[u8; 32]>
Get the client’s ephemeral DH public key (if present). Used by streaming handlers to derive shared secrets for HMAC chain keys.
Sourcepub fn stream_kem_recipient(&self) -> Option<&RecipientPublic>
pub fn stream_kem_recipient(&self) -> Option<&RecipientPublic>
Get the authenticated identified-stream HyKEM recipient.
Sourcepub fn response_kem_recipient(&self) -> Option<&RecipientPublic>
pub fn response_kem_recipient(&self) -> Option<&RecipientPublic>
The one-shot unary reply recipient authenticated by the envelope. Deferred Federate admission additionally requires the original holder proof to bind this value before any handler or authority side effect.
Sourcepub fn is_local_caller(&self) -> bool
pub fn is_local_caller(&self) -> bool
Whether this request came from a genuine in-process / IPC caller (#328).
true for the FixedSigner mutual-auth plane and internal self-calls;
false for networked / mesh peers (AnySigner). Used to confine the
empty-iss JWT shortcut to local callers.
Sourcepub fn audit_authz(&self, resource: &str, operation: &str, allowed: bool)
pub fn audit_authz(&self, resource: &str, operation: &str, allowed: bool)
Emit an accounting / audit record for an authorization decision (#445).
This is the Accounting leg of AAA: it makes every authorization
decision attributable after the fact to the cryptographically verified
subject (self.subject()), never a caller-asserted field. It is called
by generated dispatch code at the authorization decision point — the
single DRY chokepoint where the verified subject, the resource, the
operation, and the allow/deny effect are all in scope.
The record is a structured tracing event on the dedicated audit
target so it can be filtered/routed independently (e.g. shipped to an
audit sink) without coupling to the rest of the daemon’s logs. Fields:
subject, resource, action, decision (allow/deny), and
request_id for correlation. It records only identity + resource +
action + decision — never key material or request payloads.
Allow is logged at info; deny at warn (deny is the security-relevant
event), but both carry identical structured fields so “who did what” is
reconstructable for the allow path AND the deny path.
S7 (#573, #453): this is the control-plane (Casbin #[authorize])
audit surface. The data-plane MAC surface (the AVC) emits its own
records on the same unified hyprstream.mac.audit target via
hyprstream::mac::audit. Both targets fan out to OpenTelemetry when the
otel feature is active (OTel is a tracing subscriber), so denials
are first-class observable signals — closing the #453 visibility gap
where auth failures were previously buried at debug level. We also
mirror the decision onto hyprstream.mac.audit here so a single OTel
subscriber captures the whole authorization audit stream.
Trait Implementations§
Source§impl Clone for EnvelopeContext
impl Clone for EnvelopeContext
Source§fn clone(&self) -> EnvelopeContext
fn clone(&self) -> EnvelopeContext
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for EnvelopeContext
impl RefUnwindSafe for EnvelopeContext
impl Send for EnvelopeContext
impl Sync for EnvelopeContext
impl Unpin for EnvelopeContext
impl UnsafeUnpin for EnvelopeContext
impl UnwindSafe for EnvelopeContext
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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