Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jans-lock): cedarling code refactoring to improve its readability and maintainance #9493

Merged
merged 11 commits into from
Sep 16, 2024
21 changes: 2 additions & 19 deletions jans-lock/cedarling/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
[workspace]
resolver = "2"
members = [
"engines/authz_engine",
"cedarling_run",
"engines/init_engine",
"engines/jwt_engine",
"bindings/cedarling_python",
"cedarling",
]
members = ["cedarling"]

[workspace.dependencies]
cedarling = { path = "cedarling" }
authz_engine = { path = "engines/authz_engine" }
jwt_engine = { path = "engines/jwt_engine" }
init_engine = { path = "engines/init_engine" }
cedar-policy = "3.2.0"
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
thiserror = "1.0.63"
base64 = "0.22.1"
log = "0.4.22"
ehttp = { version = "0.5.0" }


[profile.release]
strip = "symbols"
Expand Down
102 changes: 15 additions & 87 deletions jans-lock/cedarling/README.md
Original file line number Diff line number Diff line change
@@ -1,88 +1,16 @@
## cedarling ⚙️
# Cedarling
The Cedarling is a performant local authorization service that runs the Rust Cedar Engine.
Cedar policies and schema are loaded at startup from a locally cached "Policy Store".
In simple terms, the Cedarling returns the answer: should the application allow this action on this resource given these JWT tokens.
"Fit for purpose" policies help developers build a better user experience.
For example, why display form fields that a user is not authorized to see?
The Cedarling is a more productive and flexible way to handle authorization.

## Rust Cedarling
Cedarling is written in the Rust programming language (folder `cedarling`). And you can import it into your project as a dependency.

## Cedarling bindings
We have support binding for this platforms:
- [ ] Python
- [ ] Wasm

### Installation

1. Ensure you have installed [Rust](https://www.rust-lang.org/tools/install) installed.
2. Clone the repository:
```bash
git clone https://github.com/JanssenProject/jans.git
cd jans/jans-lock/cedarling/
```
3. Install dependencies and build:
```bash
cargo build --release
```
4. The result of build process will be in `target/release` folder

### Notes

To execute example (`cedarling_run`)

```
cargo run
```

Path to local policy store:

```
demo\policy-store\local.json
```

Path to input data:

```
demo\input.json
```

The schema for demo was modified and placed in

```
schema/human/cedarling_demo_schema.schema
```

and policy was modified and placed in

```
demo\policies_1.cedar
```

also local policy store was modified according to files above.

# Python binding

To build the python binding you need move to the `cedarling_python` folder and follow steps written in `Readme.md`

# Unit tests of rust code

For tests we use standart unit test framework for rust.
To run tests you need to install [Rust](https://www.rust-lang.org/tools/install). And then execute:
```
cargo test
```

# Code coverage of rust code

To generate code coverage we use `cargo-llvm-cov`. To install it run:
```
cargo install cargo-llvm-cov
```

You can run code coverage by running:
### Simple table
```
cargo llvm-cov > coverage.txt
```
the result will be in `coverage.txt` file.

### HTML results
```
cargo llvm-cov --html --open
```
the result will be opened in browser.

### Generate `lcov.info` file
```
cargo llvm-cov --workspace --lcov --output-path lcov.info
```
the result will be in `lcov.info` file.
With `lcov.info` you can use IDE tools like [coverage gutters](https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters) to watch code coverage.
6 changes: 0 additions & 6 deletions jans-lock/cedarling/bindings/README.md

This file was deleted.

72 changes: 0 additions & 72 deletions jans-lock/cedarling/bindings/cedarling_python/.gitignore

This file was deleted.

15 changes: 0 additions & 15 deletions jans-lock/cedarling/bindings/cedarling_python/Cargo.toml

This file was deleted.

Loading