Skip to main content

Crate olai_datafusion_policy

Crate olai_datafusion_policy 

Source
Expand description

Engine-neutral policy enforcement for Apache DataFusion.

This crate is the DataFusion-aware, engine-agnostic core of the policy stack — the policy analog of datafusion-openlineage. It owns the decide/enforce split:

  • Decide — the PolicyEngine trait: the contract a policy engine implements to answer what is allowed (coarse gate) and what constraints apply (row filters + column masks). It names no engine type; a Cedar adapter lives in datafusion-policy-cedar, and an OPA or OpenFGA adapter could implement the same trait.
  • Enforce — the PolicyQueryPlanner (a QueryPlanner wrapper) and the pre-optimize plan rewrite (govern_plan, under fgac) that apply the engine’s answers to a session.

Everything here is expressed in neutral types — Decision, AttrValue, PrincipalIdentity, TableFacts, DataFusion Exprs — so no policy engine leaks through the seam.

Two layers:

  • Layer 1 — coarse access gate (PolicyEngine::is_allowed): does the principal have access to the tables/actions a query references?
  • Layer 2 — fine-grained governance (feature fgac): row filters and column masks the engine derives, applied before optimization.

Re-exports§

pub use govern::TablePolicy;
pub use govern::govern_plan;

Modules§

govern
Layer 2: fine-grained governance — inject row filters and column masks into a logical plan before optimization.

Structs§

AbacPolicyEngine
A PolicyEngine that enforces UC ABAC PolicyBindings directly.
AgentClaims
Agent-identity claims (OIDC-A). A placeholder seam carried on PrincipalClaims; agent principal-enrichment is deferred to the agent-PEP work, so the v1 identity provider ignores it.
CatalogFactSink
A per-query sink the catalog writes TableFacts into and the Cedar policy reads. Interior-mutable and cheap to clone (Arc<DashMap>), so the same instance reaches both build_delta (during resolution) and the policy layer (during evaluation) through a SessionConfig extension.
CatalogFactSinkExt
The SessionConfig extension carrying the per-query CatalogFactSink the catalog writes resource facts into and the policy layer reads.
ColumnMatch
A MATCH COLUMNS matcher: the columns whose governed tags satisfy condition are exposed to the function under alias.
DefaultPrincipalMatcher
The default PrincipalMatcher: strips an EntityType::"..." wrapper off both the binding name and the principal’s uid/groups before a case-sensitive compare, and treats the account users sentinel as matching every principal.
EvalContext
Per-query, non-plan facts threaded into the PolicyEngine layer.
FactStoreExt
The SessionConfig extension carrying the session’s taint ledger, attached to the per-query state so the policy layer can build the EvalContext.
FunctionResolverExt
The SessionConfig extension carrying the catalog function resolver, so the governance PEP can turn a policy-referenced masking / row-filter function name into a callable ScalarUDF.
Governance
A fully-assembled governance profile: the policy engine plus the optional identity / function / fact-store providers, and the runtime Posture.
GovernanceBuilder
Builder for Governance. See Governance::builder.
GovernedTableProvider
A TableProvider that presents a governed (secured-view) plan over a base provider.
Group
A node in the neutral group hierarchy: a group uid and its direct parent group uids. The transitive closure of a principal’s groups (each group plus its ancestors) so privileged_readers ⊂ readers resolves without a static entity bundle.
InMemoryFactStore
In-memory FactStore backed by a DashMap keyed by correlation id.
PolicyBinding
One parsed UC ABAC policy: principals × tag-matched securable/columns → a row-filter or column-mask function call.
PolicyBuilder
Builds and installs policy enforcement on a SessionState.
PolicyEngineExt
The SessionConfig extension carrying the session’s PolicyEngine, so the engine is discoverable from config on every host regardless of which enforcement tier fires first: PolicyBuilder::instrument sets it, and the provider-tier seam (govern_provider_from_config, under fgac) reads it back at table-resolution time.
PolicyExtension
Entry point for instrumenting a DataFusion session with Cedar policy enforcement.
PolicyQueryPlanner
A QueryPlanner that governs and gates a query before physical planning.
PrincipalClaims
Neutral, transport-free claims the host passes to an IdentityProvider.
PrincipalEnrichment
The facts an IdentityProvider resolves for a principal: attributes to fold onto the principal, the principal’s direct group parents, and the transitive group hierarchy needed for in to resolve the ancestry.
PrincipalExt
The SessionConfig extension carrying the per-request principal.
PrincipalIdentity
The principal on whose behalf a query executes, plus the attributes policies may condition on (e.g. role, region, name) and the group memberships they resolve in against.
SessionConfigEvalContextProvider
An EvalContextProvider that assembles the EvalContext from the session’s SessionConfig extensions: the catalog fact sink and (under fgac) the correlation id + taint ledger. The correlation id is the session id, stable per connection.
SessionConfigPrincipalProvider
A PrincipalProvider that reads the PrincipalIdentity attached to the session’s SessionConfig as a PrincipalExt extension.
StaticPolicyEngine
A PolicyEngine that returns the same decision for every query.
TableFacts
Catalog-derived attributes of one table, gathered at resolution time and folded into the Cedar Table resource entity. The host builds this from its catalog metadata (UC Table.owner/properties/comment); the Cedar layer reads only this neutral shape.
TagCondition
A governed-tag matcher: hasTag(key) when value is None, hasTagValue(key, value) otherwise.

