Expand description
§Cedar-Policy
Cedar is a language for defining permissions as policies, which describe who should have access to what. It is also a specification for evaluating those policies. Use Cedar policies to control what each user of your application is permitted to do and what resources they may access.
§Using Cedar
Cedar can be used in your application by depending on the cedar-policy crate.
Just add cedar-policy as a dependency by running
cargo add cedar-policy§Quick Start
Let’s write a super simple Cedar policy and test it:
permit(principal == User::"alice", action == Action::"view", resource == File::"93");This policy permits exactly one authorization request, alice is allowed to view file 93.
Any other authorization request will be implicitly denied. Let’s embed this policy in Rust and use the Cedar Authorizer:
use cedar_policy::*;
fn main() {
    const POLICY_SRC: &str = r#"
permit(principal == User::"alice", action == Action::"view", resource == File::"93");
"#;
    let policy: PolicySet = POLICY_SRC.parse().unwrap();
    let action = r#"Action::"view""#.parse().unwrap();
    let alice = r#"User::"alice""#.parse().unwrap();
    let file = r#"File::"93""#.parse().unwrap();
    let request = Request::new(alice, action, file, Context::empty(), None).unwrap();
    let entities = Entities::empty();
    let authorizer = Authorizer::new();
    let answer = authorizer.is_authorized(&request, &policy, &entities);
    // Should output `Allow`
    println!("{:?}", answer.decision());
    let action = r#"Action::"view""#.parse().unwrap();
    let bob = r#"User::"bob""#.parse().unwrap();
    let file = r#"File::"93""#.parse().unwrap();
    let request = Request::new(bob, action, file, Context::empty(), None).unwrap();
    let answer = authorizer.is_authorized(&request, &policy, &entities);
    // Should output `Deny`
    println!("{:?}", answer.decision());
}If you’d like to see more details on what can be expressed as Cedar policies, see the documentation.
Examples of how to use Cedar in an application are contained in the repository cedar-examples. The most full-featured of these is TinyTodo, which is a simple task list management service whose users’ requests, sent as HTTP messages, are authorized by Cedar.
§Documentation
General documentation for Cedar is available at docs.cedarpolicy.com, with source code in the cedar-policy/cedar-docs repository.
Generated documentation for the latest version of the Rust crates can be accessed on docs.rs.
If you’re looking to integrate Cedar into a production system, please be sure to read the security best practices
§Building
To build, simply run cargo build (or cargo build --release).
§What’s New
Changelogs for all release branches and the main branch of this repository are
all maintained on the main branch; the most up-to-date changelog for this
crate is
here.
For a list of the current and past releases, see crates.io or Releases.
§Security
See SECURITY
§Contributing
We welcome contributions from the community. Please either file an issue, or see CONTRIBUTING
§License
This project is licensed under the Apache-2.0 License.
Modules§
- authorization_
errors  - Error subtypes for 
AuthorizationError - cedar_
schema_ errors  - Error subtypes for 
CedarSchemaError - conformance_
errors  - Errors related to schema conformance checking for entities
 - context_
json_ errors  - Error subtypes for 
ContextJsonError - entities
 - Utilities for defining 
IntoIteratoroverEntities - entities_
errors  - Errors related to 
crate::Entities - entities_
json_ errors  - Errors related to serializing/deserializing entities or contexts to/from JSON
 - evaluation_
errors  - Error subtypes for 
EvaluationError - expression_
construction_ errors  - Error subtypes for 
ExpressionConstructionError - extension_
function_ lookup_ errors  - Error subtypes for 
ExtensionFunctionLookupError - ffi
 - FFI utilities, see comments in the module itself
 - policy_
set_ errors  - Error subtypes for 
PolicySetError - policy_
to_ json_ errors  - Error subtypes for 
PolicyToJsonError - proto
protobufs - Protobuf models of cedar-policy types
 - request_
validation_ errors  - Error subtypes for 
RequestValidationError - restricted_
expr_ errors  - Error subtypes for 
RestrictedExpressionError - schema_
errors  - Error subtypes for 
SchemaError - schema_
warnings  - Error subtypes for 
SchemaWarning - to_
cedar_ syntax_ errors  - Error subtypes for 
ToCedarSchemaError - tpe_err
tpe - This module contains possible errors thrown by various components of the type-aware partial evaluator.
 - validation_
errors  - Error subtypes for 
ValidationError. - validation_
warnings  - Error subtypes for 
ValidationWarning. 
Structs§
- Access
Trie entity-manifest - A Trie representing a set of data paths to load, starting implicitly from a Cedar value.
 - Action
Query Request tpe - Defines a 
PartialRequestwhich additionally leaves the action undefined, enabling queries listing what actions might be authorized. - Authorizer
 - Authorizer object, which provides responses to authorization queries
 - Concretization
Error  - Errors that occur during concretizing a partial request
 - Contains
Unknown  - The 
PartialValueis a residual, i.e., contains an unknown - Context
 - the Context object for an authorization request
 - Diagnostics
 - Diagnostics providing more information on how a 
Decisionwas reached - Entities
 - Represents an entity hierarchy, and allows looking up 
Entityobjects by Uid. - Entity
 - Entity datatype
 - Entity
Attr Evaluation Error  - Error when evaluating an entity attribute or tag
 - Entity
Id  - Identifier portion of the 
EntityUidtype. - Entity
Manifest entity-manifest - Data structure storing what data is needed based on the the 
RequestType. - Entity
Namespace  - Represents a namespace.
 - Entity
Type Name  - Represents an entity type name. Consists of a namespace and the type name.
 - Entity
Uid  - Unique id for an entity, such as 
User::"alice". - Expression
 - Expressions to be evaluated
 - Parse
Error  - Errors that can occur when parsing policies or expressions.
 - Parse
Errors  - Represents one or more 
ParseErrors encountered when parsing a policy or expression. - Partial
Entities tpe - Partial 
Entities - Partial
Entity Uid tpe - A partial 
EntityUid. That is, itsEntityIdcould be unknown - Partial
Request tpe - A partial 
RequestIts principal/resource types and action must be known and its context must either be fully known or unknown - Partial
Response partial-eval - A partially evaluated authorization response.
 - Policy
 - Structure for a 
Policy. Includes both static policies and template-linked policies. - Policy
From Json Error  - Error when converting a policy or template from JSON format
 - Policy
Id  - Unique ids assigned to policies and templates.
 - Policy
Set  - Represents a set of 
Policys - Principal
Query Request tpe - Like 
PartialRequestbut onlyprincipalcan be unknown - Record
 - A record of Cedar values
 - Request
 - An authorization request is a tuple 
<P, A, R, C>where - Request
Builder partial-eval - Builder for a 
Request - Request
Env  - The “type” of a 
Request, i.e., theEntityTypeNames of principal and resource, theEntityUidof action, andOption<EntityTypeName>s of principal slot and resource slot - Resource
Query Request tpe - Like 
PartialRequestbut onlyresourcecan be unknown - Response
 - Authorization response returned from the 
Authorizer - Restricted
Expression  - “Restricted” expressions are used for attribute values and 
context. - Root
Access Trie entity-manifest - A trie describing a set of data paths to retrieve.
 - Schema
 - Object containing schema information used by the validator.
 - Schema
Fragment  - Contains all the type information used to construct a 
Schemathat can be used to validate a policy. - Set
 - Sets of Cedar values
 - SlotId
 - Identifier for a Template slot
 - TPEResponse
tpe - A partial version of 
crate::Response. - Template
 - Policy template datatype
 - Test
Entity Loader tpe - Simple entity loader implementation that loads from a pre-existing Entities store
 - Unset
Schema partial-eval - A marker type that indicates 
Schemais not set for a request - Validation
Result  - Contains the result of policy validation.
 - Validator
 - Validator object, which provides policy validation and typechecking.
 
Enums§
- Action
Constraint  - Scope constraint on policy actions.
 - Authorization
Error  - Errors that can occur during authorization
 - Cedar
Schema Error  - Errors when parsing schemas
 - Context
Creation Error  - Errors while trying to create a 
Context - Context
Json Error  - Error type for parsing 
Contextfrom JSON - Decision
 - Decision returned from the 
Authorizer - Effect
 - the Effect of a policy
 - Entity
Manifest Error entity-manifest - An error generated by entity slicing.
 - Entity
Root entity-manifest - The root of a data path or 
RootAccessTrie. - Entity
Slice Error entity-manifest - An error generated by entity slicing. TODO make public API wrapper
 - Eval
Result  - Result of Evaluation
 - Evaluation
Error  - Enumeration of the possible errors that can occur during evaluation
 - Expression
Construction Error  - Errors when constructing an expression
 - Extension
Function Lookup Error  - Errors thrown when looking up an extension function in 
Extensions. - Partial
Request Creation Error tpe - Error thrown when creating a 
PartialRequest - Partial
Value ToValue Error  - Errors encountered when converting 
PartialValuetoValue - Permission
Query Error tpe - Errors that can be encountered when performing a permission query
 - Policy
SetError  - Potential errors when adding to a 
PolicySet. - Policy
ToJson Error  - Errors that can happen when getting the JSON representation of a policy
 - Principal
Constraint  - Scope constraint on policy principals.
 - Reauthorization
Error  - Errors that can be encountered when re-evaluating a partial response
 - Request
Validation Error  - The request does not conform to the schema
 - Resource
Constraint  - Scope constraint on policy resources.
 - Restricted
Expression Error  - Error when constructing a restricted expression from unrestricted expression
 - Restricted
Expression Parse Error  - Error type for parsing a 
RestrictedExpression - Schema
Error  - Error when constructing a schema
 - Schema
Warning  - Warning when constructing a schema
 - TPEReauthorization
Error tpe - Errors that can be encountered when re-evaluating a partial response
 - Template
Principal Constraint  - Scope constraint on policy principals for templates.
 - Template
Resource Constraint  - Scope constraint on policy resources for templates.
 - ToCedar
Schema Error  - Errors serializing Schemas to the Cedar syntax
 - Validation
Error  - An error generated by the validator when it finds a potential problem in a policy.
 - Validation
Mode  - Used to select how a policy will be validated.
 - Validation
Warning  - Represents the different kinds of validation warnings and information specific to that warning.
 
Traits§
- Entity
Loader tpe - Entity loader trait for batched evaluation.
 
Functions§
- compute_
entity_ manifest entity-manifest - Given a schema and policy set, compute an entity manifest.
 - confusable_
string_ checker  - Scan a set of policies for potentially confusing/obfuscating text.
 - eval_
expression  - Evaluates an expression.
 - get_
lang_ version  - Get the Cedar language version
 - get_
sdk_ version  - Get the Cedar SDK Semantic Versioning version
 - validate_
scope_ variables  - Validates scope variables against the provided schema
 
Type Aliases§
- Fields
entity-manifest - A map of data fields to 
AccessTries. The keys to this map form the edges in the access trie, pointing to sub-tries.