Skip to main content

Module te

Module te 

Source
Expand description

Type-Enforcement evaluator — the Policy Decision Point hot-path core (S4 / #570).

A TOTAL, default-deny function (subject_ctx, object_label, action) → Decision over the compiled TE matrix AND the independent MAC lattice floor. This is intentionally tiny and verifiable — it is the data-plane evaluator that runs per op. It is NOT Casbin’s general string matcher (that stays control-plane; see crate::mac module docs).

§Two independent checks, conjoined (design §3, §10)

PERMIT(subject, object, action) ⟺
      te_matrix.permits(subject.type, object.type, action)   ← compiled TE (authority gate)
    ∧ subject.clearance ⊒ object.label                       ← MAC floor (content-truth, IFC)

The lattice floor is the intrinsic dominance on S1’s SecurityLabel (SecurityLabel::can_access) — it takes no policy argument and no Lattice lookup, so it is uncircumventable: no TE entry, grant, or token can relax it (design §1 invariant 3). Default is DENY: an unknown subject type, object type, action, or a non-dominating / unlabeled clearance → DENY. There is no permissive mode.

§S1 reconciliation (#567 landed)

  • The floor is S1’s intrinsic SecurityLabel::can_access, not a Lattice::can_access trait method. The evaluator still holds the S1 Lattice policy object, but only for well-formedness concerns (column alignment / validation / version binding), never for the per-op order.
  • The subject’s clearance carried in SubjectCtx is the clearance label the PEP already produced from a verified [SecurityContext] (assurance clamped to the verified key material — #548). The PEP, not this evaluator, applies that clamp.
  • “Unlabeled ⇒ deny” lives at the PEP boundary: a subject/object with no S1 label is Option::None and never reaches evaluate. There is deliberately no Default SecurityLabel.

§Relationship to the AVC and to Casbin

  • The AVC (crate::mac::avc) caches the output of this function so the PEP (S2) never re-runs it per op once warm. This evaluator is what fills the cache on a miss, and is itself cheap enough to be the miss path.
  • Casbin authors the policy; S5’s compiler lowers it into the TeMatrix entries this evaluator reads. Casbin’s Enforcer::enforce is NEVER on this path.

Structs§

Action
Interned id of an action / op. One per distinct op in the compiled policy. Maps from S3’s action vocabulary at compile time — see Action::from_scope_action for the canonical ScopeAction→id assignment so a compiled matrix and a PEP agree on ids.
LatticeTeEvaluator
Concrete PDP: a compiled TeMatrix + the S1 Lattice policy object. Small, total, allocation-free on the hot path. This is the verifiable TCB core.
ObjectCtx
The object’s security context: a TE object type plus its content-bound label. The label comes ONLY from the content-addressed manifest (design §3, §14 “labels ONLY from manifests”), never from a token. The PEP resolves it (S1 LabeledObject::security_label, None ⇒ deny before this point) before calling the evaluator.
ObjectType
Interned id of a TE object type. One per object class in the compiled policy.
SubjectCtx
The subject’s security context as the evaluator sees it: a TE type (domain) plus the lattice clearance. Built by the PEP from the Ed25519-verified token/claims (design §2 “subject ctx from Ed25519 claims”) via S1’s [SecurityContext] — the clearance carried here is SecurityContext::clearance(), with assurance already clamped to the verified key material (#548). The TE type is an interned id; the clearance is S1’s Copy structured label — both cheap to pass per op.
SubjectType
Interned id of a TE subject type (SELinux “domain”). One per subject security context class in the compiled policy. Stable within a policy generation.
TeMatrix
The compiled type-enforcement matrix: a flat allow-set of TeRules. Default-deny — any triple not present is denied. This is the data-plane artifact loaded from signed compiled policy (see crate::mac::compiled). Kept as a HashSet so the hot-path lookup is O(1); it is also the unit S5 produces and compiled signs.
TeRule
A single permitted TE triple (subject_type, object_type, action). The compiled matrix is the allow-set of these triples (default-deny: absence = deny). Produced by S5’s UCAN→TE compiler.

Enums§

Decision
The decision a PDP returns. Three-valued per design §8 — Escalate is a deny-on-the-data-plane that the control plane may turn into a ceiling-amendment flow, but for the per-op monitor it is NOT a permit.
ScopeAction

Constants§

ACTION_UNRECOGNIZED
GRANT_PATH_OBJECT
GRANT_PATH_SUBJECT
Sentinel ids (B2, #674) for auditing a decision that is NOT a per-op TE evaluation — today, the S6 grant path (mac::exchange::evaluate_grant), which decides against a UCAN grant’s capabilities, not a compiled TE matrix. AuditRecord has one shape (it predates the grant path); rather than fork the schema, a grant record uses these reserved ids so it is self-describing and can never collide with a real interned TE id (which starts from 0 and is bounded by the compiled registry). subject_type/ object_type reuse u32::MAX; action uses ScopeAction’s id space directly when the requested ability parses, or ACTION_UNRECOGNIZED otherwise (still recorded — an audit record for an unparseable ability is exactly the diagnosable case, not a reason to drop the record).

Traits§

TeEvaluator
The Policy Decision Point evaluator interface — what S2 (the PEP) calls per op.