Understanding RBAC, ABAC, and ACL: A Comparison of the Three Main Access Control Models with Examples
In modern software systems, access control is a core part of security design. A well-designed permission management approach not only makes the system more secure but also simplifies administration and scaling. The three common access control models are:
- RBAC (Role-Based Access Control)
- ABAC (Attribute-Based Access Control)
- ACL (Access Control List)
This article takes an in-depth look at the characteristics of all three and uses sample code and visual diagrams to make them easier to understand.
1. RBAC: Role-Based Access Control
How It Works
The core idea behind RBAC is user → role → permission.
- Users are not bound directly to permissions; they get them by being assigned roles.
- A role contains a set of permissions.
- When a user's responsibilities change, you only need to update their role assignment.
Diagram
Sample Code (Python)
# 定义角色与权限
roles = {
"admin": ["create_user", "delete_user", "view_report"],
"user": ["view_report"],
"guest": []
}
# 用户与角色映射
user_roles = {
"alice": "admin",
"bob": "user",
"charlie": "guest"
}
def has_permission(username, action):
role = user_roles.get(username)
if not role:
return False
return action in roles.get(role, [])
# 测试
print(has_permission("alice", "create_user")) # True
print(has_permission("bob", "delete_user")) # False
print(has_permission("charlie", "view_report")) # False
✅ Pros: Simple, intuitive, and easy to maintain
❌ Cons: The number of roles can explode as they multiply
2. ABAC: Attribute-Based Access Control
How It Works
ABAC doesn't rely solely on user identity or roles; it makes authorization decisions based on a set of attributes.
- User attributes (such as department and level)
- Resource attributes (such as sensitivity)
- Environmental attributes (such as access time)
Policies are the core. For example: "Only a sales manager can view customer data during working hours."
Diagram
Sample Code (Python)
from datetime import datetime
# 用户属性
user_attrs = {
"david": {"department": "sales", "level": "manager"},
"eva": {"department": "sales", "level": "staff"}
}
# 策略函数
def policy(user, resource, env):
attrs = user_attrs.get(user, {})
if resource == "customer_data":
return (
attrs.get("department") == "sales" and
attrs.get("level") == "manager" and
9 <= env["hour"] <= 18
)
return False
# 测试
env = {"hour": datetime.now().hour}
print(policy("david", "customer_data", env)) # True (若在工作时间)
print(policy("eva", "customer_data", env)) # False
✅ Pros: Flexible and expressive; can handle complex business rules
❌ Cons: Complex policies and high performance overhead
3. ACL: Access Control List
How It Works
ACL is resource-centric: each resource has an access control list that specifies who can do what.
Diagram
Sample Code (Python)
✅ Pros: Intuitive and fine-grained
❌ Cons: Difficult to manage; scales poorly when there are many resources and users
4. Comparison Summary
| Model | Focus | Pros | Cons | Typical Use Cases |
|---|---|---|---|---|
| RBAC | User → role → permission | Simple and easy to manage | Not flexible enough; roles can multiply | Internal enterprise systems |
| ABAC | Attributes + policies | Flexible; adapts to complex scenarios | Complex policies; performance pressure | Finance, healthcare, government |
| ACL | Resource-centric | Intuitive and fine-grained | Difficult to manage; poor scalability | File systems, storage services |
5. Recommendations
- Clear role structure → choose RBAC
- Need granular permissions and complex conditions → choose ABAC
- Resource-centric (files/storage) → choose ACL
Conclusion
RBAC, ABAC, and ACL are not mutually exclusive; real-world systems often combine them. For example: RBAC provides basic role management, ABAC provides flexible policies, and ACL handles low-level control in file storage systems. A well-designed hybrid approach can often balance security, flexibility, and maintainability.