lanlin/god
Composer 安装命令:
composer require lanlin/god
包简介
An authority proving system that supports ACL, RBAC, ABAC
README 文档
README
"God said, Let there be light, and there was light."
"God will decide if you have permission."
"God bless you!"
Install
composer require lanlin/god
The Origin
God is written after referring to the Casbin(golang) project, thanks for their hard work.
For more detail, please refer to the documentation of Casbin.
Supported models
- ACL (Access Control List)
- ACL with superuser
- ACL without users: especially useful for systems that don't have authentication or user log-ins.
- 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. - RBAC (Role-Based Access Control)
- RBAC with resource roles: both users and resources can have roles (or groups) at the same time.
- RBAC with domains/tenants: users can have different role sets for different domains/tenants.
- ABAC (Attribute-Based Access Control): syntax sugar like
resource.Ownercan be used to get the attribute for a resource. - RESTful: supports paths like
/res/*,/res/:idand HTTP methods likeGET,POST,PUT,DELETE. - Deny-override: both allow and deny authorizations are supported, deny overrides the allow.
- Priority: the policy rules can be prioritized like firewall rules.
Supported Adapters
- file adapter
- MongoDB adapter
- PHP PDO adapters (now support: MySQL, PostgreSQL, SQLite, SqlServer.)
How it works?
does "Who" as "Role" or "Group" from "Where" do "Operator" to "What" will got "How"?
| Identifier | Description |
|---|---|
| r | Request (r = sub, obj, act) |
| p | Policy (p = sub, obj, act, eft) |
| g | Group or Role (g = _, _) |
| e | Policy Efftect (e = some(where (p.eft == allow))) |
| m | Matchers (m = r.obj == p.obj) |
| sub | Subject (Who) |
| dom | Domain (Where) |
| obj | Object (What) |
| act | Action (Operator) |
| eft | Efftect (How) (allow, deny, indeterminate) |
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.
The most basic and simplest model in God is ACL. ACL's model CONF is:
# Request definition [request_definition] r = sub, obj, act # Policy definition [policy_definition] p = sub, obj, act # Policy effect [policy_effect] e = some(where (p.eft == allow)) # Matchers [matchers] m = r.sub == p.sub && r.obj == p.obj && r.act == p.act
An example policy for ACL model is like:
p, alice, data1, read
p, bob, data2, write
It means:
- alice can read data1
- bob can write data2
Demo
use God\God; $God = new God('path/to/model.conf', 'path/to/policy.csv'); $God->allows('you', 'evil book', 'read'); // Does God allows you to do this? new God(); new God(string $modelPath); new God(string $modelPath, string $policyFile); new God(string $modelPath, Adapter $adapter); new God(Model $model); new God(Model $model, Adapter $adapter); // demo for mysql $dbHost = "127.0.0.1"; $dbPort = 3306; $dbName = "your_database_name"; $username = "root"; $password = "your_password"; // php mysql pdo demo $pdo = new \PDO("mysql:host={$dbHost};port={$dbPort};dbname={$dbName}", $username, $password); // init god model with csv $g = new God('tests/Examples/rbac_model.conf', 'tests/Examples/rbac_policy.csv'); $m = $g->getModel(); // save policy to database $a = new Adapter($pdo); $a->savePolicy($m);
For more usage demos, please view the unit tests or
License
This project is licensed under the MIT license.
lanlin/god 适用场景与选型建议
lanlin/god 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23 次下载、GitHub Stars 达 5, 最近一次更新时间为 2018 年 06 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「authorization」 「restful」 「acl」 「permission」 「rbac」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lanlin/god 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lanlin/god 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lanlin/god 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Ory-Hydra OAuth 2.0 Client Provider for The PHP League OAuth2-Client
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
This is a restful api to onesignal.
Laravel JWT auth service package
A RESTful API package for the Laravel and Lumen frameworks.
Zoho OAuth 2.0 Client Provider for The PHP League OAuth2-Client
统计信息
- 总下载量: 23
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-06-25