**Name** - Romit Karmakar **College** - National Institute of Technology, Durgapur **Email** - romitkarmakar@gmail.com **Phone No.** - +916295722469 **Resume PDF**- https://romitkarmakar.github.io/resume.pdf I want to work on the below topics for the development of Casbin and increase community support. I have studied the casbin golang implementation and your whitepaper on Casbin perm model. I loved that concept, and I will love to work on your project to expand and scale your code to support more languages and platform. ## Master Slave replication of distributed storage We can get inspired by the MongoDB model, and follow the master slave replication pattern to create distributed enforcer instances. This can provide us high availability. Primary nodes can read write the changes to the policy storage. Secondary nodes only can read policy to enforce the request. It can't perform write requests. We can use a heartbeat signal to check the health of all the nodes, so during a failover casbin can make one of its secondary node primary node. For this purpose casbin needs to run as a server to get enough privilege to replicate nodes across networks. ### Motivation As this issue has been proposed by YoshieraHuang [#403](https://github.com/casbin/casbin/issues/402), a furthur thinking into this problem has led me to solve this issue. As we can see big organisation managing thousands of policies, high availability and automatic failover have always been their no.1 priority. ## Problem Generally web servers handling network requests, keep their page assets in the cache (e.g. Nginx Reverse Proxy) to provide faster page loading experience to users. This causes conflicts with the primary memory where due to reduced free memory policies with 10000 rules causes model to be built in primary memory taking huge amount of memory, and also reduces web server performance to a great amount. Having low latency server with close proximity with the web server can handle the policy authorization load without degrading the web server performance and also providing faster request enforcement. ![](https://i.imgur.com/0eB74if.jpg) In cloud infrastructures keeping policies in public subnet leads to exposing public IP address to the internet causing easy policy breach to hackers. ### Solution ![](https://i.imgur.com/LVK3FSG.jpg) Using casbin as a server can help organisations to deploy it in private subnet leading to only private IP address helping organisations to secure their policy from outside intervention. ### Implementation A node table will be stored by all the nodes in the network. Having this specification - IP Address | Port | Priority Primary nodes initially create 2 replica nodes, means in 3 node architecture 1 primary and 2 secondary. RabbitMQ will be used to queue write changes to the policy. Secondary node workers push any changes to be written to the storage in the queue. Primary node background worker picks up the job and write them to database, thus solving the problem of data race and conflict. ![](https://i.imgur.com/0mrFYgt.png) ```initialize()``` this will read the ```casbin.config.yml``` file to read the options and call the create function based on the configuration. ```create()``` function will create node based on network permission config. If nodes are created on same sever they will be exposed using different ports generally differing by 1. By default it will create two secondary nodes. ![](https://i.imgur.com/k8MQgmS.png) ```sync()``` methos will sync data across nodes using the google protocol buffer due to its superior performance than the JSON and less network overhead. ![](https://i.imgur.com/zOe9xBS.png) **Nodes heartbeat mechanism** All the nodes will ping every 5 seconds to check the health of all the nodes. If any nodes fails to respond after 20 seconds (default timeout) then it will be moved to failed state. And failover process begins. ![](https://i.imgur.com/fMcHu8Z.png) If a secondary node fails, another secondary node is being created by the primary node and the old one is discarded. ![](https://i.imgur.com/MTqgh5y.png) If a primary node fails all the secondary nodes holds an election, the first node which calls the election gets the highest priority to which nodes it reaches first. The one node which wins the election becomes the primary node. ![](https://i.imgur.com/9yeEcoi.png) The node which request first ```requestVote()``` ping gets higher voting priority. If there are only two secondary node to break the tie we use timestamp to know which node knew earlier about the primary node failover. ![](https://i.imgur.com/XsMseNj.png) ### Use cases It will be useful for organisations to use casbin as a standalone server so that it main high availability and handles automatic failover during disasters or data center breakdown and more security. ## C++ implementation of Casbin I would like to port the casbin core engine from golang to C++, so that performance focused organisations who want to get machine level performance for their policy authorisations systems can use this library. This project will also lead to the migration of the PHP extension to C++. I will like to port the casbin project to C++, and use the modern C++ concurrency and parallelism to get the most out of any resource. ### Credits I want to personally thank [@hsluoyz](https://github.com/hsluoyz) and @xcaptain and [@techoner](https://github.com/techoner) for their valuable feedback and support in developing the project. ## Dart implementation of Casbin Current progress at https://github.com/romitkarmakar/casbin-dart With widespread usage of google new dartlang and their flutter cross platform native rendering engine, applications built on dart and flutter can leverage the power of casbin-dart to built their own policy management system. ### Motivation When I was developing a cross-platform mobile application using Flutter, I came to a problem where I was using Firebase as a backend, and Firebase in-built policy management system was difficult to grasp and even can't solve our all use-cases. Then, I came to know about the Casbin library with which I really fell into love. ### Road Map - Flutter package. - Dart package for web servers. ### Use cases - App developers can use the flutter package for in-app policy management system to help them authorize file-system access and also authorization to Firebase as firebase policy management system is difficult to grasp for beginners. - Dart webservers can use this library to manage policies in the backend. ## Optimisation to Node-Casbin I am proposing to use casbin-cpp to create native node addon. ### Problem We know that Chrome V8 engine very badly handles the heap memory, as its garbage collection algorithm is not so much advanced. So we can ffi (foreign function interoperability) to use this C++ code to better manage the heap memory, so that our library can easily handle and scale upto thousands of policies for big organisations and also handle millions of requests. ### Implementation We will use N-API to build the native addon as it will be truly independent to the chrome v8 engine. ## S3 Adapter for Config ### Summary Building S3 adapter for model storage, to ease serverless deployment. ### Motivation Today as serverless are becoming more popular, organisations are moving their applications to serverless which takes the pain of managing servers away. Serverless has a shortcomings of accessing filesystems. So having a s3 adapter for model can help them upload model to s3 and have them access model from there. ### Design **A Sample Architecture** ![](https://i.imgur.com/B3FFGR0.jpg) This is will be implemented in the following languages, whose runtimes are currently supported in lambda and azure functions: - Go Lang - NodeJS - Python - C# - Rust ### Improvements Having a S3 Adapter for serverless deployments can help organisations to easily model file anytime, and without the pain of restarting servers and lambda execution environments will automatically the fetch new file when executing the function. ## Php Extension using C++ ### Summary Currently the PHP extension lacks some serious performance due to its lack of concurrency. Building PHP extension on the top of C++ can provide us some huge gain in performance. ### Motivation If we see organisations like Facebook, wordpress is built on the top of PHP. But as PHP lacks performance, we know that companies like Facebook convert it into low level languages like C++ using Hiphop VM to gain higher performance. ### Design We will fork our Casbin-Cpp project and and convert the exporting variables to native PHP runtime variables using [PHP-CPP](http://www.php-cpp.com/). ### Improvements Currently, I don't have some metrics to support my claim. But I will soon run some metrics to calculate performance and provide them to your organisation. ### References https://www.php-cpp.com/documentation/ten-reasons-for-using-php-cpp ### Credit I want to personally thank [@techoner](https://github.com/techoner) to help me go through this idea and develop it. ## DynamoDB Adapter for Policy Storage Current progress at https://github.com/romitkarmakar/casbin-dynamodb-adapter Organisations can leverage the most dyanamodb to store polices in serverless and gaming applications. It will be available for 3 languages - - Golang - Python - Javascript ## Front End port of Casbin I want to port the node-casbin to support browser UMD modules. ### Implementation I will remove all the native nodejs api which access the filesystem like the config and the file adapter. So the persist adapter will only support the string adapter for the policy storage and the text parsing for the model storage. For this purpose, I will use webpack to convert the typescript files into browser javascript. ![](https://i.imgur.com/cCPldvL.png) Using this I will create UMD bundle definitions that can work on browser and even on servers. ## Migration to Typescript As we all know the power of Typescript which Microsoft built to solve some of the shortcomings of Javascript dynamic typing. I am proposing to migrate all the middleware built on node-casbin to Typescript. Repositories proposed to be migrated - - express authz - koa authz - mongoose adapter - egg authz ### Credit I want to personally thank to [@nodece](https://github.com/nodece) for helping me migrating plugins/middlewares to Typescript. ## Timeline **May 5, 2020 - May 10, 2020 :** Porting the Casbin Core engine from golang to C++. **May 11, 2020 - May 14, 2020 :** Migrating the PHP extension to PHP-CPP so that it can use native C++. **May 15, 2020 - June 2, 2020 :** Developing the master slave architecture for the casbin as a server project. **June 3, 2020 - June 10, 2020 :** Migrating the nodejs packages into typescript. **June 11, 2020 - June 20, 2020 :** Porting the Casbin core engine from golang to dart. **June 21, 2020 - June 25, 2020 :** Develping the Casbin.js so that users can run it also in browser. **June 26, 2020 - June 29, 2020 :** Developing Dyanmodb adapter in Nodejs **June 30. 2020 - July 2, 2020 :** Developing Dynamodb adapter in Python **July 3, 2020 - July 7, 2020 :** Developing the Dynamodb adapter in Golang. **July 9, 2020 - July 13, 2020 :** Developing the S3 adapter for Casbin. ## Contributions to casbin - [#2](https://github.com/node-casbin/hapi-authz/pull/2) Developing the hapi middleware of casbin. - [#11](https://github.com/casbin/casbin-cpp/pull/11) Development of the Casbin CPP. - [#54](https://github.com/casbin/casbin-website/pull/54) A Small bug fix in casbin website. ## About me I love to work in blockchain technology, areas where block chain can make impact like in supply chain and cloud computing infrastructure for AWS and Azure. Currently I am doing research in using Directed Acyclic Graph and using proof of work to run AI workloads rather than calculating block hash in block chain, and using RNN and CNN to analyze voice spectogram and to increase AST model accuracy. I have some open source projects made by me- - Trennds CMS - It is a serverless blog management system, which I developed so that users can spin up their own blog without managing server and scalability. - Metal UI - It is my own CSS Framework that I developed to cater some needs in our college when we wanted to keep consistent UI among event sites.