#policy #cedar #security-policy #security #authorization #access-control

cedar-policy

Cedar is a language for defining permissions as policies, which describe who should have access to what

20 stable releases

3.1.1 Mar 14, 2024
3.0.1 Dec 21, 2023
2.4.4 Mar 8, 2024
2.4.3 Dec 21, 2023
2.3.1 Jul 20, 2023

#6 in Configuration

Download history 6226/week @ 2023-12-06 5912/week @ 2023-12-13 3722/week @ 2023-12-20 3131/week @ 2023-12-27 4582/week @ 2024-01-03 6089/week @ 2024-01-10 6040/week @ 2024-01-17 5825/week @ 2024-01-24 6374/week @ 2024-01-31 7150/week @ 2024-02-07 7807/week @ 2024-02-14 8424/week @ 2024-02-21 6468/week @ 2024-02-28 8126/week @ 2024-03-06 8698/week @ 2024-03-13 7565/week @ 2024-03-20

32,214 downloads per month
Used in 50 crates (9 directly)

Apache-2.0

3MB
61K SLoC

Cedar-Policy

Cedar Logo

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(Some(alice), Some(action), Some(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(Some(bob), Some(action), Some(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 the read the security best practices

Building

To build, simply run cargo build (or cargo build --release).

What's New

See CHANGELOG

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.

Dependencies

~7–17MB
~228K SLoC