{"id":19298212,"url":"https://github.com/casbin/lua-casbin","last_synced_at":"2025-05-05T18:46:13.617Z","repository":{"id":40360113,"uuid":"94686988","full_name":"casbin/lua-casbin","owner":"casbin","description":"An authorization library that supports access control models like ACL, RBAC, ABAC in Lua (Kong, APISIX, OpenResty)","archived":false,"fork":false,"pushed_at":"2024-11-28T23:56:40.000Z","size":879,"stargazers_count":63,"open_issues_count":4,"forks_count":17,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-28T09:29:53.533Z","etag":null,"topics":["abac","access-control","acl","apisix","apisix-plugin","auth","authorization","authz","casbin","kong","kong-plugin","lua","nginx","openresty","permission","rbac"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/casbin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"casbin"}},"created_at":"2017-06-18T12:51:47.000Z","updated_at":"2025-03-11T14:40:07.000Z","dependencies_parsed_at":"2024-11-09T16:32:40.043Z","dependency_job_id":"04b01a76-144f-46d3-9e28-24938d33df43","html_url":"https://github.com/casbin/lua-casbin","commit_stats":{"total_commits":131,"total_committers":16,"mean_commits":8.1875,"dds":0.6488549618320612,"last_synced_commit":"f40b2eabe8e09d75e53f76a0f94b25aff97d98b4"},"previous_names":[],"tags_count":66,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin%2Flua-casbin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin%2Flua-casbin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin%2Flua-casbin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/casbin%2Flua-casbin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/casbin","download_url":"https://codeload.github.com/casbin/lua-casbin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252555767,"owners_count":21767229,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["abac","access-control","acl","apisix","apisix-plugin","auth","authorization","authz","casbin","kong","kong-plugin","lua","nginx","openresty","permission","rbac"],"created_at":"2024-11-09T23:07:16.240Z","updated_at":"2025-05-05T18:46:13.595Z","avatar_url":"https://github.com/casbin.png","language":"Lua","readme":"# lua-casbin\n[![GitHub Action](https://github.com/casbin/lua-casbin/workflows/build/badge.svg?branch=master)](https://github.com/casbin/lua-casbin/actions)\n[![Coverage Status](https://coveralls.io/repos/github/casbin/lua-casbin/badge.svg?branch=master)](https://coveralls.io/github/casbin/lua-casbin?branch=master)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Discord](https://img.shields.io/discord/1022748306096537660?logo=discord\u0026label=discord\u0026color=5865F2)](https://discord.gg/S5UjpzGZjN)\n\n[![LuaRocks](https://img.shields.io/luarocks/v/hsluoyz/casbin.svg)](https://luarocks.org/modules/hsluoyz/casbin)\n[![Generic badge](https://img.shields.io/badge/Lua-5.1-44cc11.svg)](https://shields.io/)\n[![Generic badge](https://img.shields.io/badge/Lua-5.2-44cc11.svg)](https://shields.io/)\n[![Generic badge](https://img.shields.io/badge/Lua-5.3-44cc11.svg)](https://shields.io/)\n[![Generic badge](https://img.shields.io/badge/Lua-5.4-44cc11.svg)](https://shields.io/)\n[![Generic badge](https://img.shields.io/badge/LuaJIT-2.0-44cc11.svg)](https://shields.io/)\n\n\nAn authorization library that supports access control models like ACL, RBAC, ABAC in Lua (OpenResty)\n\nRead the setup guide for OpenResty [here](https://github.com/casbin-lua/lua-resty-casbin/).\n\n**News**: Are you still worried about how to write the correct Casbin policy? ``Casbin online editor`` is coming to help! Try it at: http://casbin.org/editor/\n\n![casbin Logo](casbin-logo.png)\n\n## All the languages supported by Casbin:\n\n[![golang](https://casbin.org/img/langs/golang.png)](https://github.com/casbin/casbin) | [![java](https://casbin.org/img/langs/java.png)](https://github.com/casbin/jcasbin) | [![nodejs](https://casbin.org/img/langs/nodejs.png)](https://github.com/casbin/node-casbin) | [![php](https://casbin.org/img/langs/php.png)](https://github.com/php-casbin/php-casbin)\n----|----|----|----\n[Casbin](https://github.com/casbin/casbin) | [jCasbin](https://github.com/casbin/jcasbin) | [node-Casbin](https://github.com/casbin/node-casbin) | [PHP-Casbin](https://github.com/php-casbin/php-casbin)\nproduction-ready | production-ready | production-ready | production-ready\n\n[![python](https://casbin.org/img/langs/python.png)](https://github.com/casbin/pycasbin) | [![dotnet](https://casbin.org/img/langs/dotnet.png)](https://github.com/casbin-net/Casbin.NET) | [![c++](https://casbin.org/img/langs/cpp.png)](https://github.com/casbin/casbin-cpp) | [![rust](https://casbin.org/img/langs/rust.png)](https://github.com/casbin/casbin-rs)\n----|----|----|----\n[PyCasbin](https://github.com/casbin/pycasbin) | [Casbin.NET](https://github.com/casbin-net/Casbin.NET) | [Casbin-CPP](https://github.com/casbin/casbin-cpp) | [Casbin-RS](https://github.com/casbin/casbin-rs)\nproduction-ready | production-ready | beta-test | production-ready\n\n## Installation\n\n```bash\nsudo luarocks install casbin\n```\n\n## Get Started\n\n1. New Casbin enforcer with a model file and a policy file:\n```lua\nlocal Enforcer = require(\"casbin\")\nlocal e = Enforcer:new(\"path/to/model.conf\", \"path/to/policy.csv\")\n```\nNote: you can also initialize an enforcer with policy in DB instead of file, see [Policy-persistence](https://github.com/casbin/lua-casbin#policy-persistence) section for details.\n\n2. Add an enforcement hook into your code right before the access happens:\n```lua\nlocal sub = \"alice\" -- the user that wants to access a resource.\nlocal obj = \"data1\" -- the resource that is going to be accessed.\nlocal act = \"read\" -- the operation that the user performs on the resource.\n\nif e:enforce(sub, obj, act) then\n    -- permit alice to read data1\nelse\n    -- deny the request, show an error\nend\n```\n\n3. Besides the static policy file, Casbin also provides API for permission management at run-time. For example, You can get all the roles assigned to a user as below:\n```lua\nlocal roles = e:GetImplicitRolesForUser(sub)\n```\nSee [Policy management APIs](https://github.com/casbin/lua-casbin#policy-management) for more usage.\n\n\n## Supported models\n\n1. [**ACL (Access Control List)**](https://en.wikipedia.org/wiki/Access_control_list)\n2. **ACL with [superuser](https://en.wikipedia.org/wiki/Superuser)**\n3. **ACL without users**: especially useful for systems that don't have authentication or user log-ins.\n3. **ACL without resources**: some scenarios may target for a type of resources instead of an individual resource by using permissions like ``write-article``, ``read-log``. It doesn't control the access to a specific article or log.\n4. **[RBAC (Role-Based Access Control)](https://en.wikipedia.org/wiki/Role-based_access_control)**\n5. **RBAC with resource roles**: both users and resources can have roles (or groups) at the same time.\n6. **RBAC with domains/tenants**: users can have different role sets for different domains/tenants.\n7. **[ABAC (Attribute-Based Access Control)](https://en.wikipedia.org/wiki/Attribute-Based_Access_Control)**: syntax sugar like ``resource.Owner`` can be used to get the attribute for a resource.\n8. **[RESTful](https://en.wikipedia.org/wiki/Representational_state_transfer)**: supports paths like ``/res/*``, ``/res/:id`` and HTTP methods like ``GET``, ``POST``, ``PUT``, ``DELETE``.\n9. **Deny-override**: both allow and deny authorizations are supported, deny overrides the allow.\n10. **Priority**: the policy rules can be prioritized like firewall rules.\n\n## How it works?\n\nIn Casbin, an access control model is abstracted into a CONF file based on the **PERM metamodel (Policy, Effect, Request, Matchers)**. So switching or upgrading the authorization mechanism for a project is just as simple as modifying a configuration. You can customize your own access control model by combining the available models. For example, you can get RBAC roles and ABAC attributes together inside one model and share one set of policy rules.\n\nThe most basic and simplest model in Casbin is ACL. ACL's model CONF is:\n\n```ini\n# Request definition\n[request_definition]\nr = sub, obj, act\n\n# Policy definition\n[policy_definition]\np = sub, obj, act\n\n# Policy effect\n[policy_effect]\ne = some(where (p.eft == allow))\n\n# Matchers\n[matchers]\nm = r.sub == p.sub \u0026\u0026 r.obj == p.obj \u0026\u0026 r.act == p.act\n\n```\n\nAn example policy for ACL model is like:\n\n```\np, alice, data1, read\np, bob, data2, write\n```\n\nIt means:\n\n- alice can read data1\n- bob can write data2\n\n## Features\n\nWhat Casbin does:\n\n1. enforce the policy in the classic ``{subject, object, action}`` form or a customized form as you defined, both allow and deny authorizations are supported.\n2. handle the storage of the access control model and its policy.\n3. manage the role-user mappings and role-role mappings (aka role hierarchy in RBAC).\n4. support built-in superuser like ``root`` or ``administrator``. A superuser can do anything without explict permissions.\n5. multiple built-in operators to support the rule matching. For example, ``keyMatch`` can map a resource key ``/foo/bar`` to the pattern ``/foo*``.\n\nWhat Casbin does NOT do:\n\n1. authentication (aka verify ``username`` and ``password`` when a user logs in)\n2. manage the list of users or roles. I believe it's more convenient for the project itself to manage these entities. Users usually have their passwords, and Casbin is not designed as a password container. However, Casbin stores the user-role mapping for the RBAC scenario.\n\n## Documentation\n\nhttps://casbin.org/docs/overview\n\n## Online editor\n\nYou can also use the online editor (https://casbin.org/editor/) to write your Casbin model and policy in your web browser. It provides functionality such as ``syntax highlighting`` and ``code completion``, just like an IDE for a programming language.\n\n## Tutorials\n\nhttps://casbin.org/docs/tutorials\n\n## Policy management\n\nCasbin provides two sets of APIs to manage permissions:\n\n- [Management API](https://casbin.org/docs/management-api): the primitive API that provides full support for Casbin policy management.\n- [RBAC API](https://casbin.org/docs/rbac-api): a more friendly API for RBAC. This API is a subset of Management API. The RBAC users could use this API to simplify the code.\n\nWe also provide a [web-based UI](https://casbin.org/docs/admin-portal) for model management and policy management:\n\n![model editor](https://hsluoyz.github.io/casbin/ui_model_editor.png)\n\n![policy editor](https://hsluoyz.github.io/casbin/ui_policy_editor.png)\n\n## Policy persistence\n\nhttps://casbin.org/docs/adapters\n\n## Policy consistence between multiple nodes\n\nhttps://casbin.org/docs/watchers\n\n## Role manager\n\nhttps://casbin.org/docs/role-managers\n\n## Examples\n\nModel | Model file | Policy file\n----|------|----\nACL | [basic_model.conf](https://github.com/casbin/casbin/blob/master/examples/basic_model.conf) | [basic_policy.csv](https://github.com/casbin/casbin/blob/master/examples/basic_policy.csv)\nACL with superuser | [basic_model_with_root.conf](https://github.com/casbin/casbin/blob/master/examples/basic_with_root_model.conf) | [basic_policy.csv](https://github.com/casbin/casbin/blob/master/examples/basic_policy.csv)\nACL without users | [basic_model_without_users.conf](https://github.com/casbin/casbin/blob/master/examples/basic_without_users_model.conf) | [basic_policy_without_users.csv](https://github.com/casbin/casbin/blob/master/examples/basic_without_users_policy.csv)\nACL without resources | [basic_model_without_resources.conf](https://github.com/casbin/casbin/blob/master/examples/basic_without_resources_model.conf) | [basic_policy_without_resources.csv](https://github.com/casbin/casbin/blob/master/examples/basic_without_resources_policy.csv)\nRBAC | [rbac_model.conf](https://github.com/casbin/casbin/blob/master/examples/rbac_model.conf)  | [rbac_policy.csv](https://github.com/casbin/casbin/blob/master/examples/rbac_policy.csv)\nRBAC with resource roles | [rbac_model_with_resource_roles.conf](https://github.com/casbin/casbin/blob/master/examples/rbac_with_resource_roles_model.conf)  | [rbac_policy_with_resource_roles.csv](https://github.com/casbin/casbin/blob/master/examples/rbac_with_resource_roles_policy.csv)\nRBAC with domains/tenants | [rbac_model_with_domains.conf](https://github.com/casbin/casbin/blob/master/examples/rbac_with_domains_model.conf)  | [rbac_policy_with_domains.csv](https://github.com/casbin/casbin/blob/master/examples/rbac_with_domains_policy.csv)\nABAC | [abac_model.conf](https://github.com/casbin/casbin/blob/master/examples/abac_model.conf)  | N/A\nRESTful | [keymatch_model.conf](https://github.com/casbin/casbin/blob/master/examples/keymatch_model.conf)  | [keymatch_policy.csv](https://github.com/casbin/casbin/blob/master/examples/keymatch_policy.csv)\nDeny-override | [rbac_model_with_deny.conf](https://github.com/casbin/casbin/blob/master/examples/rbac_with_deny_model.conf)  | [rbac_policy_with_deny.csv](https://github.com/casbin/casbin/blob/master/examples/rbac_with_deny_policy.csv)\nPriority | [priority_model.conf](https://github.com/casbin/casbin/blob/master/examples/priority_model.conf)  | [priority_policy.csv](https://github.com/casbin/casbin/blob/master/examples/priority_policy.csv)\n\n## Middlewares\n\nAuthz middlewares for web frameworks: https://casbin.org/docs/middlewares\n\n## Our adopters\n\nhttps://casbin.org/docs/adopters\n\n## How to Contribute\n\nPlease read the [contributing guide](CONTRIBUTING.md).\n\n## Backers\n\nThank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/casbin#backer)]\n\n\u003ca href=\"https://opencollective.com/casbin#backers\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/casbin/backers.svg?width=890\"\u003e\u003c/a\u003e\n\n## Sponsors\n\nSupport this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/casbin#sponsor)]\n\n\u003ca href=\"https://opencollective.com/casbin/sponsor/0/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/casbin/sponsor/0/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/casbin/sponsor/1/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/casbin/sponsor/1/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/casbin/sponsor/2/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/casbin/sponsor/2/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/casbin/sponsor/3/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/casbin/sponsor/3/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/casbin/sponsor/4/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/casbin/sponsor/4/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/casbin/sponsor/5/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/casbin/sponsor/5/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/casbin/sponsor/6/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/casbin/sponsor/6/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/casbin/sponsor/7/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/casbin/sponsor/7/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/casbin/sponsor/8/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/casbin/sponsor/8/avatar.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://opencollective.com/casbin/sponsor/9/website\" target=\"_blank\"\u003e\u003cimg src=\"https://opencollective.com/casbin/sponsor/9/avatar.svg\"\u003e\u003c/a\u003e\n\n## License\n\nThis project is licensed under the [Apache 2.0 license](LICENSE).\n\n## Contact\n\nIf you have any issues or feature requests, please contact us. PR is welcomed.\n- https://github.com/casbin/lua-casbin/issues\n- hsluoyz@gmail.com\n- Tencent QQ group: [546057381](//shang.qq.com/wpa/qunwpa?idkey=8ac8b91fc97ace3d383d0035f7aa06f7d670fd8e8d4837347354a31c18fac885)\n","funding_links":["https://github.com/sponsors/casbin","https://opencollective.com/casbin"],"categories":["Lua"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasbin%2Flua-casbin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcasbin%2Flua-casbin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcasbin%2Flua-casbin/lists"}