{"id":21523842,"url":"https://github.com/bhojpur/policy","last_synced_at":"2025-08-23T18:14:39.296Z","repository":{"id":57652258,"uuid":"447855543","full_name":"bhojpur/policy","owner":"bhojpur","description":"The Bhojpur Policy is a web-scale backend, enterprise security policy engine applied within Bhojpur.NET Platform ecosystem for distributed application or service delivery.","archived":false,"fork":false,"pushed_at":"2022-04-30T03:11:34.000Z","size":329,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-17T17:51:03.104Z","etag":null,"topics":["access-control","acl","auth","authorization","permission","rbac"],"latest_commit_sha":null,"homepage":"https://page.bhojpur-consulting.com/product/policy/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bhojpur.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-14T05:42:36.000Z","updated_at":"2023-04-18T01:04:11.000Z","dependencies_parsed_at":"2022-08-28T02:12:07.995Z","dependency_job_id":null,"html_url":"https://github.com/bhojpur/policy","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/bhojpur/policy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhojpur%2Fpolicy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhojpur%2Fpolicy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhojpur%2Fpolicy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhojpur%2Fpolicy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bhojpur","download_url":"https://codeload.github.com/bhojpur/policy/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhojpur%2Fpolicy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271760532,"owners_count":24816441,"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","status":"online","status_checked_at":"2025-08-23T02:00:09.327Z","response_time":69,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["access-control","acl","auth","authorization","permission","rbac"],"created_at":"2024-11-24T01:19:33.293Z","updated_at":"2025-08-23T18:14:39.273Z","avatar_url":"https://github.com/bhojpur.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bhojpur Policy - Security Engine\n\nThe `Bhojpur Policy` is used as a Policy Engine. It is a powerful and efficient\naccess control framework. It provides support for enforcing authorization based\non various [access control models](https://en.wikipedia.org/wiki/Computer_security_model).\n\n## Table of contents\n\n- [Supported models](#supported-models)\n- [How it works?](#how-it-works)\n- [Features](#features)\n- [Installation](#installation)\n- [Documentation](#documentation)\n- [Online editor](#online-editor)\n- [Tutorials](#tutorials)\n- [Get started](#get-started)\n- [Policy management](#policy-management)\n- [Policy persistence](#policy-persistence)\n- [Policy consistence between multiple nodes](#policy-consistence-between-multiple-nodes)\n- [Role manager](#role-manager)\n- [Benchmarks](#benchmarks)\n- [Examples](#examples)\n- [Middlewares](#middlewares)\n- [Our adopters](#our-adopters)\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\nor user log-ins.\n3. **ACL without resources**: some scenarios may target for a type of resources instead\nof an individual resource by using permissions like ``write-article``, ``read-log``. It\ndoesn'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\nget the attribute for a resource.\n8. **[RESTful](https://en.wikipedia.org/wiki/Representational_state_transfer)**: supports\npaths 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 `Bhojpur Policy`, an access control model is abstracted into a CONF file based on the\n**PERM metamodel (Policy, Effect, Request, Matchers)**. So switching or upgrading the\nauthorization mechanism for a project is just as simple as modifying a configuration.\nYou can customize your own access control model by combining the available models. For\nexample, you can get RBAC roles and ABAC attributes together inside one model and share\none set of policy rules.\n\nThe most basic and simplest model in `Bhojpur Policy` 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```ini\np, alice, data1, read\np, bob, data2, write\n```\n\nIt means:\n\n- alice can read data1\n- bob can write data2\n\nWe also support multi-line mode by appending '\\\\'  in the end:\n\n```ini\n# Matchers\n[matchers]\nm = r.sub == p.sub \u0026\u0026 r.obj == p.obj \\\n  \u0026\u0026 r.act == p.act\n```\n\nFurther more, if you are using ABAC,  you can try operator `in` like\nin `Bhojpur Policy` (jPolicy and Node-Policy are not supported yet):\n\n```ini\n# Matchers\n[matchers]\nm = r.obj == p.obj \u0026\u0026 r.act == p.act || r.obj in ('data2', 'data3')\n```\n\nBut you **SHOULD** make sure that the length of the array is **MORE** \n**1**, otherwise there will cause it to panic.\n\nFor more operators, you may take a look at [govaluate](https://github.com/Knetic/govaluate)\n\n## Key Features\n\nWhat `Bhojpur Policy` does:\n\n1. enforce the policy in the classic ``{subject, object, action}`` form or\ncustomized 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 \nanything without explict permissions.\n5. multiple built-in operators to support the rule matching. For example, ``keyMatch``\ncan map a resource key ``/foo/bar`` to the pattern ``/foo*``.\n\nWhat Bhojpur Policy 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\nitself to manage these entities. Users usually have their passwords, and `Bhojpur Policy`\nis not designed as a password container. However, `Bhojpur Policy` stores the user-role\nmapping for the RBAC scenario.\n\n## Installation\n\n```bash\ngo get github.com/bhojpur/policy\n```\n\n## Documentation\n\nhttps://docs.bhojpur.net/en/overview\n\n## Online editor\n\nYou can also use the online editor (https://bhojpur.net/editor/) to write your\n`Bhojpur Policy` model and policy in your web browser. It provides functionality\nsuch as ``syntax highlighting`` and ``code completion``, just like an IDE for \nprogramming language.\n\n## Tutorials\n\nhttps://docs.bhojpur.net/en/tutorials\n\n## Get started\n\n1. New a `Bhojpur Policy` enforcer with a model file and a policy file:\n\n    ```go\n    e, _ := policy.NewEnforcer(\"path/to/model.conf\", \"path/to/policy.csv\")\n    ```\n\nNote: you can also initialize an enforcer with policy in DB instead of file,\nsee [Policy-persistence](#policy-persistence) section for details.\n\n2. Add an enforcement hook into your code right before the access happens:\n\n    ```go\n    sub := \"alice\" // the user that wants to access a resource.\n    obj := \"data1\" // the resource that is going to be accessed.\n    act := \"read\" // the operation that the user performs on the resource.\n\n    if res, _ := e.Enforce(sub, obj, act); res {\n        // permit alice to read data1\n    } else {\n        // deny the request, show an error\n    }\n    ```\n\n3. Besides the static policy file, Bhojpur Policy also provides API for permission\nmanagement at run-time. For example, You can get all the roles assigned to a user\nas below:\n\n    ```go\n    roles, _ := e.GetImplicitRolesForUser(sub)\n    ```\n\nSee [Policy management APIs](#policy-management) for more usage.\n\n## Policy Management\n\nThe Bhojpur Policy provides two sets of APIs to manage permissions:\n\n- [Management API](https://docs.bhojpur.net/en/management-api): the primitive API\nthat provides full support for `Bhojpur Policy` policy management.\n- [RBAC API](https://docs.bhojpur.net/en/rbac-api): a more friendly API for RBAC.\nThis API is a subset of Management API. The RBAC users could use this API to simplify\nthe code.\n\nWe also provide a [web-based UI](https://docs.bhojpur.net/en/admin-portal) for model\nmanagement and policy management:\n\n## Policy persistence\n\nhttps://docs.bhojpur.net/en/adapters\n\n## Policy consistence between multiple nodes\n\nhttps://docs.bhojpur.net/en/watchers\n\n## Role Manager\n\nhttps://docs.bhojpur.net/en/role-managers\n\n## Benchmarks\n\nhttps://docs.bhojpur.net/en/benchmark\n\n## Examples\n\nModel | Model file | Policy file\n----|------|----\nACL | [basic_model.conf](https://github.com/bhojpur/policy/blob/master/examples/basic_model.conf) | [basic_policy.csv](https://github.com/bhojpur/policy/blob/master/examples/basic_policy.csv)\nACL with superuser | [basic_model_with_root.conf](https://github.com/bhojpur/policy/blob/master/examples/basic_with_root_model.conf) | [basic_policy.csv](https://github.com/bhojpur/policy/blob/master/examples/basic_policy.csv)\nACL without users | [basic_model_without_users.conf](https://github.com/bhojpur/policy/blob/master/examples/basic_without_users_model.conf) | [basic_policy_without_users.csv](https://github.com/bhojpur/policy/blob/master/examples/basic_without_users_policy.csv)\nACL without resources | [basic_model_without_resources.conf](https://github.com/bhojpur/policy/blob/master/examples/basic_without_resources_model.conf) | [basic_policy_without_resources.csv](https://github.com/bhojpur/policy/blob/master/examples/basic_without_resources_policy.csv)\nRBAC | [rbac_model.conf](https://github.com/bhojpur/policy/blob/master/examples/rbac_model.conf)  | [rbac_policy.csv](https://github.com/bhojpur/policy/blob/master/examples/rbac_policy.csv)\nRBAC with resource roles | [rbac_model_with_resource_roles.conf](https://github.com/bhojpur/policy/blob/master/examples/rbac_with_resource_roles_model.conf)  | [rbac_policy_with_resource_roles.csv](https://github.com/bhojpur/policy/blob/master/examples/rbac_with_resource_roles_policy.csv)\nRBAC with domains/tenants | [rbac_model_with_domains.conf](https://github.com/bhojpur/policy/blob/master/examples/rbac_with_domains_model.conf)  | [rbac_policy_with_domains.csv](https://github.com/bhojpur/policy/blob/master/examples/rbac_with_domains_policy.csv)\nABAC | [abac_model.conf](https://github.com/bhojpur/policy/blob/master/examples/abac_model.conf)  | N/A\nRESTful | [keymatch_model.conf](https://github.com/bhojpur/policy/blob/master/examples/keymatch_model.conf)  | [keymatch_policy.csv](https://github.com/bhojpur/policy/blob/master/examples/keymatch_policy.csv)\nDeny-override | [rbac_model_with_deny.conf](https://github.com/bhojpur/policy/blob/master/examples/rbac_with_deny_model.conf)  | [rbac_policy_with_deny.csv](https://github.com/bhojpur/policy/blob/master/examples/rbac_with_deny_policy.csv)\nPriority | [priority_model.conf](https://github.com/bhojpur/policy/blob/master/examples/priority_model.conf)  | [priority_policy.csv](https://github.com/bhojpur/policy/blob/master/examples/priority_policy.csv)\n\n## Middlewares\n\nAuthz middlewares for web frameworks: https://docs.bhojpur.net/en/middlewares\n\n## How to Contribute\n\nPlease read the [contributing guide](CONTRIBUTING.md).\n\n## License\n\nThis project is licensed under the [MIT license](LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhojpur%2Fpolicy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbhojpur%2Fpolicy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhojpur%2Fpolicy/lists"}