oslo-policy

A parser and evaluation engine for oslo.policy rule files.

This crate may be interesting for you if you are implementing an OpenStack-like service in Rust. If your service does not have anything to do with OpenStack, there are better policy engines to choose from. This engine is designed for the highest reasonable compatibility with the OpenStack way.

Usage

Policy rules are usually stored in a YAML or JSON file on disk. Load that file into a HashMap using your IO and deserialization libraries of choice. (The example below uses std and serde_yaml.) Then use this library to parse the rules into a RuleSet object:

```rust,ignore let buf = std::fs::read("/etc/myservice/policy.yaml")?; let rules = serdeyaml::frombytes(&buf)?;

let mut ruleset = oslopolicy::RuleSet::new(); ruleset.addrules(rules)?; ```

When handling a request, you need to construct a Request object. At a minimum, a request needs to contain a Token object that describes the token which was supplied with the Request. Ideally, your OpenStack client library of choice should have a type that implements our Token trait. Once you have a Request object, you can evaluate policy rules from the RuleSet and generate your HTTP responses accordingly. (The example below implies that Hyper is used to implement the request handler.)

```rust,ignore use hyper::{Body, Request, Response, Server};

// in request handler: let req = oslo_policy::Request::new(&token); if !ruleset.evaluate("instance:create", &req) { return Err(Response::builder().status(403).body("Forbidden").unwrap()); }

```

Differences to the reference implementation

This library does not replicate all of the features and behaviors of the reference implementation.

Intentional incompatibilities

This library explicitly rejects some fallback behaviors of the reference implementation that we consider dangerous.

Intentionally out of scope

The following functionality will never be implemented in this library. PRs that add these features will be rejected.

Currently out of scope

The following functionality may be implemented in this library in the future if a practical usecase can be demonstrated. Please open an issue to discuss your usecase before sending a PR.