Enums§

AttrValue
An engine-neutral principal attribute value.
BindingKind
Whether a binding installs a row filter or a column mask — the two UC ABAC policy kinds.
Decision
The coarse allow/deny outcome of an authorization decision.
FunctionArg
One argument to a binding’s function: either a column bound by a ColumnMatch alias, or a constant passed through as a literal.
IdentityError
An error resolving identity facts. Small and crate-local so the host owns the fail-closed decision (an Err should fail the session, not proceed un-enriched).
PlanAction
An access-relevant operation discovered in a logical plan.
Posture
The runtime enforcement stance, chosen once at build time so an ungoverned session is never the accidental result of a forgotten wire-up.

Traits§

CatalogFunctionResolver
Resolves a catalog function name into a callable DataFusion ScalarUDF.
ConstraintTranslator
Translates an engine’s residual into a DataFusion row-filter predicate.
EvalContextProvider
Assembles the per-query EvalContext from the planning Session.
FactStore
Shared, session-scoped facts keyed by a correlation id (the session/trace id). v1 exposes only the monotonic taint ledger.
IdentityProvider
The principal/identity PIP: given the authenticated principal uid (plus any validated claims), pull the slice of identity facts policies condition on — attributes and group membership.
PolicyEngine
The decide contract every policy engine implements — the engine-agnostic seam the enforcement layer talks to.
PolicySessionExt
SessionContext ergonomics for policy instrumentation.
PrincipalMatcher
Decides whether a PolicyBinding’s principal lists match the querying PrincipalIdentity — a small seam so a host can override the name-normalization / all-users semantics its directory uses.
PrincipalProvider
Resolves the principal a query runs as, from the planning Session.

Functions§

authorize_and_govern
Govern plan (row filters + column masks), then gate the optimized plan on the coarse access policy — the shared enforcement sequence.
authorize_and_govern_with_posture
Govern + gate plan under an explicit Posture.
govern_provider
Wrap provider in a secured view enforcing policy.constrain(...).
govern_provider_from_config
One-call host seam: assemble the engine (PolicyEngineExt), principal (PrincipalExt), and eval context from SessionConfig extensions, then delegate to govern_provider.
instrument_session_state
Instrument state with an explicit policy and providers.
normalize
Normalize a TableReference to its fully-qualified form so the key the catalog writes (catalog.schema.table, built from UC metadata) matches the key the plan’s TableScan carries (which may be bare/partial before resolution). Both the record and get sides normalize, so a bare("t") and a full("c","s","t") referring to the same table resolve to one entry only when they share the same qualified name; refs that genuinely differ stay distinct.
plan_actions
Walk plan and return the neutral PlanActions that must be authorized for it to run. An engine adapter lowers each action to its own request.