Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsMay 21, 2026·3 min de lecture

Casbin — Flexible Policy-Based Access Control Framework

Casbin is an authorization library that supports access control models including ACL, RBAC, and ABAC. It provides a unified API across Go, Java, Node.js, Python, and other languages, letting developers define and enforce fine-grained permissions using a declarative policy language.

Prêt pour agents

Cet actif peut être lu et installé directement par les agents

TokRepo expose une commande CLI universelle, un contrat d'installation, le metadata JSON, un plan selon l'adaptateur et le contenu raw pour aider les agents à juger l'adaptation, le risque et les prochaines actions.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Casbin Overview
Commande CLI universelle
npx tokrepo install e2e074be-54ae-11f1-9bc6-00163e2b0d79

Introduction

Casbin is an open-source authorization library that decouples access control logic from application code. By separating the access model definition from policy rules, it lets teams modify permissions without changing source code, supporting everything from simple ACLs to attribute-based policies.

What Casbin Does

  • Enforces authorization decisions based on configurable access control models
  • Supports ACL, RBAC, ABAC, and custom hybrid models via PERM metamodel
  • Provides adapters for storing policies in databases, files, or external services
  • Offers role hierarchy and multi-tenancy through role managers
  • Ships client libraries for Go, Java, Node.js, Python, .NET, Rust, and PHP

Architecture Overview

Casbin uses a PERM (Policy, Effect, Request, Matchers) metamodel where the model file defines request format, policy structure, matching rules, and effect aggregation. At runtime, the enforcer loads the model and policies, then evaluates each request against the matcher expression to produce an allow or deny decision. Adapters handle persistence, while watchers enable policy synchronization across distributed instances.

Self-Hosting & Configuration

  • Add the Casbin library for your language via its package manager
  • Define a model.conf file specifying request definition, policy definition, matchers, and effect
  • Store policies in CSV files, databases (MySQL, PostgreSQL), or cloud services via adapters
  • Use the Casbin editor at casbin.org/editor to test and validate model configurations
  • Enable policy caching and watcher-based synchronization for multi-node deployments

Key Features

  • Language-agnostic model definition works identically across all supported runtimes
  • Priority-based and deny-override policy effects for complex rule evaluation
  • Built-in RBAC with resource roles and multi-level role inheritance
  • Hundreds of community-maintained adapters for policy storage backends
  • Management API for runtime policy and role modification without restarts

Comparison with Similar Tools

  • OPA (Open Policy Agent) — general-purpose policy engine using Rego; Casbin is lighter and embeds directly in application code
  • Cerbos — cloud-native PDP with YAML policies; Casbin offers more model flexibility with PERM
  • SpiceDB — Zanzibar-inspired relationship-based auth; Casbin handles broader model types beyond relationships
  • Keycloak — full identity provider with RBAC; Casbin focuses purely on authorization logic without authentication

FAQ

Q: Does Casbin handle authentication? A: No, Casbin only handles authorization. It assumes the identity has already been verified by an authentication system.

Q: Can I change policies at runtime? A: Yes, the management API allows adding, removing, and updating policies without restarting the application.

Q: How does performance scale with many policies? A: Casbin uses efficient matching algorithms and supports filtered policy loading, handling millions of rules with sub-millisecond enforcement.

Q: Is there a GUI for managing policies? A: Casdoor (a separate project) provides a web UI for managing Casbin policies and users.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires