Skip to content

Instantly share code, notes, and snippets.

@hackerchai
Last active August 31, 2020 12:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hackerchai/c8b46dff920204fb58cad9067d202538 to your computer and use it in GitHub Desktop.
Save hackerchai/c8b46dff920204fb58cad9067d202538 to your computer and use it in GitHub Desktop.
GSoC 2020 Final Report - Casbin- Casbin-RS

GSoC Final Report - Casbin-RS

Personal Details

Project Details

Overview

Casbin-RS is now ready for production

Casbin-RS aims at building reliable and high-performance library supporting various model access control for Rust projects. In the past months, I have developed Casbin Sqlx Adapter to support fully Async with Casbin Database Adapter, which gives developers an alternative in database adapter selection as well as a more high-performance adapter.

In addition, now all the components of Casbin-RS have intergrated with Github Action CI and Auto-Release support.

Casbin-RS is now ready for Actix-web Development

Actix-web is the the most popular Rust web framework at present. It is also known as the fastest web framework. With powerful extractors and extensible features, we can build rust-web application easily. In the past months, I am working on how to intergration Casbin with Actix-web together.

With Casbin Actix-web Middleware, It will provide a basic middleware to reads username(from other AuthN middleware), request path, request method from an user request and sends enforce request (subject, domain, object, action) to casbin enforcer for authorization. The middleware wll block the request if enforcer denied the request. We can automatically handle request with authorization control with this.

With Casbin Actix-web Actor, we can wrap casbin into an actor for a safer and easier way to call in request handle. In the actix system, actors are objects which encapsulate state and behavior and run within the Actor System provided by the actix library. We build this actor for basic CRUD operation of casbin instance

Casbin Actix-web Real World App is a fully functional demo which intergrated with Actix-web, Casbin Actix-web Middleware , Casbin Actix-web Actor, Diesel, Casbin Diesel Adaper. It is basically an Anonymous Forum which has admin-user system. With the intergration of casbin, it can authorize the requests and add policies when new user registered. This app provides a set of RESTful API using JWT authentication. This can be seen as an example for developers to use casbin with actix-web.

The work I have done

My Weekly Development Report can be seen here.

All the commits made by me: commit-list, this repo is mainly maintained by me.

  • Basic Api Implemntation
  • Test Module For Functions
  • Multi-Databse support: Including MySQL/PostgreSQL
  • Fully Async Support
  • CI/CD Intergrations: Github Actions
  • Auto-Release: Github Actions
  • Database Environment Setupt: Docker
  • Document Writing

All the commits made by me: commit-list, this repo is mainly maintained by me.

  • Basic Function Implementation
  • Test Module For Middleware
  • Support for AuthN Middleware Intergration
  • Support Domain Model and Domian-less Model
  • Support Get/Set Enforcer for Flexible Demand
  • CI/CD Intergrations: Github Actions
  • Auto-Release: Github Actions
  • Document Writing

All the commits made by me: commit-list, this repo is mainly maintained by me.

  • Basic Casbin Function Implementation
  • Test Module for Actor Runtime
  • Support Actix Supervisor: Auto-Restart Feature
  • Support Get/Set Enforcer for Flexible Dem,and
  • CI/CD Intergrations: Github Actions
  • Auto-Release: Github Actions
  • Document Writing

All the commits made by me: commit-list, this module is mainly maintained by me.

  • Basic Restful API Implementation using Actix-web: Anonymous Forum
  • Intergration with Casbin Actix-web Middleware and Casbin Actix-web Actor
  • User JWT Authentication Middleware Implementation
  • Database Design and Migration Implement
  • Casbin Configuration and Structure Design
  • URL White-list for Casbin AuthZ Middleware and JWT AuthN Middleware
  • Preset Policy Databse Initial Implementation
  • CI/CD Intergrations: Github Actions
  • Document Writing

All the commits made by me: commit-list

  • Code Refactor and Optimization
  • Database Environment Setup Improvement
  • CI/CD Intergrations: Github Actions
  • Auto-Release: Github Actions
  • Document Writing Improvement
  • Daily Maintenance and Upgrade

All the commits made by me: commit-list

  • Casbin-Rs Actix Middleware & Actor Documentation

Challenges and Difficulties

  1. RwLock deadlock problem

    When developing the middleware and actor, I have to use RwLock to wrap casbin instance to avoid Rust lifetime issue, they are all set and passed the Unit-Tests. But when I was developing the real-world-app, I encountered several Rwlock Deadlock problems, with my mentor's help, finally I successfully solve the problem by manually dropping the RwLock in case of middleware long-term holding the write lock.

  2. Sqlx compile-time checking and CI issues

    Sqlx-rs uses the compile-time check which forces me to set the database environment up while compiling. When it comes to the CI, it becomes a little difficult for my first time of working with Github Actions. So I have to set up the database docker for the compile time-check. But here is the good news: Sqlx officially announced it will use sqlx-cli to avoid compile-time checking. When the feature comes to stable, I will try to port this feature to our Sqlx Adapter.

After GSoC

I will definitely continue contributing to Casbin, there are still a lot to do in the future:

  • Implement new data structure for casbin-rs: For now, out data structure is tree, which causes the usage of lock and makes it hard to support multi-thread processing. In the future, maybe we can use index tree to solve this problem.
  • Implement RPC version of casbin-rs
@nodece
Copy link

nodece commented Aug 31, 2020

@hackerchai Congratulations, have a great summer with @casbin 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment