{"id":13408685,"url":"https://github.com/mikespook/gorbac","last_synced_at":"2025-05-14T22:09:06.590Z","repository":{"id":12776784,"uuid":"15450288","full_name":"mikespook/gorbac","owner":"mikespook","description":"goRBAC provides a lightweight role-based access control (RBAC) implementation in Golang.","archived":false,"fork":false,"pushed_at":"2024-07-22T08:19:49.000Z","size":101,"stargazers_count":1616,"open_issues_count":4,"forks_count":177,"subscribers_count":67,"default_branch":"master","last_synced_at":"2025-04-10T11:02:51.102Z","etag":null,"topics":["go","rbac"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mikespook.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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}},"created_at":"2013-12-26T10:00:41.000Z","updated_at":"2025-04-09T10:26:59.000Z","dependencies_parsed_at":"2024-01-08T14:30:38.854Z","dependency_job_id":"4f64572c-159c-4dd7-93f0-28dcdbf4b690","html_url":"https://github.com/mikespook/gorbac","commit_stats":{"total_commits":90,"total_committers":8,"mean_commits":11.25,"dds":0.07777777777777772,"last_synced_commit":"17f7b949ba43f1f5360f3b8bfc98591012e46721"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikespook%2Fgorbac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikespook%2Fgorbac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikespook%2Fgorbac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mikespook%2Fgorbac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mikespook","download_url":"https://codeload.github.com/mikespook/gorbac/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254235701,"owners_count":22036964,"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":["go","rbac"],"created_at":"2024-07-30T20:00:54.570Z","updated_at":"2025-05-14T22:09:01.570Z","avatar_url":"https://github.com/mikespook.png","language":"Go","funding_links":[],"categories":["Authentication and OAuth","Misc","Go","Authentication \u0026 OAuth","身份验证和OAuth","Authentication and Authorization","Authorization","Uncategorized","Repositories","认证和OAuth授权","Authorization Development","\u003cspan id=\"身份验证和oauth-authentication-and-auth\"\u003e身份验证和OAuth Authentication and Auth\u003c/span\u003e"],"sub_categories":["Contents","\u003ca name=\"authZ-golang\"\u003e\u003c/a\u003eGolang"],"readme":"goRBAC \n======\n\n[![Build Status](https://travis-ci.org/mikespook/gorbac.png?branch=master)](https://travis-ci.org/mikespook/gorbac)\n[![GoDoc](https://godoc.org/github.com/mikespook/gorbac?status.png)](https://godoc.org/github.com/mikespook/gorbac)\n[![Coverage Status](https://coveralls.io/repos/github/mikespook/gorbac/badge.svg?branch=master)](https://coveralls.io/github/mikespook/gorbac?branch=master)\n\ngoRBAC provides a lightweight role-based access control implementation\nin Golang.\n\nFor the purposes of this package:\n\n\t* an identity has one or more roles.\n\t* a role requests access to a permission.\n\t* a permission is given to a role.\n\nThus, RBAC has the following model:\n\n\t* many to many relationship between identities and roles.\n\t* many to many relationship between roles and permissions.\n\t* roles can have a parent role (inheriting permissions).\n\nVersion\n=======\n\nCurrently, goRBAC has two released versions\n\n[Version 1](https://github.com/mikespook/gorbac/tree/v1.dev) is the original design which will only be mantained to fix bugs.\n\n[Version 2](https://github.com/mikespook/gorbac/tree/v2.dev) is the new design which will only be mantained to fix bugs.\n\nand the developing branch is\n\n[The master branch](https://github.com/mikespook/gorbac) will be under development with generic (go 1.18 and higher) and can be changed without notice.\n\n\nInstall\n=======\n\nInstall the package:\n\n\u003e $ go get github.com/mikespook/gorbac\n\t\nUsage\n=====\n\nAlthough you can adjust the RBAC instance anytime and it's absolutely safe, the library is designed for use with two phases:\n\n1. Preparing\n\n2. Checking\n\nPreparing\n---------\n\nImport the library:\n\n\timport \"github.com/mikespook/gorbac\"\n\nGet a new instance of RBAC:\n\n\trbac := gorbac.New()\n\nGet some new roles:\n\n\trA := gorbac.NewRole(\"role-a\")\n\trB := gorbac.NewRole(\"role-b\")\n\trC := gorbac.NewRole(\"role-c\")\n\trD := gorbac.NewRole(\"role-d\")\n\trE := gorbac.NewRole(\"role-e\")\n\nGet some new permissions:\n\n\tpA := gorbac.NewPermission(\"permission-a\")\n\tpB := gorbac.NewPermission(\"permission-b\")\n\tpC := gorbac.NewPermission(\"permission-c\")\n\tpD := gorbac.NewPermission(\"permission-d\")\n\tpE := gorbac.NewPermission(\"permission-e\")\n\nAdd the permissions to roles:\n\n\trA.Assign(pA)\n\trB.Assign(pB)\n\trC.Assign(pC)\n\trD.Assign(pD)\n\trE.Assign(pE)\n\nAlso, you can implement `gorbac.Role` and `gorbac.Permission` for your own data structure.\n\nAfter initialization, add the roles to the RBAC instance:\n\n\trbac.Add(rA)\n\trbac.Add(rB)\n\trbac.Add(rC)\n\trbac.Add(rD)\n\trbac.Add(rE)\n\nAnd set the inheritance:\n\n\trbac.SetParent(\"role-a\", \"role-b\")\n\trbac.SetParents(\"role-b\", []string{\"role-c\", \"role-d\"})\n\trbac.SetParent(\"role-e\", \"role-d\")\n\nChecking\n--------\n\nChecking the permission is easy:\n\n\tif rbac.IsGranted(\"role-a\", pA, nil) \u0026\u0026\n\t\trbac.IsGranted(\"role-a\", pB, nil) \u0026\u0026\n\t\trbac.IsGranted(\"role-a\", pC, nil) \u0026\u0026\n\t\trbac.IsGranted(\"role-a\", pD, nil) {\n\t\tfmt.Println(\"The role-a has been granted permis-a, b, c and d.\")\n\t}\n\n\nAnd there are some built-in util-functions: \n[InherCircle](https://godoc.org/github.com/mikespook/gorbac#InherCircle),\n[AnyGranted](https://godoc.org/github.com/mikespook/gorbac#AnyGranted), \n[AllGranted](https://godoc.org/github.com/mikespook/gorbac#AllGranted). \nPlease [open an issue](https://github.com/mikespook/gorbac/issues/new) \nfor the new built-in requirement.\n\nE.g.:\n\n\trbac.SetParent(\"role-c\", \"role-a\")\n\tif err := gorbac.InherCircle(rbac); err != nil {\n\t\tfmt.Println(\"A circle inheratance occurred.\")\n\t}\n\nPersistence\n-----------\n\nThe most asked question is how to persist the goRBAC instance. Please check the post [HOW TO PERSIST GORBAC INSTANCE](https://mikespook.com/2017/04/how-to-persist-gorbac-instance/) for the details.\n\n\nAuthors\n=======\n\n * Xing Xing \u003cmikespook@gmail.com\u003e [Blog](http://mikespook.com) \n[@Twitter](http://twitter.com/mikespook)\n\nOpen Source - MIT Software License\n==================================\n\nSee LICENSE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikespook%2Fgorbac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmikespook%2Fgorbac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmikespook%2Fgorbac/lists"}