1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! # Cedar ABAC Module for PEP
//!
//! This module integrates AWS Cedar as a fine-grained, attribute-based access
//! control (ABAC) engine into the PEP library. It provides:
//!
//! - **`CedarAuthorizer`**: Loads Cedar policies and evaluates authorization requests
//! - **`CedarConfig`**: TOML-based configuration for policy paths and settings
//! - **`SchemaLoader`**: Loads Cedar schemas from `.cedarschema` files
//! - **Entity building**: Converts `JwtClaims` and resource metadata into Cedar entities
//!
//! Cedar sits after PEP's JWT authentication layer:
//!
//! ```text
//! Request → PEP (JWT validation) → Cedar (authorization) → Handler (data)
//! "Who are you?" "Can you do this?" "Here's the data"
//! ```
//!
//! Each service defines its **own** schema in a `.cedarschema` file — PEP does not
//! bake any domain-specific entity types into the library.
//!
//! # Example
//!
//! ```rust,ignore
//! use pep::cedar::{CedarAuthorizer, CedarConfig, ResourceInfo, build_principal_uid, build_action_uid};
//! use pep::oidc::types::JwtClaims;
//! use cedar_policy::{Request, Context};
//!
//! let config = CedarConfig {
//! policy_path: "./policies".into(),
//! schema_path: Some("./policies/schema.cedarschema".into()),
//! ..Default::default()
//! };
//! let authorizer = CedarAuthorizer::new(config)?;
//!
//! let principal = build_principal_uid(&claims)?;
//! let action = build_action_uid("view")?;
//! let resource = ResourceInfo::new("Task", "task-123").to_cedar_uid()?;
//!
//! let request = Request::new(principal, action, resource, Context::empty(), None)?;
//! let response = authorizer.is_allowed(&request);
//! assert!(response.allowed());
//! ```
pub use CedarAuthorizer;
pub use CedarConfig;
pub use ;
pub use CedarError;
pub use ;