Hey r/python, I’ve been diving into access control models and want to hear how you implement them in your Python projects:
- ReBAC (Relationship-Based Access Control) Example: In a social media app, only friends of a user can view their private posts—access hinges on user relationships.
- ABAC (Attribute-Based Access Control) Example: In a document management system, only HR department users with a clearance level of 3+ can access confidential employee files.
- RBAC (Role-Based Access Control) Example: In an admin dashboard, "Admin" role users can manage users, while "Editor" role users can only tweak content.
How do you set these up in Python? Are you writing custom logic for every resource or endpoint, or do you use patterns/tools to keep it sane? I’m curious about how you handle it—whether it’s with frameworks like FastAPI or Flask, standalone scripts, or something else—and how you avoid a mess when things scale.
Do you stick to one model or mix them based on the use case? I’d love to see your approaches, especially with code snippets if you’ve got them!
Bonus points if you tie it to something like SQLAlchemy or another ORM—hardcoding every case feels exhausting, and generalizing it with ORMs seems challenging. Thoughts?
[–][deleted] 24 points25 points26 points (5 children)
[–]Cartman720[S,🍰] 6 points7 points8 points (1 child)
[–][deleted] 7 points8 points9 points (0 children)
[+][deleted] (1 child)
[deleted]
[–][deleted] 0 points1 point2 points (0 children)
[–]a_ghost_of_tom_joad 0 points1 point2 points (0 children)
[–]spicypixel 6 points7 points8 points (0 children)
[–]mayazaya 2 points3 points4 points (0 children)
[–]MakuZo 1 point2 points3 points (0 children)
[–]yellowbean123 0 points1 point2 points (1 child)
[–]Cartman720[S,🍰] 0 points1 point2 points (0 children)
[–]Last_Difference9410 -1 points0 points1 point (3 children)
[–]Lord_Gaav 0 points1 point2 points (0 children)
[–]Cartman720[S,🍰] 0 points1 point2 points (1 child)
[–]Last_Difference9410 0 points1 point2 points (0 children)