Skip to main content

olai_datafusion_policy/
lib.rs

1//! Engine-neutral policy enforcement for Apache DataFusion.
2//!
3//! This crate is the DataFusion-aware, **engine-agnostic** core of the policy
4//! stack — the policy analog of `datafusion-openlineage`. It owns the
5//! decide/enforce split:
6//!
7//! - **Decide** — the [`PolicyEngine`] trait: the contract a policy engine
8//!   implements to answer *what is allowed* (coarse gate) and *what constraints
9//!   apply* (row filters + column masks). It names no engine type; a Cedar
10//!   adapter lives in [`datafusion-policy-cedar`](https://docs.rs/olai-datafusion-policy-cedar),
11//!   and an OPA or OpenFGA adapter could implement the same trait.
12//! - **Enforce** — the [`PolicyQueryPlanner`] (a `QueryPlanner` wrapper) and the
13//!   pre-optimize plan rewrite ([`govern_plan`], under `fgac`) that apply
14//!   the engine's answers to a session.
15//!
16//! Everything here is expressed in neutral types — [`Decision`], [`AttrValue`],
17//! [`PrincipalIdentity`], [`TableFacts`], DataFusion [`Expr`]s — so no policy
18//! engine leaks through the seam.
19//!
20//! Two layers:
21//!
22//! - **Layer 1 — coarse access gate** ([`PolicyEngine::is_allowed`]): does the
23//!   principal have access to the tables/actions a query references?
24//! - **Layer 2 — fine-grained governance** (feature `fgac`): row filters
25//!   and column masks the engine derives, applied before optimization.
26//!
27//! [`Expr`]: datafusion::logical_expr::Expr
28
29mod constraint;
30mod engine;
31mod facts;
32mod governance;
33mod plan_actions;
34mod principal;
35mod rule;
36mod session;
37mod types;
38
39#[cfg(feature = "fgac")]
40mod abac;
41#[cfg(feature = "fgac")]
42mod binding;
43#[cfg(feature = "fgac")]
44mod fact_store;
45#[cfg(feature = "fgac")]
46mod function;
47#[cfg(feature = "fgac")]
48pub mod govern;
49#[cfg(feature = "fgac")]
50mod provider;
51
52pub use constraint::ConstraintTranslator;
53pub use engine::{PolicyEngine, StaticPolicyEngine};
54pub use facts::{CatalogFactSink, EvalContext, TableFacts, normalize};
55pub use governance::{Governance, GovernanceBuilder, Posture};
56pub use plan_actions::{PlanAction, plan_actions};
57pub use principal::{
58    AgentClaims, Group, IdentityError, IdentityProvider, PrincipalClaims, PrincipalEnrichment,
59    PrincipalIdentity,
60};
61pub use rule::PolicyQueryPlanner;
62pub use session::{
63    CatalogFactSinkExt, EvalContextProvider, PolicyBuilder, PolicyEngineExt, PolicyExtension,
64    PolicySessionExt, PrincipalExt, PrincipalProvider, SessionConfigEvalContextProvider,
65    SessionConfigPrincipalProvider, authorize_and_govern, authorize_and_govern_with_posture,
66    instrument_session_state,
67};
68pub use types::{AttrValue, Decision};
69
70#[cfg(feature = "fgac")]
71pub use abac::{AbacPolicyEngine, DefaultPrincipalMatcher, PrincipalMatcher};
72#[cfg(feature = "fgac")]
73pub use binding::{BindingKind, ColumnMatch, FunctionArg, PolicyBinding, TagCondition};
74#[cfg(feature = "fgac")]
75pub use fact_store::{FactStore, InMemoryFactStore};
76#[cfg(feature = "fgac")]
77pub use function::CatalogFunctionResolver;
78#[cfg(feature = "fgac")]
79pub use govern::{TablePolicy, govern_plan};
80#[cfg(feature = "fgac")]
81pub use provider::{GovernedTableProvider, govern_provider, govern_provider_from_config};
82#[cfg(feature = "fgac")]
83pub use session::{FactStoreExt, FunctionResolverExt};