- Name: Yash Pandey (@EmperorYP7)
- Organisation: Casbin
- Project link: https://summerofcode.withgoogle.com/projects/#6057909131149312
- Repository link: https://github.com/casbin/casbin-cpp
- Project Name: Benchmarking, Python bindings and Migrating to CTest for Casbin-CPP
- Project Summary: Casbin is an authorization library that extends its features to implement Access
Control Lists, Role-Based Access Control,
and Attribute-Based Access Control models in various programming languages to its clients. Casbin's Core
Engine is written in GoLang. Casbin-CPP has obvious benefits of speed and efficiency compared to its
implementation in other languages and thus, benchmarking is vital for the project to stand out from the
rest. Python is the most versatile as well as the most used programming language and has huge community
support. Casbin-CPP has the potential to support new PyCasbin to compound the benefits of both languages
through language bindings and extension libraries. Currently, the project uses Microsoft Unit Testing
Framework for C++ for testing and Microsoft’s Azure DevOps pipelines for CI. CTest is truly cross-platform
and can be configured using GitHub Actions for consistent and better CI.
Project Ideas are as follows:
- Modernizing the project with C++17 standard and Google’s benchmarking tool
- Implement Python bindings for Casbin-CPP using pybind11 library
- Implement testing based on CTest and set up workflows for Continuous Integration through GitHub Actions
Casbin is an authorization libary which provides various authorization models upon which the client can build auth interfaces for their apps.
The project was using the Visual Studio workflow to build and test the project. However, the demographics of the potential clients include people who use UNIX based operating systems for development. Thus, we needed a new build system to handle the generation, testing and packaging of the library for all platforms to make it better. This can be done using CMake build system along with CTest.
Here is the current build tree of the project:
The project also involved setting up all the tests that were defined in the MS Unit Testing framework to Googletest and setting up CI workflow through GitHub Actions. A typical test may look like this:
#include <gtest/gtest.h>
#include <casbin/casbin.h>
#include "config_path.h"
TEST(TestEnforcer, TestVectorParams) {
casbin::Enforcer e(basic_model_path, basic_policy_path);
ASSERT_EQ(e.Enforce({ "alice", "data1", "read" }), true);
ASSERT_EQ(e.Enforce({ "alice", "data1", "write" }), false);
// ... and so on
}
The project also needed some performance metrics in the form of benchmarks.
I developed the benchmarking workflow for the project with Google's benchmarking tool along
with continuous testing with GitHub Actions.
Here's a simple benchmark for casbin::Enforcer::Enforce()
.
#include <benchmark/benchmark.h>
#include <casbin/casbin.h>
#include "config_path.h"
static void BM_Enforcer(benchmark::State& state) {
casbin::CachedEnforcer e(basic_model_path, basic_policy_path);
for(auto _ : state)
e.Enforce({ "alice", "data1", "read" });
}
The project needs powerful python bindings for supporting PyCasbin-on-CPP which combines the advantages of two different programming languages. This can be made with pybind11 library. A sample binding may look like this:
#include <pybind11/pybind11.h>
#include <casbin/casbin.h>
namespace py = pybind11;
void bindPyEnforcer(py::module& m) {
py::class_<casbin::Enforcer>(m, "Enforcer")
.def(py::init<const std::string &, const std::string &>(), "")
.def("Enforce", &casbin::Enforcer::Enforce);
}
I've been contributing to Casbin-CPP prior to GSoC coding period. This is when I got introduced to
the project. I tackled some good first issues and learnt about the codebase.
Major contributions include the implementation of SyncedEnforcer
along with the unit tests. Here are my contributions:
# | Title | Status |
---|---|---|
casbin-cpp#82 | feat: Replaced pragma with include guards | |
casbin-cpp#83 | feat: Implemented synced enforcer | |
casbin-cpp#84 | Python bindings to facilitate PyCasbin-on-CPP | |
casbin-cpp#90 | feat: Added async ticker | |
casbin-cpp#92 | feat: Replaced travis with GitHub Actions | |
casbin-cpp#93 | feat: Added translation unit for synced enforcer | |
casbin-cpp#94 | feat: Added Tests for SyncedEnforcer | |
casbin-cpp#96 | Upgrade to C++17 | |
casbin-cpp#98 | fix: Build on MS Visual Studio |
Here is the list of contributions I made during the coding period of GSoC i.e. 8th June 2021 to 18th August 2021.
# | Title | Status |
---|---|---|
casbin-cpp#99 | Configure CMake build system 🏗️ | |
casbin-cpp#101 | feat: Initiate CMake configuration | |
casbin-cpp#103 | feat: Completion of Enforcer API | |
casbin-cpp#104 | fix: Taking in parameters by const reference | |
casbin-cpp#105 | feat: Added ABAC entity wrapper | |
casbin-cpp#106 | feat: Added implementation and tests for UpdatePolicy API | |
casbin-cpp#107 | feat: Initiated CTest setup | |
casbin-cpp#108 | test: Management API, Utility methods and more | |
casbin-cpp#109 | test: Added RBAC, Role Manager and removed MS Unit Tests | |
casbin-cpp#110 | feat: Implemented ABAC in Internal API | |
casbin-cpp#112 | feat: Inherit std::exception |
|
casbin-cpp#113 | chore: Updated docs for build instructions | |
casbin-cpp#114 | feat: Initiated benchmark workflow | |
casbin-cpp#116 | test: Benchmarks for CachedEnforcer | |
casbin-cpp#117 | Error while using casbin::Enforcer::AddPolicies() |
|
casbin-cpp#118 | test: Benchmarks for ManagementAPI | |
casbin-cpp#119 | Memory leakage while using Enforcer::AddPolicy and RBAC workflows |
|
casbin-cpp#120 | test: Benchmarks for Model and RoleManager |
|
casbin-cpp#121 | chore: Cleanup | |
casbin-cpp#122 | feat: Streamlined types | |
casbin-website#256 | feat: Added benchmarks for Casbin-CPP | |
casbin-cpp#123 | feat: Initiated pybind11 Configuration | |
casbin-cpp#124 | chore: Util cleanup | |
casbin-cpp#125 | chore: Model Cleanup | |
casbin-cpp#127 | chore: Config and enforcer cleanup | |
casbin-cpp#128 | feat: Added python bindings for casbin::Enforcer |
|
casbin-cpp#129 | feat: Added bindings for CachedEnforcer |
|
casbin-cpp#130 | feat: Added bindings for casbin::ABACData |
|
casbin-cpp#133 | feat: Added tests for Python Bindings | |
casbin-cpp#134 | Add tests for python bindings | |
casbin-cpp#135 | feat: Added bindings for casbin::Model |
|
casbin-cpp#136 | [Test] Error in locating Test Entities in Xcode | |
casbin-cpp#137 | feat: Added config_path for test entities | |
casbin-cpp#138 | refactor: Exported targets for easy access | |
casbin-cpp#139 | feat: Added python bindings for casbin::Config |
|
casbin-cpp#141 | chore: Updated project config | |
casbin-cpp#142 | feat: Added bindings for casbin::SyncedEnforcer |
|
casbin-cpp#145 | docs: Updated documentation and version | |
casbin-cpp#146 | docs: Added documentation for python bindings |
Weekly blogs/reports can be found at https://gsoc.casbin.org.
I also documented my progress in a separate gist.
The entirety of my contributions during the coding period includes
31 Pull Requests (30 Merged, 1 Closed) and 7 issues which accounts for
18,867 lines of code added and 6,730 lines of code deleted in casbin-cpp.
The entire list of my contributions in casbin-cpp
can be accessed here.
The project's directory structure is set and CMake build system has been configured successfully and is ready to be used across all platforms.
Testing for casbin-cpp has been completed successfully. There are 57 individual and disjoint tests executed through CTest. The CI now tests the library for every platform on PR and push.
The benchmarks are functional and the
corresponding CI is up and running.
Here is the output of casbin_benchmark
on my system:
Python bindings for casbin-cpp are now ready to be used as
pycasbin
module.
Documentation for installation and usage are up as well.
Here is a summary on how to use the pycasbin
module within a
python file:
The CI test for PyCasbin-on-CPP are up and running through GitHub Actions. Here is the output of the tests:
I also made a repository to demonstrate how to integrate casbin into a CMake project for the clients. Here is the link to the same: https://github.com/EmperorYP7/casbin-CMake-setup
All the primary goals of my GSoC proposal are completed. However, there is a huge scope for improving the product.
Here are a few things which can be done in the project for any future contributor:
-
Functional tests for
casbin::SyncedEnforcer
. The problem arised due to ambiguity in handling multi-threaded tests in GoogleTest. -
Benchmarking for
casbin::SyncedEnforcer
. This one is related to the problem described above. -
Packaging of
pycasbin
as discussed in casbin-cpp#146. It is still difficult to install python bindings and we need some workflow to upload and update the package in pypi.org. -
Completion of the implementation of ABAC model within the internal API of casbin-cpp.
-
Inspecting and improving the metrics shown by the benchmarks for regular
casbin::Enforcer
as discussed in casbin-website#255.
I plan to work on these issues after the final evaluations are completed successfully and keep contributing to the project and help the organisation in their growth.
I'd like to thank Google for organizing such an amazing program for us and that it did create an impact on my immediate surroundings and peers to participate and contribute to opensource.
Apart from that, I'd like to thank my mentor Yang Luo (@hsluoyz) for their constant support and guidance and Joey (@xcaptain) for their suggestions during the program.
This was a great experience for me! I learned a lot about software engineering and sharpen my researching skills through this opportunity.
excellent