talira

Minimal authorization through OO design and pure Ruby classes

open sourceMITself-hostablefree

Pundit handles authorization in Rails with plain Ruby classes: each model gets a policy class whose methods (update?, destroy?) say whether a user may do something, and a scope class that limits which records a user can see. Controllers call authorize and policy_scope, and a check can fail any action that forgot to authorize. Varvet, a product studio in Sweden, maintains it; Jonas Nicklas first released it in 2012, and the README cites over 100 million downloads.

Problems it solves

  • decide who can edit or delete each record in my Rails app
  • only show users the records that belong to their team
  • our permission checks are scattered across controllers and views
  • make sure no controller action forgets to check permissions
  • test authorization rules without hitting controllers
  • hide the delete button from users who aren't allowed to delete
  • simple role-based permissions without a big framework
  • authorization logic in plain Ruby objects instead of a DSL

Features

  • policy classes per model
  • policy scopes
  • authorize and policy_scope helpers
  • verify_authorized and verify_policy_scoped checks
  • generators

Alternatives

The same job

These do what Pundit does.

  1. CanCanCan The authorization Gem for Ruby on Rails
  2. Ory Headless, cloud-native identity: authentication, OAuth2/OIDC and permissions
  3. Apache Casbin An authorization library that supports access control models like ACL, RBAC, ABAC

Compare Pundit with the top 3