Skip to content

[feature] Add experimental RBAC model preset (and optional helpers) #1623

@nodece

Description

@nodece

Background

Casbin models are currently defined by users via model.conf, which provides maximum flexibility but also requires users to repeatedly define common authorization patterns.

One of the most common patterns is standard RBAC (role-based access control) using p and g policies.

Proposal

Introduce an opinionated RBAC model preset that provides a reference implementation of standard RBAC.

Example usage:

m := preset.RBAC()
e, _ := casbin.NewEnforcer(m, adapter)

// optional helper
rbac.AssignRole(e, "alice", "admin")
rbac.Grant(e, "admin", "data1", "read")

ok, _ := e.Enforce("alice", "data1", "read")

Optionally, small helper functions may be provided to simplify common RBAC operations, such as assigning roles or granting permissions. These helpers operate on an existing Enforcer and do not introduce new abstractions or enforcement paths.

Design Notes

  • The preset generates a standard Casbin model equivalent to a typical model.conf
  • No new enforcement semantics are introduced
  • Existing APIs and behavior remain unchanged
  • Helpers (if included) are convenience-only and optional

Scope

In scope

  • A single, standard RBAC model preset
  • Optional helper functions for common RBAC operations

Out of scope

  • RBAC variants (e.g. domains)
  • ABAC or other authorization patterns

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions