pub enum Principal {
Operator {
id: OperatorId,
},
Platform {
id: PlatformId,
},
Delegate {
authorizing: Box<Principal>,
delegate: DelegateId,
scope: AuthorityScope,
},
Federated {
trust_root: TrustRoot,
identity: ExternalId,
},
}Expand description
A first-class principal — the entity acting in CellOS authority chains.
Per ADR-0019 §Decision, every signed event attributes one of these
four variants. Composition (Delegate.scope ⊆ authorizing.scope) is
enforced by Principal::compose.
§Wire form
The structured representation uses an internally-tagged enum with
kind as the discriminant — see the module-level docs for the URI
form. Round-trip is guaranteed:
Principal::from_source_uri(p.to_source_uri()) == Ok(p) for every
valid principal.
Variants§
Operator
The historical case: a human operator’s bearer-token identity. Preserved as the v0.5 wire form so existing consumers round-trip byte-for-byte.
Fields
id: OperatorIdPlatform
The hosted control plane itself acting on behalf of a tenant. Used for periodic compaction, tenant migration, billing snapshots.
Fields
id: PlatformIdDelegate
An LLM session / programmatic agent acting on behalf of an
authorizing principal, with bounded scope. Use
Principal::compose to construct — the constructor enforces
the narrowing invariant.
Federated
An external IAM (OIDC issuer, ADO org, GitHub org) acting as a principal via federation.
Implementations§
Source§impl Principal
impl Principal
Sourcepub fn root_operator(&self) -> Option<&OperatorId>
pub fn root_operator(&self) -> Option<&OperatorId>
Returns Some(operator_id) iff the principal chain bottoms out
at a human Principal::Operator at any depth; None
otherwise. Used by compliance queries to answer ADR-0019’s
“did a human author this action at any depth?” question.
Sourcepub fn effective_scope(&self) -> AuthorityScope
pub fn effective_scope(&self) -> AuthorityScope
The effective scope a principal exposes to a downstream delegate.
- A
Delegateexposes its own (already-narrowed)scope. - Any other variant is treated as holding the root scope
(
AuthorityScope::root) for the purpose of composition. ADR-0019 §Out-of-scope leaves “what specific capabilities a non-delegate principal holds” to the tenancy and federated- authority ADRs; pre-ratification we treat the root as unbounded so composition does not block legitimate first delegations.
Sourcepub fn compose(
authorizing: Principal,
delegate: DelegateId,
requested_scope: AuthorityScope,
) -> Result<Principal, AuthorityScopeViolation>
pub fn compose( authorizing: Principal, delegate: DelegateId, requested_scope: AuthorityScope, ) -> Result<Principal, AuthorityScopeViolation>
Compose a delegate principal. Returns
Ok(Principal::Delegate { … }) iff requested_scope is a subset
of authorizing.effective_scope(). Otherwise returns
AuthorityScopeViolation naming the first non-narrowing
capability — the admission discriminant
delegate_scope_not_narrowing.
Sourcepub fn to_source_uri(&self) -> String
pub fn to_source_uri(&self) -> String
Render the CloudEvent source URI representation per ADR-0019:
- Operator:
principal://operator/<id> - Platform:
principal://platform/<id> - Delegate:
principal://<chain>/delegate/<id>?scope=<csv>where<chain>is the authorizing principal’s URI body (everything afterprincipal://, query stripped). - Federated:
principal://federated/<root_kind>/<root_id>/identity/<external_id>
The ?scope= query carries capabilities in sorted-token form
(the AuthorityScope backing BTreeSet orders them), comma-
separated, so the URI is canonical and to_source_uri ∘ from_source_uri
is a deterministic identity on valid principals.
Sourcepub fn from_source_uri(uri: &str) -> Result<Principal, PrincipalParseError>
pub fn from_source_uri(uri: &str) -> Result<Principal, PrincipalParseError>
Parse a CloudEvent source URI back into a Principal. Returns
PrincipalParseError for any input that does not match the
grammar in Principal::to_source_uri.